【发布时间】:2020-11-24 13:56:37
【问题描述】:
我目前正在尝试使用 Pytorch 实现 ODE Solver,我的解决方案需要计算每个输出 wtr 与其输入的梯度。
y = model(x)
for i in range(len(y)): #compute output grad wrt input
y[i].backward(retain_graph=True)
ydx=x.grad
我想知道是否有更优雅的方法来计算批处理中每个输出的梯度,因为对于高阶 ODE 和 PDE,代码会变得混乱。 我尝试使用:
torch.autograd.backward(x,y,retain_graph=True)
没有太大的成功。
【问题讨论】:
标签: python pytorch ode autograd