Repository navigation
Fix consecutive cast elimination for inexact FLOAT intermediates - #3205
Open
itsrayeedscodespace wants to merge 1 commit into
Open
itsrayeedscodespace wants to merge 1 commit into
itsrayeedscodespace wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
The consecutive-cast rewrite considers the FLOAT -> FLOAT16/BFLOAT16 pair but ignores the source type. For DOUBLE input
1.00048828125 + 2**-30, the original DOUBLE -> FLOAT -> FLOAT16 graph produces 1.0, while the rewritten direct cast produces 1.0009765625 in the ONNX reference evaluator. The intermediate FLOAT rounding lands on a FLOAT16 midpoint.Require the source to be exactly representable in FLOAT before eliminating that intermediate: supported floating-point types of at most 32 bits, integers of at most 16 bits, and BOOL. Preserve the cast chain when the source type is missing or its conversion is not proven exact. This retains the intended FLOAT16/BFLOAT16 mixed-precision rewrites and FP8 paths.
Add 40 regression cases covering the numerical counterexample through both the rule and the public optimizer, unknown/wider source types, safe floating/integer conversions, and every finite encoding of the four common FP8 formats.
Fixes #3204
Validation on macOS arm64, Python 3.12.16:
python -m pytest onnxscript/rewriter/rules/common/_basic_rules_test.py onnxscript/optimizer -q: 179 passed, 1 existing skip.test_fuse_pad_into_conv_6/7. Both failures also reproduce with the original source and original tests (449 passed, the same 2 failures); they are exact-equality convolution comparisons on this local environment.lintrunner -aandgit diff --checkpass.Numerical validation uses the ONNX reference evaluator and an independent NumPy conversion check. The local ONNX Runtime CPU path returned the lower value for both graphs, so it does not independently demonstrate this rounding difference. No GPU validation or GPU performance measurement was performed. The repository's existing CPU CI matrix provides cross-platform validation.
AI assistance was used for source investigation, implementation, and the local validation runs.