diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/assert_transformer.py b/python/paddle/fluid/dygraph/dygraph_to_static/assert_transformer.py index 73dba66d3fca4f64bbe7e5ec763e541d664b9804..fe70fd1094f581caf0ae028bb63ec1dc155928fc 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/assert_transformer.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/assert_transformer.py @@ -37,8 +37,7 @@ class AssertTransformer(gast.NodeTransformer): def visit_Assert(self, node): convert_assert_node = gast.parse( - 'fluid.dygraph.dygraph_to_static.convert_operators.convert_assert({test}, {msg})'. - format( + 'paddle.jit.dy2static.convert_assert({test}, {msg})'.format( test=ast_to_source_code(node.test), msg=ast_to_source_code(node.msg) if node.msg else "")).body[0].value diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/call_transformer.py b/python/paddle/fluid/dygraph/dygraph_to_static/call_transformer.py index 7fc72d42759b0f8029ac6adfc7b9670fbffc67d5..c2481d16825ec8d5ed3903da0414b4b03ae92e03 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/call_transformer.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/call_transformer.py @@ -70,8 +70,7 @@ class CallTransformer(gast.NodeTransformer): if PDB_SET in func_str: return node - new_func_str = "fluid.dygraph.dygraph_to_static.convert_call({})".format( - func_str) + new_func_str = "paddle.jit.dy2static.convert_call({})".format(func_str) new_func_ast = gast.parse(new_func_str).body[0].value node.func = new_func_ast diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/cast_transformer.py b/python/paddle/fluid/dygraph/dygraph_to_static/cast_transformer.py index 71cb999eab0eb27935f876ad953a948881da267f..1171b5dbdfa22a21714de53ace9a8d11283bc013 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/cast_transformer.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/cast_transformer.py @@ -39,7 +39,7 @@ class CastTransformer(gast.NodeTransformer): func_str = ast_to_source_code(node.func).strip() if func_str in self._castable_type and len(node.args) > 0: args_str = ast_to_source_code(node.args[0]).strip() - new_func_str = "fluid.dygraph.dygraph_to_static.convert_operators.convert_var_dtype({}, '{}')".format( + new_func_str = "paddle.jit.dy2static.convert_var_dtype({}, '{}')".format( args_str, func_str) new_node = gast.parse(new_func_str).body[0].value return new_node diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/ifelse_transformer.py b/python/paddle/fluid/dygraph/dygraph_to_static/ifelse_transformer.py index 5b8e6d2a9bdf36d45582fcabba5a740f353f78ac..9c338546e233323ef50cb78c61907f803bf8cb17 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/ifelse_transformer.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/ifelse_transformer.py @@ -310,8 +310,8 @@ def parse_cond_return(parent_vars_dict, if_vars_dict, else_vars_dict, After transformed, q and z are created in parent scope. For example, x, y = 5, 10 - q = fluid.dygraph.dygraph_to_static.variable_trans_func.data_layer_not_check(name='q', shape=[-1], dtype='float32') - z = fluid.dygraph.dygraph_to_static.variable_trans_func.data_layer_not_check(name='z', shape=[-1], dtype='float32') + q = paddle.jit.dy2static.data_layer_not_check(name='q', shape=[-1], dtype='float32') + z = paddle.jit.dy2static.data_layer_not_check(name='z', shape=[-1], dtype='float32') def true_func(x, y, q): x = x+1 @@ -460,7 +460,7 @@ def create_convert_ifelse_node(return_name_ids, false_func, is_if_expr=False): """ - Create `fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( + Create `paddle.jit.dy2static.convert_ifelse( pred, true_fn, false_fn, true_args, false_args, return_vars)` to replace original `python if/else` statement. """ @@ -491,7 +491,7 @@ def create_convert_ifelse_node(return_name_ids, return_vars = create_name_nodes(return_name_ids) convert_ifelse_layer = gast.parse( - 'fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse(' + 'paddle.jit.dy2static.convert_ifelse(' '{pred}, {true_fn}, {false_fn}, {true_args}, {false_args}, {return_vars})'. format( pred=ast_to_source_code(pred), diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/list_transformer.py b/python/paddle/fluid/dygraph/dygraph_to_static/list_transformer.py index 03b0de99071c2d401d299905de974f0e0977b85e..9819f5fb72bbc48068629da93181f35d6087cecd 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/list_transformer.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/list_transformer.py @@ -188,8 +188,8 @@ class ListTransformer(gast.NodeTransformer): pass elif isinstance(slice_node, gast.Index): value_code = ast_to_source_code(node.value) - i = "fluid.layers.cast(" \ - "x=fluid.dygraph.dygraph_to_static.variable_trans_func.to_static_variable({})," \ + i = "paddle.cast(" \ + "x=paddle.jit.dy2static.to_static_variable({})," \ "dtype='int64')".format(ast_to_source_code(slice_node)) assign_code = "{} = fluid.layers.array_write(x={}, i={}, array={})" \ .format(target_name, value_code, i, target_name) diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/logical_transformer.py b/python/paddle/fluid/dygraph/dygraph_to_static/logical_transformer.py index d7af786ad75c7e7c4f1b5f8889c4d3ef44c2057e..8f3690f26fc23775480034f30f20d8afe358ddde 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/logical_transformer.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/logical_transformer.py @@ -34,7 +34,7 @@ class LogicalTransformer(gast.NodeTransformer): self.generic_visit(node) if isinstance(node.op, gast.Not): arg = ast_to_source_code(node.operand) - new_node_str = "fluid.dygraph.dygraph_to_static.convert_operators.convert_logical_not({})".format( + new_node_str = "paddle.jit.dy2static.convert_logical_not({})".format( arg) # NOTE: gast.parse returns Module(body=[expr(value=...)]) new_node = gast.parse(new_node_str).body[0].value @@ -67,7 +67,7 @@ class LogicalTransformer(gast.NodeTransformer): nodes = [pre_logic_node] + [post_logic_node] args = [ast_to_source_code(child) for child in nodes] - new_node_str = "fluid.dygraph.dygraph_to_static.convert_operators.convert_logical_{}(x={}, y={})".format( + new_node_str = "paddle.jit.dy2static.convert_logical_{}(x={}, y={})".format( api_type, args[0], args[1]) # NOTE: gast.parse return Module(body=[expr(...)]) new_node = gast.parse(new_node_str).body[0].value diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/loop_transformer.py b/python/paddle/fluid/dygraph/dygraph_to_static/loop_transformer.py index c66778992c25c68a5adf6a17ae0cd46b57b02fd6..0b6c7c45b3804fbf07d707995658fb17e3880d80 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/loop_transformer.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/loop_transformer.py @@ -46,7 +46,7 @@ def create_while_node(condition_name, body_name, loop_var_names): # For example: loop_var_names = [a, b, foo.x], the type of `a` or `b` is gast.Name, # but the type of `foo.x` gast.Attribute. - while_func_name = "fluid.dygraph.dygraph_to_static.convert_operators.convert_while_loop" + while_func_name = "paddle.jit.dy2static.convert_while_loop" while_node_str = "[{}] = {}({}, {}, [{}])".format( ",".join(loop_var_names), while_func_name, condition_name, body_name, ",".join(loop_var_names)) diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/print_transformer.py b/python/paddle/fluid/dygraph/dygraph_to_static/print_transformer.py index efde2481721f4f16f0ecadb1200b4abcde73e2b8..9d1ec35764b090cb786fef261e05eedd7f78247d 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/print_transformer.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/print_transformer.py @@ -51,6 +51,5 @@ class PrintTransformer(gast.NodeTransformer): def _create_print_node(self, print_args): convert_print_func = gast.parse( - 'fluid.dygraph.dygraph_to_static.convert_operators.convert_print' - ).body[0].value + 'paddle.jit.dy2static.convert_print').body[0].value return gast.Call(func=convert_print_func, args=print_args, keywords=[]) diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/tensor_shape_transformer.py b/python/paddle/fluid/dygraph/dygraph_to_static/tensor_shape_transformer.py index cad70f64c466f3ed61d65442230b246eacfd2a74..6cdf2799624586a55d9e02d2050b16ac7f5f36e1 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/tensor_shape_transformer.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/tensor_shape_transformer.py @@ -26,7 +26,7 @@ from paddle.fluid.dygraph.dygraph_to_static.static_analysis import StaticAnalysi def create_convert_shape_node(var_shape_node): assert isinstance(var_shape_node, (gast.Attribute, gast.Subscript)) - convert_var_shape_func = "fluid.dygraph.dygraph_to_static.convert_operators.convert_var_shape" + convert_var_shape_func = "paddle.jit.dy2static.convert_var_shape" if isinstance(var_shape_node, gast.Attribute): api_shape_node = gast.Call( diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/utils.py b/python/paddle/fluid/dygraph/dygraph_to_static/utils.py index 86593dc24aa8bda7906aab2001e8bd285f64288a..7a234580712ac15c946100ed60fc8e2d8849bd16 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/utils.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/utils.py @@ -427,7 +427,7 @@ def ast_to_func(ast_root, dyfunc, delete_on_exit=True): os.remove(filepath) source = ast_to_source_code(ast_root) - import_fluid = "import paddle.fluid as fluid\n" + import_fluid = "import paddle\nimport paddle.fluid as fluid\n" source = import_fluid + source if six.PY2: @@ -922,7 +922,7 @@ class ForNodeVisitor(object): else: iter_var_name = ast_to_source_code(self.iter_node).strip() - convert_len_node_source_str = '{} = fluid.dygraph.dygraph_to_static.convert_operators.convert_len({})'.format( + convert_len_node_source_str = '{} = paddle.jit.dy2static.convert_len({})'.format( self.iter_var_len_name, iter_var_name) convert_len_node = gast.parse(convert_len_node_source_str).body[0] diff --git a/python/paddle/fluid/dygraph/dygraph_to_static/variable_trans_func.py b/python/paddle/fluid/dygraph/dygraph_to_static/variable_trans_func.py index bc2851b630c1a4ff8af8802a0b984ab517b77387..8da7b40db4c6b7f732cdd66f3f1c5df483f463b1 100644 --- a/python/paddle/fluid/dygraph/dygraph_to_static/variable_trans_func.py +++ b/python/paddle/fluid/dygraph/dygraph_to_static/variable_trans_func.py @@ -22,8 +22,8 @@ from paddle.fluid.layers import fill_constant from paddle.fluid.layer_helper import LayerHelper __all__ = [ - 'to_static_variable_gast_node', 'create_static_variable_gast_node', - 'data_layer_not_check' + 'create_fill_constant_node', 'create_static_variable_gast_node', + 'data_layer_not_check', 'to_static_variable', 'to_static_variable_gast_node' ] @@ -74,20 +74,20 @@ def data_layer_not_check(name, shape, dtype='float32', lod_level=0): def to_static_variable_gast_node(name): - func_code = "{} = fluid.dygraph.dygraph_to_static.variable_trans_func\ - .to_static_variable({})".format(name, name) + func_code = "{} = paddle.jit.dy2static.to_static_variable({})".format(name, + name) return gast.parse(func_code).body[0] def create_static_variable_gast_node(name): - func_code = "{} = fluid.dygraph.dygraph_to_static.variable_trans_func\ + func_code = "{} = paddle.jit.dy2static\ .data_layer_not_check(name='{}', shape=[-1], dtype='float32')".format( name, name) return gast.parse(func_code).body[0] def create_fill_constant_node(name, value): - func_code = "{} = fluid.layers.fill_constant(shape=[1], ".format(name) + func_code = "{} = paddle.fill_constant(shape=[1], ".format(name) if isinstance(value, bool): func_code += "dtype='bool', value={})".format(value) return gast.parse(func_code).body[0] diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/ifelse_simple_func.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/ifelse_simple_func.py index 08d832b64a213fc217ae0baaba734ebfb58e9ceb..34d7b59a9b487b2424be8c9368b7dcc6dcbf59c0 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/ifelse_simple_func.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/ifelse_simple_func.py @@ -59,9 +59,9 @@ def dyfunc_with_if_else3(x): # The var is created only in one of If.body or If.orelse node, and it used as gast.Load firstly after gast.If node. # The transformed code: """ - q = fluid.dygraph.dygraph_to_static.variable_trans_func. + q = paddle.jit.dy2static. data_layer_not_check(name='q', shape=[-1], dtype='float32') - z = fluid.dygraph.dygraph_to_static.variable_trans_func. + z = paddle.jit.dy2static. data_layer_not_check(name='z', shape=[-1], dtype='float32') def true_fn_0(q, x, y): @@ -77,8 +77,8 @@ def dyfunc_with_if_else3(x): n = x + 3 return q, x, y, z q, x, y, z = fluid.layers.cond(fluid.layers.mean(x)[0] < 5, lambda : - fluid.dygraph.dygraph_to_static.convert_call(true_fn_0)(q, x, y), - lambda : fluid.dygraph.dygraph_to_static.convert_call(false_fn_0)(q, + paddle.jit.dy2static.convert_call(true_fn_0)(q, x, y), + lambda : paddle.jit.dy2static.convert_call(false_fn_0)(q, x, y)) """ y = x + 1 diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py index 3f77e9ade285e2c3d8452ea2171505442ee52fb0..144b16873aa9bc576338a71a7bc532e7df53aa4a 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_origin_info.py @@ -65,7 +65,7 @@ class TestOriginInfo(unittest.TestCase): self.func = simple_func def set_static_lineno(self): - self.static_abs_lineno_list = [2, 3, 4] + self.static_abs_lineno_list = [3, 4, 5] def set_dygraph_info(self): self.line_num = 3 @@ -149,7 +149,7 @@ class TestOriginInfoWithNestedFunc(TestOriginInfo): self.func = nested_func def set_static_lineno(self): - self.static_abs_lineno_list = [2, 4, 5, 6, 7] + self.static_abs_lineno_list = [3, 5, 6, 7, 8] def set_dygraph_info(self): self.line_num = 5 @@ -174,7 +174,7 @@ class TestOriginInfoWithDecoratedFunc(TestOriginInfo): self.func = decorated_func def set_static_lineno(self): - self.static_abs_lineno_list = [2, 3] + self.static_abs_lineno_list = [3, 4] def set_dygraph_info(self): self.line_num = 2 @@ -208,7 +208,7 @@ class TestOriginInfoWithDecoratedFunc2(TestOriginInfo): self.func = decorated_func2 def set_static_lineno(self): - self.static_abs_lineno_list = [2, 3] + self.static_abs_lineno_list = [3, 4] def set_dygraph_info(self): self.line_num = 2 diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py index b0ab55758ee7d9eeb5a9bd747934e6f7a1992f7b..b308854dc09a106e48a45fb016ac01a1bab4c234 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py @@ -64,11 +64,9 @@ def get_source_code(func): class StaticCode1(): # TODO: Transform return statement def dyfunc_with_if_else(x_v, label=None): - __return_1 = fluid.layers.fill_constant( - shape=[1], dtype='bool', value=False) - __return_0 = fluid.layers.fill_constant( - shape=[1], dtype='bool', value=False) - __return_value_init_0 = fluid.layers.fill_constant( + __return_1 = paddle.fill_constant(shape=[1], dtype='bool', value=False) + __return_0 = paddle.fill_constant(shape=[1], dtype='bool', value=False) + __return_value_init_0 = paddle.fill_constant( shape=[1], dtype='float64', value=0.0) __return_value_0 = __return_value_init_0 @@ -80,13 +78,13 @@ class StaticCode1(): x_v = x_v + 1 return x_v - x_v = fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( + x_v = paddle.jit.dy2static.convert_ifelse( fluid.layers.mean(x_v)[0] > 5, true_fn_0, false_fn_0, (x_v, ), (x_v, ), (x_v, )) def true_fn_1(__return_0, __return_value_0, label, x_v): loss = fluid.layers.cross_entropy(x_v, label) - __return_0 = fluid.layers.fill_constant( + __return_0 = paddle.fill_constant( shape=[1], dtype='bool', value=True) __return_value_0 = loss return __return_0, __return_value_0 @@ -94,14 +92,13 @@ class StaticCode1(): def false_fn_1(__return_0, __return_value_0): return __return_0, __return_value_0 - __return_0, __return_value_0 = ( - fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( - label is not None, true_fn_1, false_fn_1, - (__return_0, __return_value_0, label, x_v), - (__return_0, __return_value_0), (__return_0, __return_value_0))) + __return_0, __return_value_0 = (paddle.jit.dy2static.convert_ifelse( + label is not None, true_fn_1, false_fn_1, + (__return_0, __return_value_0, label, x_v), + (__return_0, __return_value_0), (__return_0, __return_value_0))) def true_fn_2(__return_1, __return_value_0, x_v): - __return_1 = fluid.layers.fill_constant( + __return_1 = paddle.fill_constant( shape=[1], dtype='bool', value=True) __return_value_0 = x_v return __return_1, __return_value_0 @@ -109,23 +106,19 @@ class StaticCode1(): def false_fn_2(__return_1, __return_value_0): return __return_1, __return_value_0 - __return_1, __return_value_0 = ( - fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( - fluid.dygraph.dygraph_to_static.convert_operators. - convert_logical_not(__return_0), true_fn_2, false_fn_2, - (__return_1, __return_value_0, x_v), - (__return_1, __return_value_0), (__return_1, __return_value_0))) + __return_1, __return_value_0 = (paddle.jit.dy2static.convert_ifelse( + paddle.jit.dy2static.convert_logical_not(__return_0), true_fn_2, + false_fn_2, (__return_1, __return_value_0, x_v), + (__return_1, __return_value_0), (__return_1, __return_value_0))) return __return_value_0 class StaticCode2(): # TODO: Transform return statement def dyfunc_with_if_else(x_v, label=None): - __return_3 = fluid.layers.fill_constant( - shape=[1], dtype='bool', value=False) - __return_2 = fluid.layers.fill_constant( - shape=[1], dtype='bool', value=False) - __return_value_init_1 = fluid.layers.fill_constant( + __return_3 = paddle.fill_constant(shape=[1], dtype='bool', value=False) + __return_2 = paddle.fill_constant(shape=[1], dtype='bool', value=False) + __return_value_init_1 = paddle.fill_constant( shape=[1], dtype='float64', value=0.0) __return_value_1 = __return_value_init_1 @@ -137,13 +130,13 @@ class StaticCode2(): x_v = x_v + 1 return x_v - x_v = fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( + x_v = paddle.jit.dy2static.convert_ifelse( fluid.layers.mean(x_v)[0] > 5, true_fn_3, false_fn_3, (x_v, ), (x_v, ), (x_v, )) def true_fn_4(__return_2, __return_value_1, label, x_v): loss = fluid.layers.cross_entropy(x_v, label) - __return_2 = fluid.layers.fill_constant( + __return_2 = paddle.fill_constant( shape=[1], dtype='bool', value=True) __return_value_1 = loss return __return_2, __return_value_1 @@ -151,14 +144,13 @@ class StaticCode2(): def false_fn_4(__return_2, __return_value_1): return __return_2, __return_value_1 - __return_2, __return_value_1 = ( - fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( - label is not None, true_fn_4, false_fn_4, - (__return_2, __return_value_1, label, x_v), - (__return_2, __return_value_1), (__return_2, __return_value_1))) + __return_2, __return_value_1 = (paddle.jit.dy2static.convert_ifelse( + label is not None, true_fn_4, false_fn_4, + (__return_2, __return_value_1, label, x_v), + (__return_2, __return_value_1), (__return_2, __return_value_1))) def true_fn_5(__return_3, __return_value_1, x_v): - __return_3 = fluid.layers.fill_constant( + __return_3 = paddle.fill_constant( shape=[1], dtype='bool', value=True) __return_value_1 = x_v return __return_3, __return_value_1 @@ -166,12 +158,10 @@ class StaticCode2(): def false_fn_5(__return_3, __return_value_1): return __return_3, __return_value_1 - __return_3, __return_value_1 = ( - fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( - fluid.dygraph.dygraph_to_static.convert_operators. - convert_logical_not(__return_2), true_fn_5, false_fn_5, - (__return_3, __return_value_1, x_v), - (__return_3, __return_value_1), (__return_3, __return_value_1))) + __return_3, __return_value_1 = (paddle.jit.dy2static.convert_ifelse( + paddle.jit.dy2static.convert_logical_not(__return_2), true_fn_5, + false_fn_5, (__return_3, __return_value_1, x_v), + (__return_3, __return_value_1), (__return_3, __return_value_1))) return __return_value_1 diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tensor_shape.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tensor_shape.py index 46d2b220414c4ec975824271272e0a92d3c057c4..de9554a2d4a53e36863b9ea4d534fe0087188ee5 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tensor_shape.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_tensor_shape.py @@ -52,7 +52,7 @@ def dyfunc_tensor_shape_4(x): def dyfunc_tensor_shape_5(x): # `res = fluid.layers.reshape(x, shape=(-1, s))` to # `res = fluid.layers.reshape(x, shape=(-1, - # fluid.dygraph.dygraph_to_static.convert_operators.convert_var_shape(x)[0]))` + # paddle.jit.dy2static.convert_var_shape(x)[0]))` x = fluid.dygraph.to_variable(x) s = x.shape[0] res = fluid.layers.reshape(x, shape=(-1, s)) @@ -65,7 +65,7 @@ def dyfunc_with_if_1(x): x_shape_0 = x.shape[0] if x_shape_0 < 1: # `res.shape[0]` is transformed into - # `fluid.dygraph.dygraph_to_static.convert_operators.convert_var_shape(res)[0]` + # `paddle.jit.dy2static.convert_var_shape(res)[0]` if res.shape[0] > 1: res = fluid.layers.fill_constant( value=2, shape=x.shape, dtype="int32") @@ -89,7 +89,7 @@ def dyfunc_with_if_2(x): def dyfunc_with_for_1(x): x = fluid.dygraph.to_variable(x) res = fluid.layers.fill_constant(value=0, shape=[1], dtype="int32") - # `x.shape[0]` is transformed into `fluid.dygraph.dygraph_to_static.convert_operators.convert_var_shape(x)[0]` + # `x.shape[0]` is transformed into `paddle.jit.dy2static.convert_var_shape(x)[0]` for i in range(x.shape[0]): res += 1 return res @@ -100,7 +100,7 @@ def dyfunc_with_for_2(x): x_shape_0 = x.shape[0] res = fluid.layers.fill_constant(value=0, shape=[1], dtype="int32") - # `x_shape_0` is transformed into `fluid.dygraph.dygraph_to_static.convert_operators.convert_var_shape(x)[0]` + # `x_shape_0` is transformed into `paddle.jit.dy2static.convert_var_shape(x)[0]` for i in range(x_shape_0): res += 1 return res @@ -124,7 +124,7 @@ def dyfunc_with_for_3(x): def dyfunc_with_while_1(x): x = fluid.dygraph.to_variable(x) res = fluid.layers.fill_constant(value=0, shape=[1], dtype="int32") - # `x.shape[0]` is transformed into `fluid.dygraph.dygraph_to_static.convert_operators.convert_var_shape(x)[0]` + # `x.shape[0]` is transformed into `paddle.jit.dy2static.convert_var_shape(x)[0]` i = 1 while i < x.shape[0]: res += 1 @@ -137,7 +137,7 @@ def dyfunc_with_while_2(x): x_shape_0 = x.shape[0] res = fluid.layers.fill_constant(value=0, shape=[1], dtype="int32") i = 1 - # `x_shape_0` is transformed into `fluid.dygraph.dygraph_to_static.convert_operators.convert_var_shape(x)[0]` + # `x_shape_0` is transformed into `paddle.jit.dy2static.convert_var_shape(x)[0]` while i < x_shape_0: res += 1 i = i + 2 diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_variable_trans_func.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_variable_trans_func.py index e7632a0ba8d52dc1b9158dc7283bbc6787407bdf..e79209cb538c0535acb23bfabc17dd25375fde84 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_variable_trans_func.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_variable_trans_func.py @@ -51,24 +51,24 @@ class TestDataLayerNotCheck(unittest.TestCase): class TestVariableTransFunc(unittest.TestCase): def test_create_fill_constant_node(self): node = create_fill_constant_node("a", 1.0) - source = "a = fluid.layers.fill_constant(shape=[1], dtype='float64', value=1.0)" + source = "a = paddle.fill_constant(shape=[1], dtype='float64', value=1.0)" self.assertEqual(ast_to_source_code(node).strip(), source) node = create_fill_constant_node("b", True) - source = "b = fluid.layers.fill_constant(shape=[1], dtype='bool', value=True)" + source = "b = paddle.fill_constant(shape=[1], dtype='bool', value=True)" self.assertEqual(ast_to_source_code(node).strip(), source) if six.PY2: node = create_fill_constant_node("c", 214) - source = "c = fluid.layers.fill_constant(shape=[1], dtype='int32', value=214)" + source = "c = paddle.fill_constant(shape=[1], dtype='int32', value=214)" self.assertEqual(ast_to_source_code(node).strip(), source) node = create_fill_constant_node("d", long(10086)) - source = "d = fluid.layers.fill_constant(shape=[1], dtype='int64', value=10086)" + source = "d = paddle.fill_constant(shape=[1], dtype='int64', value=10086)" self.assertEqual(ast_to_source_code(node).strip(), source) else: node = create_fill_constant_node("c", 4293) - source = "c = fluid.layers.fill_constant(shape=[1], dtype='int64', value=4293)" + source = "c = paddle.fill_constant(shape=[1], dtype='int64', value=4293)" self.assertEqual(ast_to_source_code(node).strip(), source) self.assertIsNone(create_fill_constant_node("e", None)) diff --git a/python/paddle/jit/__init__.py b/python/paddle/jit/__init__.py index d04a65ad6ea99ee2e2e67e47fd9d656f1572a02d..9e40cb18a00eaf8ddf52647544ae647927aa04b2 100644 --- a/python/paddle/jit/__init__.py +++ b/python/paddle/jit/__init__.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function + from ..fluid.dygraph.jit import save #DEFINE_ALIAS from ..fluid.dygraph.jit import load #DEFINE_ALIAS from ..fluid.dygraph.jit import TracedLayer #DEFINE_ALIAS @@ -21,6 +23,8 @@ from ..fluid.dygraph.jit import declarative as to_static #DEFINE_ALIAS from ..fluid.dygraph import ProgramTranslator #DEFINE_ALIAS from ..fluid.dygraph.io import TranslatedLayer #DEFINE_ALIAS +from . import dy2static + __all__ = [ 'save', 'load', 'TracedLayer', 'to_static', 'ProgramTranslator', 'TranslatedLayer', 'set_code_level', 'set_verbosity' diff --git a/python/paddle/jit/dy2static/__init__.py b/python/paddle/jit/dy2static/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..239b554180b1bd74517b152dfdf079082600b806 --- /dev/null +++ b/python/paddle/jit/dy2static/__init__.py @@ -0,0 +1,29 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function + +from . import convert_operators +from .convert_operators import * + +from . import convert_call_func +from .convert_call_func import * + +from . import variable_trans_func +from .variable_trans_func import * + +__all__ = [] +__all__ += convert_operators.__all__ +__all__ += convert_call_func.__all__ +__all__ += variable_trans_func.__all__ diff --git a/python/paddle/jit/dy2static/convert_call_func.py b/python/paddle/jit/dy2static/convert_call_func.py new file mode 100644 index 0000000000000000000000000000000000000000..be2377608e36c75d95cb2c1c609e99cef7d438a7 --- /dev/null +++ b/python/paddle/jit/dy2static/convert_call_func.py @@ -0,0 +1,18 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import print_function + +from ...fluid.dygraph.dygraph_to_static.convert_call_func import convert_call #DEFINE_ALIAS + +__all__ = ['convert_call'] diff --git a/python/paddle/jit/dy2static/convert_operators.py b/python/paddle/jit/dy2static/convert_operators.py new file mode 100644 index 0000000000000000000000000000000000000000..89df1d0aa77bd7055aa1967dbffe42482bb4f015 --- /dev/null +++ b/python/paddle/jit/dy2static/convert_operators.py @@ -0,0 +1,33 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import print_function + +from ...fluid.dygraph.dygraph_to_static.convert_operators import cast_bool_if_necessary #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_assert #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_ifelse #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_len #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_logical_and #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_logical_not #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_logical_or #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_print #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_var_dtype #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_var_shape #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_while_loop #DEFINE_ALIAS + +__all__ = [ + 'cast_bool_if_necessary', 'convert_assert', 'convert_ifelse', 'convert_len', + 'convert_logical_and', 'convert_logical_not', 'convert_logical_or', + 'convert_print', 'convert_var_dtype', 'convert_var_shape', + 'convert_while_loop' +] diff --git a/python/paddle/jit/dy2static/variable_trans_func.py b/python/paddle/jit/dy2static/variable_trans_func.py new file mode 100644 index 0000000000000000000000000000000000000000..08c057934a501fac86deb7afb7a8fffba1752f40 --- /dev/null +++ b/python/paddle/jit/dy2static/variable_trans_func.py @@ -0,0 +1,26 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function + +from ...fluid.dygraph.dygraph_to_static.variable_trans_func import create_fill_constant_node #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.variable_trans_func import create_static_variable_gast_node #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.variable_trans_func import data_layer_not_check #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.variable_trans_func import to_static_variable #DEFINE_ALIAS +from ...fluid.dygraph.dygraph_to_static.variable_trans_func import to_static_variable_gast_node #DEFINE_ALIAS + +__all__ = [ + 'create_fill_constant_node', 'create_static_variable_gast_node', + 'data_layer_not_check', 'to_static_variable', 'to_static_variable_gast_node' +] diff --git a/python/setup.py.in b/python/setup.py.in index 63cda05488a4d541e67a9aedefcb2e844804a008..414258a3b37561150380f5cd9898ad3c69fbd6c0 100644 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -156,6 +156,7 @@ packages=['paddle', 'paddle.distributed.fleet.utils', 'paddle.framework', 'paddle.jit', + 'paddle.jit.dy2static', 'paddle.inference', 'paddle.fluid', 'paddle.fluid.inference',