Arm backend: Add dim mapping helpers#20222
Open
AdrianLundell wants to merge 1 commit into
Open
Conversation
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
🔗 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 PendingAs of commit 538ce0a with merge base 7d365ec ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Contributor
There was a problem hiding this comment.
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
ViewMapto map reduction/permutation dims acrossview(via grouped prime-factor tracking, with limited SymInt support). - Add
PermuteMapto map dims acrosspermute. - 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. |
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.
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