-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Add a reshape_copy operator. #88314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a reshape_copy operator. #88314
Conversation
The semantics is "as if" you did a reshape, but it always copied even if the input was directly view'able. Signed-off-by: Edward Z. Yang <[email protected]> [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/88314
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 FailuresAs of commit 4c0a6a4: The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
tools/autograd/derivatives.yaml
Outdated
| - name: special_spherical_bessel_j0(Tensor x) -> Tensor | ||
| x: non_differentiable | ||
|
|
||
| - name: reshape_copy(Tensor self, SymInt[] size) -> Tensor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it work to make it a copy: bool kwarg like we did for .to() https://pytorch.org/docs/master/generated/torch.Tensor.to.html?highlight=#torch.Tensor.to ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if I did add the kwarg, I would still have to add an extra operator, similar to how we have _to_copy
albanD
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question about consistency with .to()
But if you need an actual different function and the flag is not enough, the PR sounds good.
The semantics is "as if" you did a reshape, but it always copied even if the input was directly view'able. Signed-off-by: Edward Z. Yang <ezyangfb.com> [ghstack-poisoned]
The semantics is "as if" you did a reshape, but it always copied even if the input was directly view'able. Signed-off-by: Edward Z. Yang <ezyangfb.com> [ghstack-poisoned]
| TORCH_CHECK(0, "_reshape_copy not implemented for mkldnn tesnors"); | ||
| } | ||
|
|
||
| if (self.is_contiguous()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need this conditional, you are making a clone anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I can always clone and then unsafe view... I suppose I was trying to avoid calling unsafe view in some situations haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The guts here don't really matter, the inside of this function is never traced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe view is safe really, it does check the sizes, it just doesn't set up autograd tracking that you don't need here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will update this
The semantics is "as if" you did a reshape, but it always copied even if the input was directly view'able. Signed-off-by: Edward Z. Yang <ezyangfb.com> [ghstack-poisoned]
|
@pytorchbot merge -f "failures are spurious" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
The semantics is "as if" you did a reshape, but it always copied even if the input was directly view'able. Signed-off-by: Edward Z. Yang <[email protected]> Pull Request resolved: pytorch#88314 Approved by: https://github.com/albanD
The semantics is "as if" you did a reshape, but it always copied even if the input was directly view'able. Signed-off-by: Edward Z. Yang <[email protected]> Pull Request resolved: pytorch#88314 Approved by: https://github.com/albanD
Stack from ghstack (oldest at bottom):
The semantics is "as if" you did a reshape, but it always copied
even if the input was directly view'able.
Signed-off-by: Edward Z. Yang [email protected]