From 34735e96dde5d623ddde73b54a71ee9a55ddbfbd Mon Sep 17 00:00:00 2001 From: zhhsplendid <zhhsplendid@163.com> Date: Mon, 21 Sep 2020 14:56:30 +0000 Subject: [PATCH] Fix unittest, test=develop --- .../dygraph_to_static/test_origin_info.py | 8 ++-- .../test_program_translator.py | 40 +++++++++---------- .../test_variable_trans_func.py | 10 ++--- 3 files changed, 27 insertions(+), 31 deletions(-) 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 3f77e9ade2..144b16873a 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 873d9ecb53..d1134e40a3 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 @@ -63,11 +63,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 @@ -79,13 +77,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.dygraph_to_static.convert_operators.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,13 +92,13 @@ class StaticCode1(): return __return_0, __return_value_0 __return_0, __return_value_0 = ( - fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( + paddle.jit.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))) 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,8 +107,8 @@ class StaticCode1(): 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. + paddle.jit.dygraph_to_static.convert_operators.convert_ifelse( + paddle.jit.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))) @@ -120,11 +118,9 @@ class StaticCode1(): 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 @@ -136,13 +132,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.dygraph_to_static.convert_operators.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,13 +147,13 @@ class StaticCode2(): return __return_2, __return_value_1 __return_2, __return_value_1 = ( - fluid.dygraph.dygraph_to_static.convert_operators.convert_ifelse( + paddle.jit.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))) 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,8 +162,8 @@ class StaticCode2(): 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. + paddle.jit.dygraph_to_static.convert_operators.convert_ifelse( + paddle.jit.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))) 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 e7632a0ba8..e79209cb53 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)) -- GitLab