Open dvolgyes opened 3 years ago
Hi,
The torch.Tensor()
constructor is actually being deprecated for that exact reason that it can give un-expected behavior.
You should use the torch.tensor()
one (lowercase) that will always copy the data into a new Tensor. And you can pass the requires_grad=
keyword argument to make sure the flag is set to what you want.
Hi,
I confirm that the torch.tensor
gives consistent results. If anybody looks this issue up later:
import torch
t = torch.FloatTensor([1.0])
p = torch.nn.Parameter(t)
p.requires_grad = True
print(torch.tensor(p).requires_grad) # False
print(torch.tensor([p,]).requires_grad) # False
However, I do not see any deprecation warning in 1.9.0.
Is it an official decision to deprecate torch.Tensor
?
If yes, is there / will be there a deprecation warning?
I think a warning would be reasonable until it gets removed.
However, I do not see any deprecation warning in 1.9.0. Is it an official decision to deprecate
torch.Tensor
?
Yes, and...
If yes, is there / will be there a deprecation warning?
... yes!
I think a warning would be reasonable until it gets removed.
Agreed. We we need to revisit deprecating this soon, thank you for the reminder, @dvolgyes.
🐛 Bug
If you convert a list of parameters with requires_grad=True into a tensor, you lose the gradients.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The output should be equivalent with:
Or the code should raise an exception.
Reasoning: whatever happens, a transformation like this should not silently remove the requires_grad. If legal, propagate it, if not, ban the use of it.
Environment
PyTorch version: 1.9.0 Is debug build: False CUDA used to build PyTorch: 11.1 ROCM used to build PyTorch: N/A
OS: Ubuntu 21.04 (x86_64) GCC version: (Ubuntu 10.3.0-1ubuntu1) 10.3.0 Clang version: Could not collect CMake version: Could not collect Libc version: glibc-2.33
Python version: 3.8.10 (default, Jun 4 2021, 15:09:15) [GCC 7.5.0] (64-bit runtime) Python platform: Linux-5.12.0-14.2-liquorix-amd64-x86_64-with-glibc2.17 Is CUDA available: True CUDA runtime version: 11.3.109 GPU models and configuration: GPU 0: NVIDIA GeForce RTX 2060 Nvidia driver version: 465.31 cuDNN version: Could not collect HIP runtime version: N/A MIOpen runtime version: N/A
Versions of relevant libraries:
Additional context
I don't think this is anyhow related to install or libraries, this should be core autograd issue / property.
cc @ezyang @albanD @zou3519 @gqchen @pearu @nikitaved @soulitzer @Lezcano @Varal7 @gchanan @mruberry @jbschlosser