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

Open some test error uts in pir #63607

Merged
merged 3 commits into from
Apr 18, 2024
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
2 changes: 2 additions & 0 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,8 @@ def sum(x, axis=None, dtype=None, keepdim=False, name=None):
[
'bool',
'uint16',
'int8',
'uint8',
'float16',
'float32',
'float64',
Expand Down
16 changes: 12 additions & 4 deletions test/legacy_test/test_gather_nd_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,16 +613,14 @@ def check_raise_is_test():


class TestGatherNdError(unittest.TestCase):
def test_error(self):
@test_with_pir_api
def test_error1(self):
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
shape = [8, 9, 6]
x = paddle.static.data(shape=shape, dtype='float32', name='x')
index = paddle.static.data(shape=shape, dtype='bool', name='index')
index_float = paddle.static.data(
shape=shape, dtype='float32', name='index_float'
)
np_x = np.random.random(shape).astype('float32')
np_index = np.array(np.random.randint(2, size=shape, dtype=bool))

Expand All @@ -636,6 +634,16 @@ def test_index_type():

self.assertRaises(TypeError, test_index_type)

def test_error2(self):
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
shape = [8, 9, 6]
x = paddle.static.data(shape=shape, dtype='float32', name='x')
index_float = paddle.static.data(
shape=shape, dtype='float32', name='index_float'
)

def test_index_dtype():
paddle.gather_nd(x, index_float)

Expand Down
29 changes: 13 additions & 16 deletions test/legacy_test/test_reduce_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import paddle
from paddle import base
from paddle.base import Program, core, program_guard
from paddle.base import core
from paddle.base.framework import convert_np_dtype_to_dtype_, in_pir_mode
from paddle.pir_utils import test_with_pir_api

Expand Down Expand Up @@ -963,8 +963,11 @@ def test_check_output(self):


class TestAllOpError(unittest.TestCase):
@test_with_pir_api
def test_errors(self):
with program_guard(Program(), Program()):
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
# The input type of reduce_all_op must be Variable.
input1 = 12
self.assertRaises(TypeError, paddle.all, input1)
Expand Down Expand Up @@ -1121,8 +1124,11 @@ def test_check_output(self):


class TestAnyOpError(unittest.TestCase):
@test_with_pir_api
def test_errors(self):
with program_guard(Program(), Program()):
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
# The input type of reduce_any_op must be Variable.
input1 = 12
self.assertRaises(TypeError, paddle.any, input1)
Expand Down Expand Up @@ -1640,26 +1646,17 @@ def test_check_grad(self):


class TestReduceSumOpError(unittest.TestCase):
def test_errors(self):
def test_errors1(self):
with static_guard():
with program_guard(Program(), Program()):
# The input type of reduce_sum_op must be Variable.
x1 = base.create_lod_tensor(
np.array([[-1]]), [[1]], base.CPUPlace()
)
self.assertRaises(TypeError, paddle.sum, x1)
# The input dtype of reduce_sum_op must be float32 or float64 or int32 or int64.
x2 = paddle.static.data(name='x2', shape=[-1, 4], dtype="uint8")
self.assertRaises(TypeError, paddle.sum, x2)

with paddle.pir_utils.IrGuard(), program_guard(
Program(), Program()
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
# The input type of reduce_sum_op must be Variable.
x1 = base.create_lod_tensor(
np.array([[-1]]), [[1]], base.CPUPlace()
)
self.assertRaises(TypeError, paddle.sum, x1)
# The input dtype of reduce_sum_op must be float32 or float64 or int32 or int64.


class API_TestSumOp(unittest.TestCase):
Expand Down
13 changes: 5 additions & 8 deletions test/legacy_test/test_squeeze2_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import paddle
from paddle.base import core
from paddle.base.framework import Program, program_guard
from paddle.pir_utils import test_with_pir_api

paddle.enable_static()

Expand Down Expand Up @@ -284,16 +285,12 @@ def test_api(self):

paddle.enable_static()

@test_with_pir_api
def test_error(self):
def test_axes_type():
x2 = paddle.static.data(name="x2", shape=[2, 1, 25], dtype="int32")
self.squeeze(x2, axis=2.1)

self.assertRaises(TypeError, test_axes_type)

def test_pir_error(self):
def test_axes_type():
with paddle.pir_utils.IrGuard():
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):
x2 = paddle.static.data(
name="x2", shape=[2, 1, 25], dtype="int32"
)
Expand Down
2 changes: 2 additions & 0 deletions test/legacy_test/test_subtract_op.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


class ApiSubtractTest(unittest.TestCase):
Expand All @@ -39,6 +40,7 @@ def setUp(self):
self.np_expected3 = np.subtract(self.input_a, self.input_c)
self.np_expected4 = np.subtract(self.input_b, self.input_c)

@test_with_pir_api
def test_static_api(self):
paddle.enable_static()
with paddle.static.program_guard(
Expand Down