From 2d7262186761a3b3ee83e03d110966b3da687922 Mon Sep 17 00:00:00 2001 From: Wang Xin Date: Fri, 2 Feb 2024 07:16:26 +0000 Subject: [PATCH 1/2] [Cleanup][C-18] clean some Program.random_seed for test --- test/dygraph_to_static/test_word2vec.py | 3 +-- test/dygraph_to_static/test_yolov3.py | 2 -- test/legacy_test/test_weight_decay.py | 2 +- test/quantization/test_user_defined_quantization.py | 3 +-- test/quantization/test_weight_only_linear.py | 2 -- 5 files changed, 3 insertions(+), 9 deletions(-) diff --git a/test/dygraph_to_static/test_word2vec.py b/test/dygraph_to_static/test_word2vec.py index 2aa7fa919cf3a..e285965c5e1d1 100644 --- a/test/dygraph_to_static/test_word2vec.py +++ b/test/dygraph_to_static/test_word2vec.py @@ -284,8 +284,7 @@ def train(): base.CUDAPlace(0) if base.is_compiled_with_cuda() else base.CPUPlace() ) with base.dygraph.guard(place): - base.default_startup_program().random_seed = 1000 - base.default_main_program().random_seed = 1000 + paddle.seed(1000) skip_gram_model = paddle.jit.to_static( SkipGram("skip_gram_model", vocab_size, embedding_size) diff --git a/test/dygraph_to_static/test_yolov3.py b/test/dygraph_to_static/test_yolov3.py index cbbe828c6cfb5..74f20e7209bbd 100644 --- a/test/dygraph_to_static/test_yolov3.py +++ b/test/dygraph_to_static/test_yolov3.py @@ -86,8 +86,6 @@ def train(): random.seed(0) np.random.seed(0) - paddle.static.default_startup_program().random_seed = 1000 - paddle.static.default_main_program().random_seed = 1000 model = paddle.jit.to_static(YOLOv3(3, is_train=True)) boundaries = cfg.lr_steps diff --git a/test/legacy_test/test_weight_decay.py b/test/legacy_test/test_weight_decay.py index c237aa75fd8fd..a56ea5c06b6da 100644 --- a/test/legacy_test/test_weight_decay.py +++ b/test/legacy_test/test_weight_decay.py @@ -142,7 +142,7 @@ def check_weight_decay( ): main_prog = base.framework.Program() startup_prog = base.framework.Program() - startup_prog.random_seed = 1 + paddle.seed(1) with prog_scope_guard(main_prog=main_prog, startup_prog=startup_prog): data = paddle.static.data( name="words", shape=[-1, 1], dtype="int64", lod_level=1 diff --git a/test/quantization/test_user_defined_quantization.py b/test/quantization/test_user_defined_quantization.py index 9a26cc0b4a8fe..00ea81e99d1fe 100644 --- a/test/quantization/test_user_defined_quantization.py +++ b/test/quantization/test_user_defined_quantization.py @@ -99,8 +99,7 @@ def quantization_scale( weight_quantize_func=None, ): def build_program(main, startup, is_test): - main.random_seed = seed - startup.random_seed = seed + paddle.seed(seed) with paddle.utils.unique_name.guard(): with paddle.static.program_guard(main, startup): img = paddle.static.data( diff --git a/test/quantization/test_weight_only_linear.py b/test/quantization/test_weight_only_linear.py index f09698e4a1a68..5a2e32a4194b7 100644 --- a/test/quantization/test_weight_only_linear.py +++ b/test/quantization/test_weight_only_linear.py @@ -25,12 +25,10 @@ import paddle.nn.quant as Q from paddle import base from paddle.base import core -from paddle.base.framework import default_main_program from paddle.framework import set_default_dtype np.random.seed(123) paddle.seed(123) -default_main_program().random_seed = 42 def get_cuda_version(): From 177afe0d5c28ba7bd3d5b0c8fc2252cf7b5715e9 Mon Sep 17 00:00:00 2001 From: Wang Xin Date: Fri, 2 Feb 2024 09:00:06 +0000 Subject: [PATCH 2/2] fix bug --- test/dygraph_to_static/test_yolov3.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/dygraph_to_static/test_yolov3.py b/test/dygraph_to_static/test_yolov3.py index 74f20e7209bbd..1ad1b2f1d6d24 100644 --- a/test/dygraph_to_static/test_yolov3.py +++ b/test/dygraph_to_static/test_yolov3.py @@ -85,6 +85,7 @@ def generator(): def train(): random.seed(0) np.random.seed(0) + paddle.seed(1000) model = paddle.jit.to_static(YOLOv3(3, is_train=True))