Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ai.onnxruntime.OrtException: Unsupported type - FLOAT16 #18926

Open
JiangWork opened this issue Dec 25, 2023 · 4 comments
Open

ai.onnxruntime.OrtException: Unsupported type - FLOAT16 #18926

JiangWork opened this issue Dec 25, 2023 · 4 comments
Labels
api:Java issues related to the Java API

Comments

@JiangWork
Copy link

When upgrade onnxruntime version to 1.16.x, if the onnx output type is float16, it will throw following exception:

Caused by: ai.onnxruntime.OrtException: Unsupported type - FLOAT16
	at ai.onnxruntime.TensorInfo.makeCarrier(TensorInfo.java:288)
	at ai.onnxruntime.OnnxTensor.getValue(OnnxTensor.java:86)
image

Seems it misses FLOAT16 case here:
https://github.com/microsoft/onnxruntime/blob/main/java/src/main/java/ai/onnxruntime/TensorInfo.java#L311

Related PR: #16703

@github-actions github-actions bot added the api:Java issues related to the Java API label Dec 25, 2023
@Craigacp
Copy link
Contributor

Craigacp commented Dec 25, 2023

Don't use getValue for FP16, use getShortBuffer then either work with it as shorts or use the Fp16Conversions utilities to convert it to floats.

It's noted in the PR that FP16 is currently unsupported for the methods which use arrays. I guess it could return a short array for the time being but in the future when Java has value types it would hopefully return an fp16 type.

@Craigacp
Copy link
Contributor

Ahh. So if you were already using this then you were happy with it returning float arrays for fp16 values? I'd forgot that that used to work and it got lost in the refactor. I'll put that back in with a test to catch it.

@JiangWork
Copy link
Author

Thanks for replying. When i used old runtime version, it will return float for float16. I will try this new API.

@Craigacp
Copy link
Contributor

Craigacp commented Dec 27, 2023

I've put up a PR to fix the problem - #18937. Note, the behaviour isn't identical to before as the old fp16 conversion code was very bad at handling denormals, infinities and NaNs (in that it returned incorrect fp32 values in those cases). I've added tests which compare the output against the expected result so it should behave correctly now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api:Java issues related to the Java API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants