Repository navigation
Conversation
…operand FuseTransposeMatmul crashed on two valid Relax graphs. Rank-1 permute_dims is an identity and has no second-to-last axis, but the pattern check swapped axes[-1] and axes[-2]. Skip ranks below 2. matmul(t, t) and matmul(w, permute_dims(w)) reuse one value, so FuseOpsByPattern emits a one-argument composite. Lowering that composite as NT matmul either indexes a missing argument or drops the left-hand transpose. Leave those graphs unchanged. Fixes apache#20656 Fixes apache#20809 Co-authored-by: YH <yhna940@users.noreply.github.com>
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
relax.transform.FuseTransposeMatmulraisedIndexErroron two valid Relax graphs. Invalid NT fusions are now left unchanged, and the existing matrix fusion path is unchanged.permute_dimsis an identity and has no second-to-last axis. The pattern check swappedaxes[-1]andaxes[-2]. Fixes [Bug][Relax] FuseTransposeMatmul indexes a nonexistent axis for a vector weight #20656.matmul(t, t)andmatmul(w, permute_dims(w))reuse one value, soFuseOpsByPatternbuilds a one-argument composite. The lowering then indexedcall.args[1]. Treating that composite as an NT matmul would also drop the left-hand transpose or alias both kernel inputs. Fixes [Bug] Relax FuseTransposeMatmul raises IndexError when MatMul reuses a transposed operand #20809.Test plan
IndexError: list index out of rangebefore the change and passes after. The rank-2 control still matches numerically.IndexError: Index out of range. size: 1, got index 1before the change. After the change,matmul(t, t)on[[1, 2], [3, 4]]still returns[[7, 15], [10, 22]].python -m pytest tests/python/relax/test_transform_fuse_transpose_matmul.py -xvsruff checkandruff format --checkon the touched Python files.