未验证 提交 4839aca2 编写于 作者: X xiongkun 提交者: GitHub

fix bug in convert call: tranform the static func. (#46278)

上级 1fab8908
...@@ -42,7 +42,7 @@ from paddle.fluid.dygraph.dygraph_to_static.utils import func_to_source_code ...@@ -42,7 +42,7 @@ from paddle.fluid.dygraph.dygraph_to_static.utils import func_to_source_code
from paddle.fluid.dygraph.dygraph_to_static.utils import input_specs_compatible from paddle.fluid.dygraph.dygraph_to_static.utils import input_specs_compatible
from paddle.fluid.dygraph.dygraph_to_static.utils import type_name from paddle.fluid.dygraph.dygraph_to_static.utils import type_name
from paddle.fluid.dygraph.dygraph_to_static.utils import unwrap from paddle.fluid.dygraph.dygraph_to_static.utils import unwrap
from paddle.fluid.dygraph.dygraph_to_static.utils import make_hashable from paddle.fluid.dygraph.dygraph_to_static.utils import make_hashable, ALREADY_D2S
from paddle.fluid.dygraph.dygraph_to_static.function_spec import FunctionSpec, _hash_spec_names from paddle.fluid.dygraph.dygraph_to_static.function_spec import FunctionSpec, _hash_spec_names
from paddle.fluid.dygraph.dygraph_to_static.function_spec import get_buffers, get_parameters from paddle.fluid.dygraph.dygraph_to_static.function_spec import get_buffers, get_parameters
from paddle.fluid.wrapped_decorator import signature_safe_contextmanager from paddle.fluid.wrapped_decorator import signature_safe_contextmanager
...@@ -136,8 +136,11 @@ def convert_to_static(function): ...@@ -136,8 +136,11 @@ def convert_to_static(function):
Args: Args:
function(callable): The function with dygraph layers that will be converted into static layers. function(callable): The function with dygraph layers that will be converted into static layers.
""" """
if getattr(function, ALREADY_D2S, None):
return function
with _CACHE_LOCK: with _CACHE_LOCK:
static_func = _FUNCTION_CACHE.convert_with_cache(function) static_func = _FUNCTION_CACHE.convert_with_cache(function)
setattr(static_func, ALREADY_D2S, True)
return static_func return static_func
......
...@@ -44,6 +44,7 @@ DYGRAPH_MODULE_PREFIX = 'paddle.fluid.dygraph' ...@@ -44,6 +44,7 @@ DYGRAPH_MODULE_PREFIX = 'paddle.fluid.dygraph'
DYGRAPH_TO_STATIC_MODULE_PREFIX = 'paddle.fluid.dygraph.dygraph_to_static' DYGRAPH_TO_STATIC_MODULE_PREFIX = 'paddle.fluid.dygraph.dygraph_to_static'
GET_ARGS_FUNC_PREFIX = 'get_args' GET_ARGS_FUNC_PREFIX = 'get_args'
SET_ARGS_FUNC_PREFIX = 'set_args' SET_ARGS_FUNC_PREFIX = 'set_args'
ALREADY_D2S = '__already_d2s'
ARGS_NAME = '__args' ARGS_NAME = '__args'
# NOTE(liym27): Please use `getattr(ast_node, ORIGI_INFO)` instead of . operation to get the original information of ast node. # NOTE(liym27): Please use `getattr(ast_node, ORIGI_INFO)` instead of . operation to get the original information of ast node.
ORIGI_INFO = "Original information of source code for ast node." ORIGI_INFO = "Original information of source code for ast node."
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册