Skip to content

[FIX][Relax] Restore logical layout before flattening repeat in ConvertLayout - #20863

Open
pujitha24 wants to merge 1 commit into
apache:mainfrom
pujitha24:auto/issue-20826
Open

pujitha24 wants to merge 1 commit into
apache:mainfrom
pujitha24:auto/issue-20826

Conversation

@pujitha24

Copy link
Copy Markdown

Motivation:
For relax.repeat with axis=None, InferLayoutRepeat kept the producer's
layout on the input. After ConvertLayout turned a conv2d into NHWC, the
repeat flattened the NHWC tensor, so the flattened element order differed
from the original NCHW module (reported max abs diff 16.1 on LLVM and CUDA).

Approach:
When axis is not given, request the initial (logical) layout for the input
so a permute_dims back to the original layout is inserted before the
flattening repeat. The axis-specified path is unchanged.

Impact:
Only the axis=None form of repeat is affected; it now produces the same
flattened order as before layout conversion, at the cost of one extra
permute_dims.

Validation (macOS arm64, built from source without LLVM/CUDA):

  • Before the fix, test_conv2d_repeat_flatten passed against the buggy IR
    (no permute before repeat). After the fix that expectation fails and the
    updated expectation (permute_dims NHWC->NCHW, then repeat) passes.
  • python -m pytest tests/python/relax/test_transform_convert_layout.py
    -> 75 passed.
  • pre-commit run on the changed files: passes (clang-format reflowed one line).
    Not run: numeric before/after execution of the issue reproducer (no LLVM or
    CUDA available here); correctness rests on the IR now matching the logical
    NCHW order before the flatten.

Report: #20826
Signed-off-by: Pujitha Paladugu 10557236+pujitha24@users.noreply.github.com
Assisted-by: claude-sonnet-5-5 (via Claude Code)

Fixes #20826

…rtLayout

Motivation:
For relax.repeat with axis=None, InferLayoutRepeat kept the producer's
layout on the input. After ConvertLayout turned a conv2d into NHWC, the
repeat flattened the NHWC tensor, so the flattened element order differed
from the original NCHW module (reported max abs diff 16.1 on LLVM and CUDA).

Approach:
When axis is not given, request the initial (logical) layout for the input
so a permute_dims back to the original layout is inserted before the
flattening repeat. The axis-specified path is unchanged.

Impact:
Only the axis=None form of repeat is affected; it now produces the same
flattened order as before layout conversion, at the cost of one extra
permute_dims.

Validation (macOS arm64, built from source without LLVM/CUDA):
- Before the fix, test_conv2d_repeat_flatten passed against the buggy IR
  (no permute before repeat). After the fix that expectation fails and the
  updated expectation (permute_dims NHWC->NCHW, then repeat) passes.
- python -m pytest tests/python/relax/test_transform_convert_layout.py
  -> 75 passed.
- pre-commit run on the changed files: passes (clang-format reflowed one line).
Not run: numeric before/after execution of the issue reproducer (no LLVM or
CUDA available here); correctness rests on the IR now matching the logical
NCHW order before the flatten.

Report: apache#20826
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
Assisted-by: claude-sonnet-5-5 (via Claude Code)

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

Development

Successfully merging this pull request may close these issues.

[Bug] [Relax] ConvertLayout changes the flattened order of conv2d + repeat(axis=None)

1 participant