-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
请教--关于detach #60
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
书写得很全面细致,关于detach,请教:网上很多地方都没有讲清楚detach,特别是将其值改变了之会怎么样,例如:
https://zhuanlan.zhihu.com/p/505445223 中的第一段代码,但是如果将其中“a = a0.tanh()”改为“a = a0.sin()”,如下,就可以正常运行了--没有报错,why?我的版本是2.3.0+cu121
import torch
a0 = torch.tensor([1.1, 2.2, 3.3], requires_grad = True)
a = a0.sin()
print('a=',a)
print('a.requires_grad=',a.requires_grad)
a_detach = a.detach()
print('a_detach=',a_detach)
print('a_detach.requires_grad=', a_detach.requires_grad)
a_detach.zero_()
print('a_detach=',a_detach)
print('a=',a)
print('a.requires_grad=',a.requires_grad) # 此时对原来的a求导
a.sum().backward()
print(a0.grad)
The text was updated successfully, but these errors were encountered: