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

Properly Support BFloat16 #2337

Open
AndrewJBean opened this issue Jun 6, 2024 · 1 comment
Open

Properly Support BFloat16 #2337

AndrewJBean opened this issue Jun 6, 2024 · 1 comment
Labels
bug An unexpected problem or unintended behavior

Comments

@AndrewJBean
Copy link

Describe the bug
Currently TF BFloat16 data type maps to Float16:

https://github.com/onnx/tensorflow-onnx/blob/main/tf2onnx/tf_utils.py#L31

and this is seen in onnx graphs generated by tf2onnx, where e.g. cast to bfloat16 and cast to float16 both result in elem_type: 10, which is float16, as seen here:

https://github.com/onnx/onnx/blob/main/onnx/onnx.proto#L515

however, onnx does have BFloat16, as seen here:

https://github.com/onnx/onnx/blob/main/onnx/onnx.proto#L526

I consider this a bug, rather than a feature request, because these are not interchangeable types.

Urgency

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 18.04*):
  • TensorFlow Version:
  • Python version:
  • ONNX version (if applicable, e.g. 1.11*):
  • ONNXRuntime version (if applicable, e.g. 1.11*):

To Reproduce

Screenshots

Additional context

@AndrewJBean AndrewJBean added the bug An unexpected problem or unintended behavior label Jun 6, 2024
@AndrewJBean
Copy link
Author

The following workaround seems to work for my limited purposes:

  tf2onnx.tf_utils.TF_TO_ONNX_DTYPE[types_pb2.DT_BFLOAT16] = onnx_pb.TensorProto.BFLOAT16
  fn_onnx, _ = tf2onnx.convert.from_function(
    fn,
    input_signature=input_signature,
    extra_opset=extra_opset,
  )

Unclear whether this has unforeseen consequences, though, for more complicated graph conversions than my own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

1 participant