From e025b70155639e434b71f1e63d438de2915fe234 Mon Sep 17 00:00:00 2001 From: gfwm2013 <2449465946@qq.com> Date: Wed, 9 Sep 2020 08:57:01 +0000 Subject: [PATCH 1/3] Refine the unittest to support py38 test=develop --- python/paddle/fluid/tests/unittests/test_device_guard.py | 2 -- python/paddle/fluid/tests/unittests/test_gather_op.py | 2 +- .../paddle/fluid/tests/unittests/test_save_model_without_var.py | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_device_guard.py b/python/paddle/fluid/tests/unittests/test_device_guard.py index eb8861f1bc462e..277244e8836472 100644 --- a/python/paddle/fluid/tests/unittests/test_device_guard.py +++ b/python/paddle/fluid/tests/unittests/test_device_guard.py @@ -133,7 +133,6 @@ def test_without_kernel_op(self): i = fluid.layers.increment(x=i, value=1, in_place=True) fluid.layers.less_than(x=i, y=loop_len, cond=cond) - assert len(w) == 1 all_ops = main_program.global_block().ops device_attr_name = core.op_proto_and_checker_maker.kOpDeviceAttrName() for op in all_ops: @@ -169,7 +168,6 @@ def test_warning(self): shape=[1], value=4.0, dtype='float32') result = fluid.layers.less_than(x=x, y=y, force_cpu=False) - assert len(w) == 2 all_ops = main_program.global_block().ops device_attr_name = core.op_proto_and_checker_maker.kOpDeviceAttrName() for op in all_ops: diff --git a/python/paddle/fluid/tests/unittests/test_gather_op.py b/python/paddle/fluid/tests/unittests/test_gather_op.py index 1f6e522d2668b5..5dcce88acf16b9 100644 --- a/python/paddle/fluid/tests/unittests/test_gather_op.py +++ b/python/paddle/fluid/tests/unittests/test_gather_op.py @@ -216,7 +216,7 @@ def test_out2(self): "index": index_np, 'axis': axis_np}, fetch_list=[out]) - expected_output = gather_numpy(x_np, index_np, axis_np) + expected_output = gather_numpy(x_np, index_np, axis_np[0]) self.assertTrue(np.allclose(result, expected_output)) diff --git a/python/paddle/fluid/tests/unittests/test_save_model_without_var.py b/python/paddle/fluid/tests/unittests/test_save_model_without_var.py index b74a6e10917f71..4c63dced83b199 100644 --- a/python/paddle/fluid/tests/unittests/test_save_model_without_var.py +++ b/python/paddle/fluid/tests/unittests/test_save_model_without_var.py @@ -50,7 +50,7 @@ def test_no_var_save(self): params_filename='params') expected_warn = "no variable in your model, please ensure there are any variables in your model to save" self.assertTrue(len(w) > 0) - self.assertTrue(expected_warn == str(w[0].message)) + self.assertTrue(expected_warn == str(w[-1].message)) if __name__ == '__main__': From 53305b5671a588e6d1871c98adb214fc0cb244a6 Mon Sep 17 00:00:00 2001 From: gfwm2013 <2449465946@qq.com> Date: Thu, 10 Sep 2020 02:17:01 +0000 Subject: [PATCH 2/3] Refine the unittest to support py38 test=develop --- .../fluid/tests/unittests/test_device_guard.py | 16 ++++++++++++++++ .../tests/unittests/test_imperative_mnist.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/tests/unittests/test_device_guard.py b/python/paddle/fluid/tests/unittests/test_device_guard.py index 277244e8836472..330065ecd92f15 100644 --- a/python/paddle/fluid/tests/unittests/test_device_guard.py +++ b/python/paddle/fluid/tests/unittests/test_device_guard.py @@ -33,6 +33,14 @@ def execute(main_program, startup_program): exe.run(main_program) +def get_vaild_warning_num(warning, w): + num = 0 + for i in range(len(w)): + if warning in str(w[i].message): + num += 1 + return num + + class TestDeviceGuard(unittest.TestCase): def test_device_guard(self): main_program = fluid.Program() @@ -133,6 +141,10 @@ def test_without_kernel_op(self): i = fluid.layers.increment(x=i, value=1, in_place=True) fluid.layers.less_than(x=i, y=loop_len, cond=cond) + warning = "The Op(while) is not support to set device." + warning_num = get_vaild_warning_num(warning, w) + assert warning_num == 1 + all_ops = main_program.global_block().ops device_attr_name = core.op_proto_and_checker_maker.kOpDeviceAttrName() for op in all_ops: @@ -168,6 +180,10 @@ def test_warning(self): shape=[1], value=4.0, dtype='float32') result = fluid.layers.less_than(x=x, y=y, force_cpu=False) + warning = "\'device_guard\' has higher priority when they are used at the same time." + warning_num = get_vaild_warning_num(warning, w) + assert warning_num == 2 + all_ops = main_program.global_block().ops device_attr_name = core.op_proto_and_checker_maker.kOpDeviceAttrName() for op in all_ops: diff --git a/python/paddle/fluid/tests/unittests/test_imperative_mnist.py b/python/paddle/fluid/tests/unittests/test_imperative_mnist.py index 1e509960c07633..c0112d9fb92ed2 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_mnist.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_mnist.py @@ -26,7 +26,7 @@ from paddle.fluid.dygraph.nn import Conv2D, Pool2D, Linear from paddle.fluid.dygraph.base import to_variable from test_imperative_base import new_program_scope -from utils import DyGraphProgramDescTracerTestHelper, is_equal_program +from .utils import DyGraphProgramDescTracerTestHelper, is_equal_program class SimpleImgConvPool(fluid.dygraph.Layer): From 365ff2473394841047fdca58911ddedd75092013 Mon Sep 17 00:00:00 2001 From: gfwm2013 <2449465946@qq.com> Date: Thu, 10 Sep 2020 02:57:45 +0000 Subject: [PATCH 3/3] Refine the unittest to support py38 test=develop --- python/paddle/fluid/tests/unittests/test_imperative_mnist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/paddle/fluid/tests/unittests/test_imperative_mnist.py b/python/paddle/fluid/tests/unittests/test_imperative_mnist.py index c0112d9fb92ed2..1e509960c07633 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_mnist.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_mnist.py @@ -26,7 +26,7 @@ from paddle.fluid.dygraph.nn import Conv2D, Pool2D, Linear from paddle.fluid.dygraph.base import to_variable from test_imperative_base import new_program_scope -from .utils import DyGraphProgramDescTracerTestHelper, is_equal_program +from utils import DyGraphProgramDescTracerTestHelper, is_equal_program class SimpleImgConvPool(fluid.dygraph.Layer):