diff --git a/test/legacy_test/test_multiprocess_dataloader_dataset.py b/test/legacy_test/test_multiprocess_dataloader_dataset.py index bbf13e8f57d82..e23e73eb99bca 100755 --- a/test/legacy_test/test_multiprocess_dataloader_dataset.py +++ b/test/legacy_test/test_multiprocess_dataloader_dataset.py @@ -59,8 +59,7 @@ def __iter__(self): class TestTensorDataset(unittest.TestCase): def run_main(self, num_workers, places): - paddle.static.default_startup_program().random_seed = 1 - paddle.static.default_main_program().random_seed = 1 + paddle.seed(1) place = paddle.CPUPlace() with base.dygraph.guard(place): input_np = np.random.random([16, 3, 4]).astype('float32') @@ -98,8 +97,7 @@ def test_main(self): class TestComposeDataset(unittest.TestCase): def test_main(self): - paddle.static.default_startup_program().random_seed = 1 - paddle.static.default_main_program().random_seed = 1 + paddle.seed(1) dataset1 = RandomDataset(10) dataset2 = RandomDataset(10) @@ -118,8 +116,7 @@ def test_main(self): class TestRandomSplitApi(unittest.TestCase): def test_main(self): - paddle.static.default_startup_program().random_seed = 1 - paddle.static.default_main_program().random_seed = 1 + paddle.seed(1) dataset1, dataset2 = paddle.io.random_split(range(5), [1, 4]) @@ -139,8 +136,7 @@ def test_main(self): class TestRandomSplitError(unittest.TestCase): def test_errors(self): - paddle.static.default_startup_program().random_seed = 1 - paddle.static.default_main_program().random_seed = 1 + paddle.seed(1) self.assertRaises(ValueError, paddle.io.random_split, range(5), [3, 8]) self.assertRaises(ValueError, paddle.io.random_split, range(5), [8]) @@ -149,8 +145,7 @@ def test_errors(self): class TestSubsetDataset(unittest.TestCase): def run_main(self, num_workers, places): - paddle.static.default_startup_program().random_seed = 1 - paddle.static.default_main_program().random_seed = 1 + paddle.seed(1) input_np = np.random.random([5, 3, 4]).astype('float32') input = paddle.to_tensor(input_np) @@ -201,8 +196,7 @@ def assert_basic(input, label): self.assertEqual(odd_list, elements_list) def test_main(self): - paddle.static.default_startup_program().random_seed = 1 - paddle.static.default_main_program().random_seed = 1 + paddle.seed(1) places = [paddle.CPUPlace()] if paddle.is_compiled_with_cuda(): @@ -213,8 +207,7 @@ def test_main(self): class TestChainDataset(unittest.TestCase): def run_main(self, num_workers, places): - paddle.static.default_startup_program().random_seed = 1 - paddle.static.default_main_program().random_seed = 1 + paddle.seed(1) dataset1 = RandomIterableDataset(10) dataset2 = RandomIterableDataset(10) @@ -259,8 +252,7 @@ def __getitem__(self, idx): class TestNumpyMixTensorDataset(TestTensorDataset): def run_main(self, num_workers, places): - paddle.static.default_startup_program().random_seed = 1 - paddle.static.default_main_program().random_seed = 1 + paddle.seed(1) place = paddle.CPUPlace() with base.dygraph.guard(place): dataset = NumpyMixTensorDataset(16) @@ -304,8 +296,7 @@ def __getitem__(self, idx): class TestComplextDataset(unittest.TestCase): def run_main(self, num_workers): - paddle.static.default_startup_program().random_seed = 1 - paddle.static.default_main_program().random_seed = 1 + paddle.seed(1) place = paddle.CPUPlace() with base.dygraph.guard(place): dataset = ComplextDataset(16) @@ -360,8 +351,7 @@ def init_dataset(self): self.dataset = SingleFieldDataset(self.sample_num) def run_main(self, num_workers): - paddle.static.default_startup_program().random_seed = 1 - paddle.static.default_main_program().random_seed = 1 + paddle.seed(1) place = paddle.CPUPlace() with base.dygraph.guard(place): self.init_dataset() diff --git a/test/legacy_test/test_multiprocess_dataloader_dynamic.py b/test/legacy_test/test_multiprocess_dataloader_dynamic.py index 4620a5d32d111..8fed0972326ee 100644 --- a/test/legacy_test/test_multiprocess_dataloader_dynamic.py +++ b/test/legacy_test/test_multiprocess_dataloader_dynamic.py @@ -95,8 +95,7 @@ def run_main( collate_fn, use_shared_memory, ): - base.default_startup_program().random_seed = 1 - base.default_main_program().random_seed = 1 + paddle.seed(1) with base.dygraph.guard(places[0]): fc_net = SimpleFCNet() optimizer = paddle.optimizer.Adam(parameters=fc_net.parameters()) @@ -176,8 +175,7 @@ def run_main( collate_fn, use_shared_memory, ): - base.default_startup_program().random_seed = 1 - base.default_main_program().random_seed = 1 + paddle.seed(1) with base.dygraph.guard(places[0]): fc_net = SimpleFCNet() optimizer = paddle.optimizer.Adam(parameters=fc_net.parameters()) diff --git a/test/legacy_test/test_multiprocess_dataloader_iterable_dataset_dynamic.py b/test/legacy_test/test_multiprocess_dataloader_iterable_dataset_dynamic.py index 164a6531d3ecc..58b07c981d75e 100644 --- a/test/legacy_test/test_multiprocess_dataloader_iterable_dataset_dynamic.py +++ b/test/legacy_test/test_multiprocess_dataloader_iterable_dataset_dynamic.py @@ -77,8 +77,7 @@ def forward(self, image): class TestDygraphDataLoader(unittest.TestCase): def run_main(self, num_workers, places, persistent_workers): - base.default_startup_program().random_seed = 1 - base.default_main_program().random_seed = 1 + paddle.seed(1) with base.dygraph.guard(places[0]): fc_net = SimpleFCNet() optimizer = paddle.optimizer.Adam(parameters=fc_net.parameters()) @@ -146,8 +145,7 @@ def test_main(self): class TestDygraphDataLoaderWithBatchedDataset(TestDygraphDataLoader): def run_main(self, num_workers, places, persistent_workers): - base.default_startup_program().random_seed = 1 - base.default_main_program().random_seed = 1 + paddle.seed(1) with base.dygraph.guard(places[0]): fc_net = SimpleFCNet() optimizer = paddle.optimizer.Adam(parameters=fc_net.parameters()) diff --git a/test/legacy_test/test_multiprocess_dataloader_iterable_dataset_static.py b/test/legacy_test/test_multiprocess_dataloader_iterable_dataset_static.py index 845f4b0e80582..78b8cd803fdc9 100644 --- a/test/legacy_test/test_multiprocess_dataloader_iterable_dataset_static.py +++ b/test/legacy_test/test_multiprocess_dataloader_iterable_dataset_static.py @@ -47,8 +47,7 @@ def __iter__(self): def simple_fc_net_static(): startup_prog = base.Program() main_prog = base.Program() - startup_prog.random_seed = 1 - main_prog.random_seed = 1 + paddle.seed(1) with base.unique_name.guard(): with base.program_guard(main_prog, startup_prog): diff --git a/test/legacy_test/test_multiprocess_dataloader_static.py b/test/legacy_test/test_multiprocess_dataloader_static.py index 2d465fd818df0..b01a2fa6605f2 100644 --- a/test/legacy_test/test_multiprocess_dataloader_static.py +++ b/test/legacy_test/test_multiprocess_dataloader_static.py @@ -47,8 +47,7 @@ def __len__(self): def simple_fc_net_static(): startup_prog = base.Program() main_prog = base.Program() - startup_prog.random_seed = 1 - main_prog.random_seed = 1 + paddle.seed(1) with base.unique_name.guard(): with base.program_guard(main_prog, startup_prog):