From 3374600ea0d5f9765179e7c19a5601e0f99b9112 Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Fri, 10 Feb 2023 13:59:09 +0800 Subject: [PATCH] [Dy2St]Fix func.__self__ problem in FunctionSpec (#50404) --- .../fluid/tests/unittests/dygraph_to_static/test_list.py | 4 +++- python/paddle/jit/dy2static/function_spec.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py index 3dc052cb58d..56f6add1552 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_list.py @@ -338,8 +338,10 @@ class ListWithCondNet(paddle.nn.Layer): def __init__(self): super().__init__() + # Add *args to test function.__self__ in FunctionSpec. + # DO NOT remove *args. @paddle.jit.to_static - def forward(self, x, index): + def forward(self, x, index, *args): y = paddle.nn.functional.relu(x) a = [] diff --git a/python/paddle/jit/dy2static/function_spec.py b/python/paddle/jit/dy2static/function_spec.py index 7db8dd2aad0..dd4e528259d 100644 --- a/python/paddle/jit/dy2static/function_spec.py +++ b/python/paddle/jit/dy2static/function_spec.py @@ -54,7 +54,7 @@ class FunctionSpec: # parse *args self.varargs_name = parse_varargs_name(function) if self.varargs_name is not None and isinstance( - function.__self__, TranslatedLayer + getattr(function, '__self__', None), TranslatedLayer ): self._arg_names += function.__self__._input_args_names -- GitLab