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

Test using bfloat16 and model input/output #6151

Open
josel-amd opened this issue May 31, 2024 · 1 comment
Open

Test using bfloat16 and model input/output #6151

josel-amd opened this issue May 31, 2024 · 1 comment
Labels

Comments

@josel-amd
Copy link

Bug Report

Is the issue related to model conversion?

No

Describe the bug

Tests that use bfloat16 as model input/ouput (listed in [0]) are disabled in most backends (see e.g. here). On one side, this can be problematic for other backends and, on the other, it becomes unclear what is the level of support for bfloat16.

A quick look at the test runner shows that there is support forTensorProto.BFLOAT16 where the data - in that format - gets converted to float32 through numpy_helper.bfloat16_to_float32. The problem with the test cases mentioned before is that the output_*.pb files seem to be read the reference data as TensorProto.UINT16, which then never triggers the expected conversion to float32.

I'm not sure if converting to float32 is the expected behavior but I'm assuming so, for the purpose of this discussion.

Related issue

[0]

test_castlike_BFLOAT16_to_FLOAT
test_castlike_FLOAT_to_BFLOAT16
test_cast_FLOAT_to_BFLOAT16

System information

  • OS Platform and Distribution (e.g. Linux Ubuntu 20.04): Linux Ubuntu 22.04
  • ONNX version (e.g. 1.13): 1.16.1
  • Python version: 3.10
  • Protobuf version: 5.26.1

Expected behavior

Unsure. By looking at the code, the output for the tests that return bfloat16 should be in np.float32 not in np.uint16 format

@josel-amd josel-amd added the bug label May 31, 2024
@justinchuby
Copy link
Contributor

Thanks. We can enable bfloat16 support with the ml_dtypes package in the reference evaluator.

xadupre added a commit to xadupre/onnx that referenced this issue Jun 21, 2024
…ntation (onnx#6166)

### Description
Supports bfloat16 binary, unary operations if ml_dtypes is installed.
Partially answer onnx#6151.

### Motivation and Context
numpy does not support bfloat16 natively but pytorch or tensorflow does.
The reference implementation should support that as well.

---------

Signed-off-by: Xavier Dupre <xadupre@microsoft.com>
Signed-off-by: Xavier Dupré <xadupre@users.noreply.github.com>
Co-authored-by: Justin Chu <justinchuby@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants