pytorch
59aca022 - Implement Tensor.new_empty_strided(sizes, strides, *, dtype, device, requires_grad) (#47225)

Commit
4 years ago
Implement Tensor.new_empty_strided(sizes, strides, *, dtype, device, requires_grad) (#47225) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/47225 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. Test Plan: Imported from OSS Reviewed By: ejguan Differential Revision: D24741688 Pulled By: zou3519 fbshipit-source-id: b688047d2eb3f92998896373b2e9d87caf2c4c39
Author
Parents
Loading