From a1a95f8108f56526f1dcd81a2d3ff1853f688155 Mon Sep 17 00:00:00 2001 From: songyouwei Date: Thu, 9 Apr 2020 22:15:54 +0800 Subject: [PATCH] fix no_grad signature (#23600) * fix no_grad signature test=develop * check func name instead of doc test=develop --- python/paddle/fluid/dygraph/base.py | 2 ++ .../paddle/fluid/tests/unittests/test_imperative_decorator.py | 1 + 2 files changed, 3 insertions(+) diff --git a/python/paddle/fluid/dygraph/base.py b/python/paddle/fluid/dygraph/base.py index 92ddb3223df..1015cc5d9f2 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 504c4dbdb2a..2c1481c890a 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) -- GitLab