-
Notifications
You must be signed in to change notification settings - Fork 664
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
jacobian接口问题:oneflow的_autograd_grad()函数对比pytorch的_autograd_grad()函数缺乏相关功能 #10397
Comments
是否可以直接构造一个调用 autograd.grad 接口的例子呢?我们把这个接口对齐一下,再来验证 jacobian 接口。 |
Summarytorch.autograd.grad()接口与oneflow.autograd.grad()接口对比 Code to reproduce
Run result
|
明白了,是 is_grads_batched 参数支持的这个功能,主要的作用是把 grad 打包只用走一次 AutogradEngine 就可以完成多次后向计算。我后面可以来支持下。 如果着急实现功能的话,这里有一个绕过的方案:既然这里的作用是把 grad 打包,这里就定义一个 |
wyg1997
added a commit
that referenced
this issue
Jan 10, 2024
close #10397 这里只需要在参数检查的时候对 is_grads_batched 做处理就行了,不需要侵入到 AutogradEgnine 里。 实际后向计算的时候,会自己做 broadcast 操作,如果计算错误,是算子对 broadcast 支持的不全。 --------- Co-authored-by: wyg1997 <wangyinggnag@foxmail.com>
接口已支持,可以跑一下试试 @lihuizhao |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Summary
我尝试在oneflow中添加jacobian接口。参照pytorch的文件,在/oneflow/python/oneflow/autograd/functional.py文件中添加jacobian函数。并对jacobian()函数做测试。代码分支链接:#10393
pytorch下调用torch.autograd.functional.jacobian(func, inputs, vectorize=True)函数时(在vectorize=True的条件下),会调用_autograd_grad()函数计算梯度,该函数调用torch.autograd.grad()函数进行具体计算,在调用torch.autograd.grad()前打印torch.autograd.grad()函数的输入参数new_outputs/new_grad_outputs,可以看到两者的size不同。可以得出结果。
oneflow下调用jacobian(func, inputs, vectorize=True)函数时(在vectorize=True的条件下),同样会调用_autograd_grad()函数计算梯度,该函数调用flow.autograd.grad()函数进行具体计算。我对flow.autograd.grad()函数的输入参数new_outputs/new_grad_outputs打印输出,其格式与pytorch下的格式相同,但在flow.autograd.grad()函数中会对两个参数进行进一步的size验证,此时会报错说size不匹配。
能否让oneflow下的flow.autograd.grad()像pytorch一样工作?
Code to reproduce
System Information
Run result
The text was updated successfully, but these errors were encountered: