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

pytorch初步 #6

Open
chrispher opened this issue Nov 19, 2017 · 1 comment
Open

pytorch初步 #6

chrispher opened this issue Nov 19, 2017 · 1 comment

Comments

@chrispher
Copy link
Owner

http://www.datakit.cn/blog/2017/03/03/pytorch_01_basic.html

@Jason-py
Copy link

请问,为什么运行第3部分的代码

简单的case

x = Variable(torch.ones(1), requires_grad = True)
y = x ** 2 + 3
y.backward(retain_variables=True)
print(x.grad) # 梯度值是 2*x = 2

复杂一点,

target = torch.FloatTensor([10])
y.backward(target, retain_variables=True)
print(x.grad) # 梯度值是 2*x = 20, 因为retain的设置为true, grad会加上原来的梯度值2, 结果是22

会报错
TypeError: backward() got an unexpected keyword argument 'retain_variables'

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

No branches or pull requests

2 participants