Skip to content

[rewriter] Skip FusedMatMul batch-transpose fusion on mismatched ranks - #3159

Open
Syed Mudassir (Syedmudassir1604) wants to merge 3 commits into
microsoft:mainfrom
Syedmudassir1604:cursor/fix-fusedmatmul-transbatch-rank-8456
Open

Syed Mudassir (Syedmudassir1604) wants to merge 3 commits into
microsoft:mainfrom
Syedmudassir1604:cursor/fix-fusedmatmul-transbatch-rank-8456

Conversation

@Syedmudassir1604

@Syedmudassir1604 Syed Mudassir (Syedmudassir1604) commented Nov 5, 2026 •

Copy link
Copy Markdown

Fixes #3156

Skip batch-transpose folding when the resulting transBatchA/transBatchB flags require ranks that are unknown, unequal, or below 3. Preserve valid equal-rank fusions, batch-flag cancellation, and scalar Div folding into alpha.

Regression coverage exercises both operands, existing batch flags, unknown/mismatched ranks, and initializer projections through optimize_for_ort. ORT CPU runs with graph optimizations disabled verify the rewritten graphs.

Validation: 32 tests and 200 rank/flag subtests pass; lintrunner -a is clean. Synced with current main.

…microsoft#3156)

ONNX Runtime only honors transBatchA/transBatchB when both inputs have the
same rank of at least 3. Folding a batch Transpose into FusedMatMul from the
permutation alone produced a rank-3 x rank-2 FusedMatMul that failed at runtime.

Co-authored-by: Arjun <arjunanand13@users.noreply.github.com>
Exercise both operands, unknown and mismatched ranks, existing batch flags, and valid batch-transpose cancellation. Verify initializer projections through optimize_for_ort and execute equal-rank fusions with ORT optimizations disabled.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.09091% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.83%. Comparing base (f51083c) to head (23b8be1).

Files with missing lines Patch % Lines
...ewriter/ort_fusions/fused_matmul_rule_sets_test.py 85.88% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3159      +/-   ##
==========================================
+ Coverage   73.77%   73.83%   +0.05%     
==========================================
  Files         270      270              
  Lines       33876    33979     +103     
  Branches     3243     3251       +8     
==========================================
+ Hits        24993    25089      +96     
- Misses       7829     7839      +10     
+ Partials     1054     1051       -3     

☔ 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

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Batch-transpose fusion into FusedMatMul sets transBatchA on inputs of different ranks, which ONNX Runtime can't compute

3 participants