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

[cherry-pick]Fix cuda12 test #54622

Merged
merged 3 commits into from
Jun 14, 2023
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
7 changes: 6 additions & 1 deletion test/legacy_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,12 @@ set(TEST_CINN_OPS
test_scatter_nd_op
test_strided_slice_op
test_instance_norm_op
test_cumsum_op)
test_cumsum_op
test_pad_op
test_split_op
test_erf_op
test_assign_op
test_flatten_contiguous_range_op)

foreach(TEST_CINN_OPS ${TEST_CINN_OPS})
if(WITH_CINN)
Expand Down
1 change: 0 additions & 1 deletion test/legacy_test/test_assign_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def setUp(self):
self.public_python_api = paddle.assign
self.op_type = "assign"
self.prim_op_type = "prim"
self.enable_cinn = False
x = np.random.uniform(0, 1, [100, 10]).astype(np.float32)
x = convert_float_to_uint16(x)
self.inputs = {'X': x}
Expand Down
25 changes: 3 additions & 22 deletions test/legacy_test/test_elementwise_min_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,43 +127,30 @@ def setUp(self):
self.inputs = {'X': x, 'Y': y}
self.outputs = {'Out': np.minimum(self.inputs['X'], self.inputs['Y'])}

def if_enable_cinn(self):
self.enable_cinn = False


class TestElementwiseMinFP16Op_ZeroDim1(TestElementwiseFP16Op):
def init_data(self):
self.x = np.random.uniform(0.1, 1, []).astype(np.float16)
self.y = np.random.uniform(0.1, 1, []).astype(np.float16)

def if_enable_cinn(self):
self.enable_cinn = False


class TestElementwiseMinOp_ZeroDim2(TestElementwiseOp):
def setUp(self):
self.op_type = "elementwise_min"
self.python_api = paddle.minimum
self.public_python_api = paddle.minimum
self.prim_op_type = "prim"
self.if_enable_cinn()
x = np.random.uniform(0.1, 1, [13, 17]).astype("float64")
y = np.random.uniform(0.1, 1, []).astype("float64")
self.inputs = {'X': x, 'Y': y}
self.outputs = {'Out': np.minimum(self.inputs['X'], self.inputs['Y'])}

def if_enable_cinn(self):
self.enable_cinn = False


class TestElementwiseMinFP16Op_ZeroDim2(TestElementwiseFP16Op):
def init_data(self):
self.x = np.random.uniform(0.1, 1, [13, 17]).astype("float16")
self.y = np.random.uniform(0.1, 1, []).astype("float16")

def if_enable_cinn(self):
self.enable_cinn = False


class TestElementwiseMinOp_ZeroDim3(TestElementwiseOp):
def setUp(self):
Expand All @@ -177,18 +164,12 @@ def setUp(self):
self.inputs = {'X': x, 'Y': y}
self.outputs = {'Out': np.minimum(self.inputs['X'], self.inputs['Y'])}

def if_enable_cinn(self):
self.enable_cinn = False


class TestElementwiseMinFP16Op_ZeroDim3(TestElementwiseFP16Op):
def init_data(self):
self.x = np.random.uniform(0.1, 1, []).astype("float16")
self.y = np.random.uniform(0.1, 1, [13, 17]).astype("float16")

def if_enable_cinn(self):
self.enable_cinn = False


@skip_check_grad_ci(
reason="[skip shape check] Use y_shape(1) to test broadcast."
Expand Down Expand Up @@ -388,7 +369,7 @@ def test_check_grad_normal(self):
def test_check_grad_ingore_x(self):
places = self._get_places()
for place in places:
if type(place) is paddle.fluid.libpaddle.CPUPlace:
if isinstance(place, paddle.fluid.libpaddle.CPUPlace):
check_prim = False
else:
check_prim = True
Expand All @@ -413,7 +394,7 @@ def test_check_grad_ingore_x(self):
def test_check_grad_ingore_y(self):
places = self._get_places()
for place in places:
if type(place) is paddle.fluid.libpaddle.CPUPlace:
if isinstance(place, paddle.fluid.libpaddle.CPUPlace):
check_prim = False
else:
check_prim = True
Expand All @@ -436,7 +417,7 @@ def test_check_grad_ingore_y(self):
)

def if_enable_cinn(self):
self.enable_cinn = False
pass


class TestElementwiseMinBF16Op_ZeroDim1(TestElementwiseBF16Op):
Expand Down
16 changes: 9 additions & 7 deletions test/legacy_test/test_erf_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ def _test_case(self, place):
np.testing.assert_allclose(y_ref, y_test, rtol=1e-05)

def test_case(self):
self._test_case(fluid.CPUPlace())
if fluid.is_compiled_with_cuda():
self._test_case(fluid.CUDAPlace(0))
with paddle.fluid.framework._static_guard():
self._test_case(fluid.CPUPlace())
if fluid.is_compiled_with_cuda():
self._test_case(fluid.CUDAPlace(0))

def test_name(self):
with fluid.program_guard(fluid.Program()):
x = paddle.static.data('x', [3, 4])
y = paddle.erf(x, name='erf')
self.assertTrue('erf' in y.name)
with paddle.fluid.framework._static_guard():
with fluid.program_guard(fluid.Program()):
x = paddle.static.data('x', [3, 4])
y = paddle.erf(x, name='erf')
self.assertTrue('erf' in y.name)


class TestErfFP16OP(OpTest):
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_fill_any_like_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_check_output(self):
self.check_output_with_place(place, check_prim=True)

def if_enable_cinn(self):
self.enable_cinn = False
pass


class TestFillAnyLikeOpValue1(TestFillAnyLikeOp):
Expand Down
29 changes: 25 additions & 4 deletions test/legacy_test/test_flatten_contiguous_range_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self):
self.prim_op_type = "comp"
self.start_axis = 0
self.stop_axis = -1
self.skip_cinn()
self.if_enable_cinn()
self.init_test_case()
self.init_test_dtype()
self.init_input_data()
Expand All @@ -40,8 +40,8 @@ def setUp(self):
"XShape": np.random.random(self.in_shape).astype("float32"),
}

def skip_cinn(self):
self.enable_cinn = True
def if_enable_cinn(self):
pass

def test_check_output(self):
if str(self.dtype) in {"float16", "uint16"}:
Expand Down Expand Up @@ -104,6 +104,9 @@ def init_test_dtype(self):
"core is not complied with CUDA and not support the bfloat16",
)
class TestFlattenBF16Op(TestFlattenOp):
def if_enable_cinn(self):
pass

def init_test_dtype(self):
self.dtype = "uint16"

Expand Down Expand Up @@ -142,6 +145,9 @@ def init_test_dtype(self):
"core is not complied with CUDA and not support the bfloat16",
)
class TestFlattenBF16Op_1(TestFlattenOp_1):
def if_enable_cinn(self):
pass

def init_test_dtype(self):
self.dtype = "uint16"

Expand Down Expand Up @@ -180,6 +186,9 @@ def init_test_dtype(self):
"core is not complied with CUDA and not support the bfloat16",
)
class TestFlattenBF16Op_2(TestFlattenOp_2):
def if_enable_cinn(self):
pass

def init_test_dtype(self):
self.dtype = "uint16"

Expand Down Expand Up @@ -218,6 +227,9 @@ def init_test_dtype(self):
"core is not complied with CUDA and not support the bfloat16",
)
class TestFlattenBF16Op_3(TestFlattenOp_3):
def if_enable_cinn(self):
pass

def init_test_dtype(self):
self.dtype = "uint16"

Expand Down Expand Up @@ -256,6 +268,9 @@ def init_test_dtype(self):
"core is not complied with CUDA and not support the bfloat16",
)
class TestFlattenBF16Op_4(TestFlattenOp_4):
def if_enable_cinn(self):
pass

def init_test_dtype(self):
self.dtype = "uint16"

Expand Down Expand Up @@ -294,6 +309,9 @@ def init_test_dtype(self):
"core is not complied with CUDA and not support the bfloat16",
)
class TestFlattenBF16Op_5(TestFlattenOp_5):
def if_enable_cinn(self):
pass

def init_test_dtype(self):
self.dtype = "uint16"

Expand All @@ -305,7 +323,7 @@ def init_test_case(self):
self.stop_axis = -1
self.new_shape = (1,)

def skip_cinn(self):
def if_enable_cinn(self):
self.enable_cinn = False

def init_attrs(self):
Expand Down Expand Up @@ -363,6 +381,9 @@ def init_test_dtype(self):
"core is not complied with CUDA and not support the bfloat16",
)
class TestFlattenBF16OpSixDims(TestFlattenOpSixDims):
def if_enable_cinn(self):
pass

def init_test_dtype(self):
self.dtype = "uint16"

Expand Down
14 changes: 11 additions & 3 deletions test/legacy_test/test_index_select_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import paddle
from paddle import fluid
from paddle.fluid import Program, program_guard
from paddle.fluid import Program, core, program_guard

np.random.seed(1024)

Expand Down Expand Up @@ -102,8 +102,11 @@ def init_dtype_type(self):
class TestIndexSelectBF16Op(OpTest):
def setUp(self):
self.python_api = paddle.index_select
self.public_python_api = paddle.index_select
self.prim_op_type = "comp"
self.op_type = "index_select"
self.init_dtype_type()
self.if_skip_cinn()
index_np = np.random.randint(
low=0, high=self.x_shape[self.dim], size=self.index_size
)
Expand All @@ -124,6 +127,9 @@ def setUp(self):
out = np.reshape(out_list, self.out_shape)
self.outputs = {'Out': convert_float_to_uint16(out)}

def if_skip_cinn(self):
self.enable_cinn = False

def init_dtype_type(self):
self.dim = 1
self.x_type = np.uint16
Expand All @@ -132,10 +138,12 @@ def init_dtype_type(self):
self.index_size = 100

def test_check_output(self):
self.check_output()
place = core.CUDAPlace(0)
self.check_output_with_place(place)

def test_check_grad_normal(self):
self.check_grad(['X'], 'Out')
place = core.CUDAPlace(0)
self.check_grad_with_place(place, ['X'], 'Out', check_prim=True)


class TestIndexSelectAPI(unittest.TestCase):
Expand Down
7 changes: 5 additions & 2 deletions test/legacy_test/test_pad_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_dtype(self):
return np.float16

def test_check_grad_normal(self):
self.check_grad(['X'], 'Out')
self.check_grad(['X'], 'Out', check_prim=True)

cls_name = "{}_{}".format(parent.__name__, "Fp16")
TestPadFp16.__name__ = cls_name
Expand Down Expand Up @@ -238,9 +238,12 @@ def setUp(self):
)
self.inputs = {'X': convert_float_to_uint16(x)}
self.outputs = {'Out': convert_float_to_uint16(out)}
self.enable_cinn = False
self.prim_op_type = "prim"
self.public_python_api = pad_wrapper
self.if_enable_cinn()

def if_enable_cinn(self):
pass

def initTestCase(self):
self.shape = (16, 16)
Expand Down
3 changes: 0 additions & 3 deletions test/legacy_test/test_roll_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ def test_check_output(self):
def test_check_grad_normal(self):
self.check_grad(['X'], 'Out', check_prim=True)

def test_check_grad(self):
self.check_grad(['X'], 'Out', check_prim=True)


class TestRollOpCase2(TestRollOp):
def init_dtype_type(self):
Expand Down
Loading