【发布时间】:2021-04-01 03:04:46
【问题描述】:
有人可以回答为什么我的代码显示错误。 提前致谢。
代码:
import torch
torch.manual_seed(0)
a = torch.rand((1, 3), requires_grad = True)
w1 = torch.rand((3, 3), requires_grad = True)
w2 = torch.rand((3, 1), requires_grad = True)
d = torch.matmul(torch.matmul(a, w1), w2)
L = (10 - d)
L.backward()
w1 = w1 - w1.grad*0.001
w1.grad.zero_()
错误: 属性错误 “NoneType”对象没有属性“zero_”
【问题讨论】:
标签: pytorch