Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【PIR API adaptor No.192、308】 Migrate searchsorted, tensordot into pir #60014

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion python/paddle/tensor/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4723,7 +4723,9 @@ def tensordot(x, y, axes=2, name=None):

check_variable_and_dtype(x, 'x', input_dtype, op_type)
check_variable_and_dtype(y, 'y', input_dtype, op_type)
check_type(axes, 'axes', (int, tuple, list, Variable), op_type)
check_type(
axes, 'axes', (int, tuple, list, Variable, paddle.pir.Value), op_type
)

def _var_to_list(var):
if in_dynamic_mode():
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/tensor/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ def searchsorted(
[1, 3, 4, 5]])

"""
if in_dynamic_mode():
if in_dynamic_or_pir_mode():
return _C_ops.searchsorted(sorted_sequence, values, out_int32, right)
else:
check_variable_and_dtype(
Expand Down
6 changes: 5 additions & 1 deletion test/legacy_test/test_searchsorted_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import paddle
from paddle.base import core
from paddle.pir_utils import test_with_pir_api

paddle.enable_static()

Expand All @@ -42,7 +43,7 @@ def setUp(self):
}

def test_check_output(self):
self.check_output()
self.check_output(check_pir=True)

def init_test_case(self):
self.sorted_sequence = np.array([1, 3, 5, 7, 9]).astype("float32")
Expand Down Expand Up @@ -102,6 +103,7 @@ def setUp(self):
if core.is_compiled_with_cuda():
self.place.append(paddle.CUDAPlace(0))

@test_with_pir_api
def test_static_api(self):
paddle.enable_static()

Expand Down Expand Up @@ -154,6 +156,7 @@ def test_out_int32(self):


class TestSearchSortedError(unittest.TestCase):
@test_with_pir_api
def test_error_api(self):
paddle.enable_static()

Expand Down Expand Up @@ -201,6 +204,7 @@ def test_searchsorted_sortedsequence_size_error():
RuntimeError, test_searchsorted_sortedsequence_size_error
)

def test_check_type_error(self):
def test_sortedsequence_values_type_error():
with paddle.static.program_guard(paddle.static.Program()):
sorted_sequence = paddle.static.data(
Expand Down
3 changes: 3 additions & 0 deletions test/legacy_test/test_tensordot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import paddle
from paddle.base import core
from paddle.pir_utils import test_with_pir_api

np.random.seed(2021)

Expand Down Expand Up @@ -205,6 +206,7 @@ def test_dygraph(self):
np_res = tensordot_np(self.x, self.y, axes)
np.testing.assert_allclose(paddle_res, np_res, rtol=1e-6)

@test_with_pir_api
def test_static(self):
paddle.enable_static()
for axes in self.all_axes:
Expand All @@ -226,6 +228,7 @@ def test_static(self):
np_res = tensordot_np(self.x, self.y, axes)
np.testing.assert_allclose(paddle_res[0], np_res, rtol=1e-6)

@test_with_pir_api
def test_fp16_with_gpu(self):
paddle.enable_static()
if paddle.base.core.is_compiled_with_cuda():
Expand Down