未验证 提交 4745234f 编写于 作者: z8hanghuan's avatar z8hanghuan 提交者: GitHub

new way of test case, 2nd, *test=kunlun (#39478)

* new way of test case, 2nd, *test=kunlun

* new way of test case, 2nd, *test=kunlun

* new way of test case, 2nd, *test=kunlun
上级 7e7e9404
...@@ -36,7 +36,7 @@ ENDIF() ...@@ -36,7 +36,7 @@ ENDIF()
if(NOT DEFINED XPU_BASE_URL) if(NOT DEFINED XPU_BASE_URL)
SET(XPU_BASE_URL_WITHOUT_DATE "https://baidu-kunlun-product.cdn.bcebos.com/KL-SDK/klsdk-dev") SET(XPU_BASE_URL_WITHOUT_DATE "https://baidu-kunlun-product.cdn.bcebos.com/KL-SDK/klsdk-dev")
SET(XPU_BASE_URL "${XPU_BASE_URL_WITHOUT_DATE}/20220116") SET(XPU_BASE_URL "${XPU_BASE_URL_WITHOUT_DATE}/20220119")
else() else()
SET(XPU_BASE_URL "${XPU_BASE_URL}") SET(XPU_BASE_URL "${XPU_BASE_URL}")
endif() endif()
......
...@@ -22,194 +22,107 @@ from op_test import OpTest ...@@ -22,194 +22,107 @@ from op_test import OpTest
from op_test_xpu import XPUOpTest from op_test_xpu import XPUOpTest
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
from xpu.get_test_cover_info import create_test_class, get_xpu_op_support_types, XPUOpTestWrapper
paddle.enable_static() paddle.enable_static()
np.random.seed(10) np.random.seed(10)
class TestExpandAsOpRank1(XPUOpTest): class XPUTestExpandAsV2Op(XPUOpTestWrapper):
def setUp(self): def __init__(self):
self.set_xpu() self.op_name = 'expand_as_v2'
self.place = paddle.XPUPlace(0) self.use_dynamic_create_class = False
self.op_type = "expand_as_v2"
x = np.random.rand(100).astype("float32") class TestExpandAsV2XPUOp(XPUOpTest):
target_tensor = np.random.rand(2, 100).astype("float32") def setUp(self):
self.inputs = {'X': x} self.init_dtype()
self.attrs = {'target_shape': target_tensor.shape} self.set_xpu()
bcast_dims = [2, 1] self.op_type = "expand_as_v2"
output = np.tile(self.inputs['X'], bcast_dims) self.place = paddle.XPUPlace(0)
self.outputs = {'Out': output} self.set_inputs()
self.set_output()
def set_xpu(self):
self.__class__.use_xpu = True def init_dtype(self):
self.dtype = self.in_type
def test_check_output(self):
self.check_output_with_place(self.place) def set_inputs(self):
x = np.random.rand(100).astype(self.dtype)
def test_check_grad(self): self.inputs = {'X': x}
pass target_tensor = np.random.rand(2, 100).astype(self.dtype)
self.attrs = {'target_shape': target_tensor.shape}
class TestExpandAsOpRank2(XPUOpTest): def set_output(self):
def setUp(self): bcast_dims = [2, 1]
self.set_xpu() output = np.tile(self.inputs['X'], bcast_dims)
self.place = paddle.XPUPlace(0) self.outputs = {'Out': output}
self.op_type = "expand_as_v2"
x = np.random.rand(10, 12).astype("float32") def set_xpu(self):
target_tensor = np.random.rand(10, 12).astype("float32") self.__class__.use_xpu = True
self.inputs = {'X': x} self.__class__.no_need_check_grad = True
self.attrs = {'target_shape': target_tensor.shape} self.__class__.op_type = self.in_type
bcast_dims = [1, 1]
output = np.tile(self.inputs['X'], bcast_dims) def test_check_output(self):
self.outputs = {'Out': output} self.check_output_with_place(self.place)
def set_xpu(self): class TestExpandAsOpRank2(TestExpandAsV2XPUOp):
self.__class__.use_xpu = True def set_inputs(self):
x = np.random.rand(10, 12).astype(self.dtype)
def test_check_output(self): self.inputs = {'X': x}
self.check_output_with_place(self.place) target_tensor = np.random.rand(10, 12).astype(self.dtype)
self.attrs = {'target_shape': target_tensor.shape}
def test_check_grad(self):
pass def set_output(self):
bcast_dims = [1, 1]
output = np.tile(self.inputs['X'], bcast_dims)
class TestExpandAsOpRank3(XPUOpTest): self.outputs = {'Out': output}
def setUp(self):
self.set_xpu() class TestExpandAsOpRank3(TestExpandAsV2XPUOp):
self.place = paddle.XPUPlace(0) def set_inputs(self):
self.op_type = "expand_as_v2" x = np.random.rand(2, 3, 20).astype(self.dtype)
x = np.random.rand(2, 3, 20).astype("float32") self.inputs = {'X': x}
target_tensor = np.random.rand(2, 3, 20).astype("float32") target_tensor = np.random.rand(2, 3, 20).astype(self.dtype)
self.inputs = {'X': x} self.attrs = {'target_shape': target_tensor.shape}
self.attrs = {'target_shape': target_tensor.shape}
bcast_dims = [1, 1, 1] def set_output(self):
output = np.tile(self.inputs['X'], bcast_dims) bcast_dims = [1, 1, 1]
self.outputs = {'Out': output} output = np.tile(self.inputs['X'], bcast_dims)
self.outputs = {'Out': output}
def set_xpu(self):
self.__class__.use_xpu = True class TestExpandAsOpRank4(TestExpandAsV2XPUOp):
def set_inputs(self):
def test_check_output(self): x = np.random.rand(1, 1, 7, 16).astype(self.dtype)
self.check_output_with_place(self.place) self.inputs = {'X': x}
target_tensor = np.random.rand(1, 1, 7, 16).astype(self.dtype)
def test_check_grad(self): self.attrs = {'target_shape': target_tensor.shape}
pass
def set_output(self):
bcast_dims = [4, 6, 1, 1]
class TestExpandAsOpRank4(XPUOpTest): output = np.tile(self.inputs['X'], bcast_dims)
def setUp(self): self.outputs = {'Out': output}
self.set_xpu()
self.place = paddle.XPUPlace(0) class TestExpandAsOpRank5(TestExpandAsV2XPUOp):
self.op_type = "expand_as_v2" def set_inputs(self):
x = np.random.rand(1, 1, 7, 16).astype("float32") x = np.random.rand(1, 1, 7, 16, 1).astype(self.dtype)
target_tensor = np.random.rand(4, 6, 7, 16).astype("float32") self.inputs = {'X': x}
self.inputs = {'X': x} target_tensor = np.random.rand(1, 1, 7, 16, 1).astype(self.dtype)
self.attrs = {'target_shape': target_tensor.shape} self.attrs = {'target_shape': target_tensor.shape}
bcast_dims = [4, 6, 1, 1]
output = np.tile(self.inputs['X'], bcast_dims) def set_output(self):
self.outputs = {'Out': output} bcast_dims = [4, 6, 1, 1, 1]
output = np.tile(self.inputs['X'], bcast_dims)
def set_xpu(self): self.outputs = {'Out': output}
self.__class__.use_xpu = True
class TestExpandAsOpRank6(TestExpandAsV2XPUOp):
def test_check_output(self): def set_inputs(self):
self.check_output_with_place(self.place) x = np.random.rand(1, 1, 7, 16, 1, 1).astype(self.dtype)
self.inputs = {'X': x}
def test_check_grad(self): target_tensor = np.random.rand(1, 1, 7, 16, 1, 1).astype(self.dtype)
pass self.attrs = {'target_shape': target_tensor.shape}
def set_output(self):
class TestExpandAsOpRank5(XPUOpTest): bcast_dims = [4, 6, 1, 1, 1, 1]
def setUp(self): output = np.tile(self.inputs['X'], bcast_dims)
self.set_xpu() self.outputs = {'Out': output}
self.place = paddle.XPUPlace(0)
self.op_type = "expand_as_v2"
x = np.random.rand(1, 1, 7, 16).astype("int32")
target_tensor = np.random.rand(4, 6, 7, 16).astype("int32")
self.inputs = {'X': x}
self.attrs = {'target_shape': target_tensor.shape}
bcast_dims = [4, 6, 1, 1]
output = np.tile(self.inputs['X'], bcast_dims)
self.outputs = {'Out': output}
def set_xpu(self):
self.__class__.use_xpu = True
def test_check_output(self):
self.check_output_with_place(self.place)
def test_check_grad(self):
pass
class TestExpandAsOpRank6(XPUOpTest):
def setUp(self):
self.set_xpu()
self.place = paddle.XPUPlace(0)
self.op_type = "expand_as_v2"
x = np.random.rand(1, 1, 7, 16).astype("int64")
target_tensor = np.random.rand(4, 6, 7, 16).astype("int64")
self.inputs = {'X': x}
self.attrs = {'target_shape': target_tensor.shape}
bcast_dims = [4, 6, 1, 1]
output = np.tile(self.inputs['X'], bcast_dims)
self.outputs = {'Out': output}
def set_xpu(self):
self.__class__.use_xpu = True
def test_check_output(self):
self.check_output_with_place(self.place)
def test_check_grad(self):
pass
class TestExpandAsOpRank6BOOL(XPUOpTest):
def setUp(self):
self.set_xpu()
self.place = paddle.XPUPlace(0)
self.op_type = "expand_as_v2"
x = np.random.rand(1, 1, 7, 16).astype("bool")
target_tensor = np.random.rand(4, 6, 7, 16).astype("bool")
self.inputs = {'X': x}
self.attrs = {'target_shape': target_tensor.shape}
bcast_dims = [4, 6, 1, 1]
output = np.tile(self.inputs['X'], bcast_dims)
self.outputs = {'Out': output}
def set_xpu(self):
self.__class__.use_xpu = True
def test_check_output(self):
self.check_output_with_place(self.place)
def test_check_grad(self):
pass
class TestExpandAsOpRank6FP16(XPUOpTest):
def setUp(self):
self.set_xpu()
self.place = paddle.XPUPlace(0)
self.op_type = "expand_as_v2"
x = np.random.rand(1, 1, 7, 16).astype("float16")
target_tensor = np.random.rand(4, 6, 7, 16).astype("float16")
self.inputs = {'X': x}
self.attrs = {'target_shape': target_tensor.shape}
bcast_dims = [4, 6, 1, 1]
output = np.tile(self.inputs['X'], bcast_dims)
self.outputs = {'Out': output}
def set_xpu(self):
self.__class__.use_xpu = True
self.__class__.no_need_check_grad = True
def test_check_output(self):
self.check_output_with_place(self.place)
def test_check_grad(self):
pass
# Test python API # Test python API
...@@ -236,5 +149,9 @@ class TestExpandAsV2API(unittest.TestCase): ...@@ -236,5 +149,9 @@ class TestExpandAsV2API(unittest.TestCase):
assert np.array_equal(res_1[0], np.tile(input1, (2, 1, 1))) assert np.array_equal(res_1[0], np.tile(input1, (2, 1, 1)))
support_types = get_xpu_op_support_types('expand_as_v2')
for stype in support_types:
create_test_class(globals(), XPUTestExpandAsV2Op, stype)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -22,6 +22,7 @@ from op_test_xpu import XPUOpTest ...@@ -22,6 +22,7 @@ from op_test_xpu import XPUOpTest
import paddle.fluid as fluid import paddle.fluid as fluid
from paddle.fluid import Program, program_guard from paddle.fluid import Program, program_guard
import paddle import paddle
from xpu.get_test_cover_info import create_test_class, get_xpu_op_support_types, XPUOpTestWrapper
paddle.enable_static() paddle.enable_static()
np.random.seed(10) np.random.seed(10)
...@@ -29,152 +30,132 @@ np.random.seed(10) ...@@ -29,152 +30,132 @@ np.random.seed(10)
# CANN Op Support X: float32, int32, int64 # CANN Op Support X: float32, int32, int64
# Situation 1: shape is a list(without tensor) # Situation 1: shape is a list(without tensor)
class TestExpandV2XPUOpRank1(XPUOpTest): class XPUTestExpandV2Op(XPUOpTestWrapper):
def setUp(self): def __init__(self):
self.set_xpu() self.op_name = 'expand_v2'
self.place = paddle.XPUPlace(0) self.use_dynamic_create_class = False
self.op_type = "expand_v2"
self.dtype = np.float32 class TestExpandV2XPUOp(XPUOpTest):
self.init_data() def setUp(self):
self.init_dtype()
self.inputs = {'X': np.random.random(self.ori_shape).astype(self.dtype)} self.set_xpu()
self.attrs = {'shape': self.shape} self.op_type = "expand_v2"
output = np.tile(self.inputs['X'], self.expand_times) self.place = paddle.XPUPlace(0)
self.outputs = {'Out': output} self.init_data()
self.inputs = {
def set_xpu(self): 'X': np.random.random(self.ori_shape).astype(self.dtype)
self.__class__.use_xpu = True }
self.attrs = {'shape': self.shape}
def init_data(self): output = np.tile(self.inputs['X'], self.expand_times)
self.ori_shape = [100] self.outputs = {'Out': output}
self.shape = [100]
self.expand_times = [1] def init_dtype(self):
self.dtype = self.in_type
def test_check_output(self):
self.check_output_with_place(self.place) def set_xpu(self):
self.__class__.use_xpu = True
def test_check_grad(self): self.__class__.no_need_check_grad = True
pass
def init_data(self):
self.ori_shape = [100]
class TestExpandV2OpRank2_DimExpanding(TestExpandV2XPUOpRank1): self.shape = [100]
def init_data(self): self.expand_times = [1]
self.ori_shape = [120]
self.shape = [2, 120] def test_check_output(self):
self.expand_times = [2, 1] self.check_output_with_place(self.place)
class TestExpandV2OpRank2_DimExpanding(TestExpandV2XPUOp):
class TestExpandV2OpRank2(TestExpandV2XPUOpRank1): def init_data(self):
def init_data(self): self.ori_shape = [120]
self.ori_shape = [1, 140] self.shape = [2, 120]
self.shape = [12, 140] self.expand_times = [2, 1]
self.expand_times = [12, 1]
class TestExpandV2OpRank2(TestExpandV2XPUOp):
def init_data(self):
class TestExpandV2OpRank3_Corner(TestExpandV2XPUOpRank1): self.ori_shape = [1, 140]
def init_data(self): self.shape = [12, 140]
self.ori_shape = (2, 10, 5) self.expand_times = [12, 1]
self.shape = (2, 10, 5)
self.expand_times = (1, 1, 1) class TestExpandV2OpRank3_Corner(TestExpandV2XPUOp):
def init_data(self):
self.ori_shape = (2, 10, 5)
class TestExpandV2OpRank4(TestExpandV2XPUOpRank1): self.shape = (2, 10, 5)
def init_data(self): self.expand_times = (1, 1, 1)
self.ori_shape = (2, 4, 5, 7)
self.shape = (-1, -1, -1, -1) class TestExpandV2OpRank4(TestExpandV2XPUOp):
self.expand_times = (1, 1, 1, 1) def init_data(self):
self.ori_shape = (2, 4, 5, 7)
self.shape = (-1, -1, -1, -1)
class TestExpandV2OpRank5(TestExpandV2XPUOpRank1): self.expand_times = (1, 1, 1, 1)
def init_data(self):
self.ori_shape = (2, 4, 1, 15) class TestExpandV2OpRank5(TestExpandV2XPUOp):
self.shape = (2, -1, 4, -1) def init_data(self):
self.expand_times = (1, 1, 4, 1) self.ori_shape = (2, 4, 1, 15)
self.shape = (2, -1, 4, -1)
self.expand_times = (1, 1, 4, 1)
class TestExpandV2OpRank6(TestExpandV2XPUOpRank1):
def init_data(self): class TestExpandV2OpRank6(TestExpandV2XPUOp):
self.ori_shape = (4, 1, 30) def init_data(self):
self.shape = (2, -1, 4, 30) self.ori_shape = (4, 1, 30)
self.expand_times = (2, 1, 4, 1) self.shape = (2, -1, 4, 30)
self.expand_times = (2, 1, 4, 1)
# Situation 2: shape is a list(with tensor) # Situation 2: shape is a list(with tensor)
class TestExpandV2OpXPURank1_tensor_attr(XPUOpTest): class TestExpandV2OpXPURank1_tensor_attr(TestExpandV2XPUOp):
def setUp(self): def setUp(self):
self.set_xpu() self.set_xpu()
self.place = paddle.XPUPlace(0) self.place = paddle.XPUPlace(0)
self.op_type = "expand_v2" self.op_type = "expand_v2"
self.init_data() self.init_data()
self.dtype = np.float32 self.dtype = np.float32
expand_shapes_tensor = [] expand_shapes_tensor = []
for index, ele in enumerate(self.expand_shape): for index, ele in enumerate(self.expand_shape):
expand_shapes_tensor.append(("x" + str(index), np.ones( expand_shapes_tensor.append(("x" + str(index), np.ones(
(1)).astype('int32') * ele)) (1)).astype('int32') * ele))
self.inputs = { self.inputs = {
'X': np.random.random(self.ori_shape).astype(self.dtype), 'X': np.random.random(self.ori_shape).astype(self.dtype),
'expand_shapes_tensor': expand_shapes_tensor, 'expand_shapes_tensor': expand_shapes_tensor,
} }
self.attrs = {"shape": self.infer_expand_shape} self.attrs = {"shape": self.infer_expand_shape}
output = np.tile(self.inputs['X'], self.expand_times) output = np.tile(self.inputs['X'], self.expand_times)
self.outputs = {'Out': output} self.outputs = {'Out': output}
def set_xpu(self): def init_data(self):
self.__class__.use_xpu = True self.ori_shape = [100]
self.expand_times = [1]
def init_data(self): self.expand_shape = [100]
self.ori_shape = [100] self.infer_expand_shape = [-1]
self.expand_times = [1]
self.expand_shape = [100] class TestExpandV2OpRank2_Corner_tensor_attr(
self.infer_expand_shape = [-1] TestExpandV2OpXPURank1_tensor_attr):
def init_data(self):
def test_check_output(self): self.ori_shape = [12, 14]
self.check_output_with_place(self.place) self.expand_times = [1, 1]
self.expand_shape = [12, 14]
def test_check_grad(self): self.infer_expand_shape = [12, -1]
pass
# Situation 3: shape is a tensor
class TestExpandV2XPUOp_tensor(TestExpandV2XPUOp):
class TestExpandV2OpRank2_Corner_tensor_attr( def setUp(self):
TestExpandV2OpXPURank1_tensor_attr): self.set_xpu()
def init_data(self): self.place = paddle.XPUPlace(0)
self.ori_shape = [12, 14] self.op_type = "expand_v2"
self.expand_times = [1, 1] self.init_data()
self.expand_shape = [12, 14] self.dtype = np.float32
self.infer_expand_shape = [12, -1]
self.inputs = {
'X': np.random.random(self.ori_shape).astype(self.dtype),
# Situation 3: shape is a tensor 'Shape': np.array(self.expand_shape).astype("int32"),
class TestExpandV2XPUOpRank1_tensor(XPUOpTest): }
def setUp(self): self.attrs = {}
self.set_xpu() output = np.tile(self.inputs['X'], self.expand_times)
self.place = paddle.XPUPlace(0) self.outputs = {'Out': output}
self.op_type = "expand_v2"
self.init_data() def init_data(self):
self.dtype = np.float32 self.ori_shape = [100]
self.expand_times = [2, 1]
self.inputs = { self.expand_shape = [2, 100]
'X': np.random.random(self.ori_shape).astype(self.dtype),
'Shape': np.array(self.expand_shape).astype("int32"),
}
self.attrs = {}
output = np.tile(self.inputs['X'], self.expand_times)
self.outputs = {'Out': output}
def set_xpu(self):
self.__class__.use_xpu = True
def init_data(self):
self.ori_shape = [100]
self.expand_times = [2, 1]
self.expand_shape = [2, 100]
def test_check_output(self):
self.check_output_with_place(self.place)
def test_check_grad(self):
pass
# Situation 5: input x is int32 # Situation 5: input x is int32
...@@ -206,21 +187,6 @@ class TestExpandV2OpInteger(XPUOpTest): ...@@ -206,21 +187,6 @@ class TestExpandV2OpInteger(XPUOpTest):
pass pass
class TesstExpandV2OpInt64(TestExpandV2OpInteger):
def init_dtype(self):
self.dtype = 'int64'
class TesstExpandV2OpBool(TestExpandV2OpInteger):
def init_dtype(self):
self.dtype = 'bool'
class TesstExpandV2OpFP16(TestExpandV2OpInteger):
def init_dtype(self):
self.dtype = 'float16'
# Test python API # Test python API
class TestExpandV2API(unittest.TestCase): class TestExpandV2API(unittest.TestCase):
def test_static(self): def test_static(self):
...@@ -259,5 +225,9 @@ class TestExpandV2API(unittest.TestCase): ...@@ -259,5 +225,9 @@ class TestExpandV2API(unittest.TestCase):
assert np.array_equal(res_3, np.tile(input, (1, 1))) assert np.array_equal(res_3, np.tile(input, (1, 1)))
support_types = get_xpu_op_support_types('expand_v2')
for stype in support_types:
create_test_class(globals(), XPUTestExpandV2Op, stype)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
...@@ -26,52 +26,66 @@ import unittest ...@@ -26,52 +26,66 @@ import unittest
import numpy as np import numpy as np
from op_test import OpTest from op_test import OpTest
from op_test_xpu import XPUOpTest from op_test_xpu import XPUOpTest
from xpu.get_test_cover_info import create_test_class, get_xpu_op_support_types, XPUOpTestWrapper
paddle.enable_static() paddle.enable_static()
class TestFillAnyLikeOp(OpTest): class XPUTestFillAnyLikeOp(XPUOpTestWrapper):
def setUp(self): def __init__(self):
self.op_type = "fill_any_like" self.op_name = 'fill_any_like'
self.dtype = np.float32 self.use_dynamic_create_class = False
self.use_xpu = True
self.use_mkldnn = False
self.value = 0.0
self.init()
self.inputs = {'X': np.random.random((219, 232)).astype(self.dtype)}
self.attrs = {'value': self.value, 'use_xpu': True}
self.outputs = {'Out': self.value * np.ones_like(self.inputs["X"])}
def init(self): class TestFillAnyLikeOp(XPUOpTest):
pass def setUp(self):
self.init_dtype()
self.set_xpu()
self.op_type = "fill_any_like"
self.place = paddle.XPUPlace(0)
self.set_value()
self.set_input()
self.attrs = {'value': self.value, 'use_xpu': True}
self.outputs = {'Out': self.value * np.ones_like(self.inputs["X"])}
def test_check_output(self): def init_dtype(self):
if paddle.is_compiled_with_xpu(): self.dtype = self.in_type
place = paddle.XPUPlace(0)
self.check_output_with_place(place)
def set_xpu(self):
self.__class__.use_xpu = True
self.__class__.no_need_check_grad = True
class TestFillAnyLikeOpFloat32(TestFillAnyLikeOp): def set_input(self):
def init(self): self.inputs = {'X': np.random.random((219, 232)).astype(self.dtype)}
self.dtype = np.float32
self.value = 0.0
def set_value(self):
self.value = 0.0
class TestFillAnyLikeOpValue1(TestFillAnyLikeOp): def test_check_output(self):
def init(self): self.check_output_with_place(self.place)
self.value = 1.0
class TestFillAnyLikeOp2(TestFillAnyLikeOp):
def set_value(self):
self.value = -0.0
class TestFillAnyLikeOpValue2(TestFillAnyLikeOp): class TestFillAnyLikeOp3(TestFillAnyLikeOp):
def init(self): def set_value(self):
self.value = 1e-9 self.value = 1.0
class TestFillAnyLikeOp4(TestFillAnyLikeOp):
def init(self):
self.value = 1e-9
class TestFillAnyLikeOpFloat16(TestFillAnyLikeOp): class TestFillAnyLikeOp5(TestFillAnyLikeOp):
def init(self): def set_value(self):
self.dtype = np.float16 if self.dtype == "float16":
self.value = 0.05 self.value = 0.05
else:
self.value = 5.0
support_types = get_xpu_op_support_types('fill_any_like')
for stype in support_types:
create_test_class(globals(), XPUTestFillAnyLikeOp, stype)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册