Skip to content

Conversation

@laithsakka
Copy link
Contributor

@laithsakka laithsakka commented Nov 6, 2025

Stack from ghstack (oldest at bottom):

cc @ezyang @EikanWang @jgong5 @wenzhe-nrv

@pytorch-bot
Copy link

pytorch-bot bot commented Nov 6, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit 5559787 with merge base d144382 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot bot added ciflow/inductor release notes: fx release notes category labels Nov 6, 2025
laithsakka added a commit that referenced this pull request Nov 6, 2025
ghstack-source-id: c43d51e
Pull Request resolved: #167232
We probably need something similar for expand


cc ezyang EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
laithsakka added a commit that referenced this pull request Nov 6, 2025
ghstack-source-id: 65ef5e4
Pull Request resolved: #167232
Comment on lines 430 to 433
if a == 1 and b != 1:
torch._check(shape[idx] == 1)
if b == 1 and a != 1:
torch._check(common_shape[idx] == 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just throwing a possible scenario at this

Suppose you have this simple model with backed_sized_oblivious:

def forward(user, items):
  broadcasted = user.expand_as(items)
  ...

Now, take these three cases. If we trace with one of the 3 cases, will the compiled model still work on all 3 cases at runtime?

# case 1
 user: [1, 1024]
items: [32, 1024]

# case 2
 user: [32, 1024]
items: [1, 1024]

# case 3
 user: [32, 1024]
items: [32, 1024]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would say NO
those require three different compilations unless we were able to make this works.
#165108
at least on the export layer, but idk if i trust inductor

Copy link
Contributor

Choose a reason for hiding this comment

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

okay from our offline discussion:

it's possible to get through export, but inductor will face this same scenario and it must know whether to broadcast or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

I want to clarify a meta-point here. The semantics change from unbacked IS INTENTIONAL. If I have a program x + y where x: f32[u0] and y: f32[4], the idea behind unbacked is that the only valid runtime value for u0 here is u0 = 4. In eager, u0 = 1 would lead to broadcasting and would not raise an error, but this is kind of an insane thing to do and we would rather just immediately error at compile time (and force the user to do something like torch.cond to indicate that they either want to broadcast or not.)

Comment on lines 427 to 428
a = size_hint(shape[idx], allow_none=True)
b = size_hint(common_shape[idx], allow_none=True)
Copy link
Contributor

@ColinPeppler ColinPeppler Nov 6, 2025

Choose a reason for hiding this comment

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

nit: pull this down underneath the backed_so block

with comment too

We probably need something similar for expand


cc ezyang EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
laithsakka added a commit that referenced this pull request Nov 6, 2025
ghstack-source-id: 2ac4c97
Pull Request resolved: #167232
We probably need something similar for expand


cc ezyang EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
laithsakka added a commit that referenced this pull request Nov 6, 2025
ghstack-source-id: ac34712
Pull Request resolved: #167232
We probably need something similar for expand


cc ezyang EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
laithsakka added a commit that referenced this pull request Nov 6, 2025
ghstack-source-id: 1ed1b50
Pull Request resolved: #167232
@laithsakka
Copy link
Contributor Author

@ColinPeppler address all comments

self.assertEqual(cnt.frame_count, 2)

instantiate_parametrized_tests(TestUnbacked)
instantiate_parametrized_tests(TestUnbacked)
Copy link
Contributor

Choose a reason for hiding this comment

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

dunno if it belongs at file scope, otherwise indent could throw things off

@laithsakka
Copy link
Contributor Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 11, 2025
We probably need something similar for expand


cc ezyang EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
laithsakka added a commit that referenced this pull request Nov 11, 2025
ghstack-source-id: 278652a
Pull Request resolved: #167232
@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 1 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

We probably need something similar for expand


cc ezyang EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
laithsakka added a commit that referenced this pull request Nov 12, 2025
ghstack-source-id: 992b88a
Pull Request resolved: #167232
@laithsakka
Copy link
Contributor Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

aneeshgupta42 added a commit to aneeshgupta42/pytorch that referenced this pull request Nov 12, 2025
Summary:
Support semantics when using backed_size_oblivious, similar to pytorch#167232

Earlier saw errors like 
```
RuntimeError: non-broadcasting semantics require s67 == 41

While executing %expand : [num_users=1] = call_method[target=expand](args = (%reshape_5, -1, -1, %getitem_9), kwargs = {})
```

Test Plan:
test_dynamic_shapes: 
```
test_backed_size_oblivious_expand (test_dynamic_shapes.TestUbackedOps) ... I1112 14:07:54.724596 1386932 Logger.cpp:995] Dropping logs in unit tests.
ok
```

Differential Revision: D86902546
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request fx Merged release notes: fx release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants