Dive-into-DL-PyTorch icon indicating copy to clipboard operation
Dive-into-DL-PyTorch copied to clipboard

2.3.3梯度结果问题请教

Open zthcool opened this issue 2 years ago • 1 comments

bug描述 在按照教程2.3.3梯度章节中 “

再来反向传播一次,注意grad是累加的

out2 = x.sum() out2.backward() print(x.grad) ” 时我的返回结果是 tensor([[1., 1.], [1., 1.]]) 如图 image 请问是我的输入有问题么?

版本信息 pytorch: 1.9.0 torchvision: 0.10.0 torchtext: None ...

zthcool avatar Aug 13 '21 07:08 zthcool

你backward的是out2,对应的是x.sum(),梯度是1没问题; 原章节里的操作是对out = z.mean()进行backward之后查看x.grad

dingtao-shen avatar Mar 18 '22 09:03 dingtao-shen