From 628ddcf378ba74114e325b2311e8c687da1427bd Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Tue, 14 Mar 2023 10:33:45 +0800 Subject: [PATCH] [Dy2St]Fix is_paddle_func not take effect for plain paddle API (#51585) * Fix is_paddle_func not take effect for plain paddle API * fix typo * fix typo --- .../unittests/dygraph_to_static/test_convert_call.py | 1 + python/paddle/jit/dy2static/utils.py | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_convert_call.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_convert_call.py index 49e976cd0e..e0b887acf4 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_convert_call.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_convert_call.py @@ -270,6 +270,7 @@ class TestNotToConvert2(TestRecursiveCall2): # Situation 3 : test to_static for paddle api +@paddle.jit.not_to_static def forward(self, x): if x.shape[0] > 1: x = x + 1 diff --git a/python/paddle/jit/dy2static/utils.py b/python/paddle/jit/dy2static/utils.py index 496e75914b..34d628c1d3 100644 --- a/python/paddle/jit/dy2static/utils.py +++ b/python/paddle/jit/dy2static/utils.py @@ -327,19 +327,15 @@ def is_paddle_func(func, ignore_white_list=True): func = func.func func_name = getattr(func, '__name__', None) - # In case of dynamically monkey patch customised function - # into paddle class obj, so we consider its class module - # path as prefix. - if hasattr(func, "__self__"): - func = func.__self__ - func_name = func.__class__.__name__ - elif inspect.ismethod(func): + if inspect.ismethod(func): + func_name = func.__self__.__class__.__name__ func = func.__func__ m = inspect.getmodule(func) flag = m is not None and m.__name__.startswith(PADDLE_MODULE_PREFIX) if ignore_white_list: flag = flag and not in_white_list(m, func_name) + return flag except Exception: return False -- GitLab