Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.3.3梯度结果问题请教 #174

Open
zthcool opened this issue Aug 13, 2021 · 1 comment
Open

2.3.3梯度结果问题请教 #174

zthcool opened this issue Aug 13, 2021 · 1 comment

Comments

@zthcool
Copy link

zthcool commented Aug 13, 2021

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
...

@dingtao-shen
Copy link

dingtao-shen commented Mar 18, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants