[FIX][RELAX] fix fusion of transpose + matmul when constant weight #17761
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.
Applying the FuseTransposeMatmul pass on a matmul with a constant weight would fail since the bind_constants defaults to true in the FuseOpsByPattern pass . This would lead the constant to be moved in to the fused function instead of being an input param, however on line 168 in /tvm/relax/transform/fuse_transpose_matmul.py
, called later in the FuseTransposeMatmul pass, both input and weight are expected to be inputs to the fused function leading to a crash.
I fixed it by explicitly setting bind_constants to false and I added a unit test to verify correct behavior when the weight is a constant.