Skip to content

preserve output tensor's stride in TI's fast setup - #38895

Closed
glaringlee wants to merge 5 commits into
gh/glaringlee/22/basefrom
gh/glaringlee/22/head
Closed

glaringlee wants to merge 5 commits into
gh/glaringlee/22/basefrom
gh/glaringlee/22/head

Conversation

@glaringlee

@glaringlee glaringlee commented May 21, 2020 •

Copy link
Copy Markdown
Contributor

Stack from ghstack:

For non-contiguous, non-overlapping and dense tensors, if they have same shape, we can still do fast setup (flatten to 1d tensor and loop on this 1d tensor) in tensor iterator (IT). There is a case, when input tensors all have the same strides but output tensors don't have the same strides as input tensors, the previous behavior is that we re-stride the output tensors to the same strides as input tensors so all the tensors have the same shape + strides and fast setup can be applied. But this is not compatible with numpy behavior, in numpy, if output tensors' shape are the same as input tensors, their strides are preserved. This PR is to make tensor iterator apply the same behavior as numpy. We no longer re-stride output tensor, but for undefined output tensor, we still do allocation.

This is to fix #38107
Differential Revision: D21696586

glaringlee pushed a commit that referenced this pull request May 21, 2020
ghstack-source-id: d733ee9
Pull Request resolved: #38895
@dr-ci

dr-ci Bot commented May 21, 2020 •

Copy link
Copy Markdown

💊 CI failures summary and remediations

As of commit 2cc392a (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


1 failure confirmed as flaky and can be ignored:

  • pytorch_bazel_test

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 11 times.

@glaringlee
glaringlee requested a review from VitalyFedyunin May 21, 2020 23:17
For non-contiguous, non-overlapping and dense tensors, if they have same shape, we can still do fast setup (flatten to 1d tensor and loop on this 1d tensor) in tensor iterator (IT). There is a case, when input tensors all have the same strides but output tensors don't have the same strides as input tensors, the previous behavior is that we re-stride the output tensors to the same strides as input tensors so all the tensors have the same shape + strides and fast setup can be applied. But this is not compatible with numpy behavior, in numpy, if output tensors' shape are the same as input tensors, their strides are preserved. This PR is to make tensor iterator apply the same behavior as numpy. We no longer re-stride output tensor, but for undefined output tensor, we still do allocation.

This is to fix #38107
Differential Revision: [D21696586](https://our.internmc.facebook.com/intern/diff/D21696586)

[ghstack-poisoned]
glaringlee pushed a commit that referenced this pull request May 22, 2020
ghstack-source-id: 0db3a58
Pull Request resolved: #38895
@glaringlee
glaringlee requested a review from ngimel June 12, 2020 16:04
For non-contiguous, non-overlapping and dense tensors, if they have same shape, we can still do fast setup (flatten to 1d tensor and loop on this 1d tensor) in tensor iterator (IT). There is a case, when input tensors all have the same strides but output tensors don't have the same strides as input tensors, the previous behavior is that we re-stride the output tensors to the same strides as input tensors so all the tensors have the same shape + strides and fast setup can be applied. But this is not compatible with numpy behavior, in numpy, if output tensors' shape are the same as input tensors, their strides are preserved. This PR is to make tensor iterator apply the same behavior as numpy. We no longer re-stride output tensor, but for undefined output tensor, we still do allocation.

This is to fix #38107
Differential Revision: [D21696586](https://our.internmc.facebook.com/intern/diff/D21696586)

[ghstack-poisoned]
For non-contiguous, non-overlapping and dense tensors, if they have same shape, we can still do fast setup (flatten to 1d tensor and loop on this 1d tensor) in tensor iterator (IT). There is a case, when input tensors all have the same strides but output tensors don't have the same strides as input tensors, the previous behavior is that we re-stride the output tensors to the same strides as input tensors so all the tensors have the same shape + strides and fast setup can be applied. But this is not compatible with numpy behavior, in numpy, if output tensors' shape are the same as input tensors, their strides are preserved. This PR is to make tensor iterator apply the same behavior as numpy. We no longer re-stride output tensor, but for undefined output tensor, we still do allocation.

This is to fix #38107
Differential Revision: [D21696586](https://our.internmc.facebook.com/intern/diff/D21696586)

[ghstack-poisoned]
glaringlee pushed a commit that referenced this pull request Jun 17, 2020
ghstack-source-id: d139205
Pull Request resolved: #38895
For non-contiguous, non-overlapping and dense tensors, if they have same shape, we can still do fast setup (flatten to 1d tensor and loop on this 1d tensor) in tensor iterator (IT). There is a case, when input tensors all have the same strides but output tensors don't have the same strides as input tensors, the previous behavior is that we re-stride the output tensors to the same strides as input tensors so all the tensors have the same shape + strides and fast setup can be applied. But this is not compatible with numpy behavior, in numpy, if output tensors' shape are the same as input tensors, their strides are preserved. This PR is to make tensor iterator apply the same behavior as numpy. We no longer re-stride output tensor, but for undefined output tensor, we still do allocation.

This is to fix #38107
Differential Revision: [D21696586](https://our.internmc.facebook.com/intern/diff/D21696586)

[ghstack-poisoned]
glaringlee pushed a commit that referenced this pull request Jun 17, 2020
ghstack-source-id: 09d3bf0
Pull Request resolved: #38895
@facebook-github-bot

Copy link
Copy Markdown
Contributor

@glaringlee merged this pull request in 645d6c0.

xwang233 pushed a commit to xwang233/pytorch that referenced this pull request Jun 20, 2020
Summary: Pull Request resolved: pytorch#38895

Test Plan: Imported from OSS

Differential Revision: D21696586

Pulled By: glaringlee

fbshipit-source-id: c7206dbcf74d30998544e221cd0c998c4c25663a
@facebook-github-bot
facebook-github-bot deleted the gh/glaringlee/22/head branch June 22, 2020 14:16
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.

4 participants