From 419de39aa9938d94b84e86ceb228484e65664ed7 Mon Sep 17 00:00:00 2001 From: rewang Date: Mon, 4 Jul 2022 03:06:38 +0000 Subject: [PATCH 1/4] Fix test_functional_conv2d_transpose random seed --- .../fluid/tests/unittests/test_functional_conv2d_transpose.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/python/paddle/fluid/tests/unittests/test_functional_conv2d_transpose.py b/python/paddle/fluid/tests/unittests/test_functional_conv2d_transpose.py index d1b9c68925747c..dce6a37c6bbb8e 100644 --- a/python/paddle/fluid/tests/unittests/test_functional_conv2d_transpose.py +++ b/python/paddle/fluid/tests/unittests/test_functional_conv2d_transpose.py @@ -39,6 +39,7 @@ def setUp(self): self.groups = 1 self.no_bias = False self.data_format = "NHWC" + np.random.seed(2022) def prepare(self): if isinstance(self.filter_shape, int): @@ -188,6 +189,7 @@ def setUp(self): self.groups = 1 self.no_bias = False self.data_format = "NHWC" + np.random.seed(2022) def test_exception(self): self.prepare() From 909100f64e980ff18f0fc04aaf7ac192ce3ccee2 Mon Sep 17 00:00:00 2001 From: rewang Date: Mon, 4 Jul 2022 16:32:03 +0000 Subject: [PATCH 2/4] Fix random seed and use np.testing --- .../fluid/tests/unittests/test_variable.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_variable.py b/python/paddle/fluid/tests/unittests/test_variable.py index 87802b83415d6a..5fb220da609a43 100644 --- a/python/paddle/fluid/tests/unittests/test_variable.py +++ b/python/paddle/fluid/tests/unittests/test_variable.py @@ -30,6 +30,9 @@ class TestVariable(unittest.TestCase): + def setUp(self): + np.random.seed(2022) + def test_np_dtype_convert(self): DT = core.VarDesc.VarType convert = convert_np_dtype_to_dtype_ @@ -486,6 +489,9 @@ def test_detach(self): class TestVariableSlice(unittest.TestCase): + def setUp(self): + np.random.seed(2022) + def _test_item_none(self, place): data = np.random.rand(2, 3, 4).astype("float32") prog = paddle.static.Program() @@ -545,6 +551,9 @@ def test_slice(self): class TestListIndex(unittest.TestCase): + def setUp(self): + np.random.seed(2022) + def numel(self, shape): return reduce(lambda x, y: x * y, shape) @@ -723,10 +732,10 @@ def run_getitem_list_index(self, array, index): return getitem_pp = exe.run(prog, feed={x.name: array}, fetch_list=fetch_list) - print(getitem_pp) - self.assertTrue(np.array_equal(value_np, getitem_pp[0]), - msg='\n numpy:{},\n paddle:{}'.format( - value_np, getitem_pp[0])) + np.testing.assert_allclose(value_np, + getitem_pp[0], + rtol=1e-5, + atol=1e-8) def test_static_graph_getitem_bool_index(self): paddle.enable_static() @@ -791,9 +800,7 @@ def run_setitem_list_index(self, array, index, value_np): }, fetch_list=fetch_list) - self.assertTrue(np.allclose(array2, setitem_pp[0]), - msg='\n numpy:{},\n paddle:{}'.format( - array2, setitem_pp[0])) + np.testing.assert_allclose(array2, setitem_pp[0], rtol=1e-5, atol=1e-8) def test_static_graph_setitem_list_index(self): paddle.enable_static() From e5f804d9ceb0a7efecebdf49b73576729a3d07d1 Mon Sep 17 00:00:00 2001 From: rewang Date: Wed, 6 Jul 2022 02:50:22 +0000 Subject: [PATCH 3/4] Fix random seed for test_lu_unpack_op --- python/paddle/fluid/tests/unittests/test_lu_unpack_op.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/paddle/fluid/tests/unittests/test_lu_unpack_op.py b/python/paddle/fluid/tests/unittests/test_lu_unpack_op.py index 1757adef8e36fc..97773c70e177a4 100644 --- a/python/paddle/fluid/tests/unittests/test_lu_unpack_op.py +++ b/python/paddle/fluid/tests/unittests/test_lu_unpack_op.py @@ -190,6 +190,9 @@ def config(self): class TestLU_UnpackAPI(unittest.TestCase): + def setUp(self): + np.random.seed(2022) + def test_dygraph(self): def run_lu_unpack_dygraph(shape, dtype): From c53b9b777b0aac99f72b8526c1a0af719ebacd28 Mon Sep 17 00:00:00 2001 From: rewang Date: Thu, 14 Jul 2022 03:31:28 +0000 Subject: [PATCH 4/4] Fix test_autograd_functional_dynamic random seed --- .../tests/unittests/autograd/test_autograd_functional_dynamic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/paddle/fluid/tests/unittests/autograd/test_autograd_functional_dynamic.py b/python/paddle/fluid/tests/unittests/autograd/test_autograd_functional_dynamic.py index 6c67b78d6a5392..4b615804525922 100644 --- a/python/paddle/fluid/tests/unittests/autograd/test_autograd_functional_dynamic.py +++ b/python/paddle/fluid/tests/unittests/autograd/test_autograd_functional_dynamic.py @@ -676,4 +676,5 @@ def test_all_cases(self): if __name__ == "__main__": + np.random.seed(2022) unittest.main()