diff --git a/python/paddle/fluid/dygraph/base.py b/python/paddle/fluid/dygraph/base.py index 92ddb3223dfea687bb0778fb23e8e2f95d9e92f4..1015cc5d9f23d2d9a9fd59204ca71990bb6d0bed 100644 --- a/python/paddle/fluid/dygraph/base.py +++ b/python/paddle/fluid/dygraph/base.py @@ -13,6 +13,7 @@ # limitations under the License. from ..wrapped_decorator import signature_safe_contextmanager, wrap_decorator import contextlib +import functools import sys import numpy as np from paddle.fluid import core @@ -195,6 +196,7 @@ def no_grad(func=None): return _switch_tracer_mode_guard_(is_train=False) else: + @functools.wraps(func) def __impl__(*args, **kwargs): with _switch_tracer_mode_guard_(is_train=False): return func(*args, **kwargs) diff --git a/python/paddle/fluid/tests/unittests/test_imperative_decorator.py b/python/paddle/fluid/tests/unittests/test_imperative_decorator.py index 504c4dbdb2a23083c335e1348042b629d91173d9..2c1481c890a514e37593e5d11495e9f97c01e645 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_decorator.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_decorator.py @@ -49,6 +49,7 @@ class TestTracerMode(unittest.TestCase): self.tracer._train_mode = self.init_mode self.assertEqual(self.no_grad_func(1), 1) + self.assertEqual(self.no_grad_func.__name__, "no_grad_func") self.assertEqual(self.tracer._train_mode, self.init_mode)