Skip to content

Conversation

@jgibson2
Copy link

@jgibson2 jgibson2 commented Nov 28, 2025

Summary

Support a negative dimension for MPS SplitWithSizes implementation.

Test plan

I re-registered this node visitor on a model that previously failed to export with the error message

RuntimeError: split_copy: dim -1 out of range for input tensor with 2 dimensions

and it succeeded.

Copilot AI review requested due to automatic review settings November 28, 2025 17:37
@jgibson2 jgibson2 requested a review from cccclai as a code owner November 28, 2025 17:37
@pytorch-bot
Copy link

pytorch-bot bot commented Nov 28, 2025

🔗 Helpful Links

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

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

❗ 2 Active SEVs

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

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

@meta-cla
Copy link

meta-cla bot commented Nov 28, 2025

Hi @jgibson2!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Copy link
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 adds support for negative dimension indexing in the aten.split_with_sizes_copy.default operator for the MPS backend. When a negative dimension is provided, it is converted to its positive equivalent by adding the input tensor's rank.


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

if dim < 0:
dim += len(input_shape)

if dim < 0 or dim >= len(input_shape):
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The validation condition on line 249 will always fail for negative dimensions after normalization. If the original dim was less than -len(input_shape), the normalized value will still be negative, but this is the intended behavior to catch out-of-bounds dimensions. However, the current implementation normalizes first, then validates, which means valid negative dimensions are handled correctly but the error condition dim < 0 is now checking the normalized value. The validation should only check dim >= len(input_shape) after normalization, or validate the original dimension range before normalization.

Suggested change
if dim < 0 or dim >= len(input_shape):
if dim >= len(input_shape):

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

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

The negative dimension could be outside the correct range even after normalization (e.g. if there are two dimensions and the input dimension is -3). This should probably still be an error.

@meta-cla
Copy link

meta-cla bot commented Nov 28, 2025

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@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 Nov 28, 2025
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant