From c638c4e3cad0e03ed6080330ee64a5ac760a6ef3 Mon Sep 17 00:00:00 2001 From: ooooo <3164076421@qq.com> Date: Sun, 17 Mar 2024 17:37:09 +0800 Subject: [PATCH 1/7] test_errors_d_23 --- test/legacy_test/test_randperm_op.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/legacy_test/test_randperm_op.py b/test/legacy_test/test_randperm_op.py index 9cb270801fece9..29ad737f1a0a46 100644 --- a/test/legacy_test/test_randperm_op.py +++ b/test/legacy_test/test_randperm_op.py @@ -19,6 +19,7 @@ import paddle from paddle.base import core +from paddle.pir_utils import test_with_pir_api from paddle.static import Program, program_guard @@ -156,6 +157,7 @@ def verify_output(self, outs): class TestRandpermOpError(unittest.TestCase): + @test_with_pir_api def test_errors(self): with program_guard(Program(), Program()): self.assertRaises(ValueError, paddle.randperm, -3) @@ -163,6 +165,7 @@ def test_errors(self): class TestRandpermAPI(unittest.TestCase): + @test_with_pir_api def test_out(self): n = 10 place = ( From 8011f6ba13f6f0b89027be3027484ae8bbbcf49e Mon Sep 17 00:00:00 2001 From: ooooo <3164076421@qq.com> Date: Sun, 17 Mar 2024 22:23:31 +0800 Subject: [PATCH 2/7] fix --- test/legacy_test/test_randperm_op.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/legacy_test/test_randperm_op.py b/test/legacy_test/test_randperm_op.py index 29ad737f1a0a46..44fe06ac7a4f52 100644 --- a/test/legacy_test/test_randperm_op.py +++ b/test/legacy_test/test_randperm_op.py @@ -160,7 +160,7 @@ class TestRandpermOpError(unittest.TestCase): @test_with_pir_api def test_errors(self): with program_guard(Program(), Program()): - self.assertRaises(ValueError, paddle.randperm, -3) + self.assertRaises(TypeError, paddle.randperm, -3) self.assertRaises(TypeError, paddle.randperm, 10, 'int8') From 83102afc4d746a13115c7f86aa143231c31833ac Mon Sep 17 00:00:00 2001 From: ooooo <3164076421@qq.com> Date: Sun, 17 Mar 2024 23:41:16 +0800 Subject: [PATCH 3/7] fix ValueError --- paddle/phi/infermeta/nullary.cc | 3 +++ test/legacy_test/test_randperm_op.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/paddle/phi/infermeta/nullary.cc b/paddle/phi/infermeta/nullary.cc index 5917a7a46b5ca9..247fca550bdd26 100644 --- a/paddle/phi/infermeta/nullary.cc +++ b/paddle/phi/infermeta/nullary.cc @@ -136,6 +136,9 @@ void PartialRecvInferMeta(int ring_id, } void RandpermInferMeta(int n, DataType dtype, MetaTensor* out) { + PADDLE_ENFORCE_GE( + n, 0, errors + : InvalidArgument("The upper bound %d isn't greater than 0.", n)) out->set_dims(common::make_ddim({n})); out->set_dtype(dtype); } diff --git a/test/legacy_test/test_randperm_op.py b/test/legacy_test/test_randperm_op.py index 44fe06ac7a4f52..29ad737f1a0a46 100644 --- a/test/legacy_test/test_randperm_op.py +++ b/test/legacy_test/test_randperm_op.py @@ -160,7 +160,7 @@ class TestRandpermOpError(unittest.TestCase): @test_with_pir_api def test_errors(self): with program_guard(Program(), Program()): - self.assertRaises(TypeError, paddle.randperm, -3) + self.assertRaises(ValueError, paddle.randperm, -3) self.assertRaises(TypeError, paddle.randperm, 10, 'int8') From 14ab72c917776e19d2a9a3fc12c42fff28d513d6 Mon Sep 17 00:00:00 2001 From: ooooo <3164076421@qq.com> Date: Sun, 17 Mar 2024 23:47:29 +0800 Subject: [PATCH 4/7] fix ValueError --- paddle/phi/infermeta/nullary.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/paddle/phi/infermeta/nullary.cc b/paddle/phi/infermeta/nullary.cc index 247fca550bdd26..31b6d66a999fa8 100644 --- a/paddle/phi/infermeta/nullary.cc +++ b/paddle/phi/infermeta/nullary.cc @@ -137,8 +137,9 @@ void PartialRecvInferMeta(int ring_id, void RandpermInferMeta(int n, DataType dtype, MetaTensor* out) { PADDLE_ENFORCE_GE( - n, 0, errors - : InvalidArgument("The upper bound %d isn't greater than 0.", n)) + n, + 0, + errors::InvalidArgument("The upper bound %d isn't greater than 0.", n)) out->set_dims(common::make_ddim({n})); out->set_dtype(dtype); } From 5ff4281436de1b1e3e9b6b2315656decc285a558 Mon Sep 17 00:00:00 2001 From: ooooo <3164076421@qq.com> Date: Sun, 17 Mar 2024 23:49:08 +0800 Subject: [PATCH 5/7] fix ValueError --- paddle/phi/infermeta/nullary.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/phi/infermeta/nullary.cc b/paddle/phi/infermeta/nullary.cc index 31b6d66a999fa8..8a4c6b55a56930 100644 --- a/paddle/phi/infermeta/nullary.cc +++ b/paddle/phi/infermeta/nullary.cc @@ -139,7 +139,7 @@ void RandpermInferMeta(int n, DataType dtype, MetaTensor* out) { PADDLE_ENFORCE_GE( n, 0, - errors::InvalidArgument("The upper bound %d isn't greater than 0.", n)) + errors::InvalidArgument("The upper bound %d isn't greater than 0.", n)); out->set_dims(common::make_ddim({n})); out->set_dtype(dtype); } From c13c74c254635d45daf97bd6700d53a8175a7ebd Mon Sep 17 00:00:00 2001 From: ooooo <3164076421@qq.com> Date: Mon, 18 Mar 2024 00:14:12 +0800 Subject: [PATCH 6/7] fix ge to gt --- paddle/phi/infermeta/nullary.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paddle/phi/infermeta/nullary.cc b/paddle/phi/infermeta/nullary.cc index 8a4c6b55a56930..b32b7fe2f88272 100644 --- a/paddle/phi/infermeta/nullary.cc +++ b/paddle/phi/infermeta/nullary.cc @@ -136,7 +136,7 @@ void PartialRecvInferMeta(int ring_id, } void RandpermInferMeta(int n, DataType dtype, MetaTensor* out) { - PADDLE_ENFORCE_GE( + PADDLE_ENFORCE_GT( n, 0, errors::InvalidArgument("The upper bound %d isn't greater than 0.", n)); From 9296fce9487dfe4a30a7b4c81cf509e32dbdb28d Mon Sep 17 00:00:00 2001 From: ooooo <3164076421@qq.com> Date: Mon, 18 Mar 2024 20:44:18 +0800 Subject: [PATCH 7/7] skip a case in pir_mode --- paddle/phi/infermeta/nullary.cc | 4 ---- test/legacy_test/test_randperm_op.py | 13 +++++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/paddle/phi/infermeta/nullary.cc b/paddle/phi/infermeta/nullary.cc index b32b7fe2f88272..5917a7a46b5ca9 100644 --- a/paddle/phi/infermeta/nullary.cc +++ b/paddle/phi/infermeta/nullary.cc @@ -136,10 +136,6 @@ void PartialRecvInferMeta(int ring_id, } void RandpermInferMeta(int n, DataType dtype, MetaTensor* out) { - PADDLE_ENFORCE_GT( - n, - 0, - errors::InvalidArgument("The upper bound %d isn't greater than 0.", n)); out->set_dims(common::make_ddim({n})); out->set_dtype(dtype); } diff --git a/test/legacy_test/test_randperm_op.py b/test/legacy_test/test_randperm_op.py index 29ad737f1a0a46..4d005f12be8bdf 100644 --- a/test/legacy_test/test_randperm_op.py +++ b/test/legacy_test/test_randperm_op.py @@ -19,8 +19,8 @@ import paddle from paddle.base import core +from paddle.base.framework import in_pir_mode from paddle.pir_utils import test_with_pir_api -from paddle.static import Program, program_guard def check_randperm_out(n, data_np): @@ -159,8 +159,11 @@ def verify_output(self, outs): class TestRandpermOpError(unittest.TestCase): @test_with_pir_api def test_errors(self): - with program_guard(Program(), Program()): - self.assertRaises(ValueError, paddle.randperm, -3) + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): + if not in_pir_mode(): + self.assertRaises(ValueError, paddle.randperm, -3) self.assertRaises(TypeError, paddle.randperm, 10, 'int8') @@ -173,7 +176,9 @@ def test_out(self): if core.is_compiled_with_cuda() else paddle.CPUPlace() ) - with program_guard(Program(), Program()): + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): x1 = paddle.randperm(n) x2 = paddle.randperm(n, 'float32')