调用paddle.grad函数计算指数函数和三角函数的高阶微分,报错如何解决

ddarikpa  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(53)

请提出你的问题 Please ask your question

代码:
x = paddle.rand(shape=[2, 5], dtype=np.float32)
x.stop_gradient = False
u = paddle.exp(x)
du_dx = paddle.grad(u, x, create_graph=True)[0]
d2u_dx2 = paddle.grad(du_dx, x, create_graph=True)[0]
报错:
RuntimeError: (Unavailable) The Op exp_grad doesn't have any gradop. If you don't intend calculating higher orderderivatives, please set create_graph to False. (at /paddle/paddle/fluid/eager/api/generated/eager_generated/backwards/nodes.cc:8177)

代码:
x = paddle.rand(shape=[2, 5], dtype=np.float32)
x.stop_gradient = False
u = paddle.cos(x)
du_dx = paddle.grad(u, x, create_graph=True)[0]
d2u_dx2 = paddle.grad(du_dx, x, create_graph=True)[0]
报错:
RuntimeError: (NotFound) Unable to get phi::DenseTensor data of Output d2d1y in operator CosDoubleGrad. Possible reasons are:

  1. The d2d1y is not the Output of operator CosDoubleGrad;
  2. The d2d1y has no corresponding variable passed in;
  3. The d2d1y corresponding variable is not initialized.
    [Hint: pointer ddOut should not be null.] (at /paddle/paddle/phi/kernels/funcs/activation_functor.h:405)

以上报错如何解决?

93ze6v8z

93ze6v8z1#

你好,paddle.exp暂不支持高阶微分,paddle.cos未复现到该问题,可以尝试更新到最新的paddle再试一下

相关问题