Skip to content

Arm backend: Add dim mapping helpers#20222

Open
AdrianLundell wants to merge 1 commit into
pytorch:mainfrom
AdrianLundell:change-1271418
Open

Arm backend: Add dim mapping helpers#20222
AdrianLundell wants to merge 1 commit into
pytorch:mainfrom
AdrianLundell:change-1271418

Conversation

@AdrianLundell

@AdrianLundell AdrianLundell commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Dim args such as sum(dim=1) needs to be transformed when swapping place with operators which change
shape, i.e. permutes and views.

ViewMap and PermuteMap handles and validates these transforms for reduction dims and permute dims.

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

Dim args such as sum(dim=1) needs to be transformed
when swapping place with operators which change
shape, i.e. permutes and views.

ViewMap and PermuteMap handles and validates these
transforms for reduction dims and permute dims.

Signed-off-by: Adrian Lundell <adrian.lundell@arm.com>
Change-Id: I634f4494df37294d4ac3397f8457bedfd20f5830
Copilot AI review requested due to automatic review settings June 11, 2026 17:09
@AdrianLundell AdrianLundell added partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: none Do not include this in the release notes labels Jun 11, 2026
@pytorch-bot

pytorch-bot Bot commented Jun 11, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 4 New Failures, 22 Pending

As of commit 538ce0a with merge base 7d365ec (image):

NEW FAILURES - The following jobs have failed:

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

@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 Jun 11, 2026
@github-actions github-actions Bot added ciflow/trunk module: arm Issues related to arm backend labels Jun 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 introduces dimension-mapping helpers for the Arm backend to transform reduction/permutation dimension arguments correctly when commuting shape-changing ops (notably view and permute). It also adds a dedicated test suite covering mapping behavior, including symbolic dims.

Changes:

  • Add ViewMap to map reduction/permutation dims across view (via grouped prime-factor tracking, with limited SymInt support).
  • Add PermuteMap to map dims across permute.
  • Add extensive unit tests (including randomized/bruteforce checks and SymInt cases) for the new mapping helpers.

Reviewed changes

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

File Description
backends/arm/_passes/dim_maps.py Implements ViewMap/PermuteMap utilities for mapping dims across view/permute.
backends/arm/test/passes/test_dim_maps.py Adds tests validating mapping behavior vs. identities and bruteforce enumeration, including SymInt coverage.

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

Comment on lines +518 to +526
# Compute orderd prime factorizations of input and output shapes
source_factors = _factor_shape(source_shape)
target_factors = _factor_shape(target_shape)
assert (
source_factors is not None
and (target_factors is not None)
and Counter(factor.key for factor in source_factors)
== Counter(factor.key for factor in target_factors)
), "Invalid view shapes"
Comment on lines +528 to +532
# Compute prime factor permutation between input and output shapes
factor_count = len(source_factors)
permutation = cls._find_permutation(source_factors, target_factors)
assert permutation is not None, "Invalid view shapes"

Comment on lines +624 to +630
def __init__(self, permute_node: Node) -> None:
permute_dims = permute_node.args[1]
assert isinstance(permute_dims, Sequence) and not isinstance(
permute_dims, (str, bytes)
)
self.permute_dims = list(cast(Sequence[int], permute_dims))

Comment on lines +199 to +200
SymInts are partialy supported by factorizing them as single primes as the true
value is not known, causing potentially fewer valid mappings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: arm Issues related to arm backend partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants