Skip to content

[Relax] Normalize negative concat axis in ReorderPermuteDimsAfterConcat#19588

Merged
tlopex merged 5 commits into
apache:mainfrom
cchung100m:issue-19575
May 24, 2026
Merged

[Relax] Normalize negative concat axis in ReorderPermuteDimsAfterConcat#19588
tlopex merged 5 commits into
apache:mainfrom
cchung100m:issue-19575

Conversation

@cchung100m
Copy link
Copy Markdown
Contributor

Hi Committers,

This PR fixes #19575.

Root Cause

ReorderPermuteDimsAfterConcat reads concat axis and uses it as an index into the permutation axes.

When concat(axis=-1) is used, the negative axis was converted directly to size_t before indexing, which can produce an out-of-range index and crash (e.g. IndexError: Index -1 out of bounds 4).

Solution

In src/relax/transform/reorder_permute_dims_after_concat.cc:

  1. Read concat axis as signed integer first.
  2. Normalize negative axis with axis += ndim.
  3. Add explicit range checks after normalization.
  4. Use the normalized axis for permutation-axis remapping

This keeps behavior unchanged for non-negative axes and only fixes negative-axis handling.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the reorder_permute_dims_after_concat.cc file to implement axis normalization and bounds checking for concatenation operations. A critical issue was identified where the new implementation was added alongside the old one, resulting in variable redefinitions and a compilation error.

Comment thread src/relax/transform/reorder_permute_dims_after_concat.cc
@cchung100m cchung100m changed the title [Relax] Normalize negative concat axis in ReorderPermuteDimsAfterConcat [Relax] Normalize negative concat axis in ReorderPermuteDimsAfterConcat May 19, 2026
@cchung100m cchung100m marked this pull request as ready for review May 20, 2026 02:16
Copy link
Copy Markdown
Member

@tlopex tlopex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks for the fix!

@tlopex tlopex merged commit ded35dd into apache:main May 24, 2026
11 checks passed
@cchung100m cchung100m deleted the issue-19575 branch May 24, 2026 03:54
@cchung100m
Copy link
Copy Markdown
Contributor Author

Thanks to @tlopex 😄

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] ReorderPermuteDimsAfterConcat crashes with negative concat axis

2 participants