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

[Error] Load fp16 #287

Open
phamkhactu opened this issue Apr 26, 2024 · 2 comments
Open

[Error] Load fp16 #287

phamkhactu opened this issue Apr 26, 2024 · 2 comments

Comments

@phamkhactu
Copy link

I successfully converted my model to fp16:

import onnx
from onnxconverter_common import float16

model = onnx.load("tts_quantized.onnx")
model_fp16 = float16.convert_float_to_float16(model)
onnx.save(model_fp16, "tts_quantized_fp16.onnx")

But when I load fp16 model, I get error:

    self._create_inference_session(providers, provider_options, disabled_optimizers)
  File "/home/tupk/anaconda3/envs/dl/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 397, in _create_inference_session
    sess = C.InferenceSession(session_options, self._model_path, True, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from tts_quantized_fp16.onnx failed:Type Error: Type (tensor(float16)) of output arg (/RandomNormalLike_output_0) of node (/RandomNormalLike) does not match expected type (tensor(float)).

Here is my fp16 model.

@xadupre
Copy link
Member

xadupre commented May 20, 2024

The implementation in onnxruntime does not support float16 (https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/providers/cpu/generator/random.cc#L39) but it does on CUDA. The best here is probably to surround RandomNormalLike with Cast operators. float16 is still not part of C++ standard so the most simple implementation C++ would probably do the same. You should be able to do that by adding this node to the blocklist (parameter op_block_list).

@phamkhactu
Copy link
Author

phamkhactu commented May 21, 2024

Thanks for your reply

I'm a newbie in this field.I had tried, but i still get error. I'm happy if you can give me some code example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants