Skip to content

[Fix][Relax] Skip vector weights in ReorderTakeAfterMatmul - #20815

Merged
tlopex merged 2 commits into
apache:mainfrom
hiyufan:fix/reorder-take-vector-20595
Nov 15, 2026
Merged

tlopex merged 2 commits into
apache:mainfrom
hiyufan:fix/reorder-take-vector-20595

Conversation

@hiyufan

@hiyufan hiyufan commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

With rank-one weights, take(..., axis=0) selects elements on the MatMul reduction axis. Moving it after MatMul raises on vector activations and changes results on matrix activations, even when the output shape stays the same.

Require weight rank >= 2 in the simple column-selection rewrite. Leave vector weights unchanged. Add two regressions and a positive control showing that vector activations with matrix weights still rewrite.

Fixes #20595.

Validation against main 30fd3017fd, Python 3.11, LLVM 21.1.8 and source-built pinned TIRx/FFI dependencies:

  • test_transform_reorder_take_after_matmul.py, test_transform_expand_matmul_of_sum.py, and test_op_linear_algebra.py: 26 passed.
  • CPU C-backend VM execution against NumPy: 20/20 transformed cases match values, shapes and dtypes. Covers vector/matrix/batched activations, symbolic batch dimensions, and fast/clip/wrap take modes. All 20 original modules also match the reference.
  • File-scoped pre-commit checks passed.

Prepared with OpenAI Codex assistance. The build and validation above were executed locally.

Includes the shared packaging fix in #20980: the pinned TIRx source now carries the final 0.1.0 tag, which the old CMake/Python bounds rejected on macOS and Windows. The pass/operator implementation is unchanged by this CI follow-up. Fresh CI results are pending.

@hiyufan
hiyufan marked this pull request as ready for review October 25, 2026 11:27
@hiyufan
hiyufan force-pushed the fix/reorder-take-vector-20595 branch from 8c25b3a to 2426fe9 Compare November 15, 2026 02:51
@hiyufan

hiyufan commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

@tlopex, would you have time to review this scoped correctness fix? You reviewed the related take-mode fix in #20206. Rank-one weights select along the reduction axis, so the column-selection rewrite must leave them unchanged; a positive control retains the valid vector-activation/matrix-weight rewrite.

I've rebased onto current main and rerun the three related test files (26 passed), plus 20 CPU VM cases against NumPy. Fresh CI results are pending. Thank you.

A vector weight has only a reduction axis. Moving its take after matmul either takes from a scalar or changes the result of a matrix-vector product. Require rank-two or higher weights for the column-selection rewrite, and cover both failures and the supported vector-activation case.
@hiyufan
hiyufan force-pushed the fix/reorder-take-vector-20595 branch from 2426fe9 to 7f43aec Compare November 15, 2026 03:38
@tlopex
tlopex merged commit f0267a0 into apache:main Nov 15, 2026
8 checks passed
@tlopex

tlopex commented Nov 15, 2026

Copy link
Copy Markdown
Member

LGTM. Thanks for the fixing

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Relax] ReorderTakeAfterMatmul fails on vector dot products

2 participants