From fa15709d891903a0eeaf5d60a0cbc3030f64b7d4 Mon Sep 17 00:00:00 2001 From: coco <1228759711@qq.com> Date: Sat, 11 Nov 2023 15:25:07 +0000 Subject: [PATCH 1/5] pir fit for masked_select --- python/paddle/tensor/search.py | 22 ++++++++++------------ test/legacy_test/test_masked_select_op.py | 15 +++++++++------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/python/paddle/tensor/search.py b/python/paddle/tensor/search.py index 51f09119ef2e48..cd58e3444ae998 100755 --- a/python/paddle/tensor/search.py +++ b/python/paddle/tensor/search.py @@ -913,21 +913,19 @@ def masked_select(x, mask, name=None): >>> print(out.numpy()) [1. 5. 6. 9.] """ - - if in_dynamic_mode(): + check_variable_and_dtype( + x, + 'x', + ['float16', 'float32', 'float64', 'int32', 'int64', 'uint16'], + 'paddle.tensor.search.mask_select', + ) + check_variable_and_dtype( + mask, 'mask', ['bool'], 'paddle.tensor.search.masked_select' + ) + if in_dynamic_or_pir_mode(): return _C_ops.masked_select(x, mask) - else: helper = LayerHelper("masked_select", **locals()) - check_variable_and_dtype( - x, - 'x', - ['float16', 'float32', 'float64', 'int32', 'int64', 'uint16'], - 'paddle.tensor.search.mask_select', - ) - check_variable_and_dtype( - mask, 'mask', ['bool'], 'paddle.tensor.search.masked_select' - ) out = helper.create_variable_for_type_inference(dtype=x.dtype) helper.append_op( type='masked_select', diff --git a/test/legacy_test/test_masked_select_op.py b/test/legacy_test/test_masked_select_op.py index 954f3ffd1d9b6c..5f905487e6d3bf 100644 --- a/test/legacy_test/test_masked_select_op.py +++ b/test/legacy_test/test_masked_select_op.py @@ -16,6 +16,7 @@ import numpy as np from op_test import OpTest, convert_float_to_uint16 +from paddle.pir_utils import test_with_pir_api import paddle from paddle.base import core @@ -42,10 +43,10 @@ def setUp(self): self.outputs = {'Y': out} def test_check_output(self): - self.check_output() + self.check_output(check_pir=True) def test_check_grad(self): - self.check_grad(['X'], 'Y') + self.check_grad(['X'], 'Y', check_pir=True) def init(self): self.shape = (50, 3) @@ -77,10 +78,10 @@ def setUp(self): self.outputs = {'Y': out} def test_check_output(self): - self.check_output() + self.check_output(check_pir=True) def test_check_grad(self): - self.check_grad(['X'], 'Y') + self.check_grad(['X'], 'Y', check_pir=True) def init(self): self.shape = (50, 3) @@ -114,10 +115,10 @@ def setUp(self): self.outputs = {'Y': convert_float_to_uint16(out)} def test_check_output(self): - self.check_output_with_place(core.CUDAPlace(0)) + self.check_output_with_place(core.CUDAPlace(0), check_pir=True) def test_check_grad(self): - self.check_grad_with_place(core.CUDAPlace(0), ['X'], 'Y') + self.check_grad_with_place(core.CUDAPlace(0), ['X'], 'Y', check_pir=True) def init(self): self.shape = (50, 3) @@ -146,6 +147,7 @@ def test_imperative_mode(self): np.testing.assert_allclose(out.numpy(), np_out, rtol=1e-05) paddle.enable_static() + @test_with_pir_api def test_static_mode(self): shape = [8, 9, 6] x = paddle.static.data(shape=shape, dtype='float32', name='x') @@ -170,6 +172,7 @@ class TestMaskedSelectError(unittest.TestCase): def setUp(self): paddle.enable_static() + @test_with_pir_api def test_error(self): with paddle.static.program_guard( paddle.static.Program(), paddle.static.Program() From 0d4098fc54f06cb1b69b94c70db0ee8e87d00b14 Mon Sep 17 00:00:00 2001 From: coco <1228759711@qq.com> Date: Sun, 12 Nov 2023 15:27:48 +0800 Subject: [PATCH 2/5] codestyle --- test/legacy_test/test_masked_select_op.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/legacy_test/test_masked_select_op.py b/test/legacy_test/test_masked_select_op.py index 5f905487e6d3bf..6ba69d3e7604b7 100644 --- a/test/legacy_test/test_masked_select_op.py +++ b/test/legacy_test/test_masked_select_op.py @@ -16,10 +16,10 @@ import numpy as np from op_test import OpTest, convert_float_to_uint16 -from paddle.pir_utils import test_with_pir_api import paddle from paddle.base import core +from paddle.pir_utils import test_with_pir_api def np_masked_select(x, mask): @@ -118,7 +118,9 @@ def test_check_output(self): self.check_output_with_place(core.CUDAPlace(0), check_pir=True) def test_check_grad(self): - self.check_grad_with_place(core.CUDAPlace(0), ['X'], 'Y', check_pir=True) + self.check_grad_with_place( + core.CUDAPlace(0), ['X'], 'Y', check_pir=True + ) def init(self): self.shape = (50, 3) From ec74d7940098111260889b3673dfa369f51c86a7 Mon Sep 17 00:00:00 2001 From: coco <1228759711@qq.com> Date: Mon, 13 Nov 2023 15:59:25 +0000 Subject: [PATCH 3/5] reset check dtype --- python/paddle/tensor/search.py | 18 +++++++++--------- test/legacy_test/test_masked_select_op.py | 7 ++++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/python/paddle/tensor/search.py b/python/paddle/tensor/search.py index cd58e3444ae998..48a73400778eaf 100755 --- a/python/paddle/tensor/search.py +++ b/python/paddle/tensor/search.py @@ -913,18 +913,18 @@ def masked_select(x, mask, name=None): >>> print(out.numpy()) [1. 5. 6. 9.] """ - check_variable_and_dtype( - x, - 'x', - ['float16', 'float32', 'float64', 'int32', 'int64', 'uint16'], - 'paddle.tensor.search.mask_select', - ) - check_variable_and_dtype( - mask, 'mask', ['bool'], 'paddle.tensor.search.masked_select' - ) if in_dynamic_or_pir_mode(): return _C_ops.masked_select(x, mask) else: + check_variable_and_dtype( + x, + 'x', + ['float16', 'float32', 'float64', 'int32', 'int64', 'uint16'], + 'paddle.tensor.search.mask_select', + ) + check_variable_and_dtype( + mask, 'mask', ['bool'], 'paddle.tensor.search.masked_select' + ) helper = LayerHelper("masked_select", **locals()) out = helper.create_variable_for_type_inference(dtype=x.dtype) helper.append_op( diff --git a/test/legacy_test/test_masked_select_op.py b/test/legacy_test/test_masked_select_op.py index 5f905487e6d3bf..48325d9bc283be 100644 --- a/test/legacy_test/test_masked_select_op.py +++ b/test/legacy_test/test_masked_select_op.py @@ -16,10 +16,10 @@ import numpy as np from op_test import OpTest, convert_float_to_uint16 -from paddle.pir_utils import test_with_pir_api import paddle from paddle.base import core +from paddle.pir_utils import test_with_pir_api def np_masked_select(x, mask): @@ -118,7 +118,9 @@ def test_check_output(self): self.check_output_with_place(core.CUDAPlace(0), check_pir=True) def test_check_grad(self): - self.check_grad_with_place(core.CUDAPlace(0), ['X'], 'Y', check_pir=True) + self.check_grad_with_place( + core.CUDAPlace(0), ['X'], 'Y', check_pir=True + ) def init(self): self.shape = (50, 3) @@ -172,7 +174,6 @@ class TestMaskedSelectError(unittest.TestCase): def setUp(self): paddle.enable_static() - @test_with_pir_api def test_error(self): with paddle.static.program_guard( paddle.static.Program(), paddle.static.Program() From 58e54a46ceee2d9277a0b791c483719e2428faa1 Mon Sep 17 00:00:00 2001 From: coco <1228759711@qq.com> Date: Tue, 14 Nov 2023 05:59:55 +0000 Subject: [PATCH 4/5] rerun all ci --- python/paddle/tensor/linalg.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/paddle/tensor/linalg.py b/python/paddle/tensor/linalg.py index 3907bd12077db2..35d81d3c5290ee 100644 --- a/python/paddle/tensor/linalg.py +++ b/python/paddle/tensor/linalg.py @@ -3724,3 +3724,4 @@ def cdist( return paddle.linalg.norm( x[..., None, :] - y[..., None, :, :], p=p, axis=-1 ) + \ No newline at end of file From 868bb3d9b2ee75f57c37e0e89ca46a08cef1fd9e Mon Sep 17 00:00:00 2001 From: coco <1228759711@qq.com> Date: Tue, 14 Nov 2023 14:25:12 +0800 Subject: [PATCH 5/5] codestyle --- python/paddle/tensor/linalg.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/paddle/tensor/linalg.py b/python/paddle/tensor/linalg.py index 35d81d3c5290ee..3907bd12077db2 100644 --- a/python/paddle/tensor/linalg.py +++ b/python/paddle/tensor/linalg.py @@ -3724,4 +3724,3 @@ def cdist( return paddle.linalg.norm( x[..., None, :] - y[..., None, :, :], p=p, axis=-1 ) - \ No newline at end of file