Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 14, 2025

This PR adds comprehensive support for the FLOAT8E8M0 data type that was added to ONNX in onnx/onnx#7030.

Changes Made

  • Added FLOAT8E8M0 enum value: Set to 24 (next available value after FLOAT4E2M1=23)
  • Updated numpy type mapping: Added support for ml_dtypes.float8_e8m0fnu
  • Added type properties: Configured as 8-bit floating point, signed type
  • Added short name: "f8e8m0" for compact representation
  • Updated serialization: Added FLOAT8E8M0 to appropriate sets in serde.py for proper tensor serialization/deserialization
  • Added tests: Included parameterized test case and conditional ONNX compatibility check

Testing

The implementation includes comprehensive testing:

import onnx_ir._enums as enums
import ml_dtypes
import numpy as np

# Create tensor with FLOAT8E8M0 type
data = np.array([1.0, 2.0, 3.0], dtype=ml_dtypes.float8_e8m0fnu)
tensor = ir_core.Tensor(data)
assert tensor.dtype == enums.DataType.FLOAT8E8M0

# Test properties
assert enums.DataType.FLOAT8E8M0.is_floating_point() == True
assert enums.DataType.FLOAT8E8M0.bitwidth == 8
assert enums.DataType.FLOAT8E8M0.short_name() == 'f8e8m0'

# Test serialization round-trip
tensor_proto = serde.serialize_tensor(tensor)
assert tensor_proto.data_type == 24

All existing tests continue to pass, ensuring no regression in functionality.

Fixes #127.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Support FLOAT8E8M0 Add support for FLOAT8E8M0 data type Jul 14, 2025
@Copilot Copilot AI requested a review from justinchuby July 14, 2025 19:17
Copilot finished work on behalf of justinchuby July 14, 2025 19:17
Copy link

codecov bot commented Jul 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.84%. Comparing base (d619b1b) to head (78bf606).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #128      +/-   ##
==========================================
+ Coverage   74.80%   74.84%   +0.03%     
==========================================
  Files          39       39              
  Lines        4723     4726       +3     
  Branches      966      967       +1     
==========================================
+ Hits         3533     3537       +4     
+ Misses        840      839       -1     
  Partials      350      350              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@justinchuby
Copy link
Member

Please update serde_test, core_test, tensor_adapters_test, and tensor_adapters as well. You can do a broader search for float8 to see all the places the types are mentioned.

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 14, 2025

Please update serde_test, core_test, tensor_adapters_test, and tensor_adapters as well. You can do a broader search for float8 to see all the places the types are mentioned.

Done! I've added comprehensive FLOAT8E8M0 support to all the requested files:

  • serde_test.py: Added parameterized test with special ONNX compatibility handling
  • _core_test.py: Added to both external tensor and non-native dtype tests
  • tensor_adapters.py: Added PyTorch dtype mappings (both directions)
  • tensor_adapters_test.py: Added test coverage for the new mappings

The implementation properly handles FLOAT8E8M0's unique characteristics (8 exponent bits, 0 mantissa bits) and includes conditional logic for ONNX versions that don't yet support this type.

Commit: 476ea63

Copilot finished work on behalf of justinchuby July 14, 2025 19:35
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
@Copilot Copilot AI requested a review from justinchuby July 14, 2025 19:49
Copilot finished work on behalf of justinchuby July 14, 2025 19:49
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Copilot finished work on behalf of justinchuby July 14, 2025 20:03
@Copilot Copilot AI requested a review from justinchuby July 14, 2025 20:03
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby justinchuby marked this pull request as ready for review July 14, 2025 20:08
@justinchuby justinchuby requested review from titaiwangms and a team as code owners July 14, 2025 20:08
@titaiwangms titaiwangms merged commit 329a798 into main Jul 14, 2025
24 checks passed
@titaiwangms titaiwangms deleted the copilot/fix-127 branch July 14, 2025 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support FLOAT8E8M0
3 participants