Skip to content
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

Fix random seed for several unit tests #44135

Merged
merged 4 commits into from
Jul 15, 2022
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 @@ -676,4 +676,5 @@ def test_all_cases(self):


if __name__ == "__main__":
np.random.seed(2022)
unittest.main()
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions python/paddle/fluid/tests/unittests/test_lu_unpack_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
21 changes: 14 additions & 7 deletions python/paddle/fluid/tests/unittests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down