diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py b/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py index 5aa0ffb3e4da5b2ef53dbcd6149f9e714cb2aa48..1532d5be3775309b2eb9062ecac144a7847a6ab8 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/convert_call_func.py @@ -102,7 +102,10 @@ def convert_call(func): if func.__name__ == '': return func try: - if func in func.__globals__.values(): + global_funcs = set([ + fn for fn in func.__globals__.values() if inspect.isfunction(fn) + ]) + if func in global_funcs: converted_call = to_static_func(func) func_self = getattr(func, '__self__', None) except AttributeError: diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/program_translator.py b/python/paddle/fluid/dygraph/dygraph_to_static/program_translator.py index 908250666ed8c174c838b8bfc6a61bc19fa05ba9..b8730b6af80642017c71152ee80ab55f4180eedd 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/program_translator.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/program_translator.py @@ -368,9 +368,10 @@ class ProgramTranslator(object): prog_trans = fluid.dygraph.ProgramTranslator() - x = np.ones([1, 2]) - x_v = prog_trans.get_output(func, x) - print(x_v.numpy()) # [[0. 0.]] + with fluid.dygraph.guard(): + x = np.ones([1, 2]) + x_v = prog_trans.get_output(func, x) + print(x_v.numpy()) # [[0. 0.]] """ assert callable( @@ -472,7 +473,7 @@ class ProgramTranslator(object): x = np.ones([1, 2]) main_prog, start_prog, inputs, outputs = prog_trans.get_program(func, x) print([i.name for i in inputs]) - # ['x_0'] the feed input variable name representing x + # ['feed_0'] the feed input variable name representing x print([o.name for o in outputs]) # ['_generated_var_4'] the fetch output variable name representing x_v