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
Grad is None after using view #19778
Comments
So this isn't a bug per se, but it is definitely a source of confusion. The issue with the above code is that the gradient information is attached to the initial tensor before the
Output:
|
You analysis is correct: we only retain gradients of leaf variables. Once you do Where do you think we could improve the documentation to explain this? Maybe in the https://pytorch.org/docs/stable/notes/autograd.html or in https://pytorch.org/docs/stable/notes/faq.html Also, could you send a PR improving the documentation? |
I think this "only retain gradients of leaf variables" should be in the FAQ. |
…easons (#30531) Summary: Fix #2362 and #19778 To avoid issues with frozen model, we only consider warning for Tensors that require gradients and are neither leafs nor retain gradients. Pull Request resolved: #30531 Differential Revision: D18832767 Pulled By: albanD fbshipit-source-id: 743e863dc14ab57713e66da78b2e4d759dfba0ff
…easons (pytorch#30531) Summary: Fix pytorch#2362 and pytorch#19778 To avoid issues with frozen model, we only consider warning for Tensors that require gradients and are neither leafs nor retain gradients. Pull Request resolved: pytorch#30531 Differential Revision: D18832767 Pulled By: albanD fbshipit-source-id: 743e863dc14ab57713e66da78b2e4d759dfba0ff
We added a warning for this special case. Please re-open if you need more. |
🐛 Bug
After initializing a tensor with
requires_grad=True
, applying a view, summing, and calling backward, the gradient is None. This is not the case if the tensor is initialized using the dimensions specified in the view.To Reproduce
Output
Expected behavior
Grad is not None and
X.grad
is the same asX_view.grad
Environment
Collecting environment information...
PyTorch version: 1.0.0a0
Is debug build: No
CUDA used to build PyTorch: 9.2.88
OS: CentOS Linux 7 (Core)
GCC version: (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
CMake version: Could not collect
Python version: 3.6
Is CUDA available: No
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Versions of relevant libraries:
[pip] Could not collect
[conda] Could not collect
The text was updated successfully, but these errors were encountered: