Paddle 报错:paddle.sin 函数并没有对应的梯度操作

c2e8gylq  于 2022-04-21  发布在  Java
关注(0)|答案(2)|浏览(232)

在AIStUDIo中运行代码,paddle版本是2.2.0,运行环境是CPU,执行代码是:

inp = paddle.to_tensor([1], dtype='float32', stop_gradient=False)
y = paddle.sin(inp)
y_x = paddle.grad(y, inp, create_graph=True, retain_graph=True)

报错:
(NotFound) The Op sin_grad doesn't have any grad op. If you don't intend calculating higher order derivatives, please set create_graph to False.
[Hint: double_grad_node should not be null.] (at /paddle/paddle/fluid/imperative/partial_grad_engine.cc:908)

gcuhipw9

gcuhipw91#

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

7kqas0il

7kqas0il2#

报错提示sin OP没有二阶梯度计算kernel
如果您只需要计算一阶梯度,可以设置create_graph=False

https://www.paddlepaddle.org.cn/documentation/docs/zh/api/paddle/grad_cn.html#grad
retain_graph (bool, 可选) - 是否保留计算梯度的前向图。*若值为True,则前向图会保留,用户可对同一张图求两次反向*。若值为False,则前向图会释放。默认值为None,表示值与 create_graph 相等。

相关问题