Skip to content

[Bugfix] Match eager stride semantics for cloned tensors with preserve_format in compile#163017

Closed
Lucaskabela wants to merge 6 commits intomainfrom
issue-161010-dynamo-stride-clone
Closed

[Bugfix] Match eager stride semantics for cloned tensors with preserve_format in compile#163017
Lucaskabela wants to merge 6 commits intomainfrom
issue-161010-dynamo-stride-clone

Conversation

@Lucaskabela
Copy link
Contributor

@Lucaskabela Lucaskabela commented Sep 15, 2025

Fixes #161010 by making clone_meta match the semantics of strides for eager mode.

This is:

  • Case 1: Tensor is_non_overlapping_and_dense; in this case, stride should match input tensor stride
  • Case 2: Otherwise, stride should be contiguous computed from input tensor using compute_elementwise_output_strides

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames

@pytorch-bot
Copy link

pytorch-bot bot commented Sep 15, 2025

🔗 Helpful Links

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

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

✅ No Failures

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

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

@Lucaskabela
Copy link
Contributor Author

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label Sep 15, 2025
@Lucaskabela Lucaskabela marked this pull request as ready for review September 16, 2025 16:14
@Lucaskabela Lucaskabela changed the title Issue 161010 dynamo stride clone [Bugfix] Fix #161010: match stride for cloned tensors with preserve_format Sep 16, 2025
@Lucaskabela Lucaskabela changed the title [Bugfix] Fix #161010: match stride for cloned tensors with preserve_format [Bugfix] Match eager stride semantics for cloned tensors with preserve_format in compile Sep 16, 2025
@Lucaskabela
Copy link
Contributor Author

Want to wait to see if there are any comments from @zou3519 since he had some insights on the previous PR

if utils.is_non_overlapping_and_dense(input):
computed_stride = input.stride()
else:
computed_stride = utils.compute_elementwise_output_strides(input)
Copy link
Contributor

@zou3519 zou3519 Sep 19, 2025

Choose a reason for hiding this comment

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

I think compute_elementwise_output_strides is wrong in general. We should update it to do:

if utils.is_non_overlapping_and_dense(input):
   computed_stride = input.stride()
 else:
    something()           

So while you should feel free to ship this PR, there are still problems lurking in whatever relies on compute_elementwise_output_strides (e.g. the other unary pointwise ops).

In the other PR we did try to update compute_elementwise_output_strides to do the above and it led to some issues that were not yet debugged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @morrison-turnansky ah let's follow up with this - these test cases in this PR pass, and I am not aware of others we are missing, but let's think on this and if we find anything we can work together to put out a follow up PR fixing any issues in compute_elementwise_output_strides

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Lucaskabela sounds like a plan

@Lucaskabela
Copy link
Contributor Author

@pytorchmergebot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 19, 2025
@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

mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
…e_format in compile (pytorch#163017)

Fixes pytorch#161010 by making `clone_meta` match the semantics of strides for eager mode.

This is:
  * Case 1: Tensor is_non_overlapping_and_dense; in this case, stride should match input tensor stride
  * Case 2: Otherwise, stride should be contiguous computed from input tensor using `compute_elementwise_output_strides`

Pull Request resolved: pytorch#163017
Approved by: https://github.com/williamwen42, https://github.com/xmfan

Co-authored-by: morrison-turnansky <mturnans@redhat.com>
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
…e_format in compile (pytorch#163017)

Fixes pytorch#161010 by making `clone_meta` match the semantics of strides for eager mode.

This is:
  * Case 1: Tensor is_non_overlapping_and_dense; in this case, stride should match input tensor stride
  * Case 2: Otherwise, stride should be contiguous computed from input tensor using `compute_elementwise_output_strides`

Pull Request resolved: pytorch#163017
Approved by: https://github.com/williamwen42, https://github.com/xmfan

Co-authored-by: morrison-turnansky <mturnans@redhat.com>
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
…e_format in compile (pytorch#163017)

Fixes pytorch#161010 by making `clone_meta` match the semantics of strides for eager mode.

This is:
  * Case 1: Tensor is_non_overlapping_and_dense; in this case, stride should match input tensor stride
  * Case 2: Otherwise, stride should be contiguous computed from input tensor using `compute_elementwise_output_strides`

Pull Request resolved: pytorch#163017
Approved by: https://github.com/williamwen42, https://github.com/xmfan

Co-authored-by: morrison-turnansky <mturnans@redhat.com>
@github-actions github-actions bot deleted the issue-161010-dynamo-stride-clone branch November 3, 2025 02:17
pytorchmergebot pushed a commit that referenced this pull request Jan 6, 2026
Continuation of work from #161400 and #163017.

Updating stride semantics for ```clone_meta``` and underlying function, ```compute_elementwise_output_strides```.

Pull Request resolved: #164252
Approved by: https://github.com/Lucaskabela
krastogi-in pushed a commit to krastogi-in/pytorch that referenced this pull request Jan 9, 2026
Continuation of work from pytorch#161400 and pytorch#163017.

Updating stride semantics for ```clone_meta``` and underlying function, ```compute_elementwise_output_strides```.

Pull Request resolved: pytorch#164252
Approved by: https://github.com/Lucaskabela
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.

torch.compile doesn't preserve stride with clone(memory_format=torch.preserve_format)

6 participants