import torch
x = torch.ones((2,2),requires_grad=True)
print("x>>>",x)
y = x+2
z = y*y*3
out = z.mean()
print("out>>>",out)
out.backward()
print("x.grad>>>",x.grad)

输出结果
x>>> tensor([[1., 1.],
[1., 1.]], requires_grad=True)
out>>> tensor(27., grad_fn=<MeanBackward0>)
x.grad>>> tensor([[4.5000, 4.5000],
[4.5000, 4.5000]])
1万+

被折叠的 条评论
为什么被折叠?



