Skip to content

Conversation

@GregoryComer
Copy link
Member

Summary

Fix handling of negative dims in permute ops on XNNPACK. They currently fail to lower. This bug was surfaced by the backend operator test suite.

Test plan

I've added a test to cover negative dims in permute.

@pytorch-bot
Copy link

pytorch-bot bot commented Sep 10, 2025

🔗 Helpful Links

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

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

⏳ No Failures, 21 Pending

As of commit 26d60f2 with merge base 8a0a25b (image):
💚 Looks good so far! There are no failures yet. 💚

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 Sep 10, 2025
@mergennachin mergennachin added this to the 1.0.0 milestone Sep 11, 2025
@GregoryComer GregoryComer added the release notes: none Do not include this in the release notes label Sep 11, 2025
@GregoryComer GregoryComer merged commit 3124a6b into pytorch:main Sep 11, 2025
116 of 128 checks passed

# Handle negative dimensions by converting them to positive indices
permute_order = [
(dim + input_rank) if dim < 0 else dim for dim in permute_order
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible that dim + input_rank is still negative?

Copy link
Member Author

@GregoryComer GregoryComer Sep 11, 2025

Choose a reason for hiding this comment

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

Good question. I just tried in eager mode, and it seems to enforce that dims are in the range of [-rank, rank-1] inclusive.

>>> temp = torch.randn(1,2,3,4,5)
>>> temp.permute(-9, 2, 3, 4, 0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: Dimension out of range (expected to be in range of [-5, 4], but got -9)

StrycekSimon pushed a commit to nxp-upstream/executorch that referenced this pull request Sep 23, 2025
### Summary
Fix handling of negative dims in permute ops on XNNPACK. They currently
fail to lower. This bug was surfaced by the backend operator test suite.

### Test plan
I've added a test to cover negative dims in permute.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: none Do not include this in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants