Commit dbe08e9b authored by yuguo960516yuguo's avatar yuguo960516yuguo
Browse files

2.4.2

parent b5499578
......@@ -22,12 +22,10 @@ import unittest
class TrtConvertMatmulTest_static(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input(shape):
return np.random.random(shape).astype(np.float32)
......@@ -47,48 +45,55 @@ class TrtConvertMatmulTest_static(TrtLayerAutoScanTest):
input1_shape = [batch, 32, 6]
input2_shape = [batch, 6, 11]
for alpha in [0.3, 1.0]:
dics = [{
"transpose_X": trans_x,
"transpose_Y": trans_y,
"alpha": alpha,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": []
}]
ops_config = [{
"op_type": "matmul",
"op_inputs": {
"X": ["input1_data"],
"Y": ["input2_data"]
},
"op_outputs": {
"Out": ["output_data"]
},
"op_attrs": dics[0]
}]
dics = [
{
"transpose_X": trans_x,
"transpose_Y": trans_y,
"alpha": alpha,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": [],
}
]
ops_config = [
{
"op_type": "matmul",
"op_inputs": {
"X": ["input1_data"],
"Y": ["input2_data"],
},
"op_outputs": {"Out": ["output_data"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input1_data":
TensorConfig(data_gen=partial(
generate_input, input1_shape)),
"input2_data":
TensorConfig(data_gen=partial(
generate_input, input2_shape))
"input1_data": TensorConfig(
data_gen=partial(
generate_input, input1_shape
)
),
"input2_data": TensorConfig(
data_gen=partial(
generate_input, input2_shape
)
),
},
outputs=["output_data"])
outputs=["output_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
pass
......@@ -102,19 +107,17 @@ class TrtConvertMatmulTest_static(TrtLayerAutoScanTest):
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), (1, 3), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), (1, 3), 1e-5
yield self.create_inference_config(), (1, 3), 1e-3
def test(self):
self.run_test()
class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input(shape):
return np.random.random(shape).astype(np.float32)
......@@ -133,60 +136,63 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
# input1_shape = [batch, 32, 6]
# input2_shape = [batch, 6, 11]
for alpha in [0.3, 1.0]:
dics = [{
"transpose_X": trans_x,
"transpose_Y": trans_y,
"alpha": alpha,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": []
}]
ops_config = [{
"op_type": "matmul",
"op_inputs": {
"X": ["input1_data"],
"Y": ["input2_data"]
},
"op_outputs": {
"Out": ["output_data"]
},
"op_attrs": dics[0]
}]
dics = [
{
"transpose_X": trans_x,
"transpose_Y": trans_y,
"alpha": alpha,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": [],
}
]
ops_config = [
{
"op_type": "matmul",
"op_inputs": {
"X": ["input1_data"],
"Y": ["input2_data"],
},
"op_outputs": {"Out": ["output_data"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input1_data":
TensorConfig(
data_gen=partial(generate_input, input1_shape)),
"input2_data":
TensorConfig(
data_gen=partial(generate_input, input2_shape))
"input1_data": TensorConfig(
data_gen=partial(generate_input, input1_shape)
),
"input2_data": TensorConfig(
data_gen=partial(generate_input, input2_shape)
),
},
outputs=["output_data"])
outputs=["output_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {
"input1_data": [1, 4, 4],
"input2_data": [1, 4, 4]
"input2_data": [1, 4, 4],
}
self.dynamic_shape.max_input_shape = {
"input1_data": [16, 4, 4],
"input2_data": [16, 4, 4]
"input2_data": [16, 4, 4],
}
self.dynamic_shape.opt_input_shape = {
"input1_data": [8, 4, 4],
"input2_data": [8, 4, 4]
"input2_data": [8, 4, 4],
}
attrs = [
......@@ -198,7 +204,7 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), (1, 3), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), (1, 3), 1e-5
yield self.create_inference_config(), (1, 3), 1e-3
def add_skip_trt_case(self):
pass
......
......@@ -23,9 +23,7 @@ import os
class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
def sample_program_configs(self):
def generate_input(shape):
return np.random.random(shape).astype(np.float32)
......@@ -34,53 +32,56 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
for trans_y in [False]:
input1_shape = [batch, 64, 350, 75]
input2_shape = [75, 25]
dics = [{
"trans_x": trans_x,
"trans_y": trans_y,
}]
ops_config = [{
"op_type": "matmul_v2",
"op_inputs": {
"X": ["input1_data"],
"Y": ["input2_data"]
},
"op_outputs": {
"Out": ["output_data"]
},
"op_attrs": dics[0]
}]
dics = [
{
"trans_x": trans_x,
"trans_y": trans_y,
}
]
ops_config = [
{
"op_type": "matmul_v2",
"op_inputs": {
"X": ["input1_data"],
"Y": ["input2_data"],
},
"op_outputs": {"Out": ["output_data"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input1_data":
TensorConfig(
data_gen=partial(generate_input, input1_shape)),
"input2_data":
TensorConfig(
data_gen=partial(generate_input, input2_shape))
"input1_data": TensorConfig(
data_gen=partial(generate_input, input1_shape)
),
"input2_data": TensorConfig(
data_gen=partial(generate_input, input2_shape)
),
},
outputs=["output_data"])
outputs=["output_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {
"input1_data": [10, 64, 350, 75],
"input2_data": [75, 25]
"input2_data": [75, 25],
}
self.dynamic_shape.max_input_shape = {
"input1_data": [100, 64, 350, 75],
"input2_data": [75, 25]
"input2_data": [75, 25],
}
self.dynamic_shape.opt_input_shape = {
"input1_data": [15, 64, 350, 75],
"input2_data": [75, 25]
"input2_data": [75, 25],
}
attrs = [
......@@ -90,7 +91,7 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
# The output has little diff between gpu and trt in CI-Windows-Inference
tol_fp32 = 1e-5
tol_half = 1e-5
if (os.name == 'nt'):
if os.name == 'nt':
tol_fp32 = 1e-3
tol_half = 1e-3
# for dynamic_shape
......@@ -109,9 +110,7 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
class TrtConvertMatmulTest_dynamic2(TrtLayerAutoScanTest):
def sample_program_configs(self):
def generate_input(shape):
return np.random.random(shape).astype(np.float32)
......@@ -120,53 +119,56 @@ class TrtConvertMatmulTest_dynamic2(TrtLayerAutoScanTest):
for trans_y in [False]:
input1_shape = [60, 40]
input2_shape = [batch, 40, 90]
dics = [{
"trans_x": trans_x,
"trans_y": trans_y,
}]
ops_config = [{
"op_type": "matmul_v2",
"op_inputs": {
"X": ["input1_data"],
"Y": ["input2_data"]
},
"op_outputs": {
"Out": ["output_data"]
},
"op_attrs": dics[0]
}]
dics = [
{
"trans_x": trans_x,
"trans_y": trans_y,
}
]
ops_config = [
{
"op_type": "matmul_v2",
"op_inputs": {
"X": ["input1_data"],
"Y": ["input2_data"],
},
"op_outputs": {"Out": ["output_data"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input1_data":
TensorConfig(
data_gen=partial(generate_input, input1_shape)),
"input2_data":
TensorConfig(
data_gen=partial(generate_input, input2_shape))
"input1_data": TensorConfig(
data_gen=partial(generate_input, input1_shape)
),
"input2_data": TensorConfig(
data_gen=partial(generate_input, input2_shape)
),
},
outputs=["output_data"])
outputs=["output_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {
"input1_data": [60, 40],
"input2_data": [10, 40, 90]
"input2_data": [10, 40, 90],
}
self.dynamic_shape.max_input_shape = {
"input1_data": [60, 40],
"input2_data": [20, 40, 90]
"input2_data": [20, 40, 90],
}
self.dynamic_shape.opt_input_shape = {
"input1_data": [60, 40],
"input2_data": [15, 40, 90]
"input2_data": [15, 40, 90],
}
attrs = [
......@@ -175,7 +177,7 @@ class TrtConvertMatmulTest_dynamic2(TrtLayerAutoScanTest):
# The output has little diff between gpu and trt in CI-Windows-Inference
tol_fp32 = 1e-5
tol_half = 1e-5
if (os.name == 'nt'):
if os.name == 'nt':
tol_fp32 = 1e-3
tol_half = 1e-3
# for dynamic_shape
......@@ -194,9 +196,7 @@ class TrtConvertMatmulTest_dynamic2(TrtLayerAutoScanTest):
class TrtConvertMatmulTest_dynamic3(TrtLayerAutoScanTest):
def sample_program_configs(self):
def generate_input(shape):
return np.random.random(shape).astype(np.float32)
......@@ -219,93 +219,102 @@ class TrtConvertMatmulTest_dynamic3(TrtLayerAutoScanTest):
elif case == 2:
input1_shape = [50]
input2_shape = [50]
if (case == 0 or case == 1):
dics = [{
"trans_x": False,
"trans_y": False,
}]
elif (case == 2):
dics = [{
"trans_x": trans_x,
"trans_y": trans_y,
}]
ops_config = [{
"op_type": "matmul_v2",
"op_inputs": {
"X": ["input1_data"],
"Y": ["input2_data"]
},
"op_outputs": {
"Out": ["output_data"]
},
"op_attrs": dics[0]
}]
if case == 0 or case == 1:
dics = [
{
"trans_x": False,
"trans_y": False,
}
]
elif case == 2:
dics = [
{
"trans_x": trans_x,
"trans_y": trans_y,
}
]
ops_config = [
{
"op_type": "matmul_v2",
"op_inputs": {
"X": ["input1_data"],
"Y": ["input2_data"],
},
"op_outputs": {"Out": ["output_data"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input1_data":
TensorConfig(data_gen=partial(
generate_input, input1_shape)),
"input2_data":
TensorConfig(data_gen=partial(
generate_input, input2_shape))
"input1_data": TensorConfig(
data_gen=partial(
generate_input, input1_shape
)
),
"input2_data": TensorConfig(
data_gen=partial(
generate_input, input2_shape
)
),
},
outputs=["output_data"])
outputs=["output_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape():
if (self.case == 0):
if self.case == 0:
self.dynamic_shape.min_input_shape = {
"input1_data": [20, 50],
"input2_data": [50]
"input2_data": [50],
}
self.dynamic_shape.max_input_shape = {
"input1_data": [30, 50],
"input2_data": [50]
"input2_data": [50],
}
self.dynamic_shape.opt_input_shape = {
"input1_data": [25, 50],
"input2_data": [50]
"input2_data": [50],
}
elif (self.case == 1):
elif self.case == 1:
self.dynamic_shape.min_input_shape = {
"input2_data": [50, 20],
"input1_data": [50]
"input1_data": [50],
}
self.dynamic_shape.max_input_shape = {
"input2_data": [50, 30],
"input1_data": [50]
"input1_data": [50],
}
self.dynamic_shape.opt_input_shape = {
"input2_data": [50, 25],
"input1_data": [50]
"input1_data": [50],
}
elif (self.case == 2):
elif self.case == 2:
self.dynamic_shape.min_input_shape = {
"input2_data": [30],
"input1_data": [50]
"input1_data": [50],
}
self.dynamic_shape.max_input_shape = {
"input2_data": [50],
"input1_data": [50]
"input1_data": [50],
}
self.dynamic_shape.opt_input_shape = {
"input2_data": [50],
"input1_data": [50]
"input1_data": [50],
}
generate_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), (1, 3), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), (1, 3), 1e-5
yield self.create_inference_config(), (1, 3), 1e-3
def add_skip_trt_case(self):
pass
......
......@@ -22,12 +22,10 @@ from typing import Optional, List, Callable, Dict, Any, Set
class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input1(batch, dim1):
return np.random.random((batch, dim1, 768)).astype(np.float32)
......@@ -44,103 +42,86 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
self.batch = batch
for reshape_shape in [[0, 0, 12, 64]]:
for dim1 in [128]:
input2_shapes = [[batch, reshape_shape[2], dim1, dim1],
[batch, 1, 1, dim1]]
input2_shapes = [
[batch, reshape_shape[2], dim1, dim1],
[batch, 1, 1, dim1],
]
for input2_shape in input2_shapes:
for axis in [0]:
dics = [{
"x_num_col_dims": 2,
"y_num_col_dims": 1
}, {
"axis": 2
}, {
"shape": reshape_shape
}, {
"axis": [0, 2, 1, 3]
}, {
"x_num_col_dims": 2,
"y_num_col_dims": 1
}, {
"axis": 2
}, {
"shape": reshape_shape
}, {
"axis": [0, 2, 1, 3]
}, {
"x_num_col_dims": 2,
"y_num_col_dims": 1
}, {
"axis": 2
}, {
"shape": reshape_shape
}, {
"axis": [0, 2, 1, 3]
}, {
"scale": 0.125,
"bias": 0.0,
"bias_after_scale": True
}, {
"alpha": 1.0,
"transpose_X": False,
"transpose_Y": True,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": []
}, {
"axis": axis
}, {
"axis": -1,
"is_test": True
}, {
"seed": 0,
"dropout_prob": 0.10000000149011612,
"dropout_implementation": "upscale_in_train",
"fix_seed": False,
"is_test": True
}, {
"alpha": 1.0,
"transpose_X": False,
"transpose_Y": False,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": []
}, {
"axis": [0, 2, 1, 3]
}, {
"shape": [0, 0, 768]
}, {
"x_num_col_dims": 2,
"y_num_col_dims": 1
}]
dics = [
{"x_num_col_dims": 2, "y_num_col_dims": 1},
{"axis": 2},
{"shape": reshape_shape},
{"axis": [0, 2, 1, 3]},
{"x_num_col_dims": 2, "y_num_col_dims": 1},
{"axis": 2},
{"shape": reshape_shape},
{"axis": [0, 2, 1, 3]},
{"x_num_col_dims": 2, "y_num_col_dims": 1},
{"axis": 2},
{"shape": reshape_shape},
{"axis": [0, 2, 1, 3]},
{
"scale": 0.125,
"bias": 0.0,
"bias_after_scale": True,
},
{
"alpha": 1.0,
"transpose_X": False,
"transpose_Y": True,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": [],
},
{"axis": axis},
{"axis": -1, "is_test": True},
{
"seed": 0,
"dropout_prob": 0.10000000149011612,
"dropout_implementation": "upscale_in_train",
"fix_seed": False,
"is_test": True,
},
{
"alpha": 1.0,
"transpose_X": False,
"transpose_Y": False,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": [],
},
{"axis": [0, 2, 1, 3]},
{"shape": [0, 0, 768]},
{"x_num_col_dims": 2, "y_num_col_dims": 1},
]
ops_config = [
{
"op_type": "mul",
"op_inputs": {
"X": ["input_data1"],
"Y": ["mul1_weight"]
"Y": ["mul1_weight"],
},
"op_outputs": {
"Out": ["mul1_output"]
},
"op_attrs": dics[0]
"op_outputs": {"Out": ["mul1_output"]},
"op_attrs": dics[0],
},
{
"op_type": "elementwise_add",
"op_inputs": {
"X": ["mul1_output"],
"Y": ["elementwise_add1_weight"]
"Y": ["elementwise_add1_weight"],
},
"op_outputs": {
"Out": ["elementwise_add1_output"]
},
"op_attrs": dics[1]
"op_attrs": dics[1],
},
{
"op_type": "reshape2",
......@@ -149,42 +130,38 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
},
"op_outputs": {
"Out": ["reshape21_output"],
"XShape": ["reshape21_output_xshape"]
"XShape": ["reshape21_output_xshape"],
},
"op_attrs": dics[2]
"op_attrs": dics[2],
},
{
"op_type": "transpose2",
"op_inputs": {
"X": ["reshape21_output"]
},
"op_inputs": {"X": ["reshape21_output"]},
"op_outputs": {
"Out": ["transpose21_output"],
"XShape": ["transpose21_output_xshape"]
"XShape": ["transpose21_output_xshape"],
},
"op_attrs": dics[3]
"op_attrs": dics[3],
},
{
"op_type": "mul",
"op_inputs": {
"X": ["input_data1"],
"Y": ["mul2_weight"]
"Y": ["mul2_weight"],
},
"op_outputs": {
"Out": ["mul2_output"]
},
"op_attrs": dics[4]
"op_outputs": {"Out": ["mul2_output"]},
"op_attrs": dics[4],
},
{
"op_type": "elementwise_add",
"op_inputs": {
"X": ["mul2_output"],
"Y": ["elementwise_add2_weight"]
"Y": ["elementwise_add2_weight"],
},
"op_outputs": {
"Out": ["elementwise_add2_output"]
},
"op_attrs": dics[5]
"op_attrs": dics[5],
},
{
"op_type": "reshape2",
......@@ -193,42 +170,38 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
},
"op_outputs": {
"Out": ["reshape22_output"],
"XShape": ["reshape22_output_xshape"]
"XShape": ["reshape22_output_xshape"],
},
"op_attrs": dics[6]
"op_attrs": dics[6],
},
{
"op_type": "transpose2",
"op_inputs": {
"X": ["reshape22_output"]
},
"op_inputs": {"X": ["reshape22_output"]},
"op_outputs": {
"Out": ["transpose22_output"],
"XShape": ["transpose22_output_xshape"]
"XShape": ["transpose22_output_xshape"],
},
"op_attrs": dics[7]
"op_attrs": dics[7],
},
{
"op_type": "mul",
"op_inputs": {
"X": ["input_data1"],
"Y": ["mul3_weight"]
"Y": ["mul3_weight"],
},
"op_outputs": {
"Out": ["mul3_output"]
},
"op_attrs": dics[8]
"op_outputs": {"Out": ["mul3_output"]},
"op_attrs": dics[8],
},
{
"op_type": "elementwise_add",
"op_inputs": {
"X": ["mul3_output"],
"Y": ["elementwise_add3_weight"]
"Y": ["elementwise_add3_weight"],
},
"op_outputs": {
"Out": ["elementwise_add3_output"]
},
"op_attrs": dics[9]
"op_attrs": dics[9],
},
{
"op_type": "reshape2",
......@@ -237,30 +210,26 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
},
"op_outputs": {
"Out": ["reshape23_output"],
"XShape": ["reshape23_output_xshape"]
"XShape": ["reshape23_output_xshape"],
},
"op_attrs": dics[10]
"op_attrs": dics[10],
},
{
"op_type": "transpose2",
"op_inputs": {
"X": ["reshape23_output"]
},
"op_inputs": {"X": ["reshape23_output"]},
"op_outputs": {
"Out": ["transpose23_output"],
"XShape": ["transpose23_output_xshape"]
"XShape": ["transpose23_output_xshape"],
},
"op_attrs": dics[11]
"op_attrs": dics[11],
},
{
"op_type": "scale",
"op_inputs": {
"X": ["transpose23_output"],
},
"op_outputs": {
"Out": ["scale_output"]
},
"op_attrs": dics[12]
"op_outputs": {"Out": ["scale_output"]},
"op_attrs": dics[12],
},
{
"op_type": "matmul",
......@@ -268,41 +237,35 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
"X": ["scale_output"],
"Y": ["transpose22_output"],
},
"op_outputs": {
"Out": ["matmul1_output"]
},
"op_attrs": dics[13]
"op_outputs": {"Out": ["matmul1_output"]},
"op_attrs": dics[13],
},
{
"op_type": "elementwise_add",
"op_inputs": {
"X": ["matmul1_output"],
"Y": ["input_data2"]
"Y": ["input_data2"],
},
"op_outputs": {
"Out": ["elementwise_add4_output"]
},
"op_attrs": dics[14]
"op_attrs": dics[14],
},
{
"op_type": "softmax",
"op_inputs": {
"X": ["elementwise_add4_output"]
},
"op_outputs": {
"Out": ["softmax_output"]
},
"op_attrs": dics[15]
"op_outputs": {"Out": ["softmax_output"]},
"op_attrs": dics[15],
},
{
"op_type": "dropout",
"op_inputs": {
"X": ["softmax_output"],
},
"op_outputs": {
"Out": ["dropout3_output"]
},
"op_attrs": dics[16]
"op_outputs": {"Out": ["dropout3_output"]},
"op_attrs": dics[16],
},
{
"op_type": "matmul",
......@@ -310,32 +273,26 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
"X": ["dropout3_output"],
"Y": ["transpose21_output"],
},
"op_outputs": {
"Out": ["matmul2_output"]
},
"op_attrs": dics[17]
"op_outputs": {"Out": ["matmul2_output"]},
"op_attrs": dics[17],
},
{
"op_type": "transpose2",
"op_inputs": {
"X": ["matmul2_output"]
},
"op_inputs": {"X": ["matmul2_output"]},
"op_outputs": {
"Out": ["transpose24_output"],
"XShape": ["transpose24_output_xshape"]
"XShape": ["transpose24_output_xshape"],
},
"op_attrs": dics[18]
"op_attrs": dics[18],
},
{
"op_type": "reshape2",
"op_inputs": {
"X": ["transpose24_output"]
},
"op_inputs": {"X": ["transpose24_output"]},
"op_outputs": {
"Out": ["reshape24_output"],
"XShape": ["reshape24_output_xshape"]
"XShape": ["reshape24_output_xshape"],
},
"op_attrs": dics[19]
"op_attrs": dics[19],
},
# In order to fuse ops with
# multihead_matmul_fuse_pass_v2, the last op
......@@ -344,72 +301,75 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
"op_type": "mul",
"op_inputs": {
"X": ["reshape24_output"],
"Y": ["mul4_weight"]
"Y": ["mul4_weight"],
},
"op_outputs": {
"Out": ["mul4_output"]
},
"op_attrs": dics[20]
}
"op_outputs": {"Out": ["mul4_output"]},
"op_attrs": dics[20],
},
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={
"mul1_weight":
TensorConfig(
data_gen=partial(generate_weight1)),
"mul2_weight":
TensorConfig(
data_gen=partial(generate_weight1)),
"mul3_weight":
TensorConfig(
data_gen=partial(generate_weight1)),
"mul4_weight":
TensorConfig(
data_gen=partial(generate_weight1)),
"elementwise_add1_weight":
TensorConfig(
data_gen=partial(generate_weight2)),
"elementwise_add2_weight":
TensorConfig(
data_gen=partial(generate_weight2)),
"elementwise_add3_weight":
TensorConfig(
data_gen=partial(generate_weight2)),
"mul1_weight": TensorConfig(
data_gen=partial(generate_weight1)
),
"mul2_weight": TensorConfig(
data_gen=partial(generate_weight1)
),
"mul3_weight": TensorConfig(
data_gen=partial(generate_weight1)
),
"mul4_weight": TensorConfig(
data_gen=partial(generate_weight1)
),
"elementwise_add1_weight": TensorConfig(
data_gen=partial(generate_weight2)
),
"elementwise_add2_weight": TensorConfig(
data_gen=partial(generate_weight2)
),
"elementwise_add3_weight": TensorConfig(
data_gen=partial(generate_weight2)
),
},
inputs={
"input_data1":
TensorConfig(data_gen=partial(
generate_input1, batch, dim1)),
"input_data2":
TensorConfig(data_gen=partial(
generate_input2, input2_shape)),
"input_data1": TensorConfig(
data_gen=partial(
generate_input1, batch, dim1
)
),
"input_data2": TensorConfig(
data_gen=partial(
generate_input2, input2_shape
)
),
},
outputs=["mul4_output"])
outputs=["mul4_output"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
# The last dim of input1 and input2 should be static.
self.dynamic_shape.min_input_shape = {
"input_data1": [1, 8, 768],
"input_data2": [1, 1, 1, 128],
"reshape24_output": [1, 128, 768]
"reshape24_output": [1, 128, 768],
}
self.dynamic_shape.max_input_shape = {
"input_data1": [16, 512, 768],
"input_data2": [16, 256, 512, 128],
"reshape24_output": [1, 128, 768]
"reshape24_output": [1, 128, 768],
}
self.dynamic_shape.opt_input_shape = {
"input_data1": [8, 128, 768],
"input_data2": [8, 32, 64, 128],
"reshape24_output": [1, 128, 768]
"reshape24_output": [1, 128, 768],
}
def clear_dynamic_shape():
......@@ -427,7 +387,7 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
self.trt_param.workspace_size = 2013265920
yield self.create_inference_config(), (1, 4), (1e-5, 1e-5)
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), (1, 4), (1e-5, 1e-5)
yield self.create_inference_config(), (1, 4), (1e-3, 1e-3)
# for dynamic_shape
generate_dynamic_shape(attrs)
......@@ -435,28 +395,33 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
self.trt_param.workspace_size = 2013265920
yield self.create_inference_config(), (1, 3), (1e-5, 1e-4)
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), (1, 3), (1e-5, 1e-5)
yield self.create_inference_config(), (1, 3), (1e-3, 1e-3)
def add_skip_trt_case(self):
def teller1(program_config, predictor_config):
if self.trt_param.precision == paddle_infer.PrecisionType.Half:
return True
return False
self.add_skip_case(
teller1, SkipReasons.TRT_NOT_IMPLEMENTED,
"The output has diff between gpu and trt in fp16 mode.")
teller1,
SkipReasons.TRT_NOT_IMPLEMENTED,
"The output has diff between gpu and trt in fp16 mode.",
)
def teller2(program_config, predictor_config):
if self.trt_param.precision == paddle_infer.PrecisionType.Float32 and len(
self.dynamic_shape.min_input_shape) != 0 and self.batch > 2:
if (
self.trt_param.precision == paddle_infer.PrecisionType.Float32
and len(self.dynamic_shape.min_input_shape) != 0
and self.batch > 2
):
return True
return False
self.add_skip_case(
teller2, SkipReasons.TRT_NOT_IMPLEMENTED,
"The output has diff between gpu and trt when dynamic fp32 mode and batch size > 2."
teller2,
SkipReasons.TRT_NOT_IMPLEMENTED,
"The output has diff between gpu and trt when dynamic fp32 mode and batch size > 2.",
)
def teller3(program_config, predictor_config):
......@@ -465,8 +430,10 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
return False
self.add_skip_case(
teller3, SkipReasons.TRT_NOT_IMPLEMENTED,
"The output has diff between gpu and trt in int8 mode.")
teller3,
SkipReasons.TRT_NOT_IMPLEMENTED,
"The output has diff between gpu and trt in int8 mode.",
)
def test(self):
self.add_skip_trt_case()
......@@ -474,9 +441,7 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
def sample_program_configs(self):
def generate_input1(batch, dim1):
return np.random.random((batch, dim1, 768)).astype(np.float32)
......@@ -493,112 +458,110 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
self.batch = batch
for reshape_shape in [[0, 0, 12, 64]]:
for dim1 in [128]:
input2_shapes = [[batch, reshape_shape[2], dim1, dim1],
[batch, 1, 1, dim1]]
input2_shapes = [
[batch, reshape_shape[2], dim1, dim1],
[batch, 1, 1, dim1],
]
for input2_shape in input2_shapes:
for axis in [0]:
dics = [{
"x_num_col_dims": 2,
"y_num_col_dims": 1,
"enable_int8": True,
"Input_scale": 1.0,
}, {
"axis": 2,
"out_threshold": 1.0,
}, {
"shape": reshape_shape
}, {
"axis": [0, 2, 1, 3]
}, {
"x_num_col_dims": 2,
"y_num_col_dims": 1,
"enable_int8": True,
"Input_scale": 1.0,
}, {
"axis": 2,
"out_threshold": 1.0,
}, {
"shape": reshape_shape
}, {
"axis": [0, 2, 1, 3]
}, {
"x_num_col_dims": 2,
"y_num_col_dims": 1,
"enable_int8": True,
"Input_scale": 1.0,
}, {
"axis": 2,
"out_threshold": 1.0,
}, {
"shape": reshape_shape
}, {
"axis": [0, 2, 1, 3]
}, {
"scale": 0.125,
"bias": 0.0,
"bias_after_scale": True
}, {
"alpha": 1.0,
"transpose_X": False,
"transpose_Y": True,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": []
}, {
"axis": axis
}, {
"axis": -1,
"is_test": True
}, {
"seed": 0,
"dropout_prob": 0.10000000149011612,
"dropout_implementation": "upscale_in_train",
"fix_seed": False,
"is_test": True
}, {
"alpha": 1.0,
"transpose_X": False,
"transpose_Y": False,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": []
}, {
"axis": [0, 2, 1, 3]
}, {
"shape": [0, 0, 768]
}, {
"x_num_col_dims": 2,
"y_num_col_dims": 1
}]
dics = [
{
"x_num_col_dims": 2,
"y_num_col_dims": 1,
"enable_int8": True,
"Input_scale": 1.0,
},
{
"axis": 2,
"out_threshold": 1.0,
},
{"shape": reshape_shape},
{"axis": [0, 2, 1, 3]},
{
"x_num_col_dims": 2,
"y_num_col_dims": 1,
"enable_int8": True,
"Input_scale": 1.0,
},
{
"axis": 2,
"out_threshold": 1.0,
},
{"shape": reshape_shape},
{"axis": [0, 2, 1, 3]},
{
"x_num_col_dims": 2,
"y_num_col_dims": 1,
"enable_int8": True,
"Input_scale": 1.0,
},
{
"axis": 2,
"out_threshold": 1.0,
},
{"shape": reshape_shape},
{"axis": [0, 2, 1, 3]},
{
"scale": 0.125,
"bias": 0.0,
"bias_after_scale": True,
},
{
"alpha": 1.0,
"transpose_X": False,
"transpose_Y": True,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": [],
},
{"axis": axis},
{"axis": -1, "is_test": True},
{
"seed": 0,
"dropout_prob": 0.10000000149011612,
"dropout_implementation": "upscale_in_train",
"fix_seed": False,
"is_test": True,
},
{
"alpha": 1.0,
"transpose_X": False,
"transpose_Y": False,
"fused_reshape_X": [],
"fused_reshape_Y": [],
"fused_transpose_X": [],
"fused_transpose_Y": [],
"fused_reshape_Out": [],
"fused_transpose_Out": [],
},
{"axis": [0, 2, 1, 3]},
{"shape": [0, 0, 768]},
{"x_num_col_dims": 2, "y_num_col_dims": 1},
]
ops_config = [
{
"op_type": "mul",
"op_inputs": {
"X": ["input_data1"],
"Y": ["mul1_weight"]
},
"op_outputs": {
"Out": ["mul1_output"]
"Y": ["mul1_weight"],
},
"op_attrs": dics[0]
"op_outputs": {"Out": ["mul1_output"]},
"op_attrs": dics[0],
},
{
"op_type": "elementwise_add",
"op_inputs": {
"X": ["mul1_output"],
"Y": ["elementwise_add1_weight"]
"Y": ["elementwise_add1_weight"],
},
"op_outputs": {
"Out": ["elementwise_add1_output"]
},
"op_attrs": dics[1]
"op_attrs": dics[1],
},
{
"op_type": "reshape2",
......@@ -607,42 +570,38 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
},
"op_outputs": {
"Out": ["reshape21_output"],
"XShape": ["reshape21_output_xshape"]
"XShape": ["reshape21_output_xshape"],
},
"op_attrs": dics[2]
"op_attrs": dics[2],
},
{
"op_type": "transpose2",
"op_inputs": {
"X": ["reshape21_output"]
},
"op_inputs": {"X": ["reshape21_output"]},
"op_outputs": {
"Out": ["transpose21_output"],
"XShape": ["transpose21_output_xshape"]
"XShape": ["transpose21_output_xshape"],
},
"op_attrs": dics[3]
"op_attrs": dics[3],
},
{
"op_type": "mul",
"op_inputs": {
"X": ["input_data1"],
"Y": ["mul2_weight"]
"Y": ["mul2_weight"],
},
"op_outputs": {
"Out": ["mul2_output"]
},
"op_attrs": dics[4]
"op_outputs": {"Out": ["mul2_output"]},
"op_attrs": dics[4],
},
{
"op_type": "elementwise_add",
"op_inputs": {
"X": ["mul2_output"],
"Y": ["elementwise_add2_weight"]
"Y": ["elementwise_add2_weight"],
},
"op_outputs": {
"Out": ["elementwise_add2_output"]
},
"op_attrs": dics[5]
"op_attrs": dics[5],
},
{
"op_type": "reshape2",
......@@ -651,42 +610,38 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
},
"op_outputs": {
"Out": ["reshape22_output"],
"XShape": ["reshape22_output_xshape"]
"XShape": ["reshape22_output_xshape"],
},
"op_attrs": dics[6]
"op_attrs": dics[6],
},
{
"op_type": "transpose2",
"op_inputs": {
"X": ["reshape22_output"]
},
"op_inputs": {"X": ["reshape22_output"]},
"op_outputs": {
"Out": ["transpose22_output"],
"XShape": ["transpose22_output_xshape"]
"XShape": ["transpose22_output_xshape"],
},
"op_attrs": dics[7]
"op_attrs": dics[7],
},
{
"op_type": "mul",
"op_inputs": {
"X": ["input_data1"],
"Y": ["mul3_weight"]
"Y": ["mul3_weight"],
},
"op_outputs": {
"Out": ["mul3_output"]
},
"op_attrs": dics[8]
"op_outputs": {"Out": ["mul3_output"]},
"op_attrs": dics[8],
},
{
"op_type": "elementwise_add",
"op_inputs": {
"X": ["mul3_output"],
"Y": ["elementwise_add3_weight"]
"Y": ["elementwise_add3_weight"],
},
"op_outputs": {
"Out": ["elementwise_add3_output"]
},
"op_attrs": dics[9]
"op_attrs": dics[9],
},
{
"op_type": "reshape2",
......@@ -695,30 +650,26 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
},
"op_outputs": {
"Out": ["reshape23_output"],
"XShape": ["reshape23_output_xshape"]
"XShape": ["reshape23_output_xshape"],
},
"op_attrs": dics[10]
"op_attrs": dics[10],
},
{
"op_type": "transpose2",
"op_inputs": {
"X": ["reshape23_output"]
},
"op_inputs": {"X": ["reshape23_output"]},
"op_outputs": {
"Out": ["transpose23_output"],
"XShape": ["transpose23_output_xshape"]
"XShape": ["transpose23_output_xshape"],
},
"op_attrs": dics[11]
"op_attrs": dics[11],
},
{
"op_type": "scale",
"op_inputs": {
"X": ["transpose23_output"],
},
"op_outputs": {
"Out": ["scale_output"]
},
"op_attrs": dics[12]
"op_outputs": {"Out": ["scale_output"]},
"op_attrs": dics[12],
},
{
"op_type": "matmul",
......@@ -726,41 +677,35 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
"X": ["scale_output"],
"Y": ["transpose22_output"],
},
"op_outputs": {
"Out": ["matmul1_output"]
},
"op_attrs": dics[13]
"op_outputs": {"Out": ["matmul1_output"]},
"op_attrs": dics[13],
},
{
"op_type": "elementwise_add",
"op_inputs": {
"X": ["matmul1_output"],
"Y": ["input_data2"]
"Y": ["input_data2"],
},
"op_outputs": {
"Out": ["elementwise_add4_output"]
},
"op_attrs": dics[14]
"op_attrs": dics[14],
},
{
"op_type": "softmax",
"op_inputs": {
"X": ["elementwise_add4_output"]
},
"op_outputs": {
"Out": ["softmax_output"]
},
"op_attrs": dics[15]
"op_outputs": {"Out": ["softmax_output"]},
"op_attrs": dics[15],
},
{
"op_type": "dropout",
"op_inputs": {
"X": ["softmax_output"],
},
"op_outputs": {
"Out": ["dropout3_output"]
},
"op_attrs": dics[16]
"op_outputs": {"Out": ["dropout3_output"]},
"op_attrs": dics[16],
},
{
"op_type": "matmul",
......@@ -768,32 +713,26 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
"X": ["dropout3_output"],
"Y": ["transpose21_output"],
},
"op_outputs": {
"Out": ["matmul2_output"]
},
"op_attrs": dics[17]
"op_outputs": {"Out": ["matmul2_output"]},
"op_attrs": dics[17],
},
{
"op_type": "transpose2",
"op_inputs": {
"X": ["matmul2_output"]
},
"op_inputs": {"X": ["matmul2_output"]},
"op_outputs": {
"Out": ["transpose24_output"],
"XShape": ["transpose24_output_xshape"]
"XShape": ["transpose24_output_xshape"],
},
"op_attrs": dics[18]
"op_attrs": dics[18],
},
{
"op_type": "reshape2",
"op_inputs": {
"X": ["transpose24_output"]
},
"op_inputs": {"X": ["transpose24_output"]},
"op_outputs": {
"Out": ["reshape24_output"],
"XShape": ["reshape24_output_xshape"]
"XShape": ["reshape24_output_xshape"],
},
"op_attrs": dics[19]
"op_attrs": dics[19],
},
# In order to fuse ops with
# multihead_matmul_fuse_pass_v2, the last op
......@@ -802,61 +741,62 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
"op_type": "mul",
"op_inputs": {
"X": ["reshape24_output"],
"Y": ["mul4_weight"]
"Y": ["mul4_weight"],
},
"op_outputs": {
"Out": ["mul4_output"]
},
"op_attrs": dics[20]
}
"op_outputs": {"Out": ["mul4_output"]},
"op_attrs": dics[20],
},
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={
"mul1_weight":
TensorConfig(
data_gen=partial(generate_weight1)),
"mul2_weight":
TensorConfig(
data_gen=partial(generate_weight1)),
"mul3_weight":
TensorConfig(
data_gen=partial(generate_weight1)),
"mul4_weight":
TensorConfig(
data_gen=partial(generate_weight1)),
"elementwise_add1_weight":
TensorConfig(
data_gen=partial(generate_weight2)),
"elementwise_add2_weight":
TensorConfig(
data_gen=partial(generate_weight2)),
"elementwise_add3_weight":
TensorConfig(
data_gen=partial(generate_weight2)),
"mul1_weight": TensorConfig(
data_gen=partial(generate_weight1)
),
"mul2_weight": TensorConfig(
data_gen=partial(generate_weight1)
),
"mul3_weight": TensorConfig(
data_gen=partial(generate_weight1)
),
"mul4_weight": TensorConfig(
data_gen=partial(generate_weight1)
),
"elementwise_add1_weight": TensorConfig(
data_gen=partial(generate_weight2)
),
"elementwise_add2_weight": TensorConfig(
data_gen=partial(generate_weight2)
),
"elementwise_add3_weight": TensorConfig(
data_gen=partial(generate_weight2)
),
},
inputs={
"input_data1":
TensorConfig(data_gen=partial(
generate_input1, batch, dim1)),
"input_data2":
TensorConfig(data_gen=partial(
generate_input2, input2_shape)),
"input_data1": TensorConfig(
data_gen=partial(
generate_input1, batch, dim1
)
),
"input_data2": TensorConfig(
data_gen=partial(
generate_input2, input2_shape
)
),
},
outputs=["mul4_output"])
outputs=["mul4_output"],
)
yield program_config
class TrtConvertVitToMultiHeadMatmulTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input1(batch, length):
return np.zeros((batch, length, 768), dtype=np.float32)
......@@ -868,218 +808,192 @@ class TrtConvertVitToMultiHeadMatmulTest(TrtLayerAutoScanTest):
for batch in [2, 4]:
self.batch = batch
for length in [64, 384]:
for length in [197]:
self.length = length
ops_config = [{
"op_type": "matmul_v2",
"op_inputs": {
"X": ["input_data1"],
"Y": ["matmul1_weight"]
},
"op_outputs": {
"Out": ["matmul1_output"]
},
"op_attrs": {
"trans_x": False,
"trans_y": False
}
}, {
"op_type": "elementwise_add",
"op_inputs": {
"X": ["matmul1_output"],
"Y": ["elementwise_add1_weight"]
},
"op_outputs": {
"Out": ["elementwise_add1_output"]
ops_config = [
{
"op_type": "matmul_v2",
"op_inputs": {
"X": ["input_data1"],
"Y": ["matmul1_weight"],
},
"op_outputs": {"Out": ["matmul1_output"]},
"op_attrs": {"trans_x": False, "trans_y": False},
},
"op_attrs": {
"Scale_out": 1.0,
"Scale_x": 1.0,
"Scale_y": 1.0,
"axis": 2
}
}, {
"op_type": "reshape2",
"op_inputs": {
"X": ["elementwise_add1_output"],
{
"op_type": "elementwise_add",
"op_inputs": {
"X": ["matmul1_output"],
"Y": ["elementwise_add1_weight"],
},
"op_outputs": {"Out": ["elementwise_add1_output"]},
"op_attrs": {
"Scale_out": 1.0,
"Scale_x": 1.0,
"Scale_y": 1.0,
"axis": 2,
},
},
"op_outputs": {
"Out": ["reshape1_output"],
"XShape": ["reshape1_output_xshape"]
{
"op_type": "reshape2",
"op_inputs": {
"X": ["elementwise_add1_output"],
},
"op_outputs": {
"Out": ["reshape1_output"],
"XShape": ["reshape1_output_xshape"],
},
"op_attrs": {"shape": [-1, self.length, 3, 12, 64]},
},
"op_attrs": {
"shape": [-1, self.length, 3, 12, 64]
}
}, {
"op_type": "transpose2",
"op_inputs": {
"X": ["reshape1_output"]
{
"op_type": "transpose2",
"op_inputs": {"X": ["reshape1_output"]},
"op_outputs": {
"Out": ["transpose1_output"],
"XShape": ["transpose1_output_xshape"],
},
"op_attrs": {
"axis": [2, 0, 3, 1, 4],
"data_format": "AnyLayout",
},
},
"op_outputs": {
"Out": ["transpose1_output"],
"XShape": ["transpose1_output_xshape"]
{
"op_type": "slice",
"op_inputs": {
"Input": ["transpose1_output"],
},
"op_outputs": {"Out": ["slice1_output"]},
"op_attrs": {
"axes": [0],
"starts": [0],
"ends": [1],
"decrease_axis": [0],
"infer_flags": [1],
},
},
"op_attrs": {
"axis": [2, 0, 3, 1, 4],
"data_format": "AnyLayout"
}
}, {
"op_type": "slice",
"op_inputs": {
"Input": ["transpose1_output"],
{
"op_type": "slice",
"op_inputs": {
"Input": ["transpose1_output"],
},
"op_outputs": {"Out": ["slice2_output"]},
"op_attrs": {
"axes": [0],
"starts": [1],
"ends": [2],
"decrease_axis": [0],
"infer_flags": [1],
},
},
"op_outputs": {
"Out": ["slice1_output"]
{
"op_type": "slice",
"op_inputs": {
"Input": ["transpose1_output"],
},
"op_outputs": {"Out": ["slice3_output"]},
"op_attrs": {
"axes": [0],
"starts": [2],
"ends": [3],
"decrease_axis": [0],
"infer_flags": [1],
},
},
"op_attrs": {
"axes": [0],
"starts": [0],
"ends": [1],
"decrease_axis": [0],
"infer_flags": [1]
}
}, {
"op_type": "slice",
"op_inputs": {
"Input": ["transpose1_output"],
{
"op_type": "transpose2",
"op_inputs": {"X": ["slice2_output"]},
"op_outputs": {
"Out": ["transpose2_output"],
},
"op_attrs": {
"axis": [0, 1, 3, 2],
"data_format": "AnyLayout",
},
},
"op_outputs": {
"Out": ["slice2_output"]
{
"op_type": "matmul_v2",
"op_inputs": {
"X": ["slice1_output"],
"Y": ["transpose2_output"],
},
"op_outputs": {"Out": ["matmul2_output"]},
"op_attrs": {"trans_x": False, "trans_y": False},
},
"op_attrs": {
"axes": [0],
"starts": [1],
"ends": [2],
"decrease_axis": [0],
"infer_flags": [1]
}
}, {
"op_type": "slice",
"op_inputs": {
"Input": ["transpose1_output"],
{
"op_type": "scale",
"op_inputs": {
"X": ["matmul2_output"],
},
"op_outputs": {"Out": ["scale_output"]},
"op_attrs": {
"scale": 0.125,
"bias": 0.0,
"bias_after_scale": True,
},
},
"op_outputs": {
"Out": ["slice3_output"]
{
"op_type": "softmax",
"op_inputs": {"X": ["scale_output"]},
"op_outputs": {"Out": ["softmax_output"]},
"op_attrs": {"axis": -1, "data_format": "AnyLayout"},
},
"op_attrs": {
"axes": [0],
"starts": [2],
"ends": [3],
"decrease_axis": [0],
"infer_flags": [1]
}
}, {
"op_type": "transpose2",
"op_inputs": {
"X": ["slice2_output"]
{
"op_type": "matmul_v2",
"op_inputs": {
"X": ["softmax_output"],
"Y": ["slice3_output"],
},
"op_outputs": {"Out": ["matmul3_output"]},
"op_attrs": {"trans_x": False, "trans_y": False},
},
"op_outputs": {
"Out": ["transpose2_output"],
{
"op_type": "transpose2",
"op_inputs": {"X": ["matmul3_output"]},
"op_outputs": {
"Out": ["transpose3_output"],
"XShape": ["transpose3_output_xshape"],
},
"op_attrs": {
"axis": [0, 2, 1, 3],
"data_format": "AnyLayout",
},
},
"op_attrs": {
"axis": [0, 1, 3, 2],
"data_format": "AnyLayout"
}
}, {
"op_type": "matmul_v2",
"op_inputs": {
"X": ["slice1_output"],
"Y": ["transpose2_output"]
{
"op_type": "reshape2",
"op_inputs": {"X": ["transpose3_output"]},
"op_outputs": {
"Out": ["reshape2_output"],
"XShape": ["reshape2_output_xshape"],
},
"op_attrs": {"shape": [-1, self.length, 768]},
},
"op_outputs": {
"Out": ["matmul2_output"]
},
"op_attrs": {
"trans_x": False,
"trans_y": False
}
}, {
"op_type": "scale",
"op_inputs": {
"X": ["matmul2_output"],
},
"op_outputs": {
"Out": ["scale_output"]
},
"op_attrs": {
"scale": 0.125,
"bias": 0.0,
"bias_after_scale": True
}
}, {
"op_type": "softmax",
"op_inputs": {
"X": ["scale_output"]
},
"op_outputs": {
"Out": ["softmax_output"]
},
"op_attrs": {
"axis": -1,
"data_format": "AnyLayout"
}
}, {
"op_type": "matmul_v2",
"op_inputs": {
"X": ["softmax_output"],
"Y": ["slice3_output"]
},
"op_outputs": {
"Out": ["matmul3_output"]
},
"op_attrs": {
"trans_x": False,
"trans_y": False
}
}, {
"op_type": "transpose2",
"op_inputs": {
"X": ["matmul3_output"]
},
"op_outputs": {
"Out": ["transpose3_output"],
"XShape": ["transpose3_output_xshape"]
},
"op_attrs": {
"axis": [0, 2, 1, 3],
"data_format": "AnyLayout"
}
}, {
"op_type": "reshape2",
"op_inputs": {
"X": ["transpose3_output"]
},
"op_outputs": {
"Out": ["reshape2_output"],
"XShape": ["reshape2_output_xshape"]
},
"op_attrs": {
"shape": [-1, self.length, 768]
}
}]
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={
"matmul1_weight":
TensorConfig(data_gen=partial(generate_weight1)),
"elementwise_add1_weight":
TensorConfig(data_gen=partial(generate_weight2))
"matmul1_weight": TensorConfig(
data_gen=partial(generate_weight1)
),
"elementwise_add1_weight": TensorConfig(
data_gen=partial(generate_weight2)
),
},
inputs={
"input_data1":
TensorConfig(
data_gen=partial(generate_input1, batch, length))
"input_data1": TensorConfig(
data_gen=partial(generate_input1, batch, length)
)
},
outputs=["reshape2_output"])
outputs=["reshape2_output"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
# The last dim of input1 and input2 should be static.
self.dynamic_shape.min_input_shape = {
......@@ -1111,11 +1025,15 @@ class TrtConvertVitToMultiHeadMatmulTest(TrtLayerAutoScanTest):
generate_dynamic_shape(attrs)
self.trt_param.workspace_size = 2013265920
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(), (1e-3,
1e-3)
yield self.create_inference_config(), generate_trt_nodes_num(), (
1e-3,
1e-3,
)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(), (1e-5,
1e-5)
yield self.create_inference_config(), generate_trt_nodes_num(), (
1e-5,
1e-5,
)
def add_skip_trt_case(self):
pass
......
......@@ -22,30 +22,30 @@ import unittest
class TrtConvertPad3d(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input1():
return np.ones([1, 1, 3, 64, 64]).astype(np.float32)
for value in [True, False]:
for paddings in [[0, 0, 0, 0, 1, 1], [0, 0, 1, 2, 3, 4],
[1, 1, 1, 1, 1, 1], [0, 0, -1, -1, 1, 1]]:
for paddings in [
[0, 0, 0, 0, 1, 1],
[0, 0, 1, 2, 3, 4],
[1, 1, 1, 1, 1, 1],
[0, 0, -1, -1, 1, 1],
]:
dics = [{"value": value, "paddings": paddings}, {}]
ops_config = [{
"op_type": "pad3d",
"op_inputs": {
"X": ["input_data"]
},
"op_outputs": {
"Out": ["output_data"]
},
"op_attrs": dics[0]
}]
ops_config = [
{
"op_type": "pad3d",
"op_inputs": {"X": ["input_data"]},
"op_outputs": {"Out": ["output_data"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
for i in range(10):
......@@ -53,16 +53,18 @@ class TrtConvertPad3d(TrtLayerAutoScanTest):
ops=ops,
weights={},
inputs={
"input_data":
TensorConfig(data_gen=partial(generate_input1)),
"input_data": TensorConfig(
data_gen=partial(generate_input1)
),
},
outputs=["output_data"])
outputs=["output_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {
"input_data": [1, 1, 3, 64, 64]
......@@ -88,14 +90,14 @@ class TrtConvertPad3d(TrtLayerAutoScanTest):
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), (0, 3), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), (0, 3), 1e-5
yield self.create_inference_config(), (0, 3), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), (1, 2), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), (1, 2), 1e-5
yield self.create_inference_config(), (1, 2), 1e-3
def test(self):
self.run_test()
......
......@@ -20,10 +20,10 @@ from functools import partial
from typing import Optional, List, Callable, Dict, Any, Set
import unittest
import itertools
import copy
class TrtConvertPool2dTest(TrtLayerAutoScanTest):
def is_paddings_valid(self, program_config: ProgramConfig) -> bool:
exclusive = program_config.ops[0].attrs['exclusive']
paddings = program_config.ops[0].attrs['paddings']
......@@ -65,39 +65,54 @@ class TrtConvertPool2dTest(TrtLayerAutoScanTest):
ceil_mode_options = [True, False]
configurations = [
strides_options, paddings_options, pooling_type_options,
padding_algorithm_options, ksize_options, data_format_options,
global_pooling_options, exclusive_options, adaptive_option,
ceil_mode_options
strides_options,
paddings_options,
pooling_type_options,
padding_algorithm_options,
ksize_options,
data_format_options,
global_pooling_options,
exclusive_options,
adaptive_option,
ceil_mode_options,
]
for (strides, paddings, pooling_type, padding_algorithm, ksize,
data_format, global_pooling, exclusive, adaptive,
ceil_mode) in itertools.product(*configurations):
attrs = [{
"strides": strides,
"paddings": paddings,
"pooling_type": pooling_type,
"padding_algorithm": padding_algorithm,
"ksize": ksize,
"data_format": data_format,
"global_pooling": global_pooling,
"exclusive": exclusive,
"adaptive": adaptive,
"ceil_mode": ceil_mode,
}]
ops_config = [{
"op_type": "pool2d",
"op_inputs": {
"X": ["input_data"]
},
"op_outputs": {
"Out": ["output_data"]
},
"op_attrs": attrs[0]
}]
for (
strides,
paddings,
pooling_type,
padding_algorithm,
ksize,
data_format,
global_pooling,
exclusive,
adaptive,
ceil_mode,
) in itertools.product(*configurations):
attrs = [
{
"strides": strides,
"paddings": paddings,
"pooling_type": pooling_type,
"padding_algorithm": padding_algorithm,
"ksize": ksize,
"data_format": data_format,
"global_pooling": global_pooling,
"exclusive": exclusive,
"adaptive": adaptive,
"ceil_mode": ceil_mode,
}
]
ops_config = [
{
"op_type": "pool2d",
"op_inputs": {"X": ["input_data"]},
"op_outputs": {"Out": ["output_data"]},
"op_attrs": attrs[0],
}
]
ops = self.generate_op_config(ops_config)
......@@ -105,16 +120,18 @@ class TrtConvertPool2dTest(TrtLayerAutoScanTest):
ops=ops,
weights={},
inputs={
"input_data":
TensorConfig(data_gen=partial(generate_input1, attrs))
"input_data": TensorConfig(
data_gen=partial(generate_input1, attrs)
)
},
outputs=["output_data"])
outputs=["output_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {"input_data": [1, 3, 32, 32]}
self.dynamic_shape.max_input_shape = {"input_data": [1, 3, 64, 64]}
......@@ -136,36 +153,75 @@ class TrtConvertPool2dTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), (1e-3, 1e-3)
attrs, False
), (1e-3, 1e-3)
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), (1e-3, 1e-3)
attrs, True
), (1e-3, 1e-3)
def add_skip_trt_case(self):
def teller(program_config, predictor_config):
if program_config.ops[0].attrs['pooling_type'] == 'avg' and \
program_config.ops[0].attrs['global_pooling'] == False and \
program_config.ops[0].attrs['exclusive'] == True and \
program_config.ops[0].attrs['adaptive'] == False and \
program_config.ops[0].attrs['ceil_mode'] == True:
if (
program_config.ops[0].attrs['pooling_type'] == 'avg'
and program_config.ops[0].attrs['global_pooling'] == False
and program_config.ops[0].attrs['exclusive'] == True
and program_config.ops[0].attrs['adaptive'] == False
and program_config.ops[0].attrs['ceil_mode'] == True
):
return True
return False
self.add_skip_case(
teller, SkipReasons.TRT_NOT_IMPLEMENTED,
"The results of some cases are Nan, but the results of TensorRT and GPU are the same."
teller,
SkipReasons.TRT_NOT_IMPLEMENTED,
"The results of some cases are Nan, but the results of TensorRT and GPU are the same.",
)
def assert_tensors_near(
self,
atol: float,
rtol: float,
tensor: Dict[str, np.array],
baseline: Dict[str, np.array],
):
for key, arr in tensor.items():
self.assertEqual(
baseline[key].shape,
arr.shape,
'The output shapes are not equal, the baseline shape is '
+ str(baseline[key].shape)
+ ', but got '
+ str(arr.shape),
)
# The result of Pool2d may have some elements that is the least value (-65504 for FP16),
# but for FP32 and FP16 precision, their least value are different.
# We set a threshold that is the least value of FP16,
# and make the values less than the threshold to be the threshold.
def align_less_threshold(arr, threshold):
return np.clip(arr, threshold, None)
fp16_min = np.finfo(np.float16).min
baseline_threshold = align_less_threshold(
copy.deepcopy(baseline[key]), fp16_min
)
arr_threshold = align_less_threshold(copy.deepcopy(arr), fp16_min)
np.testing.assert_allclose(
baseline_threshold, arr_threshold, rtol=rtol, atol=atol
)
def test(self):
self.add_skip_trt_case()
self.run_test()
......
......@@ -23,7 +23,6 @@ import unittest
class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
inputs = program_config.inputs
attrs = [
......@@ -41,7 +40,6 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
return True
def sample_program_configs(self):
def generate_input1(dtype, attrs: List[Dict[str, Any]]):
if dtype == -1 or dtype == 5:
return np.random.random([1, 3, 32, 32]).astype(np.float32)
......@@ -49,39 +47,52 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
return np.random.random([1, 3, 32, 32]).astype(np.int32)
for keep_dim in [True, False]:
for dim in [[], [1], [0], [0, 1], [1, 2, 3], [-2, 0, 3], [-3],
[-4, 1], [3, 4, 5]]:
for dim in [
[],
[1],
[0],
[0, 1],
[1, 2, 3],
[-2, 0, 3],
[-3],
[-4, 1],
[3, 4, 5],
]:
for reduce_all in [True, False]:
for out_dtype in [-1, 2, 5]:
dics = [{
"keep_dim": keep_dim,
"dim": dim,
"reduce_all": reduce_all,
"out_dtype": out_dtype,
"in_dtype": out_dtype,
}, {}]
ops_config = [{
"op_type": "reduce_sum",
"op_inputs": {
"X": ["input_data"]
dics = [
{
"keep_dim": keep_dim,
"dim": dim,
"reduce_all": reduce_all,
"out_dtype": out_dtype,
"in_dtype": out_dtype,
},
"op_outputs": {
"Out": ["reduce_output_data"]
},
"op_attrs": dics[0]
}]
{},
]
ops_config = [
{
"op_type": "reduce_sum",
"op_inputs": {"X": ["input_data"]},
"op_outputs": {"Out": ["reduce_output_data"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input_data":
TensorConfig(data_gen=partial(
generate_input1, out_dtype, dics))
"input_data": TensorConfig(
data_gen=partial(
generate_input1, out_dtype, dics
)
)
},
outputs=["reduce_output_data"])
outputs=["reduce_output_data"],
)
if not self.is_program_valid(program_config):
continue
......@@ -89,7 +100,6 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
yield program_config
def sample_predictor_configs(self, program_config):
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {"input_data": [1, 3, 32, 32]}
self.dynamic_shape.max_input_shape = {"input_data": [4, 3, 64, 64]}
......@@ -120,19 +130,23 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), (1e-5, 1e-5)
attrs, False
), (1e-5, 1e-5)
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), (1e-4, 1e-4)
attrs, False
), (1e-3, 1e-3)
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), (1e-5, 1e-5)
attrs, True
), (1e-5, 1e-5)
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), (1e-4, 1e-4)
attrs, True
), (1e-3, 1e-3)
pass
......
......@@ -22,7 +22,6 @@ import unittest
class TrtConvertReshapeTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
attrs = [
program_config.ops[i].attrs for i in range(len(program_config.ops))
......@@ -31,7 +30,7 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
if len(attrs[0]['shape']) != 1:
return False
#To test if the shape contains 0
# To test if the shape contains 0
if len(attrs[0]['shape']) == 3:
if attrs[0]['shape'][1] == 0:
if self.dims != 3:
......@@ -45,7 +44,6 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
return True
def sample_program_configs(self):
def generate_input1(attrs: List[Dict[str, Any]]):
if self.dims == 4:
self.input_shape = [1, 2, 4, 6]
......@@ -70,9 +68,18 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
return np.array([24]).astype(np.int32)
for dims in [4, 3, 2, 1]:
for shape in [[1, 6, 8], [1, 2, 4, 6], [1, 1, 0, 12], [1, 0, 6],
[1, -1, 12], [2, -1], [3, 16], [3, 4, 4], [48],
[-1, 48]]:
for shape in [
[1, 6, 8],
[1, 2, 4, 6],
[1, 1, 0, 12],
[1, 0, 6],
[1, -1, 12],
[2, -1],
[3, 16],
[3, 4, 4],
[48],
[-1, 48],
]:
dics = [
{
"shape": shape,
......@@ -81,29 +88,31 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
self.dims = dims
dics_intput = [{"X": ["reshape_input"]}]
ops_config = [{
"op_type": "reshape",
"op_inputs": dics_intput[0],
"op_outputs": {
"Out": ["reshape_out"]
},
"op_attrs": dics[0]
}]
ops_config = [
{
"op_type": "reshape",
"op_inputs": dics_intput[0],
"op_outputs": {"Out": ["reshape_out"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"reshape_input":
TensorConfig(data_gen=partial(generate_input1, dics))
"reshape_input": TensorConfig(
data_gen=partial(generate_input1, dics)
)
},
outputs=["reshape_out"])
outputs=["reshape_out"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
if self.dims == 4:
self.dynamic_shape.min_input_shape = {
......@@ -141,13 +150,14 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
def generate_trt_nodes_num(attrs, dynamic_shape):
# in static shape mode, here is consistent with op_teller.cc
if (not dynamic_shape):
if (attrs[0]['shape'][0] == 0):
if not dynamic_shape:
if attrs[0]['shape'][0] == 0:
return 1, 2
elif (len(attrs[0]['shape']) == 1):
elif len(attrs[0]['shape']) == 1:
return 0, 3
elif (np.prod(attrs[0]['shape'][1:]) == np.prod(
self.input_shape[1:])):
elif np.prod(attrs[0]['shape'][1:]) == np.prod(
self.input_shape[1:]
):
return 1, 2
else:
return 0, 3
......@@ -161,19 +171,23 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-3
def add_skip_trt_case(self):
pass
......@@ -185,12 +199,10 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
# reshape having three inputs.
class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input1(attrs: List[Dict[str, Any]]):
if self.dims == 4:
return np.random.random([1, 2, 4, 6]).astype(np.float32)
......@@ -203,9 +215,12 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
for dims in [4, 3, 2, 1]:
for shape in [[-1, 48]]:
dics = [{
"shape": shape,
}, {}]
dics = [
{
"shape": shape,
},
{},
]
self.dims = dims
dics_intput = [
{
......@@ -217,9 +232,7 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
{
"op_type": "fill_constant",
"op_inputs": {},
"op_outputs": {
"Out": ["shapeT1_data"]
},
"op_outputs": {"Out": ["shapeT1_data"]},
"op_attrs": {
"dtype": 2,
"str_value": "2",
......@@ -229,9 +242,7 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
{
"op_type": "fill_constant",
"op_inputs": {},
"op_outputs": {
"Out": ["shapeT2_data"]
},
"op_outputs": {"Out": ["shapeT2_data"]},
"op_attrs": {
"dtype": 2,
"str_value": "24",
......@@ -241,10 +252,8 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
{
"op_type": "reshape",
"op_inputs": dics_intput[0],
"op_outputs": {
"Out": ["reshape_out"]
},
"op_attrs": dics[0]
"op_outputs": {"Out": ["reshape_out"]},
"op_attrs": dics[0],
},
]
ops = self.generate_op_config(ops_config)
......@@ -252,16 +261,18 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
ops=ops,
weights={},
inputs={
"reshape_input":
TensorConfig(data_gen=partial(generate_input1, dics))
"reshape_input": TensorConfig(
data_gen=partial(generate_input1, dics)
)
},
outputs=["reshape_out"])
outputs=["reshape_out"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape():
if self.dims == 4:
self.dynamic_shape.min_input_shape = {
......@@ -297,7 +308,7 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), (1, 2), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), (1, 2), 1e-5
yield self.create_inference_config(), (1, 2), 1e-3
def add_skip_trt_case(self):
pass
......@@ -309,12 +320,10 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
# reshape having 2 inputs.
class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input1(attrs: List[Dict[str, Any]]):
if self.dims == 4:
return np.random.random([1, 2, 12, 6]).astype(np.float32)
......@@ -327,9 +336,12 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
for dims in [4, 3, 2, 1]:
for shape in [[-1, 144]]:
dics = [{
"shape": shape,
}, {}]
dics = [
{
"shape": shape,
},
{},
]
self.dims = dims
dics_intput = [
{
......@@ -341,9 +353,7 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
{
"op_type": "fill_constant",
"op_inputs": {},
"op_outputs": {
"Out": ["shape_data"]
},
"op_outputs": {"Out": ["shape_data"]},
"op_attrs": {
"dtype": 2,
"str_value": "12",
......@@ -353,10 +363,8 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
{
"op_type": "reshape",
"op_inputs": dics_intput[0],
"op_outputs": {
"Out": ["reshape_out"]
},
"op_attrs": dics[0]
"op_outputs": {"Out": ["reshape_out"]},
"op_attrs": dics[0],
},
]
ops = self.generate_op_config(ops_config)
......@@ -364,16 +372,18 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
ops=ops,
weights={},
inputs={
"reshape_input":
TensorConfig(data_gen=partial(generate_input1, dics))
"reshape_input": TensorConfig(
data_gen=partial(generate_input1, dics)
)
},
outputs=["reshape_out"])
outputs=["reshape_out"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape():
if self.dims == 4:
self.dynamic_shape.min_input_shape = {
......@@ -409,7 +419,7 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), (1, 2), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), (1, 2), 1e-5
yield self.create_inference_config(), (1, 2), 1e-3
def add_skip_trt_case(self):
pass
......
......@@ -22,12 +22,10 @@ from typing import Optional, List, Callable, Dict, Any, Set
class TrtConvertRoiAlignTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input1(attrs: List[Dict[str, Any]], batch):
return np.ones([batch, 256, 32, 32]).astype(np.float32)
......@@ -47,92 +45,111 @@ class TrtConvertRoiAlignTest(TrtLayerAutoScanTest):
self.num_input = num_input
if num_input == 1:
batch = 1
dics = [{
"spatial_scale": spatial_scale,
"pooled_height": pooled_height,
"pooled_width": pooled_width,
"sampling_ratio": sampling_ratio,
"aligned": aligned
}, {}]
dics_input = [{
"X": ["roi_align_input"],
"ROIs": ["ROIs"],
"RoisNum": ["RoisNum"]
}, {
"X": ["roi_align_input"],
"ROIs": ["ROIs"]
}]
program_input = [{
"roi_align_input":
TensorConfig(data_gen=partial(
generate_input1, dics, batch)),
"ROIs":
TensorConfig(data_gen=partial(
generate_input2, dics, batch)),
"RoisNum":
TensorConfig(data_gen=partial(
generate_input3, dics, batch))
}, {
"roi_align_input":
TensorConfig(data_gen=partial(
generate_input1, dics, batch)),
"ROIs":
TensorConfig(data_gen=partial(
generate_input2, dics, batch),
lod=[[32, 3]])
}]
ops_config = [{
"op_type":
"roi_align",
"op_inputs":
dics_input[num_input],
"op_outputs": {
"Out": ["roi_align_out"]
dics = [
{
"spatial_scale": spatial_scale,
"pooled_height": pooled_height,
"pooled_width": pooled_width,
"sampling_ratio": sampling_ratio,
"aligned": aligned,
},
{},
]
dics_input = [
{
"X": ["roi_align_input"],
"ROIs": ["ROIs"],
"RoisNum": ["RoisNum"],
},
{
"X": ["roi_align_input"],
"ROIs": ["ROIs"],
},
]
program_input = [
{
"roi_align_input": TensorConfig(
data_gen=partial(
generate_input1, dics, batch
)
),
"ROIs": TensorConfig(
data_gen=partial(
generate_input2, dics, batch
)
),
"RoisNum": TensorConfig(
data_gen=partial(
generate_input3, dics, batch
)
),
},
{
"roi_align_input": TensorConfig(
data_gen=partial(
generate_input1, dics, batch
)
),
"ROIs": TensorConfig(
data_gen=partial(
generate_input2, dics, batch
),
lod=[[32, 3]],
),
},
"op_attrs":
dics[0]
}]
]
ops_config = [
{
"op_type": "roi_align",
"op_inputs": dics_input[num_input],
"op_outputs": {
"Out": ["roi_align_out"]
},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs=program_input[num_input],
outputs=["roi_align_out"])
outputs=["roi_align_out"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
if self.num_input == 0:
self.dynamic_shape.min_input_shape = {
"roi_align_input": [1, 256, 32, 32],
"ROIs": [3, 4],
"RoisNum": [1]
"RoisNum": [1],
}
self.dynamic_shape.max_input_shape = {
"roi_align_input": [1, 256, 64, 64],
"ROIs": [3, 4],
"RoisNum": [1]
"RoisNum": [1],
}
self.dynamic_shape.opt_input_shape = {
"roi_align_input": [1, 256, 64, 64],
"ROIs": [3, 4],
"RoisNum": [1]
"RoisNum": [1],
}
elif self.num_input == 1:
self.dynamic_shape.min_input_shape = {
"roi_align_input": [1, 256, 32, 32],
"ROIs": [3, 4]
"ROIs": [3, 4],
}
self.dynamic_shape.max_input_shape = {
"roi_align_input": [1, 256, 64, 64],
"ROIs": [3, 4]
"ROIs": [3, 4],
}
self.dynamic_shape.opt_input_shape = {
"roi_align_input": [1, 256, 64, 64],
"ROIs": [3, 4]
"ROIs": [3, 4],
}
def clear_dynamic_shape():
......@@ -159,29 +176,33 @@ class TrtConvertRoiAlignTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-3
def add_skip_trt_case(self):
def teller1(program_config, predictor_config):
if len(program_config.inputs) == 3:
return True
return False
self.add_skip_case(teller1, SkipReasons.TRT_NOT_SUPPORT,
"INPUT RoisNum NOT SUPPORT")
self.add_skip_case(
teller1, SkipReasons.TRT_NOT_SUPPORT, "INPUT RoisNum NOT SUPPORT"
)
def test(self):
self.add_skip_trt_case()
......
......@@ -22,7 +22,6 @@ import unittest
class TrtConvertRollTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
inputs = program_config.inputs
weights = program_config.weights
......@@ -32,43 +31,44 @@ class TrtConvertRollTest(TrtLayerAutoScanTest):
return True
def sample_program_configs(self):
def generate_input1(attrs: List[Dict[str, Any]]):
return np.ones([1, 56, 56, 192]).astype(np.float32)
for axis in [[1, 2]]:
for shifts in [[-1, -1], [-3, -3]]:
dics = [{
"axis": axis,
"shifts": shifts,
}]
ops_config = [{
"op_type": "roll",
"op_inputs": {
"X": ["input_data"]
},
"op_outputs": {
"Out": ["roll_output_data"]
},
"op_attrs": dics[0]
}]
dics = [
{
"axis": axis,
"shifts": shifts,
}
]
ops_config = [
{
"op_type": "roll",
"op_inputs": {"X": ["input_data"]},
"op_outputs": {"Out": ["roll_output_data"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input_data":
TensorConfig(data_gen=partial(generate_input1, dics))
"input_data": TensorConfig(
data_gen=partial(generate_input1, dics)
)
},
outputs=["roll_output_data"])
outputs=["roll_output_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {
"input_data": [1, 56, 56, 192]
......@@ -103,19 +103,23 @@ class TrtConvertRollTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-4
attrs, False
), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-4
attrs, True
), 1e-3
def test(self):
self.run_test()
......
......@@ -22,12 +22,10 @@ import unittest
class TrtConvertScatterNd(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input1():
return np.random.random([6]).astype(np.float32)
......@@ -37,38 +35,42 @@ class TrtConvertScatterNd(TrtLayerAutoScanTest):
def generate_input3():
return np.random.random([4]).astype(np.float32)
ops_config = [{
"op_type": "scatter_nd_add",
"op_inputs": {
"X": ["input_data"],
"Index": ["index_data"],
"Updates": ["update_data"]
},
"op_outputs": {
"Out": ["output_data"]
},
"op_attrs": {}
}]
ops_config = [
{
"op_type": "scatter_nd_add",
"op_inputs": {
"X": ["input_data"],
"Index": ["index_data"],
"Updates": ["update_data"],
},
"op_outputs": {"Out": ["output_data"]},
"op_attrs": {},
}
]
ops = self.generate_op_config(ops_config)
for i in range(10):
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input_data":
TensorConfig(data_gen=partial(generate_input1)),
"index_data":
TensorConfig(data_gen=partial(generate_input2)),
"update_data":
TensorConfig(data_gen=partial(generate_input3)),
"input_data": TensorConfig(
data_gen=partial(generate_input1)
),
"index_data": TensorConfig(
data_gen=partial(generate_input2)
),
"update_data": TensorConfig(
data_gen=partial(generate_input3)
),
},
outputs=["output_data"])
outputs=["output_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {
"input_data": [1],
......@@ -100,14 +102,14 @@ class TrtConvertScatterNd(TrtLayerAutoScanTest):
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), (0, 5), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), (0, 5), 1e-5
yield self.create_inference_config(), (0, 5), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), (1, 4), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), (1, 4), 1e-5
yield self.create_inference_config(), (1, 4), 1e-3
def test(self):
self.run_test()
......
......@@ -22,12 +22,10 @@ import unittest
class TrtConvertSumTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input1(batch):
if self.dims == 4:
return np.ones([batch, 3, 24, 24]).astype(np.float32)
......@@ -41,31 +39,31 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
for dims in [1, 2, 3, 4]:
for batch in [1, 4]:
self.dims = dims
ops_config = [{
"op_type": "shape",
"op_inputs": {
"Input": ["input1"]
},
"op_outputs": {
"Out": ["output"]
},
"op_attrs": {}
}]
ops_config = [
{
"op_type": "shape",
"op_inputs": {"Input": ["input1"]},
"op_outputs": {"Out": ["output"]},
"op_attrs": {},
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input1":
TensorConfig(data_gen=partial(generate_input1, batch))
"input1": TensorConfig(
data_gen=partial(generate_input1, batch)
)
},
outputs=["output"])
outputs=["output"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape():
if self.dims == 4:
self.dynamic_shape.min_input_shape = {"input1": [1, 3, 24, 24]}
......@@ -87,7 +85,7 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
}
def generate_trt_nodes_num(dynamic_shape):
if (not dynamic_shape):
if not dynamic_shape:
return 0, 3
return 1, 2
......@@ -100,17 +98,19 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
False), 1e-5
False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
False), 1e-5
False
), 1e-3
# for dynamic_shape
generate_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(True), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(True), 1e-5
yield self.create_inference_config(), generate_trt_nodes_num(True), 1e-3
def test(self):
self.run_test()
......
......@@ -22,44 +22,41 @@ import unittest
class TrtConvertShuffleChannelTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input1(attrs: List[Dict[str, Any]], batch):
return np.ones([batch, 6, 24, 24]).astype(np.float32)
for batch in [1, 2, 4]:
for group in [1, 2, 3]:
dics = [{"group": group}, {}]
ops_config = [{
"op_type": "shuffle_channel",
"op_inputs": {
"X": ["shuffle_channel_input"]
},
"op_outputs": {
"Out": ["shuffle_channel_out"]
},
"op_attrs": dics[0]
}]
ops_config = [
{
"op_type": "shuffle_channel",
"op_inputs": {"X": ["shuffle_channel_input"]},
"op_outputs": {"Out": ["shuffle_channel_out"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"shuffle_channel_input":
TensorConfig(
data_gen=partial(generate_input1, dics, batch))
"shuffle_channel_input": TensorConfig(
data_gen=partial(generate_input1, dics, batch)
)
},
outputs=["shuffle_channel_out"])
outputs=["shuffle_channel_out"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {
"shuffle_channel_input": [1, 6, 24, 24]
......@@ -78,8 +75,10 @@ class TrtConvertShuffleChannelTest(TrtLayerAutoScanTest):
def generate_trt_nodes_num(attrs, dynamic_shape):
ver = paddle_infer.get_trt_compile_version()
if ver[0] * 1000 + ver[1] * 100 + ver[
2] * 10 < 8000 and dynamic_shape == True:
if (
ver[0] * 1000 + ver[1] * 100 + ver[2] * 10 < 8000
and dynamic_shape == True
):
return 0, 3
else:
return 1, 2
......@@ -92,19 +91,23 @@ class TrtConvertShuffleChannelTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-3
def add_skip_trt_case(self):
pass
......
......@@ -22,7 +22,6 @@ import unittest
class TrtConvertSliceTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
inputs = program_config.inputs
weights = program_config.weights
......@@ -34,13 +33,17 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
start = 0
end = 0
if attrs[0]["starts"][x] < 0:
start = attrs[0]["starts"][x] + inputs['input_data'].shape[
attrs[0]["axes"][x]]
start = (
attrs[0]["starts"][x]
+ inputs['input_data'].shape[attrs[0]["axes"][x]]
)
else:
start = attrs[0]["starts"][x]
if attrs[0]["ends"][x] < 0:
end = attrs[0]["ends"][x] + inputs['input_data'].shape[
attrs[0]["axes"][x]]
end = (
attrs[0]["ends"][x]
+ inputs['input_data'].shape[attrs[0]["axes"][x]]
)
else:
end = attrs[0]["ends"][x]
start = max(0, start)
......@@ -51,12 +54,11 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
for x in attrs[0]["decrease_axis"]:
if x < 0:
return False
if (out_shape[x] != 1):
if out_shape[x] != 1:
return False
return True
def sample_program_configs(self):
def generate_input1(attrs: List[Dict[str, Any]]):
return np.random.random([6, 6, 64, 64]).astype(np.float32)
......@@ -65,41 +67,44 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
for ends in [[2, 2], [5, 5], [1, -1]]:
for decrease_axis in [[], [1], [2], [-1], [-100]]:
for infer_flags in [[-1]]:
dics = [{
"axes": axes,
"starts": starts,
"ends": ends,
"decrease_axis": decrease_axis,
"infer_flags": infer_flags
}]
ops_config = [{
"op_type": "slice",
"op_inputs": {
"Input": ["input_data"]
},
"op_outputs": {
"Out": ["slice_output_data"]
},
"op_attrs": dics[0]
}]
dics = [
{
"axes": axes,
"starts": starts,
"ends": ends,
"decrease_axis": decrease_axis,
"infer_flags": infer_flags,
}
]
ops_config = [
{
"op_type": "slice",
"op_inputs": {"Input": ["input_data"]},
"op_outputs": {
"Out": ["slice_output_data"]
},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input_data":
TensorConfig(
data_gen=partial(generate_input1, dics))
"input_data": TensorConfig(
data_gen=partial(generate_input1, dics)
)
},
outputs=["slice_output_data"])
outputs=["slice_output_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {"input_data": [1, 3, 32, 32]}
self.dynamic_shape.max_input_shape = {"input_data": [8, 8, 64, 64]}
......@@ -125,19 +130,23 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-4
attrs, False
), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-4
attrs, True
), 1e-3
def test(self):
# TODO(inference): fix.
......
......@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
class TrtConvertSplitTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
inputs = program_config.inputs
weights = program_config.weights
......@@ -35,13 +34,13 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
if len(inputs['split_input'].shape) <= attrs[0]['axis']:
return False
#Sections and num cannot both be equal to 0.
# Sections and num cannot both be equal to 0.
if len(attrs[0]['sections']) == 0:
if attrs[0]['num'] == 0:
return False
#When sections and num are not both equal to 0, sections has higher priority.
#The sum of sections should be equal to the input size.
# When sections and num are not both equal to 0, sections has higher priority.
# The sum of sections should be equal to the input size.
if len(attrs[0]['sections']) != 0:
if attrs[0]['num'] != 0:
return False
......@@ -53,16 +52,18 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
if sum != inputs['split_input'].shape[attrs[0]['axis']]:
return False
#The size of num should be equal to the input dimension.
# The size of num should be equal to the input dimension.
if attrs[0]['num'] != 0:
if len(outputs) != attrs[0]['num']:
return False
#Test AxisTensor and SectionsTensorList
# Test AxisTensor and SectionsTensorList
if self.num_input == 0:
if self.dims == 2 and attrs[0]['sections'] == [
10, 14
] and len(outputs) == 2:
if (
self.dims == 2
and attrs[0]['sections'] == [10, 14]
and len(outputs) == 2
):
return True
else:
return False
......@@ -70,7 +71,6 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
return True
def sample_program_configs(self):
def generate_input1(attrs: List[Dict[str, Any]], batch):
if self.dims == 4:
return np.random.random([batch, 3, 3, 24]).astype(np.float32)
......@@ -93,72 +93,95 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
for num_input in [0, 1]:
for dims in [1, 2, 3, 4]:
for batch in [3, 6, 9]:
for Out in [["output_var0", "output_var1"],
["output_var0", "output_var1", "output_var2"]]:
for sections in [[], [1, 2], [2, 1], [10, 14],
[1, 1, 1], [2, 2, 2], [3, 3, 3],
[3, 7, 14]]:
for Out in [
["output_var0", "output_var1"],
["output_var0", "output_var1", "output_var2"],
]:
for sections in [
[],
[1, 2],
[2, 1],
[10, 14],
[1, 1, 1],
[2, 2, 2],
[3, 3, 3],
[3, 7, 14],
]:
for num in [0, 3]:
for axis in [0, 1, 2, 3]:
self.batch = batch
self.num_input = num_input
self.dims = dims
dics = [{
"sections": sections,
"num": num,
"axis": axis
}, {}]
dics_intput = [{
"X": ["split_input"],
"AxisTensor": ["AxisTensor"],
"SectionsTensorList": [
"SectionsTensorList1",
"SectionsTensorList2"
]
}, {
"X": ["split_input"]
}]
dics_intputs = [{
"AxisTensor":
TensorConfig(data_gen=partial(
generate_AxisTensor, dics)),
"SectionsTensorList1":
TensorConfig(data_gen=partial(
generate_SectionsTensorList1,
dics)),
"SectionsTensorList2":
TensorConfig(data_gen=partial(
generate_SectionsTensorList2, dics))
}, {}]
ops_config = [{
"op_type":
"split",
"op_inputs":
dics_intput[num_input],
"op_outputs": {
"Out": Out
dics = [
{
"sections": sections,
"num": num,
"axis": axis,
},
{},
]
dics_intput = [
{
"X": ["split_input"],
"AxisTensor": ["AxisTensor"],
"SectionsTensorList": [
"SectionsTensorList1",
"SectionsTensorList2",
],
},
"op_attrs":
dics[0]
}]
{"X": ["split_input"]},
]
dics_intputs = [
{
"AxisTensor": TensorConfig(
data_gen=partial(
generate_AxisTensor, dics
)
),
"SectionsTensorList1": TensorConfig(
data_gen=partial(
generate_SectionsTensorList1,
dics,
)
),
"SectionsTensorList2": TensorConfig(
data_gen=partial(
generate_SectionsTensorList2,
dics,
)
),
},
{},
]
ops_config = [
{
"op_type": "split",
"op_inputs": dics_intput[num_input],
"op_outputs": {"Out": Out},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights=dics_intputs[num_input],
inputs={
"split_input":
TensorConfig(data_gen=partial(
generate_input1, dics, batch))
"split_input": TensorConfig(
data_gen=partial(
generate_input1, dics, batch
)
)
},
outputs=Out)
outputs=Out,
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
if self.dims == 4:
self.dynamic_shape.min_input_shape = {
......@@ -216,30 +239,35 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-3
def add_skip_trt_case(self):
def teller1(program_config, predictor_config):
if len(program_config.weights) == 3:
return True
return False
self.add_skip_case(
teller1, SkipReasons.TRT_NOT_SUPPORT,
"INPUT AxisTensor AND SectionsTensorList NOT SUPPORT.")
teller1,
SkipReasons.TRT_NOT_SUPPORT,
"INPUT AxisTensor AND SectionsTensorList NOT SUPPORT.",
)
def test(self):
self.add_skip_trt_case()
......
......@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
class TrtConvertSplitTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
inputs = program_config.inputs
attrs = [
......@@ -40,25 +39,25 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
self.dims = dims
self.axes = axes
dics = [{"axes": axes}]
ops_config = [{
"op_type": "squeeze2",
"op_inputs": {
"X": ["in_data"]
},
"op_outputs": {
"Out": ["out_data"],
"XShape": ["XShape_data"]
},
"op_attrs": dics[0]
}]
ops_config = [
{
"op_type": "squeeze2",
"op_inputs": {"X": ["in_data"]},
"op_outputs": {
"Out": ["out_data"],
"XShape": ["XShape_data"],
},
"op_attrs": dics[0],
}
]
# new_axes is the update of axes
new_axes = list(axes)
for i in range(len(new_axes)):
if (new_axes[i] < 0):
if new_axes[i] < 0:
new_axes[i] += dims
if (max(new_axes) >= dims):
if max(new_axes) >= dims:
continue
# generate input data
# generate input data
self.input_shape = [1] * dims
for i in range(dims):
self.input_shape[i] = np.random.randint(1, 20)
......@@ -68,24 +67,26 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
for i in new_axes:
self.input_shape[i] = 1
return np.random.random(self.input_shape).astype(
np.float32)
np.float32
)
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"in_data":
TensorConfig(
data_gen=partial(generate_input1, dics, batch))
"in_data": TensorConfig(
data_gen=partial(generate_input1, dics, batch)
)
},
outputs=["out_data"])
outputs=["out_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
max_shape = list(self.input_shape)
min_shape = list(self.input_shape)
......@@ -112,19 +113,23 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-3
def add_skip_trt_case(self):
pass
......
......@@ -22,7 +22,6 @@ import unittest
class TrtConvertStackTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
inputs = program_config.inputs
weights = program_config.weights
......@@ -31,14 +30,13 @@ class TrtConvertStackTest(TrtLayerAutoScanTest):
attrs = [
program_config.ops[i].attrs for i in range(len(program_config.ops))
]
#The input dimension should be less than the set axis.
# The input dimension should be less than the set axis.
if len(inputs['stack_input1'].shape) < attrs[0]['axis']:
return False
return True
def sample_program_configs(self):
def generate_input1(attrs: List[Dict[str, Any]], batch):
if self.dims == 4:
return np.random.random([batch, 3, 24, 24]).astype(np.float32)
......@@ -74,103 +72,107 @@ class TrtConvertStackTest(TrtLayerAutoScanTest):
for axis in [-2, -1, 0, 1, 2, 3]:
self.dims = dims
dics = [{"axis": axis}, {}]
ops_config = [{
"op_type": "stack",
"op_inputs": {
"X":
["stack_input1", "stack_input2", "stack_input3"]
},
"op_outputs": {
"Y": ["stack_output"]
},
"op_attrs": dics[0]
}]
ops_config = [
{
"op_type": "stack",
"op_inputs": {
"X": [
"stack_input1",
"stack_input2",
"stack_input3",
]
},
"op_outputs": {"Y": ["stack_output"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"stack_input1":
TensorConfig(
data_gen=partial(generate_input1, dics, batch)),
"stack_input2":
TensorConfig(
data_gen=partial(generate_input2, dics, batch)),
"stack_input3":
TensorConfig(
data_gen=partial(generate_input3, dics, batch))
"stack_input1": TensorConfig(
data_gen=partial(generate_input1, dics, batch)
),
"stack_input2": TensorConfig(
data_gen=partial(generate_input2, dics, batch)
),
"stack_input3": TensorConfig(
data_gen=partial(generate_input3, dics, batch)
),
},
outputs=["stack_output"])
outputs=["stack_output"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
if self.dims == 4:
self.dynamic_shape.min_input_shape = {
"stack_input1": [1, 3, 24, 24],
"stack_input2": [1, 3, 24, 24],
"stack_input3": [1, 3, 24, 24]
"stack_input3": [1, 3, 24, 24],
}
self.dynamic_shape.max_input_shape = {
"stack_input1": [4, 3, 48, 48],
"stack_input2": [4, 3, 48, 48],
"stack_input3": [4, 3, 48, 48]
"stack_input3": [4, 3, 48, 48],
}
self.dynamic_shape.opt_input_shape = {
"stack_input1": [1, 3, 24, 24],
"stack_input2": [1, 3, 24, 24],
"stack_input3": [1, 3, 24, 24]
"stack_input3": [1, 3, 24, 24],
}
elif self.dims == 3:
self.dynamic_shape.min_input_shape = {
"stack_input1": [1, 3, 24],
"stack_input2": [1, 3, 24],
"stack_input3": [1, 3, 24]
"stack_input3": [1, 3, 24],
}
self.dynamic_shape.max_input_shape = {
"stack_input1": [4, 3, 48],
"stack_input2": [4, 3, 48],
"stack_input3": [4, 3, 48]
"stack_input3": [4, 3, 48],
}
self.dynamic_shape.opt_input_shape = {
"stack_input1": [1, 3, 24],
"stack_input2": [1, 3, 24],
"stack_input3": [1, 3, 24]
"stack_input3": [1, 3, 24],
}
elif self.dims == 2:
self.dynamic_shape.min_input_shape = {
"stack_input1": [1, 24],
"stack_input2": [1, 24],
"stack_input3": [1, 24]
"stack_input3": [1, 24],
}
self.dynamic_shape.max_input_shape = {
"stack_input1": [4, 48],
"stack_input2": [4, 48],
"stack_input3": [4, 48]
"stack_input3": [4, 48],
}
self.dynamic_shape.opt_input_shape = {
"stack_input1": [1, 24],
"stack_input2": [1, 24],
"stack_input3": [1, 24]
"stack_input3": [1, 24],
}
elif self.dims == 1:
self.dynamic_shape.min_input_shape = {
"stack_input1": [24],
"stack_input2": [24],
"stack_input3": [24]
"stack_input3": [24],
}
self.dynamic_shape.max_input_shape = {
"stack_input1": [48],
"stack_input2": [48],
"stack_input3": [48]
"stack_input3": [48],
}
self.dynamic_shape.opt_input_shape = {
"stack_input1": [24],
"stack_input2": [24],
"stack_input3": [24]
"stack_input3": [24],
}
def clear_dynamic_shape():
......@@ -191,19 +193,23 @@ class TrtConvertStackTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-3
def add_skip_trt_case(self):
pass
......
......@@ -22,12 +22,10 @@ import unittest
class TrtConvertSumTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input1(batch):
if self.dims == 4:
return np.ones([batch, 3, 24, 24]).astype(np.float32)
......@@ -61,99 +59,101 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
for dims in [1, 2, 3, 4]:
for batch in [1, 4]:
self.dims = dims
ops_config = [{
"op_type": "sum",
"op_inputs": {
"X": ["input1", "input2", "input3"]
},
"op_outputs": {
"Out": ["output"]
},
"op_attrs": {}
}]
ops_config = [
{
"op_type": "sum",
"op_inputs": {"X": ["input1", "input2", "input3"]},
"op_outputs": {"Out": ["output"]},
"op_attrs": {},
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input1":
TensorConfig(data_gen=partial(generate_input1, batch)),
"input2":
TensorConfig(data_gen=partial(generate_input2, batch)),
"input3":
TensorConfig(data_gen=partial(generate_input3, batch))
"input1": TensorConfig(
data_gen=partial(generate_input1, batch)
),
"input2": TensorConfig(
data_gen=partial(generate_input2, batch)
),
"input3": TensorConfig(
data_gen=partial(generate_input3, batch)
),
},
outputs=["output"])
outputs=["output"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape():
if self.dims == 4:
self.dynamic_shape.min_input_shape = {
"input1": [1, 3, 24, 24],
"input2": [1, 3, 24, 24],
"input3": [1, 3, 24, 24]
"input3": [1, 3, 24, 24],
}
self.dynamic_shape.max_input_shape = {
"input1": [4, 3, 48, 48],
"input2": [4, 3, 48, 48],
"input3": [4, 3, 48, 48]
"input3": [4, 3, 48, 48],
}
self.dynamic_shape.opt_input_shape = {
"input1": [1, 3, 24, 24],
"input2": [1, 3, 24, 24],
"input3": [1, 3, 24, 24]
"input3": [1, 3, 24, 24],
}
elif self.dims == 3:
self.dynamic_shape.min_input_shape = {
"input1": [1, 3, 24],
"input2": [1, 3, 24],
"input3": [1, 3, 24]
"input3": [1, 3, 24],
}
self.dynamic_shape.max_input_shape = {
"input1": [4, 3, 48],
"input2": [4, 3, 48],
"input3": [4, 3, 48]
"input3": [4, 3, 48],
}
self.dynamic_shape.opt_input_shape = {
"input1": [1, 3, 24],
"input2": [1, 3, 24],
"input3": [1, 3, 24]
"input3": [1, 3, 24],
}
elif self.dims == 2:
self.dynamic_shape.min_input_shape = {
"input1": [1, 24],
"input2": [1, 24],
"input3": [1, 24]
"input3": [1, 24],
}
self.dynamic_shape.max_input_shape = {
"input1": [4, 48],
"input2": [4, 48],
"input3": [4, 48]
"input3": [4, 48],
}
self.dynamic_shape.opt_input_shape = {
"input1": [1, 24],
"input2": [1, 24],
"input3": [1, 24]
"input3": [1, 24],
}
elif self.dims == 1:
self.dynamic_shape.min_input_shape = {
"input1": [24],
"input2": [24],
"input3": [24]
"input3": [24],
}
self.dynamic_shape.max_input_shape = {
"input1": [48],
"input2": [48],
"input3": [48]
"input3": [48],
}
self.dynamic_shape.opt_input_shape = {
"input1": [24],
"input2": [24],
"input3": [24]
"input3": [24],
}
def clear_dynamic_shape():
......@@ -162,7 +162,7 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
self.dynamic_shape.opt_input_shape = {}
def generate_trt_nodes_num(dynamic_shape):
if (self.dims == 1 and not dynamic_shape):
if self.dims == 1 and not dynamic_shape:
return 0, 5
return 1, 4
......@@ -170,17 +170,19 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
False), 1e-5
False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
False), 1e-5
False
), 1e-3
# for dynamic_shape
generate_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(True), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(True), 1e-5
yield self.create_inference_config(), generate_trt_nodes_num(True), 1e-3
def test(self):
self.run_test()
......@@ -188,12 +190,10 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
# special case when sum having olny one input
class TrtConvertSumTest1(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
def sample_program_configs(self):
def generate_input1(batch):
if self.dims == 4:
return np.ones([batch, 3, 24, 24]).astype(np.float32)
......@@ -207,31 +207,31 @@ class TrtConvertSumTest1(TrtLayerAutoScanTest):
for dims in [1, 2, 3, 4]:
for batch in [1, 4]:
self.dims = dims
ops_config = [{
"op_type": "sum",
"op_inputs": {
"X": ["input1"]
},
"op_outputs": {
"Out": ["output"]
},
"op_attrs": {}
}]
ops_config = [
{
"op_type": "sum",
"op_inputs": {"X": ["input1"]},
"op_outputs": {"Out": ["output"]},
"op_attrs": {},
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input1":
TensorConfig(data_gen=partial(generate_input1, batch)),
"input1": TensorConfig(
data_gen=partial(generate_input1, batch)
),
},
outputs=["output"])
outputs=["output"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape():
if self.dims == 4:
self.dynamic_shape.min_input_shape = {"input1": [1, 3, 24, 24]}
......@@ -268,7 +268,7 @@ class TrtConvertSumTest1(TrtLayerAutoScanTest):
self.dynamic_shape.opt_input_shape = {}
def generate_trt_nodes_num(dynamic_shape):
if (self.dims == 1 and not dynamic_shape):
if self.dims == 1 and not dynamic_shape:
return 0, 3
return 1, 2
......@@ -276,17 +276,19 @@ class TrtConvertSumTest1(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
False), 1e-5
False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
False), 1e-5
False
), 1e-3
# for dynamic_shape
generate_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(True), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(True), 1e-5
yield self.create_inference_config(), generate_trt_nodes_num(True), 1e-3
def test(self):
self.run_test()
......
......@@ -26,7 +26,6 @@ import hypothesis.strategies as st
class TrtConvertTileTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
inputs = program_config.inputs
attrs = [
......@@ -39,38 +38,37 @@ class TrtConvertTileTest(TrtLayerAutoScanTest):
return True
def sample_program_configs(self, *args, **kwargs):
def generate_input1(attrs: List[Dict[str, Any]]):
return np.ones([1, 2, 3, 4]).astype(np.float32)
dics = [{"repeat_times": kwargs['repeat_times']}]
ops_config = [{
"op_type": "tile",
"op_inputs": {
"X": ["input_data"]
},
"op_outputs": {
"Out": ["tile_output_data"]
},
"op_attrs": dics[0]
}]
ops_config = [
{
"op_type": "tile",
"op_inputs": {"X": ["input_data"]},
"op_outputs": {"Out": ["tile_output_data"]},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input_data":
TensorConfig(data_gen=partial(generate_input1, dics))
"input_data": TensorConfig(
data_gen=partial(generate_input1, dics)
)
},
outputs=["tile_output_data"])
outputs=["tile_output_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
self.dynamic_shape.min_input_shape = {"input_data": [1, 3, 32, 32]}
self.dynamic_shape.max_input_shape = {"input_data": [4, 3, 64, 64]}
......@@ -99,19 +97,23 @@ class TrtConvertTileTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-4
attrs, False
), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-4
attrs, True
), 1e-3
@given(repeat_times=st.sampled_from([[100], [1, 2], [0, 3], [1, 2, 100]]))
def test(self, *args, **kwargs):
......
......@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
class TrtConvertActivationTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
return True
......@@ -44,34 +43,37 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
for k in [1, 3]:
self.dims = dims
dics = [{"k": k}]
ops_config = [{
"op_type": "top_k",
"op_inputs": {
"X": ["input_data"]
},
"op_outputs": {
"Out": ["output_data"],
"Indices": ["indices_data"]
},
"op_attrs": dics[0]
}]
ops_config = [
{
"op_type": "top_k",
"op_inputs": {"X": ["input_data"]},
"op_outputs": {
"Out": ["output_data"],
"Indices": ["indices_data"],
},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input_data":
TensorConfig(data_gen=partial(
generate_input1, dims, batch, dics))
"input_data": TensorConfig(
data_gen=partial(
generate_input1, dims, batch, dics
)
)
},
outputs=["output_data", "indices_data"])
outputs=["output_data", "indices_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
if self.dims == 1:
self.dynamic_shape.min_input_shape = {"input_data": [1]}
......@@ -114,19 +116,23 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-3
## for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-3
def test(self):
self.run_test()
......
......@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
class TrtConvertActivationTest(TrtLayerAutoScanTest):
def is_program_valid(self, program_config: ProgramConfig) -> bool:
inputs = program_config.inputs
attrs = [
......@@ -53,40 +52,48 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
for sort in [True, False]:
self.dims = dims
self.sort = sort
dics = [{
"k": k,
"axis": axis,
"largest": largest,
"sorted": sort
}]
ops_config = [{
"op_type": "top_k_v2",
"op_inputs": {
"X": ["input_data"]
},
"op_outputs": {
"Out": ["output_data"],
"Indices": ["indices_data"]
},
"op_attrs": dics[0]
}]
dics = [
{
"k": k,
"axis": axis,
"largest": largest,
"sorted": sort,
}
]
ops_config = [
{
"op_type": "top_k_v2",
"op_inputs": {"X": ["input_data"]},
"op_outputs": {
"Out": ["output_data"],
"Indices": ["indices_data"],
},
"op_attrs": dics[0],
}
]
ops = self.generate_op_config(ops_config)
program_config = ProgramConfig(
ops=ops,
weights={},
inputs={
"input_data":
TensorConfig(data_gen=partial(
generate_input1, dims, batch, dics))
"input_data": TensorConfig(
data_gen=partial(
generate_input1,
dims,
batch,
dics,
)
)
},
outputs=["output_data", "indices_data"])
outputs=["output_data", "indices_data"],
)
yield program_config
def sample_predictor_configs(
self, program_config) -> (paddle_infer.Config, List[int], float):
self, program_config
) -> (paddle_infer.Config, List[int], float):
def generate_dynamic_shape(attrs):
if self.dims == 1:
self.dynamic_shape.min_input_shape = {"input_data": [1]}
......@@ -131,19 +138,23 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
clear_dynamic_shape()
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, False), 1e-5
attrs, False
), 1e-3
# for dynamic_shape
generate_dynamic_shape(attrs)
self.trt_param.precision = paddle_infer.PrecisionType.Float32
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-5
self.trt_param.precision = paddle_infer.PrecisionType.Half
yield self.create_inference_config(), generate_trt_nodes_num(
attrs, True), 1e-5
attrs, True
), 1e-3
def test(self):
self.run_test()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment