KEMBAR78
handle unbacked index in meta_select by laithsakka · Pull Request #156906 · pytorch/pytorch · GitHub
Skip to content

Conversation

@laithsakka
Copy link
Contributor

@laithsakka laithsakka commented Jun 26, 2025

@pytorch-bot
Copy link

pytorch-bot bot commented Jun 26, 2025

🔗 Helpful Links

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

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

❌ 13 New Failures, 1 Unrelated Failure

As of commit d8a0615 with merge base d98fa4a (image):

NEW FAILURES - The following jobs have failed:

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

laithsakka added a commit that referenced this pull request Jun 26, 2025
ghstack-source-id: b95c875
Pull Request resolved: #156906
@laithsakka laithsakka requested a review from pianpwk June 26, 2025 00:40
@laithsakka laithsakka added the topic: not user facing topic category label Jun 26, 2025
torch._check(
index >= 0,
lambda: "unbacked index assumed >=0, if that's not correct consider adding a torch._check on index {index}",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this along with slicing, is one of the unsafe cases for compile?

Copy link
Contributor Author

@laithsakka laithsakka Jun 26, 2025

Choose a reason for hiding this comment

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

why would you say its unsafe?do you mean that users can hit this error by unsafe?
I think we are free to define unbacked semantics, and as long as in the error message
we specify how the user can control the behaviour of this by adding torch.check, then we are good.

for example here index is either >=0 or <0 currently we do not support a choice that allow for both in compile
(while we could potentially with your idea of allocating a new unbacked symbol) but at least for now.
we assume positive by default if it end up wrong users can go back and decide on the neg by adding a torch check.

they anyway would have had to do that in the case of DDE.

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess, users can have a model that sometimes indexes positively, sometimes negatively, turn on torch.compile + capture_scalar_outputs, and now they hit Runtime assertion: u0 >= 0 when they do the negative index?

Copy link
Contributor Author

@laithsakka laithsakka Jun 26, 2025

Choose a reason for hiding this comment

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

yes but they will get
Runtime assertion: u0 >= 0 "unbacked index assumed >=0, if that's not correct consider adding a torch._check on index u0"

note that before this they would hit a DDE, the model wont compile anyway.
do you say that we rather throw DDE than have this unbacked semantics?

Copy link
Contributor

Choose a reason for hiding this comment

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

Before this, they could still graph break and their program could run both positive & negative indexing with capture_scalar_outputs = True.

Now with the assert, they're restricted to just one of those options?

Copy link
Contributor Author

@laithsakka laithsakka Jun 26, 2025

Choose a reason for hiding this comment

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

regarding graphs break i think the moment users flipped capture_scalar_outputs, they opted into unbacked semantics if they prefer to graph break they probably should keep capture_scalar_outputs turned off.

that said i agree its worth to look into how hard is it to allocate a new unbacked symbol to resolve this before landing this, if its not too hard its better indeed. i will look into that.

@laithsakka laithsakka marked this pull request as draft June 26, 2025 17:01
@laithsakka laithsakka changed the title handle unbacked indexn in meta_select handle unbacked index in meta_select Jun 26, 2025
@laithsakka
Copy link
Contributor Author

closing in favor of #157605

@laithsakka laithsakka closed this Jul 4, 2025
@github-actions github-actions bot deleted the gh/laithsakka/230/head branch August 3, 2025 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants