From a4131ff6b37bc47e23f36e734f49ddf4392d260b Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Tue, 19 Mar 2024 21:45:21 +0800 Subject: [PATCH 1/6] supper normal --- python/paddle/tensor/random.py | 6 +++--- test/legacy_test/test_zero_dim_no_backward_api.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/python/paddle/tensor/random.py b/python/paddle/tensor/random.py index 551fa2336e8d19..8ad8d65907cad0 100644 --- a/python/paddle/tensor/random.py +++ b/python/paddle/tensor/random.py @@ -763,8 +763,8 @@ def normal(mean=0.0, std=1.0, shape=None, name=None): if shape is not None: check_shape(shape, 'normal') - if isinstance(mean, Variable): - if isinstance(std, Variable): + if isinstance(mean, (Variable, paddle.pir.Value)): + if isinstance(std, (Variable, paddle.pir.Value)): if std.dtype != mean.dtype: std = paddle.cast(std, mean.dtype) mean_shape = paddle.shape(mean) @@ -772,7 +772,7 @@ def normal(mean=0.0, std=1.0, shape=None, name=None): else: std = float(std) out = standard_normal(paddle.shape(mean), mean.dtype, name) - elif isinstance(std, Variable): + elif isinstance(std, (Variable, paddle.pir.Value)): mean = float(mean) out = standard_normal(paddle.shape(std), std.dtype, name) else: diff --git a/test/legacy_test/test_zero_dim_no_backward_api.py b/test/legacy_test/test_zero_dim_no_backward_api.py index 8709ae92f8aaba..6582d4b3ee6806 100644 --- a/test/legacy_test/test_zero_dim_no_backward_api.py +++ b/test/legacy_test/test_zero_dim_no_backward_api.py @@ -313,6 +313,7 @@ def test_arange(self): )[0] np.testing.assert_array_equal(res, [1.0, 2.0, 3.0, 4.0, 5.0]) + @test_with_pir_api def test_normal(self): mean = paddle.full([], 0.0) std = paddle.full([], 0.0) From 389755ec558216a0db90bc88c3de9e49cfe2c739 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Tue, 19 Mar 2024 23:12:46 +0800 Subject: [PATCH 2/6] add checktype and open test_normal --- python/paddle/tensor/random.py | 14 +++++++++----- test/legacy_test/test_normal.py | 15 ++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/python/paddle/tensor/random.py b/python/paddle/tensor/random.py index 8ad8d65907cad0..a35e2430748931 100644 --- a/python/paddle/tensor/random.py +++ b/python/paddle/tensor/random.py @@ -741,10 +741,14 @@ def normal(mean=0.0, std=1.0, shape=None, name=None): [0.48646951, 0.00815189, 3.74022293]) >>> # doctest: -SKIP """ - if not in_dynamic_or_pir_mode(): - check_type(mean, 'mean', (int, float, Variable), 'normal') - check_type(std, 'std', (int, float, Variable), 'normal') - if isinstance(mean, Variable): + if not in_dynamic_mode(): + check_type( + mean, 'mean', (int, float, Variable, paddle.pir.Value), 'normal' + ) + check_type( + std, 'std', (int, float, Variable, paddle.pir.Value), 'normal' + ) + if isinstance(mean, (Variable, paddle.pir.Value)): check_dtype( mean.dtype, 'mean', @@ -752,7 +756,7 @@ def normal(mean=0.0, std=1.0, shape=None, name=None): 'normal', "If mean is Tensor, it's data type only support float32, float64.", ) - if isinstance(std, Variable): + if isinstance(std, (Variable, paddle.pir.Value)): check_dtype( std.dtype, 'std', diff --git a/test/legacy_test/test_normal.py b/test/legacy_test/test_normal.py index d03e311f8c1c31..bdb9dbcade24bb 100644 --- a/test/legacy_test/test_normal.py +++ b/test/legacy_test/test_normal.py @@ -18,6 +18,7 @@ import numpy as np import paddle +from paddle.pir_utils import test_with_pir_api np.random.seed(10) paddle.seed(10) @@ -62,10 +63,11 @@ def static_api(self): ret_all_shape = copy.deepcopy(shape) ret_all_shape.insert(0, self.repeat_num) ret_all = np.zeros(ret_all_shape, self.dtype) + main_program = paddle.static.Program() if isinstance(self.mean, np.ndarray) and isinstance( self.std, np.ndarray ): - with paddle.static.program_guard(paddle.static.Program()): + with paddle.static.program_guard(main_program): mean = paddle.static.data( 'Mean', self.mean.shape, self.mean.dtype ) @@ -84,7 +86,7 @@ def static_api(self): ret_all[i] = ret[0] return ret_all elif isinstance(self.mean, np.ndarray): - with paddle.static.program_guard(paddle.static.Program()): + with paddle.static.program_guard(main_program): mean = paddle.static.data( 'Mean', self.mean.shape, self.mean.dtype ) @@ -96,7 +98,7 @@ def static_api(self): ret_all[i] = ret[0] return ret_all elif isinstance(self.std, np.ndarray): - with paddle.static.program_guard(paddle.static.Program()): + with paddle.static.program_guard(main_program): std = paddle.static.data('Std', self.std.shape, self.std.dtype) out = paddle.normal(self.mean, std, self.shape) @@ -106,7 +108,7 @@ def static_api(self): ret_all[i] = ret[0] return ret_all else: - with paddle.static.program_guard(paddle.static.Program()): + with paddle.static.program_guard(main_program): out = paddle.normal(self.mean, self.std, self.shape) exe = paddle.static.Executor(self.place) @@ -138,6 +140,7 @@ def dygraph_api(self): paddle.enable_static() return ret_all + @test_with_pir_api def test_api(self): ret_static = self.static_api() ret_dygraph = self.dygraph_api() @@ -185,6 +188,7 @@ def set_attrs(self): class TestNormalAlias(unittest.TestCase): + @test_with_pir_api def test_alias(self): paddle.disable_static() shape = [1, 2, 3] @@ -196,7 +200,8 @@ def test_alias(self): class TestNormalErrors(unittest.TestCase): def test_errors(self): - with paddle.static.program_guard(paddle.static.Program()): + main_program = paddle.static.Program() + with paddle.static.program_guard(main_program): mean = [1, 2, 3] self.assertRaises(TypeError, paddle.normal, mean) From b7d790fdab72d24a0bca33f8f78ab768d101397c Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 20 Mar 2024 00:02:52 +0800 Subject: [PATCH 3/6] add test_error --- test/legacy_test/test_normal.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/legacy_test/test_normal.py b/test/legacy_test/test_normal.py index bdb9dbcade24bb..84a8926debeead 100644 --- a/test/legacy_test/test_normal.py +++ b/test/legacy_test/test_normal.py @@ -199,6 +199,7 @@ def test_alias(self): class TestNormalErrors(unittest.TestCase): + @test_with_pir_api def test_errors(self): main_program = paddle.static.Program() with paddle.static.program_guard(main_program): From d7feced2846bf869741e3c3862231041890db8c5 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 20 Mar 2024 08:05:43 +0800 Subject: [PATCH 4/6] rename test --- test/legacy_test/{test_normal.py => test_normal1.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/legacy_test/{test_normal.py => test_normal1.py} (100%) diff --git a/test/legacy_test/test_normal.py b/test/legacy_test/test_normal1.py similarity index 100% rename from test/legacy_test/test_normal.py rename to test/legacy_test/test_normal1.py From 65c09633a7b906a174bae7db027d7994719114df Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 20 Mar 2024 08:37:08 +0800 Subject: [PATCH 5/6] rename again --- test/legacy_test/CMakeLists.txt | 2 +- tools/parallel_UT_rule.py | 4 ++-- tools/static_mode_white_list.py | 2 +- tools/windows/run_unittests.sh | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/legacy_test/CMakeLists.txt b/test/legacy_test/CMakeLists.txt index 2f729cc1f3b9dd..7998a33a0cd044 100644 --- a/test/legacy_test/CMakeLists.txt +++ b/test/legacy_test/CMakeLists.txt @@ -1093,7 +1093,7 @@ set_tests_properties(test_imperative_optimizer_v2 PROPERTIES TIMEOUT 250) set_tests_properties(test_pool2d_op PROPERTIES TIMEOUT 120) set_tests_properties(test_transpose_op PROPERTIES TIMEOUT 120) set_tests_properties(test_activation_op PROPERTIES TIMEOUT 270) -set_tests_properties(test_normal PROPERTIES TIMEOUT 120) +set_tests_properties(test_normal1 PROPERTIES TIMEOUT 120) set_tests_properties(test_bilinear_interp_op PROPERTIES TIMEOUT 120) set_tests_properties(test_decoupled_py_reader PROPERTIES TIMEOUT 120) set_tests_properties(test_fuse_bn_act_pass PROPERTIES TIMEOUT 120) diff --git a/tools/parallel_UT_rule.py b/tools/parallel_UT_rule.py index ef2eb620eddda0..cfab503f47e707 100755 --- a/tools/parallel_UT_rule.py +++ b/tools/parallel_UT_rule.py @@ -1167,7 +1167,7 @@ 'test_elementwise_sub_op', 'test_compare_op', 'test_simnet', - 'test_normal', + 'test_normal1', 'test_tensor_scalar_type_promotion_static', 'test_trt_group_norm_op', 'test_learning_rate_scheduler', @@ -2695,7 +2695,7 @@ 'test_grid_sample_function', 'test_huber_loss_op', 'test_one_hot_op', - 'test_normal', + 'test_normal1', 'test_imperative_auto_prune', 'test_nn_grad', 'test_nearest_interp_op', diff --git a/tools/static_mode_white_list.py b/tools/static_mode_white_list.py index 48f7178fa23dca..c10a8e14f1330d 100755 --- a/tools/static_mode_white_list.py +++ b/tools/static_mode_white_list.py @@ -341,7 +341,7 @@ 'test_norm_all', 'test_norm_nn_grad', 'test_norm_op', - 'test_normal', + 'test_normal1', 'test_normalization_wrapper', 'test_npair_loss_op', 'test_numel_op', diff --git a/tools/windows/run_unittests.sh b/tools/windows/run_unittests.sh index f99f7c8cc58e7a..9c91a443b3dd58 100644 --- a/tools/windows/run_unittests.sh +++ b/tools/windows/run_unittests.sh @@ -484,7 +484,7 @@ long_time_test="^test_gru_op$|\ ^test_nearest_interp_v2_op$|\ ^test_nn_grad$|\ ^test_norm_nn_grad$|\ -^test_normal$|\ +^test_normal1$|\ ^test_pool3d_op$|\ ^test_static_save_load$|\ ^test_trilinear_interp_op$|\ From b2f12fe40504ed1ebef7874e863047a529d0becc Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Wed, 20 Mar 2024 19:07:28 +0800 Subject: [PATCH 6/6] RollBACK test name --- test/legacy_test/CMakeLists.txt | 2 +- test/legacy_test/{test_normal1.py => test_normal.py} | 0 tools/parallel_UT_rule.py | 4 ++-- tools/static_mode_white_list.py | 2 +- tools/windows/run_unittests.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename test/legacy_test/{test_normal1.py => test_normal.py} (100%) diff --git a/test/legacy_test/CMakeLists.txt b/test/legacy_test/CMakeLists.txt index 7998a33a0cd044..2f729cc1f3b9dd 100644 --- a/test/legacy_test/CMakeLists.txt +++ b/test/legacy_test/CMakeLists.txt @@ -1093,7 +1093,7 @@ set_tests_properties(test_imperative_optimizer_v2 PROPERTIES TIMEOUT 250) set_tests_properties(test_pool2d_op PROPERTIES TIMEOUT 120) set_tests_properties(test_transpose_op PROPERTIES TIMEOUT 120) set_tests_properties(test_activation_op PROPERTIES TIMEOUT 270) -set_tests_properties(test_normal1 PROPERTIES TIMEOUT 120) +set_tests_properties(test_normal PROPERTIES TIMEOUT 120) set_tests_properties(test_bilinear_interp_op PROPERTIES TIMEOUT 120) set_tests_properties(test_decoupled_py_reader PROPERTIES TIMEOUT 120) set_tests_properties(test_fuse_bn_act_pass PROPERTIES TIMEOUT 120) diff --git a/test/legacy_test/test_normal1.py b/test/legacy_test/test_normal.py similarity index 100% rename from test/legacy_test/test_normal1.py rename to test/legacy_test/test_normal.py diff --git a/tools/parallel_UT_rule.py b/tools/parallel_UT_rule.py index cfab503f47e707..ef2eb620eddda0 100755 --- a/tools/parallel_UT_rule.py +++ b/tools/parallel_UT_rule.py @@ -1167,7 +1167,7 @@ 'test_elementwise_sub_op', 'test_compare_op', 'test_simnet', - 'test_normal1', + 'test_normal', 'test_tensor_scalar_type_promotion_static', 'test_trt_group_norm_op', 'test_learning_rate_scheduler', @@ -2695,7 +2695,7 @@ 'test_grid_sample_function', 'test_huber_loss_op', 'test_one_hot_op', - 'test_normal1', + 'test_normal', 'test_imperative_auto_prune', 'test_nn_grad', 'test_nearest_interp_op', diff --git a/tools/static_mode_white_list.py b/tools/static_mode_white_list.py index c10a8e14f1330d..48f7178fa23dca 100755 --- a/tools/static_mode_white_list.py +++ b/tools/static_mode_white_list.py @@ -341,7 +341,7 @@ 'test_norm_all', 'test_norm_nn_grad', 'test_norm_op', - 'test_normal1', + 'test_normal', 'test_normalization_wrapper', 'test_npair_loss_op', 'test_numel_op', diff --git a/tools/windows/run_unittests.sh b/tools/windows/run_unittests.sh index 9c91a443b3dd58..f99f7c8cc58e7a 100644 --- a/tools/windows/run_unittests.sh +++ b/tools/windows/run_unittests.sh @@ -484,7 +484,7 @@ long_time_test="^test_gru_op$|\ ^test_nearest_interp_v2_op$|\ ^test_nn_grad$|\ ^test_norm_nn_grad$|\ -^test_normal1$|\ +^test_normal$|\ ^test_pool3d_op$|\ ^test_static_save_load$|\ ^test_trilinear_interp_op$|\