Fix GemmTransposeFusion handling of identity Transpose - #32428
Closed
Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 4 commits into
Closed
Fix GemmTransposeFusion handling of identity Transpose#32428Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 4 commits into
Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 4 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Copilot started reviewing on behalf of
Sylvester Kaczmarek (sylvesterkaczmarek)
September 3, 2026 18:34
View session
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The newly guarded input-B and output-Transpose paths need regression coverage.
Pull request overview
Fixes incorrect GemmTransposeFusion handling of identity transposes.
Changes:
- Restricts fusion to matrix transposes using
[1, 0]or the rank-2 default permutation. - Adds input-A regression coverage.
File summaries
| File | Review |
|---|---|
onnxruntime/test/optimizer/gemm_transpose_fusion_test.cc |
Tests input-A permutations; add identity-permutation coverage for input B and output Transpose paths. |
onnxruntime/core/optimizer/gemm_transpose_fusion.cc |
Validates permutations across all Gemm paths; add identity and [1, 0] tests for input B and output Transpose behavior. |
Review details
Suppressed comments (3)
onnxruntime/core/optimizer/gemm_transpose_fusion.cc:63
- The regression tests only place the Transpose on input A, so the newly guarded input-B path is not exercised. A future omission or regression of this
IsMatrixTransposecheck would still pass both new tests; add corresponding identity and[1, 0]cases with the Transpose feeding Gemm input 1 and asserttransB.
if (B_node_ptr != nullptr && B_node_ptr->OpType() == "Transpose" && IsMatrixTranspose(*B_node_ptr)) {
onnxruntime/core/optimizer/gemm_transpose_fusion.cc:84
- The output-Transpose permutation check is also new behavior, but the added tests cover only an input Transpose. Add output-side identity and
[1, 0]cases so this path verifies that identity remains and a real matrix transpose still fuses with the expected swapped inputs/flags.
output_node_ptr->OpType() == "Transpose" &&
IsMatrixTranspose(*output_node_ptr)) {
onnxruntime/test/optimizer/gemm_transpose_fusion_test.cc:72
- These regressions exercise the new permutation check only for input A. The same predicate now gates input B and the output-Transpose rewrite, but neither path verifies that
perm={0, 1}is preserved; a future omission or branch-specific regression there would still pass. Please add identity-permutation cases for B and the output path (the existing graph-transform tests cover their successful matrix-transpose fusion).
TEST(GemmTransposeFusionTest, IdentityInputTransposeIsNotFolded) {
RunInputTransposeTest({0, 1}, {2, 3}, false, 0);
}
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Member
|
duplicate of #32429 |
Contributor
Author
|
Closing as a duplicate of #32429. |
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.
Description
Fixes #32228.
GemmTransposeFusioncurrently treats anyTransposeadjacent toGemmas a matrix transpose and togglestransAortransBwithout checking thepermattribute. For an identity transpose (perm=[0,1]), removing the node and toggling the Gemm flag changes the computation and can silently produce incorrect results.This change only folds Transpose nodes that actually swap the two Gemm matrix axes (
[1,0], including the rank-2 default permutation). The check is applied to input A, input B, and output Transpose paths.Tests
Adds regression coverage showing that
perm=[0,1]is left intact withtransAunchanged, whileperm=[1,0]continues to fuse.