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
Implement Tensor.new_empty_strided(sizes, strides, *, dtype, device, requires_grad) #47225
Conversation
…requires_grad) Summary ------- This PR implements Tensor.new_empty_strided. Many of our torch.* factory functions have a corresponding new_* method (e.g., torch.empty and torch.new_empty), but there is no corresponding method to torch.empty_strided. This PR adds one. Motivation ---------- The real motivation behind this is for vmap to be able to work through CopySlices. CopySlices shows up a lot in double backwards because a lot of view functions have backward formulas that perform view+inplace. https://github.com/pytorch/pytorch/blob/e0fd590ec950cb1e65ea0431c9e765f8cda27908/torch/csrc/autograd/functions/tensor.cpp#L78-L106 To support vmap through CopySlices, the approach in this stack is to: - add `Tensor.new_empty_strided` and replace `empty_strided` in CopySlices with that so that we can propagate batch information. - Make some slight modifications to AsStridedBackward (and add as_strided batching rule) Please let me know if it would be better if I squashed everything related to supporting vmap over CopySlices together into a single big PR. Test Plan --------- - New tests. [ghstack-poisoned]
…e, device, requires_grad)" Summary ------- This PR implements Tensor.new_empty_strided. Many of our torch.* factory functions have a corresponding new_* method (e.g., torch.empty and torch.new_empty), but there is no corresponding method to torch.empty_strided. This PR adds one. Motivation ---------- The real motivation behind this is for vmap to be able to work through CopySlices. CopySlices shows up a lot in double backwards because a lot of view functions have backward formulas that perform view+inplace. https://github.com/pytorch/pytorch/blob/e0fd590ec950cb1e65ea0431c9e765f8cda27908/torch/csrc/autograd/functions/tensor.cpp#L78-L106 To support vmap through CopySlices, the approach in this stack is to: - add `Tensor.new_empty_strided` and replace `empty_strided` in CopySlices with that so that we can propagate batch information. - Make some slight modifications to AsStridedBackward (and add as_strided batching rule) Please let me know if it would be better if I squashed everything related to supporting vmap over CopySlices together into a single big PR. Test Plan --------- - New tests. [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit 7ea21b5 (more details on the Dr. CI page):
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages: binary_linux_libtorch_3_7m_cpu_devtoolset7_shared-with-deps_build (1/1)Step: "Checkout pytorch/builder repo" (full log | diagnosis details | 🔁 rerun)
|
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.
lgtm
…e, device, requires_grad)" Summary ------- This PR implements Tensor.new_empty_strided. Many of our torch.* factory functions have a corresponding new_* method (e.g., torch.empty and torch.new_empty), but there is no corresponding method to torch.empty_strided. This PR adds one. Motivation ---------- The real motivation behind this is for vmap to be able to work through CopySlices. CopySlices shows up a lot in double backwards because a lot of view functions have backward formulas that perform view+inplace. https://github.com/pytorch/pytorch/blob/e0fd590ec950cb1e65ea0431c9e765f8cda27908/torch/csrc/autograd/functions/tensor.cpp#L78-L106 To support vmap through CopySlices, the approach in this stack is to: - add `Tensor.new_empty_strided` and replace `empty_strided` in CopySlices with that so that we can propagate batch information. - Make some slight modifications to AsStridedBackward (and add as_strided batching rule) Please let me know if it would be better if I squashed everything related to supporting vmap over CopySlices together into a single big PR. Test Plan --------- - New tests. [ghstack-poisoned]
…e, device, requires_grad)" Summary ------- This PR implements Tensor.new_empty_strided. Many of our torch.* factory functions have a corresponding new_* method (e.g., torch.empty and torch.new_empty), but there is no corresponding method to torch.empty_strided. This PR adds one. Motivation ---------- The real motivation behind this is for vmap to be able to work through CopySlices. CopySlices shows up a lot in double backwards because a lot of view functions have backward formulas that perform view+inplace. https://github.com/pytorch/pytorch/blob/e0fd590ec950cb1e65ea0431c9e765f8cda27908/torch/csrc/autograd/functions/tensor.cpp#L78-L106 To support vmap through CopySlices, the approach in this stack is to: - add `Tensor.new_empty_strided` and replace `empty_strided` in CopySlices with that so that we can propagate batch information. - Make some slight modifications to AsStridedBackward (and add as_strided batching rule) Please let me know if it would be better if I squashed everything related to supporting vmap over CopySlices together into a single big PR. Test Plan --------- - New tests. [ghstack-poisoned]
…e, device, requires_grad)" Summary ------- This PR implements Tensor.new_empty_strided. Many of our torch.* factory functions have a corresponding new_* method (e.g., torch.empty and torch.new_empty), but there is no corresponding method to torch.empty_strided. This PR adds one. Motivation ---------- The real motivation behind this is for vmap to be able to work through CopySlices. CopySlices shows up a lot in double backwards because a lot of view functions have backward formulas that perform view+inplace. https://github.com/pytorch/pytorch/blob/e0fd590ec950cb1e65ea0431c9e765f8cda27908/torch/csrc/autograd/functions/tensor.cpp#L78-L106 To support vmap through CopySlices, the approach in this stack is to: - add `Tensor.new_empty_strided` and replace `empty_strided` in CopySlices with that so that we can propagate batch information. - Make some slight modifications to AsStridedBackward (and add as_strided batching rule) Please let me know if it would be better if I squashed everything related to supporting vmap over CopySlices together into a single big PR. Test Plan --------- - New tests. [ghstack-poisoned]
…e, device, requires_grad)" Summary ------- This PR implements Tensor.new_empty_strided. Many of our torch.* factory functions have a corresponding new_* method (e.g., torch.empty and torch.new_empty), but there is no corresponding method to torch.empty_strided. This PR adds one. Motivation ---------- The real motivation behind this is for vmap to be able to work through CopySlices. CopySlices shows up a lot in double backwards because a lot of view functions have backward formulas that perform view+inplace. https://github.com/pytorch/pytorch/blob/e0fd590ec950cb1e65ea0431c9e765f8cda27908/torch/csrc/autograd/functions/tensor.cpp#L78-L106 To support vmap through CopySlices, the approach in this stack is to: - add `Tensor.new_empty_strided` and replace `empty_strided` in CopySlices with that so that we can propagate batch information. - Make some slight modifications to AsStridedBackward (and add as_strided batching rule) Please let me know if it would be better if I squashed everything related to supporting vmap over CopySlices together into a single big PR. Test Plan --------- - New tests. [ghstack-poisoned]
Note that CI failures are real because |
…e, device, requires_grad)" Summary ------- This PR implements Tensor.new_empty_strided. Many of our torch.* factory functions have a corresponding new_* method (e.g., torch.empty and torch.new_empty), but there is no corresponding method to torch.empty_strided. This PR adds one. Motivation ---------- The real motivation behind this is for vmap to be able to work through CopySlices. CopySlices shows up a lot in double backwards because a lot of view functions have backward formulas that perform view+inplace. https://github.com/pytorch/pytorch/blob/e0fd590ec950cb1e65ea0431c9e765f8cda27908/torch/csrc/autograd/functions/tensor.cpp#L78-L106 To support vmap through CopySlices, the approach in this stack is to: - add `Tensor.new_empty_strided` and replace `empty_strided` in CopySlices with that so that we can propagate batch information. - Make some slight modifications to AsStridedBackward (and add as_strided batching rule) Please let me know if it would be better if I squashed everything related to supporting vmap over CopySlices together into a single big PR. Test Plan --------- - New tests. [ghstack-poisoned]
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.
Separate is better. Thanks!
…e, device, requires_grad)" Summary ------- This PR implements Tensor.new_empty_strided. Many of our torch.* factory functions have a corresponding new_* method (e.g., torch.empty and torch.new_empty), but there is no corresponding method to torch.empty_strided. This PR adds one. Motivation ---------- The real motivation behind this is for vmap to be able to work through CopySlices. CopySlices shows up a lot in double backwards because a lot of view functions have backward formulas that perform view+inplace. https://github.com/pytorch/pytorch/blob/e0fd590ec950cb1e65ea0431c9e765f8cda27908/torch/csrc/autograd/functions/tensor.cpp#L78-L106 To support vmap through CopySlices, the approach in this stack is to: - add `Tensor.new_empty_strided` and replace `empty_strided` in CopySlices with that so that we can propagate batch information. - Make some slight modifications to AsStridedBackward (and add as_strided batching rule) Please let me know if it would be better if I squashed everything related to supporting vmap over CopySlices together into a single big PR. Test Plan --------- - New tests. Differential Revision: [D24741688](https://our.internmc.facebook.com/intern/diff/D24741688) [ghstack-poisoned]
Stack from ghstack:
Summary
This PR implements Tensor.new_empty_strided. Many of our torch.* factory
functions have a corresponding new_* method (e.g., torch.empty and
torch.new_empty), but there is no corresponding method to
torch.empty_strided. This PR adds one.
Motivation
The real motivation behind this is for vmap to be able to work through
CopySlices. CopySlices shows up a lot in double backwards because a lot
of view functions have backward formulas that perform view+inplace.
pytorch/torch/csrc/autograd/functions/tensor.cpp
Lines 78 to 106 in e0fd590
To support vmap through CopySlices, the approach in this stack is to:
Tensor.new_empty_strided
and replaceempty_strided
inCopySlices with that so that we can propagate batch information.
as_strided batching rule)
Please let me know if it would be better if I squashed everything related to
supporting vmap over CopySlices together into a single big PR.
Test Plan
Differential Revision: D24741688