Skip to content

[Relax] Fix FuseTransposeMatmul crash on rank-1 transpose and reused operand - #20814

Open
yhna940 wants to merge 1 commit into
apache:mainfrom
yhna940:fix/fuse-transpose-matmul-crashes
Open

yhna940 wants to merge 1 commit into
apache:mainfrom
yhna940:fix/fuse-transpose-matmul-crashes

Conversation

@yhna940

@yhna940 yhna940 commented Oct 25, 2026

Copy link
Copy Markdown

Summary

relax.transform.FuseTransposeMatmul raised IndexError on two valid Relax graphs. Invalid NT fusions are now left unchanged, and the existing matrix fusion path is unchanged.

Test plan

  • Rank-1 reproducer raises IndexError: list index out of range before the change and passes after. The rank-2 control still matches numerically.
  • Shared-operand reproducer raises IndexError: Index out of range. size: 1, got index 1 before 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 -xvs
  • ruff check and ruff format --check on the touched Python files.

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant