Repository navigation
[Rewriter] Match omitted Transpose perm and support commutative Add in matmul_add_to_gemm - #3211
Open
Hardik K (hardikkaurani) wants to merge 10 commits into
Conversation
…l_add_to_gemm Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…dToGemm Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…dToGemm Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…ddToGemm Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…tributes safely Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…o_gemm Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…se perm in Gemm fusion Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Contributor
Author
|
Hi Ti-Tai Wang (@titaiwangms), I've opened this PR to improve the
All local tests pass (25 dedicated unit tests and all 396 common rewriter rules). Whenever you have time, I'd appreciate your review and feedback. Thank you! |
…l equivalence in Gemm fusion Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Hardik K (hardikkaurani)
force-pushed
the
fix/matmul-add-to-gemm-perm-and-commutative
branch
from
November 14, 2026 22:48
d0dec51 to
9bebc29
Compare
…l_add_to_gemm Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
…acting dimensions in Gemm fusion Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
Contributor
Author
|
Hi Ti-Tai Wang (@titaiwangms), I've pushed updates addressing the Copilot review feedback:
All 27 dedicated tests in |
Ti-Tai Wang (titaiwangms)
approved these changes
Nov 16, 2026
Contributor
Author
|
Thanks for the review and approval, Ti-Tai Wang (@titaiwangms)! All tests and checks are passing cleanly. Ready to be merged whenever convenient. |
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.

Description
This PR improves the
matmul_add_to_gemmrewrite rules by supporting omitted defaultpermattributes in inputTransposenodes, validatingpermattributes safely, and matching commutativeAddoperand orders.Problem
Omitted Default Transpose Perm: ONNX allows the
permattribute onTransposeto be omitted. For rank-2 tensors, the default permutation is[1, 0]. Previously, the rewrite rules explicitly requiredperm=[1, 0], rejecting valid models where the attribute was omitted.Missing Perm Validation: Function reference attributes were not checked, and explicitly provided permutations were not consistently validated in
check().Commutative Add: Existing rules only matched
Add(MatMul(...), C), missing equivalent expressions in the orderAdd(C, MatMul(...)).Solution
perm=[1, 0]requirements fromTransAMatMulAddToGemm,TransBMatMulAddToGemm, andTransABMatMulAddToGemm._is_valid_2d_transposeto accept omittedpermattributes, reject function reference attributes, and validate explicit permutations against[1, 0].Add(C, MatMul(...))across the standard and transposed variants.permattributes, invalid permutations, function reference attributes, commutative operand ordering, and numerical equivalence.