PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
http://www.paddlepaddle.org/
Apache License 2.0
21.69k stars 5.45k forks source link

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

Open ChevalierOhm opened 2 weeks ago

ChevalierOhm commented 2 weeks ago

请提出你的问题 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_graphto 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)

以上报错如何解决?

ZhangHandi commented 1 week ago

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