Add CPU Cast op support for Float8E8M0
Merged
TI
6mo ago+510+510+012345678901234567890123456789-40-40-01234567890123456789
Description
This PR adds Float8E8M0 support to the CPU Cast operator, implementing follow-up items 3 (Cast op support) and 4 (rounding mode) from PR #28381.
Changes
Float8E8M0 RoundMode (include/onnxruntime/core/common/float8.h)
- Added
RoundModeenum (Up,Down,Nearest) toFloat8E8M0struct - Extended the constructor with an optional
round_modeparameter (default:Up) Up/Nearest: ties round away from zero (higher power of 2)Down: ties round towards zero (lower power of 2)- Backward-compatible — existing callers use the default
Upmode
CPU Cast op (onnxruntime/core/providers/cpu/tensor/cast_op.cc)
- Added
Float8E8M0to the Cast kernel's enabled type list (AllIRv10WithInt2) - Added
FLOAT8E8M0to thesaturateattribute validation - Added
round_modeattribute parsing ("up","down","nearest") per the ONNX opset 25 Cast schema - Added
CastToE8M0Dispatchertemplate that handles casting from any source type (float, double, int, MLFloat16, BFloat16, Int4, Int2, string, other Float8 types) to Float8E8M0 with propersaturateandround_modesupport - E8M0 destination dispatch is handled separately from the other Float8 types to thread
round_modethrough
Tests (onnxruntime/test/providers/cpu/tensor/cast_op_test.cc)
- 10 new tests:
FloatToFloat8E8M0_Saturate/_NoSaturate— basic float→E8M0 with saturate on/offFloatToFloat8E8M0_RoundModeUp/_RoundModeDown/_RoundModeNearest— all three rounding modesFloat8E8M0ToFloat/Float8E8M0ToDouble— E8M0→float/double conversionMLFloat16ToFloat8E8M0/DoubleToFloat8E8M0/Int32ToFloat8E8M0— various source types
Motivation and Context
PR #28381 added the Float8E8M0 data type to ORT but deferred Cast op support. This PR completes the Cast op integration so that models can use Cast(to=FLOAT8E8M0) with proper saturate and round_mode semantics as defined in the ONNX opset 25 spec.
Testing
All 10 new Cast op tests pass. All 19 existing Float8E8M0 unit tests and all 4 existing Float8 Cast tests continue to pass.
./onnxruntime_provider_test --gtest_filter="CastOpTest.*Float8E8M0*"
./onnxruntime_test_all --gtest_filter="Float8E8M0_Tests.*"
./onnxruntime_provider_test --gtest_filter="CastOpTest.ToFloat8*"