Paddle 动态图应用fluid.dygraph.grad 报错

wfsdck30  于 2021-11-30  发布在  Java
关注(0)|答案(16)|浏览(559)

Paddle 版本 1.8.1
程序:

import paddle.fluid as fluid
import numpy as np

with fluid.dygraph.guard():
    value = np.arange(100).reshape(10,2, 5).astype("float32")
    out1 = np.zeros((2,3),dtype=np.float32)
    out=fluid.dygraph.to_variable(out1)
    a = fluid.dygraph.to_variable(value)
    a.stop_gradient=False
    linear=[]
    for i in range(10):
       linear.append(fluid.dygraph.Linear(5, 3))

    for i in range(10):
       out = out+linear[i](a[i,:,:])
    print(out)
    dx=fluid.dygraph.grad(outputs=out,inputs=a,create_graph=True,retain_graph=True,  \
    only_inputs=True,allow_unused=False)[0]
    print(dx.numpy())
    dx.backward()
    print(a.gradient())

报错信息
Traceback (most recent call last):
File "31.py", line 17, in
only_inputs=True,allow_unused=False)[0]
File "", line 2, in grad
File "/share/group-soft/anaconda/install/envs/paddle/lib/python3.7/site-packages/paddle/fluid/wrapped_decorator.py", line 25, inimpl
return wrapped_func(args,kwargs)
File "/share/group-soft/anaconda/install/envs/paddle/lib/python3.7/site-packages/paddle/fluid/framework.py", line 216, in
impl
*
return func(*args,**kwargs)
File "/share/group-soft/anaconda/install/envs/paddle/lib/python3.7/site-packages/paddle/fluid/dygraph/base.py", line 559, in grad
create_graph, retain_graph, allow_unused, only_inputs)
paddle.fluid.core_avx.EnforceNotMet:

C++ Call Stacks (More useful to developers):

0 std::string paddle::platform::GetTraceBackString<std::string const&>(std::string const&, char const*, int)
1 paddle::platform::EnforceNotMet::EnforceNotMet(std::string const&, char const*, int)
2 paddle::imperative::ReadyGradVarInfoMap::GetTarget(paddle::imperative::VariableWrapper const*) const
3 paddle::imperative::PartialGradTask::CreateResult()
4 paddle::imperative::PartialGradTask::Run()
5 paddle::imperative::PartialGradEngine::Execute()

Error Message Summary:

PermissionDeniedError: Target var generated_var_1@GRAD should not be nullptr
[Hint: iter->second should not be null.] at (/paddle/paddle/fluid/imperative/partial_grad_engine.cc:501)

我发现去掉python的控制流(for 循环),就可以跑通,可以得到正确的dx, 但是a.gradient()返回的是None, 就是请教一下,grad这个api使用时,组网过程不能有python的控制流吗?还有为什么直接手动append的组网返回的 a.gradient() 依然是None?

0ejtzxu1

0ejtzxu116#

。。。。不可以啊。我就是在1.8.4上测试的,2.0alpha我之前也测试过不行, ylzustc@mail.ustc.edu.cn 发件人: Ryan_Huang 发送时间: 2020-08-30 22:18 收件人: PaddlePaddle/Paddle 抄送: zyl12138; Author 主题: Re: [PaddlePaddle/Paddle]动态图应用fluid.dygraph.grad 报错 (#25703) paddle 2.0 依然有这个问题,用1.8.4就可以了吗?? ---------------------- Error Message Summary: ---------------------- PermissionDeniedError: Target var generated_var_0@GRAD should not be nullptr [Hint: iter->second should not be null.] at (D:\2.0.0a0\paddle\paddle\fluid\imperative\partial_grad_engine.cc:501) — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

相关问题