Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimizer.setp() Cannot set gradient op twice unless using Inplace Strategy. #32710

Closed
Reatris opened this issue Apr 30, 2021 · 4 comments
Closed
Assignees

Comments

@Reatris
Copy link

Reatris commented Apr 30, 2021

paddle.regularizer 异常

我想通过对指定层自定义ParamAttr 添加regularizer 但是使用paddle.regularizer却提示了异常

后来我查看了官方API文档,按照示例代码运行,也提示了同样的异常
paddle.regularizer

   1)PaddlePaddle版本:paddlepaddle-gpu==2.0.2
   3)GPU:v100
   4)系统环境:Linux ,win10

执行的代码

import paddle
from paddle.regularizer import L1Decay
linear = paddle.nn.Linear(10, 10)
inp = paddle.rand(shape=[10, 10], dtype="float32")
out = linear(inp)
loss = paddle.mean(out)
print(loss)
beta1 = paddle.to_tensor([0.9], dtype="float32")
beta2 = paddle.to_tensor([0.99], dtype="float32")
momentum = paddle.optimizer.Momentum(
    learning_rate=0.1,
    parameters=linear.parameters(),
    weight_decay=L1Decay(0.0001))
back = out.backward()
momentum.step()
momentum.clear_grad()

提示的异常

momentum.step()

Cannot set gradient op twice unless using Inplace Strategy.

Traceback (most recent call last):
  File "D:/Progect/ASUDIO/cls_cat12/test.py", line 15, in <module>
    momentum.step()
  File "<decorator-gen-195>", line 2, in step
  File "D:\Progect\ASUDIO\venv\lib\site-packages\paddle\fluid\wrapped_decorator.py", line 25, in __impl__
    return wrapped_func(*args, **kwargs)
  File "D:\Progect\ASUDIO\venv\lib\site-packages\paddle\fluid\framework.py", line 225, in __impl__
    return func(*args, **kwargs)
  File "D:\Progect\ASUDIO\venv\lib\site-packages\paddle\optimizer\optimizer.py", line 923, in step
    loss=None, startup_program=None, params_grads=params_grads)
  File "D:\Progect\ASUDIO\venv\lib\site-packages\paddle\optimizer\optimizer.py", line 774, in _apply_optimize
    self.regularization)
  File "D:\Progect\ASUDIO\venv\lib\site-packages\paddle\fluid\regularizer.py", line 90, in append_regularization_ops
    regularization)
  File "D:\Progect\ASUDIO\venv\lib\site-packages\paddle\fluid\regularizer.py", line 38, in _create_regularization_of_grad
    regularization_term = regularization(param, grad, grad.block)
  File "D:\Progect\ASUDIO\venv\lib\site-packages\paddle\fluid\regularizer.py", line 341, in __call__
    attrs={"scale": self._regularization_coeff})
  File "D:\Progect\ASUDIO\venv\lib\site-packages\paddle\fluid\framework.py", line 3018, in append_op
    kwargs.get("stop_gradient", False))
  File "D:\Progect\ASUDIO\venv\lib\site-packages\paddle\fluid\dygraph\tracer.py", line 45, in trace_op
    not stop_gradient)
RuntimeError: (PermissionDenied) Cannot set gradient op twice unless using Inplace Strategy.
  [Hint: Expected shared_node == nullptr, but received shared_node != nullptr.] (at D:\v2.0.2\paddle\paddle/fluid/imperative/variable_wrapper.h:265)
  [operator < scale > error]
W0430 16:17:38.330472 12912 device_context.cc:362] Please NOTE: device: 0, GPU Compute Capability: 7.5, Driver API Version: 11.0, Runtime API Version: 10.2
W0430 16:17:38.343436 12912 device_context.cc:372] device: 0, cuDNN Version: 7.6.

Process finished with exit code 1
@paddle-bot-old
Copy link

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网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!

@littletomatodonkey
Copy link
Contributor

你好,感谢反馈,已经在PR中修复了哈~

@Reatris
Copy link
Author

Reatris commented May 1, 2021

嗯,运行正常了~

@Reatris Reatris closed this as completed May 1, 2021
@paddle-bot-old
Copy link

paddle-bot-old bot commented May 1, 2021

Are you satisfied with the resolution of your issue?

YES
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants