Repository navigation
Preserve arg-reduction axes during reshape fusion - #5413
Open
royzhang-amd wants to merge 1 commit into
Open
royzhang-amd wants to merge 1 commit into
royzhang-amd wants to merge 1 commit into
Conversation
royzhang-amd
force-pushed
the
fix-arg-reduction-reshape-axes-squashed
branch
from
October 20, 2026 09:10
25253aa to
b86d9a1
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Committed regressions still need to cover successful per-operation remapping and destination-side rejection.
2 open issues
What changed in this PR
Preserves ArgMin/ArgMax index semantics during MIGraphX reshape fusion, avoiding invalid split-axis rewrites.
Changes:
- Checks source and destination support before modifying the graph.
- Remaps supported arg-reduction axes individually while preserving attributes.
- Updates expected graphs and adds split-axis/squeeze regression coverage.
| File | Description |
|---|---|
test/verify/test_arg_reduce_split_axis_squeeze.cpp |
Adds GPU/reference cases for ties and index-selection modes. |
test/fuse_reduce.cpp |
Updates expected graphs and adds squeeze regressions. |
src/include/migraphx/rewrite_reshapes.hpp |
Checks support before rewriting either operation. |
src/fuse_reduce.cpp |
Rejects unsupported axis mappings and remaps each arg reduction. |
Review effort: Balanced
pfultz2
reviewed
Oct 20, 2026
royzhang-amd
force-pushed
the
fix-arg-reduction-reshape-axes-squashed
branch
2 times, most recently
from
October 21, 2026 07:07
09a89d1 to
b7f7365
Compare
pfultz2
reviewed
Oct 23, 2026
Restrict ArgMin and ArgMax reshape rewrites to one aggregate reduction axis that maps to one common axis. Skip multi-axis and split-axis rewrites while retaining axes.front() and index-selection attributes. Cover split-axis squeeze failures, supported transposes, multi-axis bypass, and first/last index selection with structural and numerical regressions.
royzhang-amd
force-pushed
the
fix-arg-reduction-reshape-axes-squashed
branch
from
October 26, 2026 05:11
b7f7365 to
56d01e9
Compare
pfultz2
approved these changes
Oct 26, 2026
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.

Motivation
Graphs with an ArgMax reduction followed by a squeeze can fail during reshape fusion with
SQUEEZE: axis dimension should be equal to 1. For example, ArgMax operations can reduce axis 1 of inputs shaped{1, 2304, 1}and{1, 2304, 17}, followed by a squeeze of the reduced axis.Reshape fusion can split the reduction dimension into common dimensions such as
48 x 48. ArgMin and ArgMax return indices into the original axis, so reducing only one component changes the index semantics and can leave a non-singleton dimension for the downstream squeeze. Using the first combined reduction axis is unambiguous only when the fused reduction has one axis and that axis remains whole after remapping.This change limits arg-reduction reshape fusion to one aggregate reduction axis that maps to exactly one common axis. Multi-axis or split-axis cases skip the rewrite.
Technical Details
reduce_reshape::supports: for a fused module containing ArgMin or ArgMax, requireaxes.size() == 1and exactly one common axis in its mapping. This permits supported transpose remapping and skips multi-axis or split-axis rewrites before graph mutation.Use the existing source and destination support checks in
rewrite_reshapesbefore inserting instructions or replacing the graph. The rebase incorporates the newer upstream reshape-fusion implementation.Keep the existing
axes.front()remapping inreduce_reshape::insert. The preflight guard guarantees one mapped reduction axis; the remaining attributes, includingselect_last_index, are preserved.test/fuse_reduce.cpp: compare complete expected programs for split-axis/squeeze rejection, supported source and destination transposes, and destination split rejection. ArgMin and ArgMax regressions also assert that a multi-axis fused module followed by a nontrivial transpose stays unchanged. Check preservation ofselect_last_index=true.test/verify/test_arg_reduce_split_axis_squeeze.cpp: verify ArgMin and ArgMax, first/last index selection, and tied/varied runtime inputs against the reference target. Usemake_opfor construction. Bound runtime addends with int8 inputs converted to int64, retaining exact integer output checks while avoiding precision loss in the CPU floating fallback and overflow in verification arithmetic.Scope: the restriction applies to fused modules containing arg reductions. Multi-axis and split-axis cases skip reshape fusion without throwing; the original graph remains available for compilation.
Validation on a Windows Radeon 880M (
gfx1150) board:Initial validation before this rebase reproduced the original compilation failure and the regression failure with the pre-fix production code.
Before this rebase, the fixed FP32 model passed all seven deterministic input cases against ONNX Runtime CPU with both default and serial scheduling. CPU fallback was disabled; profiles showed only MIGraphX execution. Output shape and type checks and exact repeated-output checks passed. Maximum absolute error was
5.14e-6, withinatol=1e-4, rtol=1e-3for every output element. These checks use synthetic inputs, not a labeled pose-accuracy dataset.The original fix passed 208 targeted tests: 60
test_fuse_reduce, 52test_fuse_pointwise, and 96test_shape_transform_descriptorcases.Initial cleanup validation: all 11 selected
arg*unit cases and all 16 new GPU/reference verification cases passed against the validated fixed runtime.Before this rebase, additional small ONNX models covered source/destination axis splits, supported remapping, transpose, and singleton dimensions. All 24 IR checks and 48 numerical comparisons passed. Last-index cases used direct MIGraphX GPU/reference verification because the installed ONNX Runtime MIGraphX EP rejects
select_last_index=1during capability checks; the pre-fix runtime has the same restriction.Previous revision
09a89d1e0passed 219 targeted unit tests (71test_fuse_reduce, 52test_fuse_pointwise, 96test_shape_transform_descriptor).On revision
09a89d1e0, all eight verification variants matched exactly when replaying CPU unsupported-type lowering on the reference target; the original unbounded inputs reproduced eight mismatches in the same check. That verification graph is unchanged by the single-axis restriction. This replay does not replace a full CPU backend run.Current single-axis-only revision: all 72
test_fuse_reducecases passed. Mutation checks confirmed failures when the aggregate single-axis condition is removed, split axes are accepted, or every arg-reduction rewrite is rejected. Restoring the candidate passed all 72 cases again.Formatting with CI's pinned clang-format 22.1.5 and
git diff --checkpassed. Full CPU/GPU CI and static analysis for the updated commit remain pending.Changelog Category
Add a
CHANGELOG.mdentry for any option other thanNot ApplicableFollow the LLVM AI Tool Use Policy for contributions using AI.