Skip to content

Arm backend: Fix rejection criteria of TRANSPOSE from VIEW#19044

Open
gggekov wants to merge 1 commit intopytorch:mainfrom
gggekov:relax_view_transpose_limits_u55
Open

Arm backend: Fix rejection criteria of TRANSPOSE from VIEW#19044
gggekov wants to merge 1 commit intopytorch:mainfrom
gggekov:relax_view_transpose_limits_u55

Conversation

@gggekov
Copy link
Copy Markdown
Collaborator

@gggekov gggekov commented Apr 22, 2026

When delegating a VIEW for Ethos-U55, we were overly pessimistic whether we can delegate the TRANSPOSE that is needed for the NHWC -> NCHW or NCHW -> NHWC permutation. As a result, some RESHAPEs were left-over to the CPU when actually they could have been run on NPU.

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell

When delegating a VIEW for Ethos-U55, we were overly pessimistic
whether we can delegate the TRANSPOSE that is needed for the
NHWC -> NCHW or NCHW -> NHWC permutation. As a result, some
RESHAPEs were left-over to the CPU when actually they could have
been run on NPU.

Signed-off-by: George Gekov <george.gekov@arm.com>
Change-Id: I34cc3b38cf0dbb0ceee32ac5d0044805c4e1f085
Copilot AI review requested due to automatic review settings April 22, 2026 10:12
@gggekov gggekov requested a review from digantdesai as a code owner April 22, 2026 10:12
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 22, 2026
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 22, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19044

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (3 Unrelated Failures)

As of commit 415811f with merge base 63217d2 (image):

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@gggekov gggekov added partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm and removed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Apr 22, 2026
@github-actions github-actions Bot added ciflow/trunk module: arm Issues related to arm backend labels Apr 22, 2026
@gggekov gggekov removed the module: arm Issues related to arm backend label Apr 22, 2026
@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Arm Ethos-U55 VIEW support checks to be less pessimistic about whether required layout transposes can be delegated, aiming to reduce CPU fallbacks (e.g., leftover reshapes) when NHWC↔NCHW permutations are needed.

Changes:

  • Add new VIEW test cases intended to exercise delegation scenarios that require NHWC↔NCHW transposes.
  • Update Ethos-U55 VIEW transpose feasibility checks from “full axis product” to a more targeted axis-product constraint.
  • Tighten the U55 VIEW INT test to assert that aten_view_copy is not left in EXIR after lowering/partitioning.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
backends/arm/test/ops/test_view.py Adds/adjusts VIEW test vectors and strengthens the U55 INT test expectations.
backends/arm/operator_support/ethos_u55_support.py Refines U55 VIEW transpose eligibility checks using a new axis-product helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

rank_product_too_large = {
"rand_4d_large": lambda: (torch.rand(1, 49, 16, 128), (1, 16, 49, 128)),
"rand_5d_large": lambda: (torch.rand(2, 25, 16, 8, 64), (2, 16, 25, 8, 64)),
"rand_5d_large": lambda: (torch.rand(2, 256, 512, 8, 64), (2, 512, 256, 8, 64)),
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

rand_5d_large allocates a very large tensor (2×256×512×8×64 ≈ 134M elements ≈ 512MB in fp32), which is likely to cause OOMs or very slow CI runs. Consider using a much smaller shape that still violates the U55 transpose axis-product constraint (e.g. choose a rank-5 shape where at least one (rank-2) axis-product exceeds 65536 but total elements stay small).

Suggested change
"rand_5d_large": lambda: (torch.rand(2, 256, 512, 8, 64), (2, 512, 256, 8, 64)),
"rand_5d_large": lambda: (torch.rand(1, 257, 256, 1, 2), (1, 256, 257, 1, 2)),

Copilot uses AI. Check for mistakes.
"rand_5d_3d": lambda: (torch.rand(1, 1, 4, 5, 6), (2, 3, -1)),
"rand_3d_5d": lambda: (torch.rand(4, 5, 6), (1, 1, 2, -1, 3)),
"rank4_rank3_large": lambda: (torch.rand(1, 256, 6, 48), (6, 48, 256)),
"rank5_rank_4_large": lambda: (torch.rand(1, 256, 2, 3, 48), (1, 256, 6, 48)),
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

Test case key rank5_rank_4_large is inconsistent with the surrounding naming (rank4_rank3_large) and looks like a typo (rank_4). Consider renaming to something like rank5_rank4_large/rank5_to_rank4_large to keep the test matrix easy to read and search.

Suggested change
"rank5_rank_4_large": lambda: (torch.rand(1, 256, 2, 3, 48), (1, 256, 6, 48)),
"rank5_rank4_large": lambda: (torch.rand(1, 256, 2, 3, 48), (1, 256, 6, 48)),

Copilot uses AI. Check for mistakes.
Comment on lines +285 to 289
def _max_product_axis(self, shape: shape_t):
"""Return shape padded to rank4.
Args:
shape (shape_t): Shape.

Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

_max_product_axis’s docstring is misleading/inaccurate: it says it “Return[s] shape padded to rank4” but the function actually returns a boolean, and it doesn’t pad the shape. Consider renaming the helper to reflect that it validates axis-product constraints (and add a -> bool return type), and update the docstring to describe the boolean semantics and the rule being enforced.

Copilot uses AI. Check for mistakes.
Comment on lines +471 to 476
# For TRANSPOSE originating from a VIEW, we know we will only do
# NHWC -> NCHW or NCHW -> NHWC permutations, hence we only need to validate
# these two TRANSPOSEs. For the general case of any permutation on TRANSPOSE,
# we reason via the checks in EthosU55TransposeCheck
if needs_input_transpose and not (self._max_product_axis(input_shape)):
self.reporter.report_reject(
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

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

The new _max_product_axis constraint for view-inserted transposes (checking all (rank-2)-axis products) is stricter than the existing U55 permute constraints encoded in EthosU55TransposeCheck for NHWC<->NCHW-like permutations (which only bounds N*H, W, and C). This divergence can lead to inconsistent accept/reject decisions between a VIEW-induced transpose and an explicit permute_copy. Consider reusing/factoring the transpose constraint logic so both paths enforce the same rule set for the relevant permutation(s).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants