oneflow
oneflow copied to clipboard
Add autograd engine debug graph
打开 ONEFLOW_DEBUG_MODE=1 环境变量后, 每次后向计算都会生成 AutogradEngine 执行图到 log 目录下的 dot file。可以从图中看到后向执行的算子以及拓扑结构,方便算法人员和研发人员 debug 后向的问题。
autograd.grad
import oneflow as flow
# autograd.grad
a = flow.rand(2, 3).requires_grad_()
b = flow.rand(2, 3).requires_grad_()
c = a * b
d = c ** 2
e = flow.rand(3).requires_grad_()
d[0, :] = e
f = d.sum()
a_grad, b_grad = flow.autograd.grad(f, [a, b])[0]
autograd.backward
# autograd.backward
a = flow.rand(2, 3).requires_grad_()
b = flow.rand(2, 3).requires_grad_()
c = a * b
d = c ** 2
e = flow.rand(3).requires_grad_()
d[0, :] = e
f = d.sum()
f.backward()