Repository navigation
Fix ORT GQA mask contracts and FusedMatMul division boundaries - #3134
Open
G. Ramalingam (gramalingam) wants to merge 4 commits into
Open
G. Ramalingam (gramalingam) wants to merge 4 commits into
G. Ramalingam (gramalingam) wants to merge 4 commits into
Conversation
Reject failed or unsupported sliding-window mask matches while explicitly recognizing supported pure causal exporter forms. Validate FusedMatMul divisor dtypes and finite normal alpha scaling before rewriting. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Reject causal masks with unproven query or cache lengths. Preserve known-zero no-cache Gemma masks after constant folding, and require singleton divisors not to expand MatMul output rank. Add provenance, broadcasting, vector-dot, and unknown-rank regression coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3134 +/- ##
==========================================
+ Coverage 73.24% 74.03% +0.78%
==========================================
Files 267 270 +3
Lines 33158 34130 +972
Branches 3176 3285 +109
==========================================
+ Hits 24288 25269 +981
- Misses 7801 7812 +11
+ Partials 1069 1049 -20 ☔ View full report in Codecov by Harness. |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the attention-mask and FusedMatMul fusion guard changes.
No open issues 🎉
What changed in this PR
This PR strengthens ONNX Runtime-specific rewrite guards to preserve attention-mask semantics and prevent unsafe FusedMatMul division fusions.
Changes:
- Validate GQA mask matches and sequence lengths while retaining supported causal-mask forms and rejecting unsupported sliding windows.
- Share FusedMatMul division checks for compatible dtypes, safe scaling, and output-rank preservation.
- Add regression coverage and document conservative fusion boundaries.
| File | Description |
|---|---|
onnxscript/rewriter/ort_fusions/gqa.py |
Validates causal-mask structure, window bindings, and query/cache lengths. |
onnxscript/rewriter/ort_fusions/gqa_test.py |
Covers supported masks, rejected variants, diagnostics, and numerical equivalence. |
onnxscript/rewriter/ort_fusions/fused_matmul_rule_sets.py |
Centralizes divisor, scaling, dtype, and output-rank validation. |
onnxscript/rewriter/ort_fusions/fused_matmul_rule_sets_test.py |
Tests division boundaries, rank preservation, and supported rewrites. |
docs/api/rewriter.md |
Documents supported fusion contracts and conservative rejection behavior. |
Review effort: Balanced
G. Ramalingam (gramalingam)
marked this pull request as ready for review
November 2, 2026 20:35
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Justin Chu (justinchuby)
approved these changes
Nov 3, 2026
CI's ORT CPU kernels lack double-precision FusedMatMul support. Preserve numerical coverage with the existing reference evaluator and retain ORT execution for float32. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Justin Chu (justinchuby)
approved these changes
Nov 11, 2026
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.
Summary
window_size; reject unsupported sliding-window and structurally different masks with useful diagnostics instead of discarding their semantics.alphascaling. Conservatively decline signed zero, nonfinite divisors/alpha, overflow, underflow, subnormal scales, and double scales not exactly representable by the float32 attribute.ac47c2d2e6210131c174afddf0ca508592311c0c.Validation
python -m pytest onnxscript\rewriter\ort_fusions\gqa_test.py onnxscript\rewriter\ort_fusions\gqa_extended_test.py onnxscript\rewriter\ort_fusions\gqa_packed_qkv_test.py onnxscript\rewriter\ort_fusions\gqa_packed_qkv_extended_test.py onnxscript\rewriter\ort_fusions\fused_matmul_rule_sets_test.py -q— 48 passed, 1 existing memory-related skip; independently rerun by reviewer.lintrunner -arun before each commit; reports unrelated baseline TID251/RUF036 warnings in examples/framework/generated-opset files. No unrelated files changed.lintrunner -a -m 0c3ae10481d53cbba2e19979e41a53b92704e34b— passes with no lint issues, using repository-pinned Ruff 0.15.8.git diff --checkpasses.This change is independent of #3133 and does not implement other rewriter-readiness workstreams.