fix: export fp8e4m3fnuz tensors with the correct onnx type - #4843
Open
rootkiller6788 wants to merge 2 commits into
Open
fix: export fp8e4m3fnuz tensors with the correct onnx type#4843rootkiller6788 wants to merge 2 commits into
rootkiller6788 wants to merge 2 commits into
Conversation
dtype_to_onnx mapped ml_dtypes float8_e4m3fnuz to FLOAT8E4M3FN instead of FLOAT8E4M3FNUZ (copy-paste of the fn entry). A constant with fnuz values would get silently relabeled as fn on export.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A Constant whose values are ml_dtypes.float8_e4m3fnuz was getting exported to ONNX as FLOAT8E4M3FN. The lookup table in dtype_to_onnx mapped fnuz to "FLOAT8E4M3FN" (looks like a copy-paste of the line above it), so the type enum was silently wrong. Anything reading the exported weights later would interpret the fp8e4m3fnuz bytes as fp8e4m3fn, which gives different numbers for most values.
This shows up as soon as you touch the tensor: either create a Constant with fp8e4m3fnuz values, or import an ONNX model that has a FLOAT8E4M3FNUZ initializer and access
.values(which forces LazyValues to load into a numpy fnuz array), then export.Fixed the mapping to FLOAT8E4M3FNUZ and added a regression test that checks the exported data_type and that the raw bytes round-trip. Verified with the onnx-graphsurgeon test suite (tests/test_exporters.py and tests/test_importers.py pass; the remaining failures in test_examples.py are a local no-python3-in-bash environment issue, unrelated).