8000 introduce definitely_contiguous and use it for reshape and tensor meta data computation. by laithsakka · Pull Request #153432 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@laithsakka
Copy link
Contributor
@laithsakka laithsakka commented May 12, 2025

Stack from ghstack (oldest at bottom):

when a tensor has unbacked symbols it can be general enough to represent both contiguous and non contiguous tensors.
in that case we cant really evaluate is_contiguous. In many places in the code base, we check for is_contiguous to take a fast path. but the general path usually works for both contiguous and not contiguous in that case we probably want
to use definitely _contiguous API.

This is appleid for reshape in this PR and also to tensor meta data computation, the meta data now will have an attribute that says that its contiguous when its always contiguous. We would store that only if definitely _contiguous is true now.

cc @ezyang @SherlockNoMad @EikanWang @jgong5 @wenzhe-nrv @voznesenskym @penguinwu @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @jiayisunx @ipiszy @chenyang78 @kadeng @muchulee8 @amjames @chauhang @aakhundov

[ghstack-poisoned]
@pytorch-bot
Copy link
8000
pytorch-bot bot commented May 12, 2025

🔗 Helpful Links

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

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

✅ You can merge normally! (3 Unrelated Failures)

As of commit f11560c with merge base b8452e5 (image):

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@pytorch-bot pytorch-bot bot added the release notes: fx release notes category label May 12, 2025
@laithsakka laithsakka changed the title known _contig introduce is_known _contiguous and use it for reshape and tensor meta data computation. May 12, 2025
…tensor meta data computation. "


when a tensor has unbacked symbols it can be general enough to represent both contiguous and non contiguous tensors. 
in that case we cant really evaluate is_contiguous. In many places in the code base, we check for is_contiguous to take a fast path. but the general path usually works for both contiguous and not contiguous in that case we probably want 
to use is_known _contiguous API. 

This is appleid for reshape in this PR and also to  tensor meta data computation, the meta data now will have an attribute that says that its contiguous when its always contiguous. We would store that only if is_known _contiguous  now. 


cc ezyang SherlockNoMad EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
…tensor meta data computation. "


when a tensor has unbacked symbols it can be general enough to represent both contiguous and non contiguous tensors. 
in that case we cant really evaluate is_contiguous. In many places in the code base, we check for is_contiguous to take a fast path. but the general path usually works for both contiguous and not contiguous in that case we probably want 
to use is_known _contiguous API. 

This is appleid for reshape in this PR and also to  tensor meta data computation, the meta data now will have an attribute that says that its contiguous when its always contiguous. We would store that only if is_known _contiguous  now. 


cc ezyang SherlockNoMad EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
…tensor meta data computation. "


when a tensor has unbacked symbols it can be general enough to represent both contiguous and non contiguous tensors. 
in that case we cant really evaluate is_contiguous. In many places in the code base, we check for is_contiguous to take a fast path. but the general path usually works for both contiguous and not contiguous in that case we probably want 
to use is_known _contiguous API. 

This is appleid for reshape in this PR and also to  tensor meta data computation, the meta data now will have an attribute that says that its contiguous when its always contiguous. We would store that only if is_known _contiguous  now. 


cc ezyang SherlockNoMad EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
@laithsakka laithsakka requested review from ColinPeppler and removed request for aorenste May 13, 2025 00:14
…tensor meta data computation. "


when a tensor has unbacked symbols it can be general enough to represent both contiguous and non contiguous tensors. 
in that case we cant really evaluate is_contiguous. In many places in the code base, we check for is_contiguous to take a fast path. but the general path usually works for both contiguous and not contiguous in that case we probably want 
to use is_known _contiguous API. 

This is appleid for reshape in this PR and also to  tensor meta data computation, the meta data now will have an attribute that says that its contiguous when its always contiguous. We would store that only if is_known _contiguous  now. 


cc ezyang SherlockNoMad EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
…tensor meta data computation. "


when a tensor has unbacked symbols it can be general enough to represent both contiguous and non contiguous tensors. 
in that case we cant really evaluate is_contiguous. In many places in the code base, we check for is_contiguous to take a fast path. but the general path usually works for both contiguous and not contiguous in that case we probably want 
to use is_known _contiguous API. 

This is appleid for reshape in this PR and also to  tensor meta data computation, the meta data now will have an attribute that says that its contiguous when its always contiguous. We would store that only if is_known _contiguous  now. 


cc ezyang SherlockNoMad EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
laithsakka added a commit that referenced this pull request May 13, 2025
ghstack-source-id: 6d453a8
Pull Request resolved: #153432
@albanD albanD removed their request for review May 13, 2025 20:47
…tensor meta data computation. "


when a tensor has unbacked symbols it can be general enough to represent both contiguous and non contiguous tensors. 
in that case we cant really evaluate is_contiguous. In many places in the code base, we check for is_contiguous to take a fast path. but the general path usually works for both contiguous and not contiguous in that case we probably want 
to use is_known _contiguous API. 

This is appleid for reshape in this PR and also to  tensor meta data computation, the meta data now will have an attribute that says that its contiguous when its always contiguous. We would store that only if is_known _contiguous  now. 


cc ezyang SherlockNoMad EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
@malfet
Copy link
Contributor
malfet comme 8000 nted May 27, 2025

@pytorchbot revert -m "Looks like it broke flex attention tests, see https://hud.pytorch.org/hud/pytorch/pytorch/main/1?per_page=50&name_filter=g6.4xlarge&mergeEphemeralLF=true" -c nosignal

@pytorchmergebot
Copy link
Collaborator

@pytorchbot successfully started a revert job. Check the current status here.
Questions? Feedback? Please reach out to the PyTorch DevX Team

@pytorchmergebot
Copy link
Collaborator

@laithsakka your PR has been successfully reverted.

pytorchmergebot added a commit that referenced this pull request May 27, 2025
@pytorchmergebot pytorchmergebot added Reverted ci-no-td Do not run TD on this PR labels May 27, 2025
… tensor meta data computation. "


when a tensor has unbacked symbols it can be general enough to represent both contiguous and non contiguous tensors. 
in that case we cant really evaluate is_contiguous. In many places in the code base, we check for is_contiguous to take a fast path. but the general path usually works for both contiguous and not contiguous in that case we probably want 
to use definitely _contiguous API. 

This is appleid for reshape in this PR and also to  tensor meta data computation, the meta data now will have an attribute that says that its contiguous when its always contiguous. We would store that only if definitely _contiguous is true  now. 


cc ezyang SherlockNoMad EikanWang jgong5 wenzhe-nrv

[ghstack-poisoned]
… tensor meta data computation. "


when a tensor has unbacked symbols it can be general enough to represent both contiguous and non contiguous tensors. 
in that case we cant really evaluate is_contiguous. In many places in the code base, we check for is_contiguous to take a fast path. but the general path usually works for both contiguous and not contiguous in that case we probably want 
to use definitely _contiguous API. 

This is appleid for reshape in this PR and also to  tensor meta data computation, the meta data now will have an attribute that says that its contiguous when its always contiguous. We would store that only if definitely _contiguous is true  now. 


cc ezyang SherlockNoMad EikanWang jgong5 wenzhe-nrv voznesenskym penguinwu Guobing-Chen XiaobingSuper zhuhaozhe blzheng jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
… tensor meta data computation. "


when a tensor has unbacked symbols it can be general enough to represent both contiguous and non contiguous tensors. 
in that case we cant really evaluate is_contiguous. In many places in the code base, we check for is_contiguous to take a fast path. but the general path usually works for both contiguous and not contiguous in that case we probably want 
to use definitely _contiguous API. 

This is appleid for reshape in this PR and also to  tensor meta data computation, the meta data now will have an attribute that says that its contiguous when its always contiguous. We would store that only if definitely _contiguous is true  now. 


cc ezyang SherlockNoMad EikanWang jgong5 wenzhe-nrv voznesenskym penguinwu Guobing-Chen XiaobingSuper zhuhaozhe blzheng jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
@laithsakka
Copy link
Contributor Author

rebase and fix inductor out of bounds bug


if a.is_contiguous():
if definitely_contiguous(a):
return a.as_strided(shape, utils.make_contiguous_strides_for(shape))
Copy link
Contributor
@pianpwk pianpwk May 27, 2025

Choose a reason for hiding this comment

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

also apply this to

if a.is_contiguous():
? maybe that's planned for another PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in the next PR we should avoid hitting that completely thats why i did not mark it https://github.com/pytorch/pytorch/pulls/laithsakka

… tensor meta data computation. "


when a tensor has unbacked symbols it can be general enough to represent both contiguous and non contiguous tensors. 
in that case we cant really evaluate is_contiguous. In many places in the code base, we check for is_contiguous to take a fast path. but the general path usually works for both contiguous and not contiguous in that case we probably want 
to use definitely _contiguous API. 

This is appleid for reshape in this PR and also to  tensor meta data computation, the meta data now will have an attribute that says that its contiguous when its always contiguous. We would store that only if definitely _contiguous is true  now. 


cc ezyang SherlockNoMad EikanWang jgong5 wenzhe-nrv voznesenskym penguinwu Guobing-Chen XiaobingSuper zhuhaozhe blzheng jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov

[ghstack-poisoned]
laithsakka added a commit that referenced this pull request May 27, 2025
ghstack-source-id: 754c787
Pull Request resolved: #153432
@pytorchmergebot
Copy link
Collaborator

Starting merge as part of PR stack under #153441

pytorchmergebot pushed a commit that referenced this pull request May 28, 2025
…153441)

*
This verifies that the check short circuit is not material. #153431
```
import torch
from torch.export import Dim, export
class MyModel(torch.nn.Module):
    def forward(self, x, ranks):
        first_k = ranks.max().item()
        torch._check_is_size(first_k)
        narrow = x.narrow(dim = 1, start = 0, length = first_k)
        lt = narrow < narrow.size(1)
        return lt
inps = (
    torch.randn((8, 16), device="cuda"),
    torch.arange(8, device="cuda", dtype=torch.int8)
)
spec = {
    "x": (Dim.AUTO, Dim.AUTO),
    "ranks": (Dim.AUTO,),
}
traced = export(MyModel(), inps, dynamic_shapes=spec, strict=True).run_decompositions({})

```

Pull Request resolved: #153441
Approved by: https://github.com/jansel
ghstack dependencies: #153432
@jbschlosser
Copy link
Contributor

@laithsakka this change:

expected_stride = expected_stride * sym_max(x, 1)

breaks the is_contiguous() prim for NJT because NJTs contain nested ints in their shape, and sym_max() is not supported for nested ints. I'm a little surprised this wasn't caught by NJT compile tests?

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

Labels

ci-no-td Do not run TD on this PR ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request fx Merged module: dynamo module: inductor release notes: fx release notes category Reverted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

0