What is the rationale for allowing the t.tolist()
method to be called on a tensor t
with requires_grad=True
, but not t.numpy()
? I’d have thought it would make sense to allow both or neither, but it doesn’t make sense to me why one would be allowed and not the other. Example:
import torch
t = torch.arange(5, dtype=torch.float32, requires_grad=True)
print(t, type(t), type(t[0]))
# >>> tensor([0., 1., 2., 3., 4.], requires_grad=True) <class 'torch.Tensor'> <class 'torch.Tensor'>
print(t.tolist(), type(t.tolist()), type(t.tolist()[0]))
# >>> [0.0, 1.0, 2.0, 3.0, 4.0] <class 'list'> <class 'float'>
print(t.numpy())
# >>> RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.