Skip to content

fix: export fp8e4m3fnuz tensors with the correct onnx type - #4843

Open
rootkiller6788 wants to merge 2 commits into
NVIDIA:mainfrom
rootkiller6788:fix-fnuz-dtype-export
Open

fix: export fp8e4m3fnuz tensors with the correct onnx type#4843
rootkiller6788 wants to merge 2 commits into
NVIDIA:mainfrom
rootkiller6788:fix-fnuz-dtype-export

Conversation

@rootkiller6788

Copy link
Copy Markdown

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).

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.
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

Successfully merging this pull request may close these issues.

1 participant