Skip to content

Guard mixed-precision skip RMS normalization fusion - #3163

Open
Justin Chu (justinchuby) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-fuse-skip-rms-normalization
Open

Justin Chu (justinchuby) with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-fuse-skip-rms-normalization

Conversation

Copilot AI commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Skip RMS fusion can combine float16 residual inputs with a float32 scale, producing a graph ONNX Runtime rejects.

  • Preserve safe fusion: Narrow constant float32 scales only when they round-trip exactly through float16 and the norm output exclusively feeds a cast back to float16. Replace that cast with the fused output.
  • Reject unsafe fusion: Require matching input, skip, and optional bias dtypes; skip incompatible scales or output consumers.
  • Regression coverage: Cover exact and inexact scales, dynamic scales, shared outputs, bias variants, and Gemma-style optimization.

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix float16 residual fusion with float32 scale in norm Guard mixed-precision skip RMS normalization fusion Nov 5, 2026
@justinchuby
Justin Chu (justinchuby) requested a balanced review from Copilot November 5, 2026 21:23
@justinchuby
Justin Chu (justinchuby) marked this pull request as ready for review November 5, 2026 21:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The fusion can silently replace an overridable graph-input scale with a fixed constant, ignoring runtime values, and abort when external scale data is unavailable.

2 open issues
What changed in this PR

This PR addresses #3155 by guarding skip RMS normalization fusion against mixed dtypes that ONNX Runtime rejects, while preserving fusion for eligible float32 scales.

Changes:

  • Require matching input, skip, and optional bias dtypes.
  • Narrow exactly representable constant scales to float16 when normalization exclusively feeds a cast back to float16.
  • Add regression coverage for safe and unsafe scales, shared outputs, bias variants, and Gemma-style optimization.
File Description
onnxscript/​rewriter/​ort_fusions/​skip_normalization.py Adds dtype guards and cast-back fusion rules with scale narrowing.
onnxscript/​rewriter/​ort_fusions/​skip_normalization_unit_test.py Tests mixed-precision fusion eligibility and numerical equivalence.

Review effort: Balanced

Comment on lines +84 to +85
if gamma.const_value is None:
return check_result.fail("Scale narrowing requires a constant scale.", gamma)
)
if gamma.const_value is None:
return check_result.fail("Scale narrowing requires a constant scale.", gamma)
scale = gamma.const_value.numpy()
@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.32710% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.42%. Comparing base (5b210da) to head (9164e8d).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...writer/ort_fusions/skip_normalization_unit_test.py 93.97% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3163      +/-   ##
==========================================
+ Coverage   73.34%   73.42%   +0.07%     
==========================================
  Files         269      269              
  Lines       33564    33668     +104     
  Branches     3210     3226      +16     
==========================================
+ Hits        24618    24720     +102     
- Misses       7876     7879       +3     
+ Partials     1070     1069       -1     

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

fuse_skip_rms_normalization fuses a float16 residual into a norm whose scale is float32, which ONNX Runtime rejects

3 participants