Open JimXiongGM opened 5 years ago
应该更新为:
from torch import tensor x = torch.rand(4) x = x.clone().detach().requiresgrad(True) y= x * 3 grad_variables = torch.FloatTensor([1,2,3,4]) y.backward(grad_variables) x.grad tensor([ 3., 6., 9., 12.])
谢谢,原来代码是0.3版本的。
from torch import tensor import torch x = torch.rand(4, requires_grad=True) y= x * 3 grad_variables = torch.FloatTensor([1,2,3,4]) y.backward(grad_variables) print(x.grad)
应该更新为: