Skip to content

[Dy2stat] Fix function lookup bug in convert_call #24567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ def dyfunc(x):
if func.__name__ == '<lambda>':
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,10 @@ def func(x):

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(
Expand Down Expand Up @@ -472,7 +473,7 @@ def func(x):
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

Expand Down Expand Up @@ -573,6 +574,7 @@ def save_inference_model(self, dirname, feed=None, fetch=None):
import numpy as np
import paddle.fluid as fluid
from paddle.fluid.dygraph import Linear
from paddle.fluid.dygraph import declarative
from paddle.fluid.dygraph import ProgramTranslator

class SimpleNet(fluid.dygraph.Layer):
Expand Down