PaddlePaddle / Paddle

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

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

Closed Reatris closed 3 years ago

Reatris commented 3 years ago

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[bot] commented 3 years ago

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

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

Reatris commented 3 years ago

嗯,运行正常了~

paddle-bot-old[bot] commented 3 years ago

Are you satisfied with the resolution of your issue?

YES No