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 3dc052cb58d1e88ed4c4422310a213427dac8045..56f6add1552ea092683c3ca84a984f307772fa03 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 7db8dd2aad0c85753b303d3afb5673b9dedcedc6..dd4e528259de9b07ae0b0f17bf069d9dbb267994 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