-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Closed
Description
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
Metadata
Metadata
Assignees
Labels
No labels