Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Paddle
Commits
dbe08e9b
Commit
dbe08e9b
authored
Jun 12, 2023
by
yuguo960516yuguo
Browse files
2.4.2
parent
b5499578
Changes
302
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1493 additions
and
1379 deletions
+1493
-1379
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_matmul.py
...d/tests/unittests/ir/inference/test_trt_convert_matmul.py
+77
-71
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_matmul_v2.py
...ests/unittests/ir/inference/test_trt_convert_matmul_v2.py
+114
-105
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_multihead_matmul.py
...ittests/ir/inference/test_trt_convert_multihead_matmul.py
+497
-579
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_pad3d.py
...id/tests/unittests/ir/inference/test_trt_convert_pad3d.py
+23
-21
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_pool2d.py
...d/tests/unittests/ir/inference/test_trt_convert_pool2d.py
+105
-49
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce_sum.py
...sts/unittests/ir/inference/test_trt_convert_reduce_sum.py
+44
-30
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reshape.py
.../tests/unittests/ir/inference/test_trt_convert_reshape.py
+77
-67
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_roi_align.py
...ests/unittests/ir/inference/test_trt_convert_roi_align.py
+83
-62
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_roll.py
...uid/tests/unittests/ir/inference/test_trt_convert_roll.py
+30
-26
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_scatter_nd_add.py
...unittests/ir/inference/test_trt_convert_scatter_nd_add.py
+27
-25
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_shape.py
...id/tests/unittests/ir/inference/test_trt_convert_shape.py
+21
-21
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_shuffle_channel.py
...nittests/ir/inference/test_trt_convert_shuffle_channel.py
+27
-24
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_slice.py
...id/tests/unittests/ir/inference/test_trt_convert_slice.py
+44
-35
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_split.py
...id/tests/unittests/ir/inference/test_trt_convert_split.py
+95
-67
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_squeeze2.py
...tests/unittests/ir/inference/test_trt_convert_squeeze2.py
+31
-26
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_stack.py
...id/tests/unittests/ir/inference/test_trt_convert_stack.py
+48
-42
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_sum.py
...luid/tests/unittests/ir/inference/test_trt_convert_sum.py
+60
-58
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_tile.py
...uid/tests/unittests/ir/inference/test_trt_convert_tile.py
+23
-21
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_top_k.py
...id/tests/unittests/ir/inference/test_trt_convert_top_k.py
+28
-22
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_top_k_v2.py
...tests/unittests/ir/inference/test_trt_convert_top_k_v2.py
+39
-28
No files found.
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_matmul.py
View file @
dbe08e9b
...
@@ -22,12 +22,10 @@ import unittest
...
@@ -22,12 +22,10 @@ import unittest
class
TrtConvertMatmulTest_static
(
TrtLayerAutoScanTest
):
class
TrtConvertMatmulTest_static
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input
(
shape
):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
...
@@ -47,48 +45,55 @@ class TrtConvertMatmulTest_static(TrtLayerAutoScanTest):
...
@@ -47,48 +45,55 @@ class TrtConvertMatmulTest_static(TrtLayerAutoScanTest):
input1_shape
=
[
batch
,
32
,
6
]
input1_shape
=
[
batch
,
32
,
6
]
input2_shape
=
[
batch
,
6
,
11
]
input2_shape
=
[
batch
,
6
,
11
]
for
alpha
in
[
0.3
,
1.0
]:
for
alpha
in
[
0.3
,
1.0
]:
dics
=
[{
dics
=
[
"transpose_X"
:
trans_x
,
{
"transpose_Y"
:
trans_y
,
"transpose_X"
:
trans_x
,
"alpha"
:
alpha
,
"transpose_Y"
:
trans_y
,
"fused_reshape_X"
:
[],
"alpha"
:
alpha
,
"fused_reshape_Y"
:
[],
"fused_reshape_X"
:
[],
"fused_transpose_X"
:
[],
"fused_reshape_Y"
:
[],
"fused_transpose_Y"
:
[],
"fused_transpose_X"
:
[],
"fused_reshape_Out"
:
[],
"fused_transpose_Y"
:
[],
"fused_transpose_Out"
:
[]
"fused_reshape_Out"
:
[],
}]
"fused_transpose_Out"
:
[],
ops_config
=
[{
}
"op_type"
:
"matmul"
,
]
"op_inputs"
:
{
ops_config
=
[
"X"
:
[
"input1_data"
],
{
"Y"
:
[
"input2_data"
]
"op_type"
:
"matmul"
,
},
"op_inputs"
:
{
"op_outputs"
:
{
"X"
:
[
"input1_data"
],
"Out"
:
[
"output_data"
]
"Y"
:
[
"input2_data"
],
},
},
"op_attrs"
:
dics
[
0
]
"op_outputs"
:
{
"Out"
:
[
"output_data"
]},
}]
"op_attrs"
:
dics
[
0
],
}
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input1_data"
:
"input1_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
data_gen
=
partial
(
generate_input
,
input1_shape
)),
generate_input
,
input1_shape
"input2_data"
:
)
TensorConfig
(
data_gen
=
partial
(
),
generate_input
,
input2_shape
))
"input2_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
input2_shape
)
),
},
},
outputs
=
[
"output_data"
])
outputs
=
[
"output_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
pass
pass
...
@@ -102,19 +107,17 @@ class TrtConvertMatmulTest_static(TrtLayerAutoScanTest):
...
@@ -102,19 +107,17 @@ class TrtConvertMatmulTest_static(TrtLayerAutoScanTest):
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
):
def
test
(
self
):
self
.
run_test
()
self
.
run_test
()
class
TrtConvertMatmulTest_dynamic
(
TrtLayerAutoScanTest
):
class
TrtConvertMatmulTest_dynamic
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input
(
shape
):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
...
@@ -133,60 +136,63 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
...
@@ -133,60 +136,63 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
# input1_shape = [batch, 32, 6]
# input1_shape = [batch, 32, 6]
# input2_shape = [batch, 6, 11]
# input2_shape = [batch, 6, 11]
for
alpha
in
[
0.3
,
1.0
]:
for
alpha
in
[
0.3
,
1.0
]:
dics
=
[{
dics
=
[
"transpose_X"
:
trans_x
,
{
"transpose_Y"
:
trans_y
,
"transpose_X"
:
trans_x
,
"alpha"
:
alpha
,
"transpose_Y"
:
trans_y
,
"fused_reshape_X"
:
[],
"alpha"
:
alpha
,
"fused_reshape_Y"
:
[],
"fused_reshape_X"
:
[],
"fused_transpose_X"
:
[],
"fused_reshape_Y"
:
[],
"fused_transpose_Y"
:
[],
"fused_transpose_X"
:
[],
"fused_reshape_Out"
:
[],
"fused_transpose_Y"
:
[],
"fused_transpose_Out"
:
[]
"fused_reshape_Out"
:
[],
}]
"fused_transpose_Out"
:
[],
ops_config
=
[{
}
"op_type"
:
"matmul"
,
]
"op_inputs"
:
{
ops_config
=
[
"X"
:
[
"input1_data"
],
{
"Y"
:
[
"input2_data"
]
"op_type"
:
"matmul"
,
},
"op_inputs"
:
{
"op_outputs"
:
{
"X"
:
[
"input1_data"
],
"Out"
:
[
"output_data"
]
"Y"
:
[
"input2_data"
],
},
},
"op_attrs"
:
dics
[
0
]
"op_outputs"
:
{
"Out"
:
[
"output_data"
]},
}]
"op_attrs"
:
dics
[
0
],
}
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input1_data"
:
"input1_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input
,
input1_shape
)
data_gen
=
partial
(
generate_input
,
input1_shape
)
),
),
"input2_data"
:
"input2_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input
,
input2_shape
)
data_gen
=
partial
(
generate_input
,
input2_shape
)
)
)
,
},
},
outputs
=
[
"output_data"
])
outputs
=
[
"output_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input1_data"
:
[
1
,
4
,
4
],
"input1_data"
:
[
1
,
4
,
4
],
"input2_data"
:
[
1
,
4
,
4
]
"input2_data"
:
[
1
,
4
,
4
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"input1_data"
:
[
16
,
4
,
4
],
"input1_data"
:
[
16
,
4
,
4
],
"input2_data"
:
[
16
,
4
,
4
]
"input2_data"
:
[
16
,
4
,
4
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"input1_data"
:
[
8
,
4
,
4
],
"input1_data"
:
[
8
,
4
,
4
],
"input2_data"
:
[
8
,
4
,
4
]
"input2_data"
:
[
8
,
4
,
4
]
,
}
}
attrs
=
[
attrs
=
[
...
@@ -198,7 +204,7 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
...
@@ -198,7 +204,7 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
):
def
add_skip_trt_case
(
self
):
pass
pass
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_matmul_v2.py
View file @
dbe08e9b
...
@@ -23,9 +23,7 @@ import os
...
@@ -23,9 +23,7 @@ import os
class
TrtConvertMatmulTest_dynamic
(
TrtLayerAutoScanTest
):
class
TrtConvertMatmulTest_dynamic
(
TrtLayerAutoScanTest
):
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input
(
shape
):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
...
@@ -34,53 +32,56 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
...
@@ -34,53 +32,56 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
for
trans_y
in
[
False
]:
for
trans_y
in
[
False
]:
input1_shape
=
[
batch
,
64
,
350
,
75
]
input1_shape
=
[
batch
,
64
,
350
,
75
]
input2_shape
=
[
75
,
25
]
input2_shape
=
[
75
,
25
]
dics
=
[{
dics
=
[
"trans_x"
:
trans_x
,
{
"trans_y"
:
trans_y
,
"trans_x"
:
trans_x
,
}]
"trans_y"
:
trans_y
,
ops_config
=
[{
}
"op_type"
:
"matmul_v2"
,
]
"op_inputs"
:
{
ops_config
=
[
"X"
:
[
"input1_data"
],
{
"Y"
:
[
"input2_data"
]
"op_type"
:
"matmul_v2"
,
},
"op_inputs"
:
{
"op_outputs"
:
{
"X"
:
[
"input1_data"
],
"Out"
:
[
"output_data"
]
"Y"
:
[
"input2_data"
],
},
},
"op_attrs"
:
dics
[
0
]
"op_outputs"
:
{
"Out"
:
[
"output_data"
]},
}]
"op_attrs"
:
dics
[
0
],
}
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input1_data"
:
"input1_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input
,
input1_shape
)
data_gen
=
partial
(
generate_input
,
input1_shape
)
),
),
"input2_data"
:
"input2_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input
,
input2_shape
)
data_gen
=
partial
(
generate_input
,
input2_shape
)
)
)
,
},
},
outputs
=
[
"output_data"
])
outputs
=
[
"output_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input1_data"
:
[
10
,
64
,
350
,
75
],
"input1_data"
:
[
10
,
64
,
350
,
75
],
"input2_data"
:
[
75
,
25
]
"input2_data"
:
[
75
,
25
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"input1_data"
:
[
100
,
64
,
350
,
75
],
"input1_data"
:
[
100
,
64
,
350
,
75
],
"input2_data"
:
[
75
,
25
]
"input2_data"
:
[
75
,
25
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"input1_data"
:
[
15
,
64
,
350
,
75
],
"input1_data"
:
[
15
,
64
,
350
,
75
],
"input2_data"
:
[
75
,
25
]
"input2_data"
:
[
75
,
25
]
,
}
}
attrs
=
[
attrs
=
[
...
@@ -90,7 +91,7 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
...
@@ -90,7 +91,7 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
# The output has little diff between gpu and trt in CI-Windows-Inference
# The output has little diff between gpu and trt in CI-Windows-Inference
tol_fp32
=
1e-5
tol_fp32
=
1e-5
tol_half
=
1e-5
tol_half
=
1e-5
if
(
os
.
name
==
'nt'
)
:
if
os
.
name
==
'nt'
:
tol_fp32
=
1e-3
tol_fp32
=
1e-3
tol_half
=
1e-3
tol_half
=
1e-3
# for dynamic_shape
# for dynamic_shape
...
@@ -109,9 +110,7 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
...
@@ -109,9 +110,7 @@ class TrtConvertMatmulTest_dynamic(TrtLayerAutoScanTest):
class
TrtConvertMatmulTest_dynamic2
(
TrtLayerAutoScanTest
):
class
TrtConvertMatmulTest_dynamic2
(
TrtLayerAutoScanTest
):
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input
(
shape
):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
...
@@ -120,53 +119,56 @@ class TrtConvertMatmulTest_dynamic2(TrtLayerAutoScanTest):
...
@@ -120,53 +119,56 @@ class TrtConvertMatmulTest_dynamic2(TrtLayerAutoScanTest):
for
trans_y
in
[
False
]:
for
trans_y
in
[
False
]:
input1_shape
=
[
60
,
40
]
input1_shape
=
[
60
,
40
]
input2_shape
=
[
batch
,
40
,
90
]
input2_shape
=
[
batch
,
40
,
90
]
dics
=
[{
dics
=
[
"trans_x"
:
trans_x
,
{
"trans_y"
:
trans_y
,
"trans_x"
:
trans_x
,
}]
"trans_y"
:
trans_y
,
ops_config
=
[{
}
"op_type"
:
"matmul_v2"
,
]
"op_inputs"
:
{
ops_config
=
[
"X"
:
[
"input1_data"
],
{
"Y"
:
[
"input2_data"
]
"op_type"
:
"matmul_v2"
,
},
"op_inputs"
:
{
"op_outputs"
:
{
"X"
:
[
"input1_data"
],
"Out"
:
[
"output_data"
]
"Y"
:
[
"input2_data"
],
},
},
"op_attrs"
:
dics
[
0
]
"op_outputs"
:
{
"Out"
:
[
"output_data"
]},
}]
"op_attrs"
:
dics
[
0
],
}
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input1_data"
:
"input1_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input
,
input1_shape
)
data_gen
=
partial
(
generate_input
,
input1_shape
)
),
),
"input2_data"
:
"input2_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input
,
input2_shape
)
data_gen
=
partial
(
generate_input
,
input2_shape
)
)
)
,
},
},
outputs
=
[
"output_data"
])
outputs
=
[
"output_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input1_data"
:
[
60
,
40
],
"input1_data"
:
[
60
,
40
],
"input2_data"
:
[
10
,
40
,
90
]
"input2_data"
:
[
10
,
40
,
90
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"input1_data"
:
[
60
,
40
],
"input1_data"
:
[
60
,
40
],
"input2_data"
:
[
20
,
40
,
90
]
"input2_data"
:
[
20
,
40
,
90
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"input1_data"
:
[
60
,
40
],
"input1_data"
:
[
60
,
40
],
"input2_data"
:
[
15
,
40
,
90
]
"input2_data"
:
[
15
,
40
,
90
]
,
}
}
attrs
=
[
attrs
=
[
...
@@ -175,7 +177,7 @@ class TrtConvertMatmulTest_dynamic2(TrtLayerAutoScanTest):
...
@@ -175,7 +177,7 @@ class TrtConvertMatmulTest_dynamic2(TrtLayerAutoScanTest):
# The output has little diff between gpu and trt in CI-Windows-Inference
# The output has little diff between gpu and trt in CI-Windows-Inference
tol_fp32
=
1e-5
tol_fp32
=
1e-5
tol_half
=
1e-5
tol_half
=
1e-5
if
(
os
.
name
==
'nt'
)
:
if
os
.
name
==
'nt'
:
tol_fp32
=
1e-3
tol_fp32
=
1e-3
tol_half
=
1e-3
tol_half
=
1e-3
# for dynamic_shape
# for dynamic_shape
...
@@ -194,9 +196,7 @@ class TrtConvertMatmulTest_dynamic2(TrtLayerAutoScanTest):
...
@@ -194,9 +196,7 @@ class TrtConvertMatmulTest_dynamic2(TrtLayerAutoScanTest):
class
TrtConvertMatmulTest_dynamic3
(
TrtLayerAutoScanTest
):
class
TrtConvertMatmulTest_dynamic3
(
TrtLayerAutoScanTest
):
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input
(
shape
):
def
generate_input
(
shape
):
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
return
np
.
random
.
random
(
shape
).
astype
(
np
.
float32
)
...
@@ -219,93 +219,102 @@ class TrtConvertMatmulTest_dynamic3(TrtLayerAutoScanTest):
...
@@ -219,93 +219,102 @@ class TrtConvertMatmulTest_dynamic3(TrtLayerAutoScanTest):
elif
case
==
2
:
elif
case
==
2
:
input1_shape
=
[
50
]
input1_shape
=
[
50
]
input2_shape
=
[
50
]
input2_shape
=
[
50
]
if
(
case
==
0
or
case
==
1
):
if
case
==
0
or
case
==
1
:
dics
=
[{
dics
=
[
"trans_x"
:
False
,
{
"trans_y"
:
False
,
"trans_x"
:
False
,
}]
"trans_y"
:
False
,
elif
(
case
==
2
):
}
dics
=
[{
]
"trans_x"
:
trans_x
,
elif
case
==
2
:
"trans_y"
:
trans_y
,
dics
=
[
}]
{
ops_config
=
[{
"trans_x"
:
trans_x
,
"op_type"
:
"matmul_v2"
,
"trans_y"
:
trans_y
,
"op_inputs"
:
{
}
"X"
:
[
"input1_data"
],
]
"Y"
:
[
"input2_data"
]
ops_config
=
[
},
{
"op_outputs"
:
{
"op_type"
:
"matmul_v2"
,
"Out"
:
[
"output_data"
]
"op_inputs"
:
{
},
"X"
:
[
"input1_data"
],
"op_attrs"
:
dics
[
0
]
"Y"
:
[
"input2_data"
],
}]
},
"op_outputs"
:
{
"Out"
:
[
"output_data"
]},
"op_attrs"
:
dics
[
0
],
}
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input1_data"
:
"input1_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
data_gen
=
partial
(
generate_input
,
input1_shape
)),
generate_input
,
input1_shape
"input2_data"
:
)
TensorConfig
(
data_gen
=
partial
(
),
generate_input
,
input2_shape
))
"input2_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input
,
input2_shape
)
),
},
},
outputs
=
[
"output_data"
])
outputs
=
[
"output_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
():
def
generate_dynamic_shape
():
if
(
self
.
case
==
0
)
:
if
self
.
case
==
0
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input1_data"
:
[
20
,
50
],
"input1_data"
:
[
20
,
50
],
"input2_data"
:
[
50
]
"input2_data"
:
[
50
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"input1_data"
:
[
30
,
50
],
"input1_data"
:
[
30
,
50
],
"input2_data"
:
[
50
]
"input2_data"
:
[
50
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"input1_data"
:
[
25
,
50
],
"input1_data"
:
[
25
,
50
],
"input2_data"
:
[
50
]
"input2_data"
:
[
50
]
,
}
}
elif
(
self
.
case
==
1
)
:
elif
self
.
case
==
1
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input2_data"
:
[
50
,
20
],
"input2_data"
:
[
50
,
20
],
"input1_data"
:
[
50
]
"input1_data"
:
[
50
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"input2_data"
:
[
50
,
30
],
"input2_data"
:
[
50
,
30
],
"input1_data"
:
[
50
]
"input1_data"
:
[
50
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"input2_data"
:
[
50
,
25
],
"input2_data"
:
[
50
,
25
],
"input1_data"
:
[
50
]
"input1_data"
:
[
50
]
,
}
}
elif
(
self
.
case
==
2
)
:
elif
self
.
case
==
2
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input2_data"
:
[
30
],
"input2_data"
:
[
30
],
"input1_data"
:
[
50
]
"input1_data"
:
[
50
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"input2_data"
:
[
50
],
"input2_data"
:
[
50
],
"input1_data"
:
[
50
]
"input1_data"
:
[
50
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"input2_data"
:
[
50
],
"input2_data"
:
[
50
],
"input1_data"
:
[
50
]
"input1_data"
:
[
50
]
,
}
}
generate_dynamic_shape
()
generate_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
):
def
add_skip_trt_case
(
self
):
pass
pass
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_multihead_matmul.py
View file @
dbe08e9b
...
@@ -22,12 +22,10 @@ from typing import Optional, List, Callable, Dict, Any, Set
...
@@ -22,12 +22,10 @@ from typing import Optional, List, Callable, Dict, Any, Set
class
TrtConvertMultiHeadMatmulTest
(
TrtLayerAutoScanTest
):
class
TrtConvertMultiHeadMatmulTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
batch
,
dim1
):
def
generate_input1
(
batch
,
dim1
):
return
np
.
random
.
random
((
batch
,
dim1
,
768
)).
astype
(
np
.
float32
)
return
np
.
random
.
random
((
batch
,
dim1
,
768
)).
astype
(
np
.
float32
)
...
@@ -44,103 +42,86 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -44,103 +42,86 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
self
.
batch
=
batch
self
.
batch
=
batch
for
reshape_shape
in
[[
0
,
0
,
12
,
64
]]:
for
reshape_shape
in
[[
0
,
0
,
12
,
64
]]:
for
dim1
in
[
128
]:
for
dim1
in
[
128
]:
input2_shapes
=
[[
batch
,
reshape_shape
[
2
],
dim1
,
dim1
],
input2_shapes
=
[
[
batch
,
1
,
1
,
dim1
]]
[
batch
,
reshape_shape
[
2
],
dim1
,
dim1
],
[
batch
,
1
,
1
,
dim1
],
]
for
input2_shape
in
input2_shapes
:
for
input2_shape
in
input2_shapes
:
for
axis
in
[
0
]:
for
axis
in
[
0
]:
dics
=
[{
dics
=
[
"x_num_col_dims"
:
2
,
{
"x_num_col_dims"
:
2
,
"y_num_col_dims"
:
1
},
"y_num_col_dims"
:
1
{
"axis"
:
2
},
},
{
{
"shape"
:
reshape_shape
},
"axis"
:
2
{
"axis"
:
[
0
,
2
,
1
,
3
]},
},
{
{
"x_num_col_dims"
:
2
,
"y_num_col_dims"
:
1
},
"shape"
:
reshape_shape
{
"axis"
:
2
},
},
{
{
"shape"
:
reshape_shape
},
"axis"
:
[
0
,
2
,
1
,
3
]
{
"axis"
:
[
0
,
2
,
1
,
3
]},
},
{
{
"x_num_col_dims"
:
2
,
"y_num_col_dims"
:
1
},
"x_num_col_dims"
:
2
,
{
"axis"
:
2
},
"y_num_col_dims"
:
1
{
"shape"
:
reshape_shape
},
},
{
{
"axis"
:
[
0
,
2
,
1
,
3
]},
"axis"
:
2
{
},
{
"scale"
:
0.125
,
"shape"
:
reshape_shape
"bias"
:
0.0
,
},
{
"bias_after_scale"
:
True
,
"axis"
:
[
0
,
2
,
1
,
3
]
},
},
{
{
"x_num_col_dims"
:
2
,
"alpha"
:
1.0
,
"y_num_col_dims"
:
1
"transpose_X"
:
False
,
},
{
"transpose_Y"
:
True
,
"axis"
:
2
"fused_reshape_X"
:
[],
},
{
"fused_reshape_Y"
:
[],
"shape"
:
reshape_shape
"fused_transpose_X"
:
[],
},
{
"fused_transpose_Y"
:
[],
"axis"
:
[
0
,
2
,
1
,
3
]
"fused_reshape_Out"
:
[],
},
{
"fused_transpose_Out"
:
[],
"scale"
:
0.125
,
},
"bias"
:
0.0
,
{
"axis"
:
axis
},
"bias_after_scale"
:
True
{
"axis"
:
-
1
,
"is_test"
:
True
},
},
{
{
"alpha"
:
1.0
,
"seed"
:
0
,
"transpose_X"
:
False
,
"dropout_prob"
:
0.10000000149011612
,
"transpose_Y"
:
True
,
"dropout_implementation"
:
"upscale_in_train"
,
"fused_reshape_X"
:
[],
"fix_seed"
:
False
,
"fused_reshape_Y"
:
[],
"is_test"
:
True
,
"fused_transpose_X"
:
[],
},
"fused_transpose_Y"
:
[],
{
"fused_reshape_Out"
:
[],
"alpha"
:
1.0
,
"fused_transpose_Out"
:
[]
"transpose_X"
:
False
,
},
{
"transpose_Y"
:
False
,
"axis"
:
axis
"fused_reshape_X"
:
[],
},
{
"fused_reshape_Y"
:
[],
"axis"
:
-
1
,
"fused_transpose_X"
:
[],
"is_test"
:
True
"fused_transpose_Y"
:
[],
},
{
"fused_reshape_Out"
:
[],
"seed"
:
0
,
"fused_transpose_Out"
:
[],
"dropout_prob"
:
0.10000000149011612
,
},
"dropout_implementation"
:
"upscale_in_train"
,
{
"axis"
:
[
0
,
2
,
1
,
3
]},
"fix_seed"
:
False
,
{
"shape"
:
[
0
,
0
,
768
]},
"is_test"
:
True
{
"x_num_col_dims"
:
2
,
"y_num_col_dims"
:
1
},
},
{
]
"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
=
[
ops_config
=
[
{
{
"op_type"
:
"mul"
,
"op_type"
:
"mul"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"input_data1"
],
"X"
:
[
"input_data1"
],
"Y"
:
[
"mul1_weight"
]
"Y"
:
[
"mul1_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"mul1_output"
]},
"Out"
:
[
"mul1_output"
]
"op_attrs"
:
dics
[
0
],
},
"op_attrs"
:
dics
[
0
]
},
},
{
{
"op_type"
:
"elementwise_add"
,
"op_type"
:
"elementwise_add"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"mul1_output"
],
"X"
:
[
"mul1_output"
],
"Y"
:
[
"elementwise_add1_weight"
]
"Y"
:
[
"elementwise_add1_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"elementwise_add1_output"
]
"Out"
:
[
"elementwise_add1_output"
]
},
},
"op_attrs"
:
dics
[
1
]
"op_attrs"
:
dics
[
1
]
,
},
},
{
{
"op_type"
:
"reshape2"
,
"op_type"
:
"reshape2"
,
...
@@ -149,42 +130,38 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -149,42 +130,38 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"reshape21_output"
],
"Out"
:
[
"reshape21_output"
],
"XShape"
:
[
"reshape21_output_xshape"
]
"XShape"
:
[
"reshape21_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
2
]
"op_attrs"
:
dics
[
2
]
,
},
},
{
{
"op_type"
:
"transpose2"
,
"op_type"
:
"transpose2"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"reshape21_output"
]},
"X"
:
[
"reshape21_output"
]
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"transpose21_output"
],
"Out"
:
[
"transpose21_output"
],
"XShape"
:
[
"transpose21_output_xshape"
]
"XShape"
:
[
"transpose21_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
3
]
"op_attrs"
:
dics
[
3
]
,
},
},
{
{
"op_type"
:
"mul"
,
"op_type"
:
"mul"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"input_data1"
],
"X"
:
[
"input_data1"
],
"Y"
:
[
"mul2_weight"
]
"Y"
:
[
"mul2_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"mul2_output"
]},
"Out"
:
[
"mul2_output"
]
"op_attrs"
:
dics
[
4
],
},
"op_attrs"
:
dics
[
4
]
},
},
{
{
"op_type"
:
"elementwise_add"
,
"op_type"
:
"elementwise_add"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"mul2_output"
],
"X"
:
[
"mul2_output"
],
"Y"
:
[
"elementwise_add2_weight"
]
"Y"
:
[
"elementwise_add2_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"elementwise_add2_output"
]
"Out"
:
[
"elementwise_add2_output"
]
},
},
"op_attrs"
:
dics
[
5
]
"op_attrs"
:
dics
[
5
]
,
},
},
{
{
"op_type"
:
"reshape2"
,
"op_type"
:
"reshape2"
,
...
@@ -193,42 +170,38 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -193,42 +170,38 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"reshape22_output"
],
"Out"
:
[
"reshape22_output"
],
"XShape"
:
[
"reshape22_output_xshape"
]
"XShape"
:
[
"reshape22_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
6
]
"op_attrs"
:
dics
[
6
]
,
},
},
{
{
"op_type"
:
"transpose2"
,
"op_type"
:
"transpose2"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"reshape22_output"
]},
"X"
:
[
"reshape22_output"
]
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"transpose22_output"
],
"Out"
:
[
"transpose22_output"
],
"XShape"
:
[
"transpose22_output_xshape"
]
"XShape"
:
[
"transpose22_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
7
]
"op_attrs"
:
dics
[
7
]
,
},
},
{
{
"op_type"
:
"mul"
,
"op_type"
:
"mul"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"input_data1"
],
"X"
:
[
"input_data1"
],
"Y"
:
[
"mul3_weight"
]
"Y"
:
[
"mul3_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"mul3_output"
]},
"Out"
:
[
"mul3_output"
]
"op_attrs"
:
dics
[
8
],
},
"op_attrs"
:
dics
[
8
]
},
},
{
{
"op_type"
:
"elementwise_add"
,
"op_type"
:
"elementwise_add"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"mul3_output"
],
"X"
:
[
"mul3_output"
],
"Y"
:
[
"elementwise_add3_weight"
]
"Y"
:
[
"elementwise_add3_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"elementwise_add3_output"
]
"Out"
:
[
"elementwise_add3_output"
]
},
},
"op_attrs"
:
dics
[
9
]
"op_attrs"
:
dics
[
9
]
,
},
},
{
{
"op_type"
:
"reshape2"
,
"op_type"
:
"reshape2"
,
...
@@ -237,30 +210,26 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -237,30 +210,26 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"reshape23_output"
],
"Out"
:
[
"reshape23_output"
],
"XShape"
:
[
"reshape23_output_xshape"
]
"XShape"
:
[
"reshape23_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
10
]
"op_attrs"
:
dics
[
10
]
,
},
},
{
{
"op_type"
:
"transpose2"
,
"op_type"
:
"transpose2"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"reshape23_output"
]},
"X"
:
[
"reshape23_output"
]
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"transpose23_output"
],
"Out"
:
[
"transpose23_output"
],
"XShape"
:
[
"transpose23_output_xshape"
]
"XShape"
:
[
"transpose23_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
11
]
"op_attrs"
:
dics
[
11
]
,
},
},
{
{
"op_type"
:
"scale"
,
"op_type"
:
"scale"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"transpose23_output"
],
"X"
:
[
"transpose23_output"
],
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"scale_output"
]},
"Out"
:
[
"scale_output"
]
"op_attrs"
:
dics
[
12
],
},
"op_attrs"
:
dics
[
12
]
},
},
{
{
"op_type"
:
"matmul"
,
"op_type"
:
"matmul"
,
...
@@ -268,41 +237,35 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -268,41 +237,35 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
"X"
:
[
"scale_output"
],
"X"
:
[
"scale_output"
],
"Y"
:
[
"transpose22_output"
],
"Y"
:
[
"transpose22_output"
],
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"matmul1_output"
]},
"Out"
:
[
"matmul1_output"
]
"op_attrs"
:
dics
[
13
],
},
"op_attrs"
:
dics
[
13
]
},
},
{
{
"op_type"
:
"elementwise_add"
,
"op_type"
:
"elementwise_add"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"matmul1_output"
],
"X"
:
[
"matmul1_output"
],
"Y"
:
[
"input_data2"
]
"Y"
:
[
"input_data2"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"elementwise_add4_output"
]
"Out"
:
[
"elementwise_add4_output"
]
},
},
"op_attrs"
:
dics
[
14
]
"op_attrs"
:
dics
[
14
]
,
},
},
{
{
"op_type"
:
"softmax"
,
"op_type"
:
"softmax"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"elementwise_add4_output"
]
"X"
:
[
"elementwise_add4_output"
]
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"softmax_output"
]},
"Out"
:
[
"softmax_output"
]
"op_attrs"
:
dics
[
15
],
},
"op_attrs"
:
dics
[
15
]
},
},
{
{
"op_type"
:
"dropout"
,
"op_type"
:
"dropout"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"softmax_output"
],
"X"
:
[
"softmax_output"
],
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"dropout3_output"
]},
"Out"
:
[
"dropout3_output"
]
"op_attrs"
:
dics
[
16
],
},
"op_attrs"
:
dics
[
16
]
},
},
{
{
"op_type"
:
"matmul"
,
"op_type"
:
"matmul"
,
...
@@ -310,32 +273,26 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -310,32 +273,26 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
"X"
:
[
"dropout3_output"
],
"X"
:
[
"dropout3_output"
],
"Y"
:
[
"transpose21_output"
],
"Y"
:
[
"transpose21_output"
],
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"matmul2_output"
]},
"Out"
:
[
"matmul2_output"
]
"op_attrs"
:
dics
[
17
],
},
"op_attrs"
:
dics
[
17
]
},
},
{
{
"op_type"
:
"transpose2"
,
"op_type"
:
"transpose2"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"matmul2_output"
]},
"X"
:
[
"matmul2_output"
]
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"transpose24_output"
],
"Out"
:
[
"transpose24_output"
],
"XShape"
:
[
"transpose24_output_xshape"
]
"XShape"
:
[
"transpose24_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
18
]
"op_attrs"
:
dics
[
18
]
,
},
},
{
{
"op_type"
:
"reshape2"
,
"op_type"
:
"reshape2"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"transpose24_output"
]},
"X"
:
[
"transpose24_output"
]
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"reshape24_output"
],
"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
# In order to fuse ops with
# multihead_matmul_fuse_pass_v2, the last op
# multihead_matmul_fuse_pass_v2, the last op
...
@@ -344,72 +301,75 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -344,72 +301,75 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
"op_type"
:
"mul"
,
"op_type"
:
"mul"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"reshape24_output"
],
"X"
:
[
"reshape24_output"
],
"Y"
:
[
"mul4_weight"
]
"Y"
:
[
"mul4_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"mul4_output"
]},
"Out"
:
[
"mul4_output"
]
"op_attrs"
:
dics
[
20
],
},
},
"op_attrs"
:
dics
[
20
]
}
]
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{
weights
=
{
"mul1_weight"
:
"mul1_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight1
)
data_gen
=
partial
(
generate_weight1
)
),
),
"mul2_weight"
:
"mul2_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight1
)
data_gen
=
partial
(
generate_weight1
)
),
),
"mul3_weight"
:
"mul3_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight1
)
data_gen
=
partial
(
generate_weight1
)
),
),
"mul4_weight"
:
"mul4_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight1
)
data_gen
=
partial
(
generate_weight1
)
),
),
"elementwise_add1_weight"
:
"elementwise_add1_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight2
)
data_gen
=
partial
(
generate_weight2
)
),
),
"elementwise_add2_weight"
:
"elementwise_add2_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight2
)
data_gen
=
partial
(
generate_weight2
)
),
),
"elementwise_add3_weight"
:
"elementwise_add3_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight2
)
data_gen
=
partial
(
generate_weight2
)
),
),
},
},
inputs
=
{
inputs
=
{
"input_data1"
:
"input_data1"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
data_gen
=
partial
(
generate_input1
,
batch
,
dim1
)),
generate_input1
,
batch
,
dim1
"input_data2"
:
)
TensorConfig
(
data_gen
=
partial
(
),
generate_input2
,
input2_shape
)),
"input_data2"
:
TensorConfig
(
data_gen
=
partial
(
generate_input2
,
input2_shape
)
),
},
},
outputs
=
[
"mul4_output"
])
outputs
=
[
"mul4_output"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
# The last dim of input1 and input2 should be static.
# The last dim of input1 and input2 should be static.
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data1"
:
[
1
,
8
,
768
],
"input_data1"
:
[
1
,
8
,
768
],
"input_data2"
:
[
1
,
1
,
1
,
128
],
"input_data2"
:
[
1
,
1
,
1
,
128
],
"reshape24_output"
:
[
1
,
128
,
768
]
"reshape24_output"
:
[
1
,
128
,
768
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data1"
:
[
16
,
512
,
768
],
"input_data1"
:
[
16
,
512
,
768
],
"input_data2"
:
[
16
,
256
,
512
,
128
],
"input_data2"
:
[
16
,
256
,
512
,
128
],
"reshape24_output"
:
[
1
,
128
,
768
]
"reshape24_output"
:
[
1
,
128
,
768
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data1"
:
[
8
,
128
,
768
],
"input_data1"
:
[
8
,
128
,
768
],
"input_data2"
:
[
8
,
32
,
64
,
128
],
"input_data2"
:
[
8
,
32
,
64
,
128
],
"reshape24_output"
:
[
1
,
128
,
768
]
"reshape24_output"
:
[
1
,
128
,
768
]
,
}
}
def
clear_dynamic_shape
():
def
clear_dynamic_shape
():
...
@@ -427,7 +387,7 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -427,7 +387,7 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
self
.
trt_param
.
workspace_size
=
2013265920
self
.
trt_param
.
workspace_size
=
2013265920
yield
self
.
create_inference_config
(),
(
1
,
4
),
(
1e-5
,
1e-5
)
yield
self
.
create_inference_config
(),
(
1
,
4
),
(
1e-5
,
1e-5
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
...
@@ -435,28 +395,33 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -435,28 +395,33 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
self
.
trt_param
.
workspace_size
=
2013265920
self
.
trt_param
.
workspace_size
=
2013265920
yield
self
.
create_inference_config
(),
(
1
,
3
),
(
1e-5
,
1e-4
)
yield
self
.
create_inference_config
(),
(
1
,
3
),
(
1e-5
,
1e-4
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
add_skip_trt_case
(
self
):
def
teller1
(
program_config
,
predictor_config
):
def
teller1
(
program_config
,
predictor_config
):
if
self
.
trt_param
.
precision
==
paddle_infer
.
PrecisionType
.
Half
:
if
self
.
trt_param
.
precision
==
paddle_infer
.
PrecisionType
.
Half
:
return
True
return
True
return
False
return
False
self
.
add_skip_case
(
self
.
add_skip_case
(
teller1
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
teller1
,
"The output has diff between gpu and trt in fp16 mode."
)
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"The output has diff between gpu and trt in fp16 mode."
,
)
def
teller2
(
program_config
,
predictor_config
):
def
teller2
(
program_config
,
predictor_config
):
if
self
.
trt_param
.
precision
==
paddle_infer
.
PrecisionType
.
Float32
and
len
(
if
(
self
.
dynamic_shape
.
min_input_shape
)
!=
0
and
self
.
batch
>
2
:
self
.
trt_param
.
precision
==
paddle_infer
.
PrecisionType
.
Float32
and
len
(
self
.
dynamic_shape
.
min_input_shape
)
!=
0
and
self
.
batch
>
2
):
return
True
return
True
return
False
return
False
self
.
add_skip_case
(
self
.
add_skip_case
(
teller2
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
teller2
,
"The output has diff between gpu and trt when dynamic fp32 mode and batch size > 2."
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
):
def
teller3
(
program_config
,
predictor_config
):
...
@@ -465,8 +430,10 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -465,8 +430,10 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
return
False
return
False
self
.
add_skip_case
(
self
.
add_skip_case
(
teller3
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
teller3
,
"The output has diff between gpu and trt in int8 mode."
)
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"The output has diff between gpu and trt in int8 mode."
,
)
def
test
(
self
):
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
add_skip_trt_case
()
...
@@ -474,9 +441,7 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -474,9 +441,7 @@ class TrtConvertMultiHeadMatmulTest(TrtLayerAutoScanTest):
class
TrtConvertMultiHeadMatmulTestInt8
(
TrtConvertMultiHeadMatmulTest
):
class
TrtConvertMultiHeadMatmulTestInt8
(
TrtConvertMultiHeadMatmulTest
):
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
batch
,
dim1
):
def
generate_input1
(
batch
,
dim1
):
return
np
.
random
.
random
((
batch
,
dim1
,
768
)).
astype
(
np
.
float32
)
return
np
.
random
.
random
((
batch
,
dim1
,
768
)).
astype
(
np
.
float32
)
...
@@ -493,112 +458,110 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
...
@@ -493,112 +458,110 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
self
.
batch
=
batch
self
.
batch
=
batch
for
reshape_shape
in
[[
0
,
0
,
12
,
64
]]:
for
reshape_shape
in
[[
0
,
0
,
12
,
64
]]:
for
dim1
in
[
128
]:
for
dim1
in
[
128
]:
input2_shapes
=
[[
batch
,
reshape_shape
[
2
],
dim1
,
dim1
],
input2_shapes
=
[
[
batch
,
1
,
1
,
dim1
]]
[
batch
,
reshape_shape
[
2
],
dim1
,
dim1
],
[
batch
,
1
,
1
,
dim1
],
]
for
input2_shape
in
input2_shapes
:
for
input2_shape
in
input2_shapes
:
for
axis
in
[
0
]:
for
axis
in
[
0
]:
dics
=
[{
dics
=
[
"x_num_col_dims"
:
2
,
{
"y_num_col_dims"
:
1
,
"x_num_col_dims"
:
2
,
"enable_int8"
:
True
,
"y_num_col_dims"
:
1
,
"Input_scale"
:
1.0
,
"enable_int8"
:
True
,
},
{
"Input_scale"
:
1.0
,
"axis"
:
2
,
},
"out_threshold"
:
1.0
,
{
},
{
"axis"
:
2
,
"shape"
:
reshape_shape
"out_threshold"
:
1.0
,
},
{
},
"axis"
:
[
0
,
2
,
1
,
3
]
{
"shape"
:
reshape_shape
},
},
{
{
"axis"
:
[
0
,
2
,
1
,
3
]},
"x_num_col_dims"
:
2
,
{
"y_num_col_dims"
:
1
,
"x_num_col_dims"
:
2
,
"enable_int8"
:
True
,
"y_num_col_dims"
:
1
,
"Input_scale"
:
1.0
,
"enable_int8"
:
True
,
},
{
"Input_scale"
:
1.0
,
"axis"
:
2
,
},
"out_threshold"
:
1.0
,
{
},
{
"axis"
:
2
,
"shape"
:
reshape_shape
"out_threshold"
:
1.0
,
},
{
},
"axis"
:
[
0
,
2
,
1
,
3
]
{
"shape"
:
reshape_shape
},
},
{
{
"axis"
:
[
0
,
2
,
1
,
3
]},
"x_num_col_dims"
:
2
,
{
"y_num_col_dims"
:
1
,
"x_num_col_dims"
:
2
,
"enable_int8"
:
True
,
"y_num_col_dims"
:
1
,
"Input_scale"
:
1.0
,
"enable_int8"
:
True
,
},
{
"Input_scale"
:
1.0
,
"axis"
:
2
,
},
"out_threshold"
:
1.0
,
{
},
{
"axis"
:
2
,
"shape"
:
reshape_shape
"out_threshold"
:
1.0
,
},
{
},
"axis"
:
[
0
,
2
,
1
,
3
]
{
"shape"
:
reshape_shape
},
},
{
{
"axis"
:
[
0
,
2
,
1
,
3
]},
"scale"
:
0.125
,
{
"bias"
:
0.0
,
"scale"
:
0.125
,
"bias_after_scale"
:
True
"bias"
:
0.0
,
},
{
"bias_after_scale"
:
True
,
"alpha"
:
1.0
,
},
"transpose_X"
:
False
,
{
"transpose_Y"
:
True
,
"alpha"
:
1.0
,
"fused_reshape_X"
:
[],
"transpose_X"
:
False
,
"fused_reshape_Y"
:
[],
"transpose_Y"
:
True
,
"fused_transpose_X"
:
[],
"fused_reshape_X"
:
[],
"fused_transpose_Y"
:
[],
"fused_reshape_Y"
:
[],
"fused_reshape_Out"
:
[],
"fused_transpose_X"
:
[],
"fused_transpose_Out"
:
[]
"fused_transpose_Y"
:
[],
},
{
"fused_reshape_Out"
:
[],
"axis"
:
axis
"fused_transpose_Out"
:
[],
},
{
},
"axis"
:
-
1
,
{
"axis"
:
axis
},
"is_test"
:
True
{
"axis"
:
-
1
,
"is_test"
:
True
},
},
{
{
"seed"
:
0
,
"seed"
:
0
,
"dropout_prob"
:
0.10000000149011612
,
"dropout_prob"
:
0.10000000149011612
,
"dropout_implementation"
:
"upscale_in_train"
,
"dropout_implementation"
:
"upscale_in_train"
,
"fix_seed"
:
False
,
"fix_seed"
:
False
,
"is_test"
:
True
"is_test"
:
True
,
},
{
},
"alpha"
:
1.0
,
{
"transpose_X"
:
False
,
"alpha"
:
1.0
,
"transpose_Y"
:
False
,
"transpose_X"
:
False
,
"fused_reshape_X"
:
[],
"transpose_Y"
:
False
,
"fused_reshape_Y"
:
[],
"fused_reshape_X"
:
[],
"fused_transpose_X"
:
[],
"fused_reshape_Y"
:
[],
"fused_transpose_Y"
:
[],
"fused_transpose_X"
:
[],
"fused_reshape_Out"
:
[],
"fused_transpose_Y"
:
[],
"fused_transpose_Out"
:
[]
"fused_reshape_Out"
:
[],
},
{
"fused_transpose_Out"
:
[],
"axis"
:
[
0
,
2
,
1
,
3
]
},
},
{
{
"axis"
:
[
0
,
2
,
1
,
3
]},
"shape"
:
[
0
,
0
,
768
]
{
"shape"
:
[
0
,
0
,
768
]},
},
{
{
"x_num_col_dims"
:
2
,
"y_num_col_dims"
:
1
},
"x_num_col_dims"
:
2
,
]
"y_num_col_dims"
:
1
}]
ops_config
=
[
ops_config
=
[
{
{
"op_type"
:
"mul"
,
"op_type"
:
"mul"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"input_data1"
],
"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_type"
:
"elementwise_add"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"mul1_output"
],
"X"
:
[
"mul1_output"
],
"Y"
:
[
"elementwise_add1_weight"
]
"Y"
:
[
"elementwise_add1_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"elementwise_add1_output"
]
"Out"
:
[
"elementwise_add1_output"
]
},
},
"op_attrs"
:
dics
[
1
]
"op_attrs"
:
dics
[
1
]
,
},
},
{
{
"op_type"
:
"reshape2"
,
"op_type"
:
"reshape2"
,
...
@@ -607,42 +570,38 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
...
@@ -607,42 +570,38 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"reshape21_output"
],
"Out"
:
[
"reshape21_output"
],
"XShape"
:
[
"reshape21_output_xshape"
]
"XShape"
:
[
"reshape21_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
2
]
"op_attrs"
:
dics
[
2
]
,
},
},
{
{
"op_type"
:
"transpose2"
,
"op_type"
:
"transpose2"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"reshape21_output"
]},
"X"
:
[
"reshape21_output"
]
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"transpose21_output"
],
"Out"
:
[
"transpose21_output"
],
"XShape"
:
[
"transpose21_output_xshape"
]
"XShape"
:
[
"transpose21_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
3
]
"op_attrs"
:
dics
[
3
]
,
},
},
{
{
"op_type"
:
"mul"
,
"op_type"
:
"mul"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"input_data1"
],
"X"
:
[
"input_data1"
],
"Y"
:
[
"mul2_weight"
]
"Y"
:
[
"mul2_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"mul2_output"
]},
"Out"
:
[
"mul2_output"
]
"op_attrs"
:
dics
[
4
],
},
"op_attrs"
:
dics
[
4
]
},
},
{
{
"op_type"
:
"elementwise_add"
,
"op_type"
:
"elementwise_add"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"mul2_output"
],
"X"
:
[
"mul2_output"
],
"Y"
:
[
"elementwise_add2_weight"
]
"Y"
:
[
"elementwise_add2_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"elementwise_add2_output"
]
"Out"
:
[
"elementwise_add2_output"
]
},
},
"op_attrs"
:
dics
[
5
]
"op_attrs"
:
dics
[
5
]
,
},
},
{
{
"op_type"
:
"reshape2"
,
"op_type"
:
"reshape2"
,
...
@@ -651,42 +610,38 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
...
@@ -651,42 +610,38 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"reshape22_output"
],
"Out"
:
[
"reshape22_output"
],
"XShape"
:
[
"reshape22_output_xshape"
]
"XShape"
:
[
"reshape22_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
6
]
"op_attrs"
:
dics
[
6
]
,
},
},
{
{
"op_type"
:
"transpose2"
,
"op_type"
:
"transpose2"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"reshape22_output"
]},
"X"
:
[
"reshape22_output"
]
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"transpose22_output"
],
"Out"
:
[
"transpose22_output"
],
"XShape"
:
[
"transpose22_output_xshape"
]
"XShape"
:
[
"transpose22_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
7
]
"op_attrs"
:
dics
[
7
]
,
},
},
{
{
"op_type"
:
"mul"
,
"op_type"
:
"mul"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"input_data1"
],
"X"
:
[
"input_data1"
],
"Y"
:
[
"mul3_weight"
]
"Y"
:
[
"mul3_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"mul3_output"
]},
"Out"
:
[
"mul3_output"
]
"op_attrs"
:
dics
[
8
],
},
"op_attrs"
:
dics
[
8
]
},
},
{
{
"op_type"
:
"elementwise_add"
,
"op_type"
:
"elementwise_add"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"mul3_output"
],
"X"
:
[
"mul3_output"
],
"Y"
:
[
"elementwise_add3_weight"
]
"Y"
:
[
"elementwise_add3_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"elementwise_add3_output"
]
"Out"
:
[
"elementwise_add3_output"
]
},
},
"op_attrs"
:
dics
[
9
]
"op_attrs"
:
dics
[
9
]
,
},
},
{
{
"op_type"
:
"reshape2"
,
"op_type"
:
"reshape2"
,
...
@@ -695,30 +650,26 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
...
@@ -695,30 +650,26 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"reshape23_output"
],
"Out"
:
[
"reshape23_output"
],
"XShape"
:
[
"reshape23_output_xshape"
]
"XShape"
:
[
"reshape23_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
10
]
"op_attrs"
:
dics
[
10
]
,
},
},
{
{
"op_type"
:
"transpose2"
,
"op_type"
:
"transpose2"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"reshape23_output"
]},
"X"
:
[
"reshape23_output"
]
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"transpose23_output"
],
"Out"
:
[
"transpose23_output"
],
"XShape"
:
[
"transpose23_output_xshape"
]
"XShape"
:
[
"transpose23_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
11
]
"op_attrs"
:
dics
[
11
]
,
},
},
{
{
"op_type"
:
"scale"
,
"op_type"
:
"scale"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"transpose23_output"
],
"X"
:
[
"transpose23_output"
],
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"scale_output"
]},
"Out"
:
[
"scale_output"
]
"op_attrs"
:
dics
[
12
],
},
"op_attrs"
:
dics
[
12
]
},
},
{
{
"op_type"
:
"matmul"
,
"op_type"
:
"matmul"
,
...
@@ -726,41 +677,35 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
...
@@ -726,41 +677,35 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
"X"
:
[
"scale_output"
],
"X"
:
[
"scale_output"
],
"Y"
:
[
"transpose22_output"
],
"Y"
:
[
"transpose22_output"
],
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"matmul1_output"
]},
"Out"
:
[
"matmul1_output"
]
"op_attrs"
:
dics
[
13
],
},
"op_attrs"
:
dics
[
13
]
},
},
{
{
"op_type"
:
"elementwise_add"
,
"op_type"
:
"elementwise_add"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"matmul1_output"
],
"X"
:
[
"matmul1_output"
],
"Y"
:
[
"input_data2"
]
"Y"
:
[
"input_data2"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"elementwise_add4_output"
]
"Out"
:
[
"elementwise_add4_output"
]
},
},
"op_attrs"
:
dics
[
14
]
"op_attrs"
:
dics
[
14
]
,
},
},
{
{
"op_type"
:
"softmax"
,
"op_type"
:
"softmax"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"elementwise_add4_output"
]
"X"
:
[
"elementwise_add4_output"
]
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"softmax_output"
]},
"Out"
:
[
"softmax_output"
]
"op_attrs"
:
dics
[
15
],
},
"op_attrs"
:
dics
[
15
]
},
},
{
{
"op_type"
:
"dropout"
,
"op_type"
:
"dropout"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"softmax_output"
],
"X"
:
[
"softmax_output"
],
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"dropout3_output"
]},
"Out"
:
[
"dropout3_output"
]
"op_attrs"
:
dics
[
16
],
},
"op_attrs"
:
dics
[
16
]
},
},
{
{
"op_type"
:
"matmul"
,
"op_type"
:
"matmul"
,
...
@@ -768,32 +713,26 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
...
@@ -768,32 +713,26 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
"X"
:
[
"dropout3_output"
],
"X"
:
[
"dropout3_output"
],
"Y"
:
[
"transpose21_output"
],
"Y"
:
[
"transpose21_output"
],
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"matmul2_output"
]},
"Out"
:
[
"matmul2_output"
]
"op_attrs"
:
dics
[
17
],
},
"op_attrs"
:
dics
[
17
]
},
},
{
{
"op_type"
:
"transpose2"
,
"op_type"
:
"transpose2"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"matmul2_output"
]},
"X"
:
[
"matmul2_output"
]
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"transpose24_output"
],
"Out"
:
[
"transpose24_output"
],
"XShape"
:
[
"transpose24_output_xshape"
]
"XShape"
:
[
"transpose24_output_xshape"
]
,
},
},
"op_attrs"
:
dics
[
18
]
"op_attrs"
:
dics
[
18
]
,
},
},
{
{
"op_type"
:
"reshape2"
,
"op_type"
:
"reshape2"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"transpose24_output"
]},
"X"
:
[
"transpose24_output"
]
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"reshape24_output"
],
"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
# In order to fuse ops with
# multihead_matmul_fuse_pass_v2, the last op
# multihead_matmul_fuse_pass_v2, the last op
...
@@ -802,61 +741,62 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
...
@@ -802,61 +741,62 @@ class TrtConvertMultiHeadMatmulTestInt8(TrtConvertMultiHeadMatmulTest):
"op_type"
:
"mul"
,
"op_type"
:
"mul"
,
"op_inputs"
:
{
"op_inputs"
:
{
"X"
:
[
"reshape24_output"
],
"X"
:
[
"reshape24_output"
],
"Y"
:
[
"mul4_weight"
]
"Y"
:
[
"mul4_weight"
]
,
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"mul4_output"
]},
"Out"
:
[
"mul4_output"
]
"op_attrs"
:
dics
[
20
],
},
},
"op_attrs"
:
dics
[
20
]
}
]
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{
weights
=
{
"mul1_weight"
:
"mul1_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight1
)
data_gen
=
partial
(
generate_weight1
)
),
),
"mul2_weight"
:
"mul2_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight1
)
data_gen
=
partial
(
generate_weight1
)
),
),
"mul3_weight"
:
"mul3_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight1
)
data_gen
=
partial
(
generate_weight1
)
),
),
"mul4_weight"
:
"mul4_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight1
)
data_gen
=
partial
(
generate_weight1
)
),
),
"elementwise_add1_weight"
:
"elementwise_add1_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight2
)
data_gen
=
partial
(
generate_weight2
)
),
),
"elementwise_add2_weight"
:
"elementwise_add2_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight2
)
data_gen
=
partial
(
generate_weight2
)
),
),
"elementwise_add3_weight"
:
"elementwise_add3_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight2
)
data_gen
=
partial
(
generate_weight2
)
),
),
},
},
inputs
=
{
inputs
=
{
"input_data1"
:
"input_data1"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
data_gen
=
partial
(
generate_input1
,
batch
,
dim1
)),
generate_input1
,
batch
,
dim1
"input_data2"
:
)
TensorConfig
(
data_gen
=
partial
(
),
generate_input2
,
input2_shape
)),
"input_data2"
:
TensorConfig
(
data_gen
=
partial
(
generate_input2
,
input2_shape
)
),
},
},
outputs
=
[
"mul4_output"
])
outputs
=
[
"mul4_output"
],
)
yield
program_config
yield
program_config
class
TrtConvertVitToMultiHeadMatmulTest
(
TrtLayerAutoScanTest
):
class
TrtConvertVitToMultiHeadMatmulTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
batch
,
length
):
def
generate_input1
(
batch
,
length
):
return
np
.
zeros
((
batch
,
length
,
768
),
dtype
=
np
.
float32
)
return
np
.
zeros
((
batch
,
length
,
768
),
dtype
=
np
.
float32
)
...
@@ -868,218 +808,192 @@ class TrtConvertVitToMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -868,218 +808,192 @@ class TrtConvertVitToMultiHeadMatmulTest(TrtLayerAutoScanTest):
for
batch
in
[
2
,
4
]:
for
batch
in
[
2
,
4
]:
self
.
batch
=
batch
self
.
batch
=
batch
for
length
in
[
64
,
384
]:
for
length
in
[
197
]:
self
.
length
=
length
self
.
length
=
length
ops_config
=
[{
ops_config
=
[
"op_type"
:
"matmul_v2"
,
{
"op_inputs"
:
{
"op_type"
:
"matmul_v2"
,
"X"
:
[
"input_data1"
],
"op_inputs"
:
{
"Y"
:
[
"matmul1_weight"
]
"X"
:
[
"input_data1"
],
},
"Y"
:
[
"matmul1_weight"
],
"op_outputs"
:
{
},
"Out"
:
[
"matmul1_output"
]
"op_outputs"
:
{
"Out"
:
[
"matmul1_output"
]},
},
"op_attrs"
:
{
"trans_x"
:
False
,
"trans_y"
:
False
},
"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"
]
},
},
"op_attrs"
:
{
{
"Scale_out"
:
1.0
,
"op_type"
:
"elementwise_add"
,
"Scale_x"
:
1.0
,
"op_inputs"
:
{
"Scale_y"
:
1.0
,
"X"
:
[
"matmul1_output"
],
"axis"
:
2
"Y"
:
[
"elementwise_add1_weight"
],
}
},
},
{
"op_outputs"
:
{
"Out"
:
[
"elementwise_add1_output"
]},
"op_type"
:
"reshape2"
,
"op_attrs"
:
{
"op_inputs"
:
{
"Scale_out"
:
1.0
,
"X"
:
[
"elementwise_add1_output"
],
"Scale_x"
:
1.0
,
"Scale_y"
:
1.0
,
"axis"
:
2
,
},
},
},
"op_outputs"
:
{
{
"Out"
:
[
"reshape1_output"
],
"op_type"
:
"reshape2"
,
"XShape"
:
[
"reshape1_output_xshape"
]
"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_outputs"
:
{
"op_type"
:
"transpose2"
,
"Out"
:
[
"transpose1_output"
],
"op_inputs"
:
{
"XShape"
:
[
"transpose1_output_xshape"
],
"X"
:
[
"reshape1_output"
]
},
"op_attrs"
:
{
"axis"
:
[
2
,
0
,
3
,
1
,
4
],
"data_format"
:
"AnyLayout"
,
},
},
},
"op_outputs"
:
{
{
"Out"
:
[
"transpose1_output"
],
"op_type"
:
"slice"
,
"XShape"
:
[
"transpose1_output_xshape"
]
"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
],
"op_type"
:
"slice"
,
"data_format"
:
"AnyLayout"
"op_inputs"
:
{
}
"Input"
:
[
"transpose1_output"
],
},
{
},
"op_type"
:
"slice"
,
"op_outputs"
:
{
"Out"
:
[
"slice2_output"
]},
"op_inputs"
:
{
"op_attrs"
:
{
"Input"
:
[
"transpose1_output"
],
"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
],
"op_type"
:
"transpose2"
,
"starts"
:
[
0
],
"op_inputs"
:
{
"X"
:
[
"slice2_output"
]},
"ends"
:
[
1
],
"op_outputs"
:
{
"decrease_axis"
:
[
0
],
"Out"
:
[
"transpose2_output"
],
"infer_flags"
:
[
1
]
},
}
"op_attrs"
:
{
},
{
"axis"
:
[
0
,
1
,
3
,
2
],
"op_type"
:
"slice"
,
"data_format"
:
"AnyLayout"
,
"op_inputs"
:
{
},
"Input"
:
[
"transpose1_output"
],
},
},
"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
]
,
"
op_type"
:
"scale"
,
"
star
ts"
:
[
1
],
"
op_inpu
ts"
:
{
"ends"
:
[
2
],
"X"
:
[
"matmul2_output"
],
"decrease_axis"
:
[
0
]
,
}
,
"
infer_flags"
:
[
1
]
"
op_outputs"
:
{
"Out"
:
[
"scale_output"
]},
}
"op_attrs"
:
{
},
{
"scale"
:
0.125
,
"op_type"
:
"slice"
,
"bias"
:
0.0
,
"op_inputs"
:
{
"bias_after_scale"
:
True
,
"Input"
:
[
"transpose1_output"
]
,
}
,
},
},
"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
],
"op_type"
:
"matmul_v2"
,
"starts"
:
[
2
],
"op_inputs"
:
{
"ends"
:
[
3
],
"X"
:
[
"softmax_output"
],
"decrease_axis"
:
[
0
],
"Y"
:
[
"slice3_output"
],
"infer_flags"
:
[
1
]
},
}
"op_outputs"
:
{
"Out"
:
[
"matmul3_output"
]},
},
{
"op_attrs"
:
{
"trans_x"
:
False
,
"trans_y"
:
False
},
"op_type"
:
"transpose2"
,
"op_inputs"
:
{
"X"
:
[
"slice2_output"
]
},
},
"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
],
"op_type"
:
"reshape2"
,
"data_format"
:
"AnyLayout"
"op_inputs"
:
{
"X"
:
[
"transpose3_output"
]},
}
"op_outputs"
:
{
},
{
"Out"
:
[
"reshape2_output"
],
"op_type"
:
"matmul_v2"
,
"XShape"
:
[
"reshape2_output_xshape"
],
"op_inputs"
:
{
},
"X"
:
[
"slice1_output"
],
"op_attrs"
:
{
"shape"
:
[
-
1
,
self
.
length
,
768
]},
"Y"
:
[
"transpose2_output"
]
},
},
"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
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{
weights
=
{
"matmul1_weight"
:
"matmul1_weight"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_weight1
)),
data_gen
=
partial
(
generate_weight1
)
"elementwise_add1_weight"
:
),
TensorConfig
(
data_gen
=
partial
(
generate_weight2
))
"elementwise_add1_weight"
:
TensorConfig
(
data_gen
=
partial
(
generate_weight2
)
),
},
},
inputs
=
{
inputs
=
{
"input_data1"
:
"input_data1"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
batch
,
length
)
data_gen
=
partial
(
generate_input1
,
batch
,
length
)
)
)
},
},
outputs
=
[
"reshape2_output"
])
outputs
=
[
"reshape2_output"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
# The last dim of input1 and input2 should be static.
# The last dim of input1 and input2 should be static.
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
...
@@ -1111,11 +1025,15 @@ class TrtConvertVitToMultiHeadMatmulTest(TrtLayerAutoScanTest):
...
@@ -1111,11 +1025,15 @@ class TrtConvertVitToMultiHeadMatmulTest(TrtLayerAutoScanTest):
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
workspace_size
=
2013265920
self
.
trt_param
.
workspace_size
=
2013265920
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(),
(
1e-3
,
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(),
(
1e-3
)
1e-3
,
1e-3
,
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(),
(
1e-5
,
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(),
(
1e-5
)
1e-5
,
1e-5
,
)
def
add_skip_trt_case
(
self
):
def
add_skip_trt_case
(
self
):
pass
pass
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_pad3d.py
View file @
dbe08e9b
...
@@ -22,30 +22,30 @@ import unittest
...
@@ -22,30 +22,30 @@ import unittest
class
TrtConvertPad3d
(
TrtLayerAutoScanTest
):
class
TrtConvertPad3d
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
():
def
generate_input1
():
return
np
.
ones
([
1
,
1
,
3
,
64
,
64
]).
astype
(
np
.
float32
)
return
np
.
ones
([
1
,
1
,
3
,
64
,
64
]).
astype
(
np
.
float32
)
for
value
in
[
True
,
False
]:
for
value
in
[
True
,
False
]:
for
paddings
in
[[
0
,
0
,
0
,
0
,
1
,
1
],
[
0
,
0
,
1
,
2
,
3
,
4
],
for
paddings
in
[
[
1
,
1
,
1
,
1
,
1
,
1
],
[
0
,
0
,
-
1
,
-
1
,
1
,
1
]]:
[
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
},
{}]
dics
=
[{
"value"
:
value
,
"paddings"
:
paddings
},
{}]
ops_config
=
[{
ops_config
=
[
"op_type"
:
"pad3d"
,
{
"op_inputs"
:
{
"op_type"
:
"pad3d"
,
"X"
:
[
"input_data"
]
"op_inputs"
:
{
"X"
:
[
"input_data"
]},
},
"op_outputs"
:
{
"Out"
:
[
"output_data"
]},
"op_outputs"
:
{
"op_attrs"
:
dics
[
0
],
"Out"
:
[
"output_data"
]
}
},
]
"op_attrs"
:
dics
[
0
]
}]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
for
i
in
range
(
10
):
for
i
in
range
(
10
):
...
@@ -53,16 +53,18 @@ class TrtConvertPad3d(TrtLayerAutoScanTest):
...
@@ -53,16 +53,18 @@ class TrtConvertPad3d(TrtLayerAutoScanTest):
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input_data"
:
"input_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
)),
data_gen
=
partial
(
generate_input1
)
),
},
},
outputs
=
[
"output_data"
])
outputs
=
[
"output_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
1
,
3
,
64
,
64
]
"input_data"
:
[
1
,
1
,
3
,
64
,
64
]
...
@@ -88,14 +90,14 @@ class TrtConvertPad3d(TrtLayerAutoScanTest):
...
@@ -88,14 +90,14 @@ class TrtConvertPad3d(TrtLayerAutoScanTest):
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
0
,
3
),
1e-5
yield
self
.
create_inference_config
(),
(
0
,
3
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
1
,
2
),
1e-5
yield
self
.
create_inference_config
(),
(
1
,
2
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
):
def
test
(
self
):
self
.
run_test
()
self
.
run_test
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_pool2d.py
View file @
dbe08e9b
...
@@ -20,10 +20,10 @@ from functools import partial
...
@@ -20,10 +20,10 @@ from functools import partial
from
typing
import
Optional
,
List
,
Callable
,
Dict
,
Any
,
Set
from
typing
import
Optional
,
List
,
Callable
,
Dict
,
Any
,
Set
import
unittest
import
unittest
import
itertools
import
itertools
import
copy
class
TrtConvertPool2dTest
(
TrtLayerAutoScanTest
):
class
TrtConvertPool2dTest
(
TrtLayerAutoScanTest
):
def
is_paddings_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_paddings_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
exclusive
=
program_config
.
ops
[
0
].
attrs
[
'exclusive'
]
exclusive
=
program_config
.
ops
[
0
].
attrs
[
'exclusive'
]
paddings
=
program_config
.
ops
[
0
].
attrs
[
'paddings'
]
paddings
=
program_config
.
ops
[
0
].
attrs
[
'paddings'
]
...
@@ -65,39 +65,54 @@ class TrtConvertPool2dTest(TrtLayerAutoScanTest):
...
@@ -65,39 +65,54 @@ class TrtConvertPool2dTest(TrtLayerAutoScanTest):
ceil_mode_options
=
[
True
,
False
]
ceil_mode_options
=
[
True
,
False
]
configurations
=
[
configurations
=
[
strides_options
,
paddings_options
,
pooling_type_options
,
strides_options
,
padding_algorithm_options
,
ksize_options
,
data_format_options
,
paddings_options
,
global_pooling_options
,
exclusive_options
,
adaptive_option
,
pooling_type_options
,
ceil_mode_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
,
for
(
data_format
,
global_pooling
,
exclusive
,
adaptive
,
strides
,
ceil_mode
)
in
itertools
.
product
(
*
configurations
):
paddings
,
pooling_type
,
attrs
=
[{
padding_algorithm
,
"strides"
:
strides
,
ksize
,
"paddings"
:
paddings
,
data_format
,
"pooling_type"
:
pooling_type
,
global_pooling
,
"padding_algorithm"
:
padding_algorithm
,
exclusive
,
"ksize"
:
ksize
,
adaptive
,
"data_format"
:
data_format
,
ceil_mode
,
"global_pooling"
:
global_pooling
,
)
in
itertools
.
product
(
*
configurations
):
"exclusive"
:
exclusive
,
"adaptive"
:
adaptive
,
attrs
=
[
"ceil_mode"
:
ceil_mode
,
{
}]
"strides"
:
strides
,
"paddings"
:
paddings
,
ops_config
=
[{
"pooling_type"
:
pooling_type
,
"op_type"
:
"pool2d"
,
"padding_algorithm"
:
padding_algorithm
,
"op_inputs"
:
{
"ksize"
:
ksize
,
"X"
:
[
"input_data"
]
"data_format"
:
data_format
,
},
"global_pooling"
:
global_pooling
,
"op_outputs"
:
{
"exclusive"
:
exclusive
,
"Out"
:
[
"output_data"
]
"adaptive"
:
adaptive
,
},
"ceil_mode"
:
ceil_mode
,
"op_attrs"
:
attrs
[
0
]
}
}]
]
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
)
ops
=
self
.
generate_op_config
(
ops_config
)
...
@@ -105,16 +120,18 @@ class TrtConvertPool2dTest(TrtLayerAutoScanTest):
...
@@ -105,16 +120,18 @@ class TrtConvertPool2dTest(TrtLayerAutoScanTest):
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input_data"
:
"input_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
attrs
))
data_gen
=
partial
(
generate_input1
,
attrs
)
)
},
},
outputs
=
[
"output_data"
])
outputs
=
[
"output_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
3
,
32
,
32
]}
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
3
,
32
,
32
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
1
,
3
,
64
,
64
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
1
,
3
,
64
,
64
]}
...
@@ -136,36 +153,75 @@ class TrtConvertPool2dTest(TrtLayerAutoScanTest):
...
@@ -136,36 +153,75 @@ class TrtConvertPool2dTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
(
1e-3
,
1e-3
)
attrs
,
False
),
(
1e-3
,
1e-3
)
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
add_skip_trt_case
(
self
):
def
teller
(
program_config
,
predictor_config
):
def
teller
(
program_config
,
predictor_config
):
if
program_config
.
ops
[
0
].
attrs
[
'pooling_type'
]
==
'avg'
and
\
if
(
program_config
.
ops
[
0
].
attrs
[
'global_pooling'
]
==
False
and
\
program_config
.
ops
[
0
].
attrs
[
'pooling_type'
]
==
'avg'
program_config
.
ops
[
0
].
attrs
[
'exclusive'
]
==
True
and
\
and
program_config
.
ops
[
0
].
attrs
[
'global_pooling'
]
==
False
program_config
.
ops
[
0
].
attrs
[
'adaptive'
]
==
False
and
\
and
program_config
.
ops
[
0
].
attrs
[
'exclusive'
]
==
True
program_config
.
ops
[
0
].
attrs
[
'ceil_mode'
]
==
True
:
and
program_config
.
ops
[
0
].
attrs
[
'adaptive'
]
==
False
and
program_config
.
ops
[
0
].
attrs
[
'ceil_mode'
]
==
True
):
return
True
return
True
return
False
return
False
self
.
add_skip_case
(
self
.
add_skip_case
(
teller
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
teller
,
"The results of some cases are Nan, but the results of TensorRT and GPU are the same."
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
):
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
add_skip_trt_case
()
self
.
run_test
()
self
.
run_test
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce_sum.py
View file @
dbe08e9b
...
@@ -23,7 +23,6 @@ import unittest
...
@@ -23,7 +23,6 @@ import unittest
class
TrtConvertReduceSumTest
(
TrtLayerAutoScanTest
):
class
TrtConvertReduceSumTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
inputs
=
program_config
.
inputs
inputs
=
program_config
.
inputs
attrs
=
[
attrs
=
[
...
@@ -41,7 +40,6 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
...
@@ -41,7 +40,6 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
dtype
,
attrs
:
List
[
Dict
[
str
,
Any
]]):
def
generate_input1
(
dtype
,
attrs
:
List
[
Dict
[
str
,
Any
]]):
if
dtype
==
-
1
or
dtype
==
5
:
if
dtype
==
-
1
or
dtype
==
5
:
return
np
.
random
.
random
([
1
,
3
,
32
,
32
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
1
,
3
,
32
,
32
]).
astype
(
np
.
float32
)
...
@@ -49,39 +47,52 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
...
@@ -49,39 +47,52 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
return
np
.
random
.
random
([
1
,
3
,
32
,
32
]).
astype
(
np
.
int32
)
return
np
.
random
.
random
([
1
,
3
,
32
,
32
]).
astype
(
np
.
int32
)
for
keep_dim
in
[
True
,
False
]:
for
keep_dim
in
[
True
,
False
]:
for
dim
in
[[],
[
1
],
[
0
],
[
0
,
1
],
[
1
,
2
,
3
],
[
-
2
,
0
,
3
],
[
-
3
],
for
dim
in
[
[
-
4
,
1
],
[
3
,
4
,
5
]]:
[],
[
1
],
[
0
],
[
0
,
1
],
[
1
,
2
,
3
],
[
-
2
,
0
,
3
],
[
-
3
],
[
-
4
,
1
],
[
3
,
4
,
5
],
]:
for
reduce_all
in
[
True
,
False
]:
for
reduce_all
in
[
True
,
False
]:
for
out_dtype
in
[
-
1
,
2
,
5
]:
for
out_dtype
in
[
-
1
,
2
,
5
]:
dics
=
[{
dics
=
[
"keep_dim"
:
keep_dim
,
{
"dim"
:
dim
,
"keep_dim"
:
keep_dim
,
"reduce_all"
:
reduce_all
,
"dim"
:
dim
,
"out_dtype"
:
out_dtype
,
"reduce_all"
:
reduce_all
,
"in_dtype"
:
out_dtype
,
"out_dtype"
:
out_dtype
,
},
{}]
"in_dtype"
:
out_dtype
,
ops_config
=
[{
"op_type"
:
"reduce_sum"
,
"op_inputs"
:
{
"X"
:
[
"input_data"
]
},
},
"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
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input_data"
:
"input_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
data_gen
=
partial
(
generate_input1
,
out_dtype
,
dics
))
generate_input1
,
out_dtype
,
dics
)
)
},
},
outputs
=
[
"reduce_output_data"
])
outputs
=
[
"reduce_output_data"
],
)
if
not
self
.
is_program_valid
(
program_config
):
if
not
self
.
is_program_valid
(
program_config
):
continue
continue
...
@@ -89,7 +100,6 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
...
@@ -89,7 +100,6 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
yield
program_config
yield
program_config
def
sample_predictor_configs
(
self
,
program_config
):
def
sample_predictor_configs
(
self
,
program_config
):
def
generate_dynamic_shape
(
attrs
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
3
,
32
,
32
]}
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
3
,
32
,
32
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
4
,
3
,
64
,
64
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
4
,
3
,
64
,
64
]}
...
@@ -120,19 +130,23 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
...
@@ -120,19 +130,23 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
(
1e-4
,
1e-4
)
attrs
,
False
),
(
1e-3
,
1e-3
)
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
(
1e-4
,
1e-4
)
attrs
,
True
),
(
1e-3
,
1e-3
)
pass
pass
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reshape.py
View file @
dbe08e9b
...
@@ -22,7 +22,6 @@ import unittest
...
@@ -22,7 +22,6 @@ import unittest
class
TrtConvertReshapeTest
(
TrtLayerAutoScanTest
):
class
TrtConvertReshapeTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
attrs
=
[
attrs
=
[
program_config
.
ops
[
i
].
attrs
for
i
in
range
(
len
(
program_config
.
ops
))
program_config
.
ops
[
i
].
attrs
for
i
in
range
(
len
(
program_config
.
ops
))
...
@@ -31,7 +30,7 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
...
@@ -31,7 +30,7 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
if
len
(
attrs
[
0
][
'shape'
])
!=
1
:
if
len
(
attrs
[
0
][
'shape'
])
!=
1
:
return
False
return
False
#To test if the shape contains 0
#
To test if the shape contains 0
if
len
(
attrs
[
0
][
'shape'
])
==
3
:
if
len
(
attrs
[
0
][
'shape'
])
==
3
:
if
attrs
[
0
][
'shape'
][
1
]
==
0
:
if
attrs
[
0
][
'shape'
][
1
]
==
0
:
if
self
.
dims
!=
3
:
if
self
.
dims
!=
3
:
...
@@ -45,7 +44,6 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
...
@@ -45,7 +44,6 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
self
.
input_shape
=
[
1
,
2
,
4
,
6
]
self
.
input_shape
=
[
1
,
2
,
4
,
6
]
...
@@ -70,9 +68,18 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
...
@@ -70,9 +68,18 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
return
np
.
array
([
24
]).
astype
(
np
.
int32
)
return
np
.
array
([
24
]).
astype
(
np
.
int32
)
for
dims
in
[
4
,
3
,
2
,
1
]:
for
dims
in
[
4
,
3
,
2
,
1
]:
for
shape
in
[[
1
,
6
,
8
],
[
1
,
2
,
4
,
6
],
[
1
,
1
,
0
,
12
],
[
1
,
0
,
6
],
for
shape
in
[
[
1
,
-
1
,
12
],
[
2
,
-
1
],
[
3
,
16
],
[
3
,
4
,
4
],
[
48
],
[
1
,
6
,
8
],
[
-
1
,
48
]]:
[
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
=
[
dics
=
[
{
{
"shape"
:
shape
,
"shape"
:
shape
,
...
@@ -81,29 +88,31 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
...
@@ -81,29 +88,31 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
self
.
dims
=
dims
self
.
dims
=
dims
dics_intput
=
[{
"X"
:
[
"reshape_input"
]}]
dics_intput
=
[{
"X"
:
[
"reshape_input"
]}]
ops_config
=
[
{
ops_config
=
[
"op_type"
:
"reshape"
,
{
"op_inputs"
:
dics_intput
[
0
]
,
"op_type"
:
"reshape"
,
"op_
out
puts"
:
{
"op_
in
puts"
:
dics_intput
[
0
],
"Out"
:
[
"reshape_out"
]
"op_outputs"
:
{
"Out"
:
[
"reshape_out"
]
},
}
,
"op_attrs"
:
dics
[
0
]
,
"op_attrs"
:
dics
[
0
]
}
}
]
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"reshape_input"
:
"reshape_input"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
))
data_gen
=
partial
(
generate_input1
,
dics
)
)
},
},
outputs
=
[
"reshape_out"
])
outputs
=
[
"reshape_out"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
...
@@ -141,13 +150,14 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
...
@@ -141,13 +150,14 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
def
generate_trt_nodes_num
(
attrs
,
dynamic_shape
):
def
generate_trt_nodes_num
(
attrs
,
dynamic_shape
):
# in static shape mode, here is consistent with op_teller.cc
# in static shape mode, here is consistent with op_teller.cc
if
(
not
dynamic_shape
)
:
if
not
dynamic_shape
:
if
(
attrs
[
0
][
'shape'
][
0
]
==
0
)
:
if
attrs
[
0
][
'shape'
][
0
]
==
0
:
return
1
,
2
return
1
,
2
elif
(
len
(
attrs
[
0
][
'shape'
])
==
1
)
:
elif
len
(
attrs
[
0
][
'shape'
])
==
1
:
return
0
,
3
return
0
,
3
elif
(
np
.
prod
(
attrs
[
0
][
'shape'
][
1
:])
==
np
.
prod
(
elif
np
.
prod
(
attrs
[
0
][
'shape'
][
1
:])
==
np
.
prod
(
self
.
input_shape
[
1
:])):
self
.
input_shape
[
1
:]
):
return
1
,
2
return
1
,
2
else
:
else
:
return
0
,
3
return
0
,
3
...
@@ -161,19 +171,23 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
...
@@ -161,19 +171,23 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
attrs
,
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
attrs
,
True
),
1e-3
def
add_skip_trt_case
(
self
):
def
add_skip_trt_case
(
self
):
pass
pass
...
@@ -185,12 +199,10 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
...
@@ -185,12 +199,10 @@ class TrtConvertReshapeTest(TrtLayerAutoScanTest):
# reshape having three inputs.
# reshape having three inputs.
class
TrtConvertReshapeTest2
(
TrtLayerAutoScanTest
):
class
TrtConvertReshapeTest2
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
return
np
.
random
.
random
([
1
,
2
,
4
,
6
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
1
,
2
,
4
,
6
]).
astype
(
np
.
float32
)
...
@@ -203,9 +215,12 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
...
@@ -203,9 +215,12 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
for
dims
in
[
4
,
3
,
2
,
1
]:
for
dims
in
[
4
,
3
,
2
,
1
]:
for
shape
in
[[
-
1
,
48
]]:
for
shape
in
[[
-
1
,
48
]]:
dics
=
[{
dics
=
[
"shape"
:
shape
,
{
},
{}]
"shape"
:
shape
,
},
{},
]
self
.
dims
=
dims
self
.
dims
=
dims
dics_intput
=
[
dics_intput
=
[
{
{
...
@@ -217,9 +232,7 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
...
@@ -217,9 +232,7 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
{
{
"op_type"
:
"fill_constant"
,
"op_type"
:
"fill_constant"
,
"op_inputs"
:
{},
"op_inputs"
:
{},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"shapeT1_data"
]},
"Out"
:
[
"shapeT1_data"
]
},
"op_attrs"
:
{
"op_attrs"
:
{
"dtype"
:
2
,
"dtype"
:
2
,
"str_value"
:
"2"
,
"str_value"
:
"2"
,
...
@@ -229,9 +242,7 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
...
@@ -229,9 +242,7 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
{
{
"op_type"
:
"fill_constant"
,
"op_type"
:
"fill_constant"
,
"op_inputs"
:
{},
"op_inputs"
:
{},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"shapeT2_data"
]},
"Out"
:
[
"shapeT2_data"
]
},
"op_attrs"
:
{
"op_attrs"
:
{
"dtype"
:
2
,
"dtype"
:
2
,
"str_value"
:
"24"
,
"str_value"
:
"24"
,
...
@@ -241,10 +252,8 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
...
@@ -241,10 +252,8 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
{
{
"op_type"
:
"reshape"
,
"op_type"
:
"reshape"
,
"op_inputs"
:
dics_intput
[
0
],
"op_inputs"
:
dics_intput
[
0
],
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"reshape_out"
]},
"Out"
:
[
"reshape_out"
]
"op_attrs"
:
dics
[
0
],
},
"op_attrs"
:
dics
[
0
]
},
},
]
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
...
@@ -252,16 +261,18 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
...
@@ -252,16 +261,18 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"reshape_input"
:
"reshape_input"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
))
data_gen
=
partial
(
generate_input1
,
dics
)
)
},
},
outputs
=
[
"reshape_out"
])
outputs
=
[
"reshape_out"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
():
def
generate_dynamic_shape
():
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
...
@@ -297,7 +308,7 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
...
@@ -297,7 +308,7 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
1
,
2
),
1e-5
yield
self
.
create_inference_config
(),
(
1
,
2
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
):
def
add_skip_trt_case
(
self
):
pass
pass
...
@@ -309,12 +320,10 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
...
@@ -309,12 +320,10 @@ class TrtConvertReshapeTest2(TrtLayerAutoScanTest):
# reshape having 2 inputs.
# reshape having 2 inputs.
class
TrtConvertReshapeTest3
(
TrtLayerAutoScanTest
):
class
TrtConvertReshapeTest3
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
return
np
.
random
.
random
([
1
,
2
,
12
,
6
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
1
,
2
,
12
,
6
]).
astype
(
np
.
float32
)
...
@@ -327,9 +336,12 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
...
@@ -327,9 +336,12 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
for
dims
in
[
4
,
3
,
2
,
1
]:
for
dims
in
[
4
,
3
,
2
,
1
]:
for
shape
in
[[
-
1
,
144
]]:
for
shape
in
[[
-
1
,
144
]]:
dics
=
[{
dics
=
[
"shape"
:
shape
,
{
},
{}]
"shape"
:
shape
,
},
{},
]
self
.
dims
=
dims
self
.
dims
=
dims
dics_intput
=
[
dics_intput
=
[
{
{
...
@@ -341,9 +353,7 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
...
@@ -341,9 +353,7 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
{
{
"op_type"
:
"fill_constant"
,
"op_type"
:
"fill_constant"
,
"op_inputs"
:
{},
"op_inputs"
:
{},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"shape_data"
]},
"Out"
:
[
"shape_data"
]
},
"op_attrs"
:
{
"op_attrs"
:
{
"dtype"
:
2
,
"dtype"
:
2
,
"str_value"
:
"12"
,
"str_value"
:
"12"
,
...
@@ -353,10 +363,8 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
...
@@ -353,10 +363,8 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
{
{
"op_type"
:
"reshape"
,
"op_type"
:
"reshape"
,
"op_inputs"
:
dics_intput
[
0
],
"op_inputs"
:
dics_intput
[
0
],
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"reshape_out"
]},
"Out"
:
[
"reshape_out"
]
"op_attrs"
:
dics
[
0
],
},
"op_attrs"
:
dics
[
0
]
},
},
]
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
...
@@ -364,16 +372,18 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
...
@@ -364,16 +372,18 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"reshape_input"
:
"reshape_input"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
))
data_gen
=
partial
(
generate_input1
,
dics
)
)
},
},
outputs
=
[
"reshape_out"
])
outputs
=
[
"reshape_out"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
():
def
generate_dynamic_shape
():
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
...
@@ -409,7 +419,7 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
...
@@ -409,7 +419,7 @@ class TrtConvertReshapeTest3(TrtLayerAutoScanTest):
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
1
,
2
),
1e-5
yield
self
.
create_inference_config
(),
(
1
,
2
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
):
def
add_skip_trt_case
(
self
):
pass
pass
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_roi_align.py
View file @
dbe08e9b
...
@@ -22,12 +22,10 @@ from typing import Optional, List, Callable, Dict, Any, Set
...
@@ -22,12 +22,10 @@ from typing import Optional, List, Callable, Dict, Any, Set
class
TrtConvertRoiAlignTest
(
TrtLayerAutoScanTest
):
class
TrtConvertRoiAlignTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
return
np
.
ones
([
batch
,
256
,
32
,
32
]).
astype
(
np
.
float32
)
return
np
.
ones
([
batch
,
256
,
32
,
32
]).
astype
(
np
.
float32
)
...
@@ -47,92 +45,111 @@ class TrtConvertRoiAlignTest(TrtLayerAutoScanTest):
...
@@ -47,92 +45,111 @@ class TrtConvertRoiAlignTest(TrtLayerAutoScanTest):
self
.
num_input
=
num_input
self
.
num_input
=
num_input
if
num_input
==
1
:
if
num_input
==
1
:
batch
=
1
batch
=
1
dics
=
[{
dics
=
[
"spatial_scale"
:
spatial_scale
,
{
"pooled_height"
:
pooled_height
,
"spatial_scale"
:
spatial_scale
,
"pooled_width"
:
pooled_width
,
"pooled_height"
:
pooled_height
,
"sampling_ratio"
:
sampling_ratio
,
"pooled_width"
:
pooled_width
,
"aligned"
:
aligned
"sampling_ratio"
:
sampling_ratio
,
},
{}]
"aligned"
:
aligned
,
dics_input
=
[{
},
"X"
:
[
"roi_align_input"
],
{},
"ROIs"
:
[
"ROIs"
],
]
"RoisNum"
:
[
"RoisNum"
]
dics_input
=
[
},
{
{
"X"
:
[
"roi_align_input"
],
"X"
:
[
"roi_align_input"
],
"ROIs"
:
[
"ROIs"
]
"ROIs"
:
[
"ROIs"
],
}]
"RoisNum"
:
[
"RoisNum"
],
program_input
=
[{
},
"roi_align_input"
:
{
TensorConfig
(
data_gen
=
partial
(
"X"
:
[
"roi_align_input"
],
generate_input1
,
dics
,
batch
)),
"ROIs"
:
[
"ROIs"
],
"ROIs"
:
},
TensorConfig
(
data_gen
=
partial
(
]
generate_input2
,
dics
,
batch
)),
program_input
=
[
"RoisNum"
:
{
TensorConfig
(
data_gen
=
partial
(
"roi_align_input"
:
TensorConfig
(
generate_input3
,
dics
,
batch
))
data_gen
=
partial
(
},
{
generate_input1
,
dics
,
batch
"roi_align_input"
:
)
TensorConfig
(
data_gen
=
partial
(
),
generate_input1
,
dics
,
batch
)),
"ROIs"
:
TensorConfig
(
"ROIs"
:
data_gen
=
partial
(
TensorConfig
(
data_gen
=
partial
(
generate_input2
,
dics
,
batch
generate_input2
,
dics
,
batch
),
)
lod
=
[[
32
,
3
]])
),
}]
"RoisNum"
:
TensorConfig
(
ops_config
=
[{
data_gen
=
partial
(
"op_type"
:
generate_input3
,
dics
,
batch
"roi_align"
,
)
"op_inputs"
:
),
dics_input
[
num_input
],
},
"op_outputs"
:
{
{
"Out"
:
[
"roi_align_out"
]
"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
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
program_input
[
num_input
],
inputs
=
program_input
[
num_input
],
outputs
=
[
"roi_align_out"
])
outputs
=
[
"roi_align_out"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
if
self
.
num_input
==
0
:
if
self
.
num_input
==
0
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"roi_align_input"
:
[
1
,
256
,
32
,
32
],
"roi_align_input"
:
[
1
,
256
,
32
,
32
],
"ROIs"
:
[
3
,
4
],
"ROIs"
:
[
3
,
4
],
"RoisNum"
:
[
1
]
"RoisNum"
:
[
1
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"roi_align_input"
:
[
1
,
256
,
64
,
64
],
"roi_align_input"
:
[
1
,
256
,
64
,
64
],
"ROIs"
:
[
3
,
4
],
"ROIs"
:
[
3
,
4
],
"RoisNum"
:
[
1
]
"RoisNum"
:
[
1
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"roi_align_input"
:
[
1
,
256
,
64
,
64
],
"roi_align_input"
:
[
1
,
256
,
64
,
64
],
"ROIs"
:
[
3
,
4
],
"ROIs"
:
[
3
,
4
],
"RoisNum"
:
[
1
]
"RoisNum"
:
[
1
]
,
}
}
elif
self
.
num_input
==
1
:
elif
self
.
num_input
==
1
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"roi_align_input"
:
[
1
,
256
,
32
,
32
],
"roi_align_input"
:
[
1
,
256
,
32
,
32
],
"ROIs"
:
[
3
,
4
]
"ROIs"
:
[
3
,
4
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"roi_align_input"
:
[
1
,
256
,
64
,
64
],
"roi_align_input"
:
[
1
,
256
,
64
,
64
],
"ROIs"
:
[
3
,
4
]
"ROIs"
:
[
3
,
4
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"roi_align_input"
:
[
1
,
256
,
64
,
64
],
"roi_align_input"
:
[
1
,
256
,
64
,
64
],
"ROIs"
:
[
3
,
4
]
"ROIs"
:
[
3
,
4
]
,
}
}
def
clear_dynamic_shape
():
def
clear_dynamic_shape
():
...
@@ -159,29 +176,33 @@ class TrtConvertRoiAlignTest(TrtLayerAutoScanTest):
...
@@ -159,29 +176,33 @@ class TrtConvertRoiAlignTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
attrs
,
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
attrs
,
True
),
1e-3
def
add_skip_trt_case
(
self
):
def
add_skip_trt_case
(
self
):
def
teller1
(
program_config
,
predictor_config
):
def
teller1
(
program_config
,
predictor_config
):
if
len
(
program_config
.
inputs
)
==
3
:
if
len
(
program_config
.
inputs
)
==
3
:
return
True
return
True
return
False
return
False
self
.
add_skip_case
(
teller1
,
SkipReasons
.
TRT_NOT_SUPPORT
,
self
.
add_skip_case
(
"INPUT RoisNum NOT SUPPORT"
)
teller1
,
SkipReasons
.
TRT_NOT_SUPPORT
,
"INPUT RoisNum NOT SUPPORT"
)
def
test
(
self
):
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
add_skip_trt_case
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_roll.py
View file @
dbe08e9b
...
@@ -22,7 +22,6 @@ import unittest
...
@@ -22,7 +22,6 @@ import unittest
class
TrtConvertRollTest
(
TrtLayerAutoScanTest
):
class
TrtConvertRollTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
inputs
=
program_config
.
inputs
inputs
=
program_config
.
inputs
weights
=
program_config
.
weights
weights
=
program_config
.
weights
...
@@ -32,43 +31,44 @@ class TrtConvertRollTest(TrtLayerAutoScanTest):
...
@@ -32,43 +31,44 @@ class TrtConvertRollTest(TrtLayerAutoScanTest):
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
return
np
.
ones
([
1
,
56
,
56
,
192
]).
astype
(
np
.
float32
)
return
np
.
ones
([
1
,
56
,
56
,
192
]).
astype
(
np
.
float32
)
for
axis
in
[[
1
,
2
]]:
for
axis
in
[[
1
,
2
]]:
for
shifts
in
[[
-
1
,
-
1
],
[
-
3
,
-
3
]]:
for
shifts
in
[[
-
1
,
-
1
],
[
-
3
,
-
3
]]:
dics
=
[
{
dics
=
[
"axis"
:
axis
,
{
"shifts"
:
shift
s
,
"axis"
:
axi
s
,
}]
"shifts"
:
shifts
,
}
ops_config
=
[{
]
"op_type"
:
"roll"
,
"op_inputs"
:
{
ops_config
=
[
"X"
:
[
"input_data"
]
{
}
,
"op_type"
:
"roll"
,
"op_
out
puts"
:
{
"op_
in
puts"
:
{
"X"
:
[
"input_data"
]},
"Out"
:
[
"roll_output_data"
]
"op_outputs"
:
{
"Out"
:
[
"roll_output_data"
]
},
}
,
"op_attrs"
:
dics
[
0
]
,
"op_attrs"
:
dics
[
0
]
}
}
]
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input_data"
:
"input_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
))
data_gen
=
partial
(
generate_input1
,
dics
)
)
},
},
outputs
=
[
"roll_output_data"
])
outputs
=
[
"roll_output_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
56
,
56
,
192
]
"input_data"
:
[
1
,
56
,
56
,
192
]
...
@@ -103,19 +103,23 @@ class TrtConvertRollTest(TrtLayerAutoScanTest):
...
@@ -103,19 +103,23 @@ class TrtConvertRollTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-4
attrs
,
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-4
attrs
,
True
),
1e-3
def
test
(
self
):
def
test
(
self
):
self
.
run_test
()
self
.
run_test
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_scatter_nd_add.py
View file @
dbe08e9b
...
@@ -22,12 +22,10 @@ import unittest
...
@@ -22,12 +22,10 @@ import unittest
class
TrtConvertScatterNd
(
TrtLayerAutoScanTest
):
class
TrtConvertScatterNd
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
():
def
generate_input1
():
return
np
.
random
.
random
([
6
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
6
]).
astype
(
np
.
float32
)
...
@@ -37,38 +35,42 @@ class TrtConvertScatterNd(TrtLayerAutoScanTest):
...
@@ -37,38 +35,42 @@ class TrtConvertScatterNd(TrtLayerAutoScanTest):
def
generate_input3
():
def
generate_input3
():
return
np
.
random
.
random
([
4
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
4
]).
astype
(
np
.
float32
)
ops_config
=
[
{
ops_config
=
[
"op_type"
:
"scatter_nd_add"
,
{
"op_inputs"
:
{
"op_type"
:
"scatter_nd_add"
,
"
X"
:
[
"input_data"
],
"
op_inputs"
:
{
"Index
"
:
[
"in
dex
_data"
],
"X
"
:
[
"in
put
_data"
],
"Updates"
:
[
"update
_data"
]
"Index"
:
[
"index
_data"
]
,
}
,
"Updates"
:
[
"update_data"
]
,
"op_outputs"
:
{
},
"Out"
:
[
"output_data"
]
"op_outputs"
:
{
"Out"
:
[
"output_data"
]
},
},
"op_attrs"
:
{
},
"op_attrs"
:
{
}
}
}
]
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
for
i
in
range
(
10
):
for
i
in
range
(
10
):
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input_data"
:
"input_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
)),
data_gen
=
partial
(
generate_input1
)
"index_data"
:
),
TensorConfig
(
data_gen
=
partial
(
generate_input2
)),
"index_data"
:
TensorConfig
(
"update_data"
:
data_gen
=
partial
(
generate_input2
)
TensorConfig
(
data_gen
=
partial
(
generate_input3
)),
),
"update_data"
:
TensorConfig
(
data_gen
=
partial
(
generate_input3
)
),
},
},
outputs
=
[
"output_data"
])
outputs
=
[
"output_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
],
"input_data"
:
[
1
],
...
@@ -100,14 +102,14 @@ class TrtConvertScatterNd(TrtLayerAutoScanTest):
...
@@ -100,14 +102,14 @@ class TrtConvertScatterNd(TrtLayerAutoScanTest):
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
0
,
5
),
1e-5
yield
self
.
create_inference_config
(),
(
0
,
5
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
1
,
4
),
1e-5
yield
self
.
create_inference_config
(),
(
1
,
4
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
):
def
test
(
self
):
self
.
run_test
()
self
.
run_test
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_shape.py
View file @
dbe08e9b
...
@@ -22,12 +22,10 @@ import unittest
...
@@ -22,12 +22,10 @@ import unittest
class
TrtConvertSumTest
(
TrtLayerAutoScanTest
):
class
TrtConvertSumTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
batch
):
def
generate_input1
(
batch
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
return
np
.
ones
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
return
np
.
ones
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
...
@@ -41,31 +39,31 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
...
@@ -41,31 +39,31 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
for
dims
in
[
1
,
2
,
3
,
4
]:
for
dims
in
[
1
,
2
,
3
,
4
]:
for
batch
in
[
1
,
4
]:
for
batch
in
[
1
,
4
]:
self
.
dims
=
dims
self
.
dims
=
dims
ops_config
=
[{
ops_config
=
[
"op_type"
:
"shape"
,
{
"op_inputs"
:
{
"op_type"
:
"shape"
,
"Input"
:
[
"input1"
]
"op_inputs"
:
{
"Input"
:
[
"input1"
]},
},
"op_outputs"
:
{
"Out"
:
[
"output"
]},
"op_outputs"
:
{
"op_attrs"
:
{},
"Out"
:
[
"output"
]
}
},
]
"op_attrs"
:
{}
}]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input1"
:
"input1"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
batch
))
data_gen
=
partial
(
generate_input1
,
batch
)
)
},
},
outputs
=
[
"output"
])
outputs
=
[
"output"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
():
def
generate_dynamic_shape
():
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input1"
:
[
1
,
3
,
24
,
24
]}
self
.
dynamic_shape
.
min_input_shape
=
{
"input1"
:
[
1
,
3
,
24
,
24
]}
...
@@ -87,7 +85,7 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
...
@@ -87,7 +85,7 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
}
}
def
generate_trt_nodes_num
(
dynamic_shape
):
def
generate_trt_nodes_num
(
dynamic_shape
):
if
(
not
dynamic_shape
)
:
if
not
dynamic_shape
:
return
0
,
3
return
0
,
3
return
1
,
2
return
1
,
2
...
@@ -100,17 +98,19 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
...
@@ -100,17 +98,19 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
False
),
1e-5
False
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
False
),
1e-5
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
()
generate_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
True
),
1e-5
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
True
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
):
def
test
(
self
):
self
.
run_test
()
self
.
run_test
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_shuffle_channel.py
View file @
dbe08e9b
...
@@ -22,44 +22,41 @@ import unittest
...
@@ -22,44 +22,41 @@ import unittest
class
TrtConvertShuffleChannelTest
(
TrtLayerAutoScanTest
):
class
TrtConvertShuffleChannelTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
return
np
.
ones
([
batch
,
6
,
24
,
24
]).
astype
(
np
.
float32
)
return
np
.
ones
([
batch
,
6
,
24
,
24
]).
astype
(
np
.
float32
)
for
batch
in
[
1
,
2
,
4
]:
for
batch
in
[
1
,
2
,
4
]:
for
group
in
[
1
,
2
,
3
]:
for
group
in
[
1
,
2
,
3
]:
dics
=
[{
"group"
:
group
},
{}]
dics
=
[{
"group"
:
group
},
{}]
ops_config
=
[{
ops_config
=
[
"op_type"
:
"shuffle_channel"
,
{
"op_inputs"
:
{
"op_type"
:
"shuffle_channel"
,
"X"
:
[
"shuffle_channel_input"
]
"op_inputs"
:
{
"X"
:
[
"shuffle_channel_input"
]},
},
"op_outputs"
:
{
"Out"
:
[
"shuffle_channel_out"
]},
"op_outputs"
:
{
"op_attrs"
:
dics
[
0
],
"Out"
:
[
"shuffle_channel_out"
]
}
},
]
"op_attrs"
:
dics
[
0
]
}]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"shuffle_channel_input"
:
"shuffle_channel_input"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
,
batch
)
data_gen
=
partial
(
generate_input1
,
dics
,
batch
)
)
)
},
},
outputs
=
[
"shuffle_channel_out"
])
outputs
=
[
"shuffle_channel_out"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"shuffle_channel_input"
:
[
1
,
6
,
24
,
24
]
"shuffle_channel_input"
:
[
1
,
6
,
24
,
24
]
...
@@ -78,8 +75,10 @@ class TrtConvertShuffleChannelTest(TrtLayerAutoScanTest):
...
@@ -78,8 +75,10 @@ class TrtConvertShuffleChannelTest(TrtLayerAutoScanTest):
def
generate_trt_nodes_num
(
attrs
,
dynamic_shape
):
def
generate_trt_nodes_num
(
attrs
,
dynamic_shape
):
ver
=
paddle_infer
.
get_trt_compile_version
()
ver
=
paddle_infer
.
get_trt_compile_version
()
if
ver
[
0
]
*
1000
+
ver
[
1
]
*
100
+
ver
[
if
(
2
]
*
10
<
8000
and
dynamic_shape
==
True
:
ver
[
0
]
*
1000
+
ver
[
1
]
*
100
+
ver
[
2
]
*
10
<
8000
and
dynamic_shape
==
True
):
return
0
,
3
return
0
,
3
else
:
else
:
return
1
,
2
return
1
,
2
...
@@ -92,19 +91,23 @@ class TrtConvertShuffleChannelTest(TrtLayerAutoScanTest):
...
@@ -92,19 +91,23 @@ class TrtConvertShuffleChannelTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
attrs
,
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
attrs
,
True
),
1e-3
def
add_skip_trt_case
(
self
):
def
add_skip_trt_case
(
self
):
pass
pass
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_slice.py
View file @
dbe08e9b
...
@@ -22,7 +22,6 @@ import unittest
...
@@ -22,7 +22,6 @@ import unittest
class
TrtConvertSliceTest
(
TrtLayerAutoScanTest
):
class
TrtConvertSliceTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
inputs
=
program_config
.
inputs
inputs
=
program_config
.
inputs
weights
=
program_config
.
weights
weights
=
program_config
.
weights
...
@@ -34,13 +33,17 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
...
@@ -34,13 +33,17 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
start
=
0
start
=
0
end
=
0
end
=
0
if
attrs
[
0
][
"starts"
][
x
]
<
0
:
if
attrs
[
0
][
"starts"
][
x
]
<
0
:
start
=
attrs
[
0
][
"starts"
][
x
]
+
inputs
[
'input_data'
].
shape
[
start
=
(
attrs
[
0
][
"axes"
][
x
]]
attrs
[
0
][
"starts"
][
x
]
+
inputs
[
'input_data'
].
shape
[
attrs
[
0
][
"axes"
][
x
]]
)
else
:
else
:
start
=
attrs
[
0
][
"starts"
][
x
]
start
=
attrs
[
0
][
"starts"
][
x
]
if
attrs
[
0
][
"ends"
][
x
]
<
0
:
if
attrs
[
0
][
"ends"
][
x
]
<
0
:
end
=
attrs
[
0
][
"ends"
][
x
]
+
inputs
[
'input_data'
].
shape
[
end
=
(
attrs
[
0
][
"axes"
][
x
]]
attrs
[
0
][
"ends"
][
x
]
+
inputs
[
'input_data'
].
shape
[
attrs
[
0
][
"axes"
][
x
]]
)
else
:
else
:
end
=
attrs
[
0
][
"ends"
][
x
]
end
=
attrs
[
0
][
"ends"
][
x
]
start
=
max
(
0
,
start
)
start
=
max
(
0
,
start
)
...
@@ -51,12 +54,11 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
...
@@ -51,12 +54,11 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
for
x
in
attrs
[
0
][
"decrease_axis"
]:
for
x
in
attrs
[
0
][
"decrease_axis"
]:
if
x
<
0
:
if
x
<
0
:
return
False
return
False
if
(
out_shape
[
x
]
!=
1
)
:
if
out_shape
[
x
]
!=
1
:
return
False
return
False
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
return
np
.
random
.
random
([
6
,
6
,
64
,
64
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
6
,
6
,
64
,
64
]).
astype
(
np
.
float32
)
...
@@ -65,41 +67,44 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
...
@@ -65,41 +67,44 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
for
ends
in
[[
2
,
2
],
[
5
,
5
],
[
1
,
-
1
]]:
for
ends
in
[[
2
,
2
],
[
5
,
5
],
[
1
,
-
1
]]:
for
decrease_axis
in
[[],
[
1
],
[
2
],
[
-
1
],
[
-
100
]]:
for
decrease_axis
in
[[],
[
1
],
[
2
],
[
-
1
],
[
-
100
]]:
for
infer_flags
in
[[
-
1
]]:
for
infer_flags
in
[[
-
1
]]:
dics
=
[{
dics
=
[
"axes"
:
axes
,
{
"starts"
:
starts
,
"axes"
:
axes
,
"ends"
:
ends
,
"starts"
:
starts
,
"decrease_axis"
:
decrease_axis
,
"ends"
:
ends
,
"infer_flags"
:
infer_flags
"decrease_axis"
:
decrease_axis
,
}]
"infer_flags"
:
infer_flags
,
}
ops_config
=
[{
]
"op_type"
:
"slice"
,
"op_inputs"
:
{
ops_config
=
[
"Input"
:
[
"input_data"
]
{
},
"op_type"
:
"slice"
,
"op_outputs"
:
{
"op_inputs"
:
{
"Input"
:
[
"input_data"
]},
"Out"
:
[
"slice_output_data"
]
"op_outputs"
:
{
},
"Out"
:
[
"slice_output_data"
]
"op_attrs"
:
dics
[
0
]
},
}]
"op_attrs"
:
dics
[
0
],
}
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input_data"
:
"input_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
)
data_gen
=
partial
(
generate_input1
,
dics
)
)
)
},
},
outputs
=
[
"slice_output_data"
])
outputs
=
[
"slice_output_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
3
,
32
,
32
]}
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
3
,
32
,
32
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
8
,
8
,
64
,
64
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
8
,
8
,
64
,
64
]}
...
@@ -125,19 +130,23 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
...
@@ -125,19 +130,23 @@ class TrtConvertSliceTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-4
attrs
,
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-4
attrs
,
True
),
1e-3
def
test
(
self
):
def
test
(
self
):
# TODO(inference): fix.
# TODO(inference): fix.
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_split.py
View file @
dbe08e9b
...
@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
...
@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
class
TrtConvertSplitTest
(
TrtLayerAutoScanTest
):
class
TrtConvertSplitTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
inputs
=
program_config
.
inputs
inputs
=
program_config
.
inputs
weights
=
program_config
.
weights
weights
=
program_config
.
weights
...
@@ -35,13 +34,13 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -35,13 +34,13 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
if
len
(
inputs
[
'split_input'
].
shape
)
<=
attrs
[
0
][
'axis'
]:
if
len
(
inputs
[
'split_input'
].
shape
)
<=
attrs
[
0
][
'axis'
]:
return
False
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
len
(
attrs
[
0
][
'sections'
])
==
0
:
if
attrs
[
0
][
'num'
]
==
0
:
if
attrs
[
0
][
'num'
]
==
0
:
return
False
return
False
#When sections and num are not both equal to 0, sections has higher priority.
#
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.
#
The sum of sections should be equal to the input size.
if
len
(
attrs
[
0
][
'sections'
])
!=
0
:
if
len
(
attrs
[
0
][
'sections'
])
!=
0
:
if
attrs
[
0
][
'num'
]
!=
0
:
if
attrs
[
0
][
'num'
]
!=
0
:
return
False
return
False
...
@@ -53,16 +52,18 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -53,16 +52,18 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
if
sum
!=
inputs
[
'split_input'
].
shape
[
attrs
[
0
][
'axis'
]]:
if
sum
!=
inputs
[
'split_input'
].
shape
[
attrs
[
0
][
'axis'
]]:
return
False
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
attrs
[
0
][
'num'
]
!=
0
:
if
len
(
outputs
)
!=
attrs
[
0
][
'num'
]:
if
len
(
outputs
)
!=
attrs
[
0
][
'num'
]:
return
False
return
False
#Test AxisTensor and SectionsTensorList
#
Test AxisTensor and SectionsTensorList
if
self
.
num_input
==
0
:
if
self
.
num_input
==
0
:
if
self
.
dims
==
2
and
attrs
[
0
][
'sections'
]
==
[
if
(
10
,
14
self
.
dims
==
2
]
and
len
(
outputs
)
==
2
:
and
attrs
[
0
][
'sections'
]
==
[
10
,
14
]
and
len
(
outputs
)
==
2
):
return
True
return
True
else
:
else
:
return
False
return
False
...
@@ -70,7 +71,6 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -70,7 +71,6 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
return
np
.
random
.
random
([
batch
,
3
,
3
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
3
,
3
,
24
]).
astype
(
np
.
float32
)
...
@@ -93,72 +93,95 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -93,72 +93,95 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
for
num_input
in
[
0
,
1
]:
for
num_input
in
[
0
,
1
]:
for
dims
in
[
1
,
2
,
3
,
4
]:
for
dims
in
[
1
,
2
,
3
,
4
]:
for
batch
in
[
3
,
6
,
9
]:
for
batch
in
[
3
,
6
,
9
]:
for
Out
in
[[
"output_var0"
,
"output_var1"
],
for
Out
in
[
[
"output_var0"
,
"output_var1"
,
"output_var2"
]]:
[
"output_var0"
,
"output_var1"
],
for
sections
in
[[],
[
1
,
2
],
[
2
,
1
],
[
10
,
14
],
[
"output_var0"
,
"output_var1"
,
"output_var2"
],
[
1
,
1
,
1
],
[
2
,
2
,
2
],
[
3
,
3
,
3
],
]:
[
3
,
7
,
14
]]:
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
num
in
[
0
,
3
]:
for
axis
in
[
0
,
1
,
2
,
3
]:
for
axis
in
[
0
,
1
,
2
,
3
]:
self
.
batch
=
batch
self
.
batch
=
batch
self
.
num_input
=
num_input
self
.
num_input
=
num_input
self
.
dims
=
dims
self
.
dims
=
dims
dics
=
[{
dics
=
[
"sections"
:
sections
,
{
"num"
:
num
,
"sections"
:
sections
,
"axis"
:
axis
"num"
:
num
,
},
{}]
"axis"
:
axis
,
},
dics_intput
=
[{
{},
"X"
:
[
"split_input"
],
]
"AxisTensor"
:
[
"AxisTensor"
],
"SectionsTensorList"
:
[
dics_intput
=
[
"SectionsTensorList1"
,
{
"SectionsTensorList2"
"X"
:
[
"split_input"
],
]
"AxisTensor"
:
[
"AxisTensor"
],
},
{
"SectionsTensorList"
:
[
"X"
:
[
"split_input"
]
"SectionsTensorList1"
,
}]
"SectionsTensorList2"
,
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"
:
{
"X"
:
[
"split_input"
]},
dics
[
0
]
]
}]
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
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
dics_intputs
[
num_input
],
weights
=
dics_intputs
[
num_input
],
inputs
=
{
inputs
=
{
"split_input"
:
"split_input"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
data_gen
=
partial
(
generate_input1
,
dics
,
batch
))
generate_input1
,
dics
,
batch
)
)
},
},
outputs
=
Out
)
outputs
=
Out
,
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
...
@@ -216,30 +239,35 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -216,30 +239,35 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
attrs
,
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
attrs
,
True
),
1e-3
def
add_skip_trt_case
(
self
):
def
add_skip_trt_case
(
self
):
def
teller1
(
program_config
,
predictor_config
):
def
teller1
(
program_config
,
predictor_config
):
if
len
(
program_config
.
weights
)
==
3
:
if
len
(
program_config
.
weights
)
==
3
:
return
True
return
True
return
False
return
False
self
.
add_skip_case
(
self
.
add_skip_case
(
teller1
,
SkipReasons
.
TRT_NOT_SUPPORT
,
teller1
,
"INPUT AxisTensor AND SectionsTensorList NOT SUPPORT."
)
SkipReasons
.
TRT_NOT_SUPPORT
,
"INPUT AxisTensor AND SectionsTensorList NOT SUPPORT."
,
)
def
test
(
self
):
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
add_skip_trt_case
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_squeeze2.py
View file @
dbe08e9b
...
@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
...
@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
class
TrtConvertSplitTest
(
TrtLayerAutoScanTest
):
class
TrtConvertSplitTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
inputs
=
program_config
.
inputs
inputs
=
program_config
.
inputs
attrs
=
[
attrs
=
[
...
@@ -40,25 +39,25 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -40,25 +39,25 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
self
.
dims
=
dims
self
.
dims
=
dims
self
.
axes
=
axes
self
.
axes
=
axes
dics
=
[{
"axes"
:
axes
}]
dics
=
[{
"axes"
:
axes
}]
ops_config
=
[
{
ops_config
=
[
"op_type"
:
"squeeze2"
,
{
"op_inputs"
:
{
"op_type"
:
"squeeze2"
,
"X"
:
[
"in_data"
]
"op_inputs"
:
{
"X"
:
[
"in_data"
]
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"out_data"
],
"Out"
:
[
"out
_data"
],
"XShape"
:
[
"XShape
_data"
],
"XShape"
:
[
"XShape_data"
]
},
}
,
"op_attrs"
:
dics
[
0
]
,
"op_attrs"
:
dics
[
0
]
}
}
]
]
# new_axes is the update of axes
# new_axes is the update of axes
new_axes
=
list
(
axes
)
new_axes
=
list
(
axes
)
for
i
in
range
(
len
(
new_axes
)):
for
i
in
range
(
len
(
new_axes
)):
if
(
new_axes
[
i
]
<
0
)
:
if
new_axes
[
i
]
<
0
:
new_axes
[
i
]
+=
dims
new_axes
[
i
]
+=
dims
if
(
max
(
new_axes
)
>=
dims
)
:
if
max
(
new_axes
)
>=
dims
:
continue
continue
# generate input data
# generate input data
self
.
input_shape
=
[
1
]
*
dims
self
.
input_shape
=
[
1
]
*
dims
for
i
in
range
(
dims
):
for
i
in
range
(
dims
):
self
.
input_shape
[
i
]
=
np
.
random
.
randint
(
1
,
20
)
self
.
input_shape
[
i
]
=
np
.
random
.
randint
(
1
,
20
)
...
@@ -68,24 +67,26 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -68,24 +67,26 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
for
i
in
new_axes
:
for
i
in
new_axes
:
self
.
input_shape
[
i
]
=
1
self
.
input_shape
[
i
]
=
1
return
np
.
random
.
random
(
self
.
input_shape
).
astype
(
return
np
.
random
.
random
(
self
.
input_shape
).
astype
(
np
.
float32
)
np
.
float32
)
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"in_data"
:
"in_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
,
batch
)
data_gen
=
partial
(
generate_input1
,
dics
,
batch
)
)
)
},
},
outputs
=
[
"out_data"
])
outputs
=
[
"out_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
max_shape
=
list
(
self
.
input_shape
)
max_shape
=
list
(
self
.
input_shape
)
min_shape
=
list
(
self
.
input_shape
)
min_shape
=
list
(
self
.
input_shape
)
...
@@ -112,19 +113,23 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
...
@@ -112,19 +113,23 @@ class TrtConvertSplitTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
attrs
,
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
attrs
,
True
),
1e-3
def
add_skip_trt_case
(
self
):
def
add_skip_trt_case
(
self
):
pass
pass
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_stack.py
View file @
dbe08e9b
...
@@ -22,7 +22,6 @@ import unittest
...
@@ -22,7 +22,6 @@ import unittest
class
TrtConvertStackTest
(
TrtLayerAutoScanTest
):
class
TrtConvertStackTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
inputs
=
program_config
.
inputs
inputs
=
program_config
.
inputs
weights
=
program_config
.
weights
weights
=
program_config
.
weights
...
@@ -31,14 +30,13 @@ class TrtConvertStackTest(TrtLayerAutoScanTest):
...
@@ -31,14 +30,13 @@ class TrtConvertStackTest(TrtLayerAutoScanTest):
attrs
=
[
attrs
=
[
program_config
.
ops
[
i
].
attrs
for
i
in
range
(
len
(
program_config
.
ops
))
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'
]:
if
len
(
inputs
[
'stack_input1'
].
shape
)
<
attrs
[
0
][
'axis'
]:
return
False
return
False
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]],
batch
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
return
np
.
random
.
random
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
return
np
.
random
.
random
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
...
@@ -74,103 +72,107 @@ class TrtConvertStackTest(TrtLayerAutoScanTest):
...
@@ -74,103 +72,107 @@ class TrtConvertStackTest(TrtLayerAutoScanTest):
for
axis
in
[
-
2
,
-
1
,
0
,
1
,
2
,
3
]:
for
axis
in
[
-
2
,
-
1
,
0
,
1
,
2
,
3
]:
self
.
dims
=
dims
self
.
dims
=
dims
dics
=
[{
"axis"
:
axis
},
{}]
dics
=
[{
"axis"
:
axis
},
{}]
ops_config
=
[{
ops_config
=
[
"op_type"
:
"stack"
,
{
"op_inputs"
:
{
"op_type"
:
"stack"
,
"X"
:
"op_inputs"
:
{
[
"stack_input1"
,
"stack_input2"
,
"stack_input3"
]
"X"
:
[
},
"stack_input1"
,
"op_outputs"
:
{
"stack_input2"
,
"Y"
:
[
"stack_output"
]
"stack_input3"
,
},
]
"op_attrs"
:
dics
[
0
]
},
}]
"op_outputs"
:
{
"Y"
:
[
"stack_output"
]},
"op_attrs"
:
dics
[
0
],
}
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"stack_input1"
:
"stack_input1"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
,
batch
)
data_gen
=
partial
(
generate_input1
,
dics
,
batch
)
),
),
"stack_input2"
:
"stack_input2"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input2
,
dics
,
batch
)
data_gen
=
partial
(
generate_input2
,
dics
,
batch
)
),
),
"stack_input3"
:
"stack_input3"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input3
,
dics
,
batch
)
data_gen
=
partial
(
generate_input3
,
dics
,
batch
)
)
)
,
},
},
outputs
=
[
"stack_output"
])
outputs
=
[
"stack_output"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"stack_input1"
:
[
1
,
3
,
24
,
24
],
"stack_input1"
:
[
1
,
3
,
24
,
24
],
"stack_input2"
:
[
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
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"stack_input1"
:
[
4
,
3
,
48
,
48
],
"stack_input1"
:
[
4
,
3
,
48
,
48
],
"stack_input2"
:
[
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
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"stack_input1"
:
[
1
,
3
,
24
,
24
],
"stack_input1"
:
[
1
,
3
,
24
,
24
],
"stack_input2"
:
[
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
:
elif
self
.
dims
==
3
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"stack_input1"
:
[
1
,
3
,
24
],
"stack_input1"
:
[
1
,
3
,
24
],
"stack_input2"
:
[
1
,
3
,
24
],
"stack_input2"
:
[
1
,
3
,
24
],
"stack_input3"
:
[
1
,
3
,
24
]
"stack_input3"
:
[
1
,
3
,
24
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"stack_input1"
:
[
4
,
3
,
48
],
"stack_input1"
:
[
4
,
3
,
48
],
"stack_input2"
:
[
4
,
3
,
48
],
"stack_input2"
:
[
4
,
3
,
48
],
"stack_input3"
:
[
4
,
3
,
48
]
"stack_input3"
:
[
4
,
3
,
48
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"stack_input1"
:
[
1
,
3
,
24
],
"stack_input1"
:
[
1
,
3
,
24
],
"stack_input2"
:
[
1
,
3
,
24
],
"stack_input2"
:
[
1
,
3
,
24
],
"stack_input3"
:
[
1
,
3
,
24
]
"stack_input3"
:
[
1
,
3
,
24
]
,
}
}
elif
self
.
dims
==
2
:
elif
self
.
dims
==
2
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"stack_input1"
:
[
1
,
24
],
"stack_input1"
:
[
1
,
24
],
"stack_input2"
:
[
1
,
24
],
"stack_input2"
:
[
1
,
24
],
"stack_input3"
:
[
1
,
24
]
"stack_input3"
:
[
1
,
24
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"stack_input1"
:
[
4
,
48
],
"stack_input1"
:
[
4
,
48
],
"stack_input2"
:
[
4
,
48
],
"stack_input2"
:
[
4
,
48
],
"stack_input3"
:
[
4
,
48
]
"stack_input3"
:
[
4
,
48
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"stack_input1"
:
[
1
,
24
],
"stack_input1"
:
[
1
,
24
],
"stack_input2"
:
[
1
,
24
],
"stack_input2"
:
[
1
,
24
],
"stack_input3"
:
[
1
,
24
]
"stack_input3"
:
[
1
,
24
]
,
}
}
elif
self
.
dims
==
1
:
elif
self
.
dims
==
1
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"stack_input1"
:
[
24
],
"stack_input1"
:
[
24
],
"stack_input2"
:
[
24
],
"stack_input2"
:
[
24
],
"stack_input3"
:
[
24
]
"stack_input3"
:
[
24
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"stack_input1"
:
[
48
],
"stack_input1"
:
[
48
],
"stack_input2"
:
[
48
],
"stack_input2"
:
[
48
],
"stack_input3"
:
[
48
]
"stack_input3"
:
[
48
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"stack_input1"
:
[
24
],
"stack_input1"
:
[
24
],
"stack_input2"
:
[
24
],
"stack_input2"
:
[
24
],
"stack_input3"
:
[
24
]
"stack_input3"
:
[
24
]
,
}
}
def
clear_dynamic_shape
():
def
clear_dynamic_shape
():
...
@@ -191,19 +193,23 @@ class TrtConvertStackTest(TrtLayerAutoScanTest):
...
@@ -191,19 +193,23 @@ class TrtConvertStackTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
attrs
,
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
attrs
,
True
),
1e-3
def
add_skip_trt_case
(
self
):
def
add_skip_trt_case
(
self
):
pass
pass
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_sum.py
View file @
dbe08e9b
...
@@ -22,12 +22,10 @@ import unittest
...
@@ -22,12 +22,10 @@ import unittest
class
TrtConvertSumTest
(
TrtLayerAutoScanTest
):
class
TrtConvertSumTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
batch
):
def
generate_input1
(
batch
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
return
np
.
ones
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
return
np
.
ones
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
...
@@ -61,99 +59,101 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
...
@@ -61,99 +59,101 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
for
dims
in
[
1
,
2
,
3
,
4
]:
for
dims
in
[
1
,
2
,
3
,
4
]:
for
batch
in
[
1
,
4
]:
for
batch
in
[
1
,
4
]:
self
.
dims
=
dims
self
.
dims
=
dims
ops_config
=
[{
ops_config
=
[
"op_type"
:
"sum"
,
{
"op_inputs"
:
{
"op_type"
:
"sum"
,
"X"
:
[
"input1"
,
"input2"
,
"input3"
]
"op_inputs"
:
{
"X"
:
[
"input1"
,
"input2"
,
"input3"
]},
},
"op_outputs"
:
{
"Out"
:
[
"output"
]},
"op_outputs"
:
{
"op_attrs"
:
{},
"Out"
:
[
"output"
]
}
},
]
"op_attrs"
:
{}
}]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input1"
:
"input1"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
batch
)),
data_gen
=
partial
(
generate_input1
,
batch
)
"input2"
:
),
TensorConfig
(
data_gen
=
partial
(
generate_input2
,
batch
)),
"input2"
:
TensorConfig
(
"input3"
:
data_gen
=
partial
(
generate_input2
,
batch
)
TensorConfig
(
data_gen
=
partial
(
generate_input3
,
batch
))
),
"input3"
:
TensorConfig
(
data_gen
=
partial
(
generate_input3
,
batch
)
),
},
},
outputs
=
[
"output"
])
outputs
=
[
"output"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
():
def
generate_dynamic_shape
():
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input1"
:
[
1
,
3
,
24
,
24
],
"input1"
:
[
1
,
3
,
24
,
24
],
"input2"
:
[
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
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"input1"
:
[
4
,
3
,
48
,
48
],
"input1"
:
[
4
,
3
,
48
,
48
],
"input2"
:
[
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
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"input1"
:
[
1
,
3
,
24
,
24
],
"input1"
:
[
1
,
3
,
24
,
24
],
"input2"
:
[
1
,
3
,
24
,
24
],
"input2"
:
[
1
,
3
,
24
,
24
],
"input3"
:
[
1
,
3
,
24
,
24
]
"input3"
:
[
1
,
3
,
24
,
24
]
,
}
}
elif
self
.
dims
==
3
:
elif
self
.
dims
==
3
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input1"
:
[
1
,
3
,
24
],
"input1"
:
[
1
,
3
,
24
],
"input2"
:
[
1
,
3
,
24
],
"input2"
:
[
1
,
3
,
24
],
"input3"
:
[
1
,
3
,
24
]
"input3"
:
[
1
,
3
,
24
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"input1"
:
[
4
,
3
,
48
],
"input1"
:
[
4
,
3
,
48
],
"input2"
:
[
4
,
3
,
48
],
"input2"
:
[
4
,
3
,
48
],
"input3"
:
[
4
,
3
,
48
]
"input3"
:
[
4
,
3
,
48
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"input1"
:
[
1
,
3
,
24
],
"input1"
:
[
1
,
3
,
24
],
"input2"
:
[
1
,
3
,
24
],
"input2"
:
[
1
,
3
,
24
],
"input3"
:
[
1
,
3
,
24
]
"input3"
:
[
1
,
3
,
24
]
,
}
}
elif
self
.
dims
==
2
:
elif
self
.
dims
==
2
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input1"
:
[
1
,
24
],
"input1"
:
[
1
,
24
],
"input2"
:
[
1
,
24
],
"input2"
:
[
1
,
24
],
"input3"
:
[
1
,
24
]
"input3"
:
[
1
,
24
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"input1"
:
[
4
,
48
],
"input1"
:
[
4
,
48
],
"input2"
:
[
4
,
48
],
"input2"
:
[
4
,
48
],
"input3"
:
[
4
,
48
]
"input3"
:
[
4
,
48
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"input1"
:
[
1
,
24
],
"input1"
:
[
1
,
24
],
"input2"
:
[
1
,
24
],
"input2"
:
[
1
,
24
],
"input3"
:
[
1
,
24
]
"input3"
:
[
1
,
24
]
,
}
}
elif
self
.
dims
==
1
:
elif
self
.
dims
==
1
:
self
.
dynamic_shape
.
min_input_shape
=
{
self
.
dynamic_shape
.
min_input_shape
=
{
"input1"
:
[
24
],
"input1"
:
[
24
],
"input2"
:
[
24
],
"input2"
:
[
24
],
"input3"
:
[
24
]
"input3"
:
[
24
]
,
}
}
self
.
dynamic_shape
.
max_input_shape
=
{
self
.
dynamic_shape
.
max_input_shape
=
{
"input1"
:
[
48
],
"input1"
:
[
48
],
"input2"
:
[
48
],
"input2"
:
[
48
],
"input3"
:
[
48
]
"input3"
:
[
48
]
,
}
}
self
.
dynamic_shape
.
opt_input_shape
=
{
self
.
dynamic_shape
.
opt_input_shape
=
{
"input1"
:
[
24
],
"input1"
:
[
24
],
"input2"
:
[
24
],
"input2"
:
[
24
],
"input3"
:
[
24
]
"input3"
:
[
24
]
,
}
}
def
clear_dynamic_shape
():
def
clear_dynamic_shape
():
...
@@ -162,7 +162,7 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
...
@@ -162,7 +162,7 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
self
.
dynamic_shape
.
opt_input_shape
=
{}
self
.
dynamic_shape
.
opt_input_shape
=
{}
def
generate_trt_nodes_num
(
dynamic_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
0
,
5
return
1
,
4
return
1
,
4
...
@@ -170,17 +170,19 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
...
@@ -170,17 +170,19 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
False
),
1e-5
False
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
False
),
1e-5
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
()
generate_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
True
),
1e-5
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
True
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
):
def
test
(
self
):
self
.
run_test
()
self
.
run_test
()
...
@@ -188,12 +190,10 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
...
@@ -188,12 +190,10 @@ class TrtConvertSumTest(TrtLayerAutoScanTest):
# special case when sum having olny one input
# special case when sum having olny one input
class
TrtConvertSumTest1
(
TrtLayerAutoScanTest
):
class
TrtConvertSumTest1
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
def
sample_program_configs
(
self
):
def
sample_program_configs
(
self
):
def
generate_input1
(
batch
):
def
generate_input1
(
batch
):
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
return
np
.
ones
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
return
np
.
ones
([
batch
,
3
,
24
,
24
]).
astype
(
np
.
float32
)
...
@@ -207,31 +207,31 @@ class TrtConvertSumTest1(TrtLayerAutoScanTest):
...
@@ -207,31 +207,31 @@ class TrtConvertSumTest1(TrtLayerAutoScanTest):
for
dims
in
[
1
,
2
,
3
,
4
]:
for
dims
in
[
1
,
2
,
3
,
4
]:
for
batch
in
[
1
,
4
]:
for
batch
in
[
1
,
4
]:
self
.
dims
=
dims
self
.
dims
=
dims
ops_config
=
[{
ops_config
=
[
"op_type"
:
"sum"
,
{
"op_inputs"
:
{
"op_type"
:
"sum"
,
"X"
:
[
"input1"
]
"op_inputs"
:
{
"X"
:
[
"input1"
]},
},
"op_outputs"
:
{
"Out"
:
[
"output"
]},
"op_outputs"
:
{
"op_attrs"
:
{},
"Out"
:
[
"output"
]
}
},
]
"op_attrs"
:
{}
}]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input1"
:
"input1"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
batch
)),
data_gen
=
partial
(
generate_input1
,
batch
)
),
},
},
outputs
=
[
"output"
])
outputs
=
[
"output"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
():
def
generate_dynamic_shape
():
if
self
.
dims
==
4
:
if
self
.
dims
==
4
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input1"
:
[
1
,
3
,
24
,
24
]}
self
.
dynamic_shape
.
min_input_shape
=
{
"input1"
:
[
1
,
3
,
24
,
24
]}
...
@@ -268,7 +268,7 @@ class TrtConvertSumTest1(TrtLayerAutoScanTest):
...
@@ -268,7 +268,7 @@ class TrtConvertSumTest1(TrtLayerAutoScanTest):
self
.
dynamic_shape
.
opt_input_shape
=
{}
self
.
dynamic_shape
.
opt_input_shape
=
{}
def
generate_trt_nodes_num
(
dynamic_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
0
,
3
return
1
,
2
return
1
,
2
...
@@ -276,17 +276,19 @@ class TrtConvertSumTest1(TrtLayerAutoScanTest):
...
@@ -276,17 +276,19 @@ class TrtConvertSumTest1(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
False
),
1e-5
False
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
False
),
1e-5
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
()
generate_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
True
),
1e-5
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
True
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
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
):
def
test
(
self
):
self
.
run_test
()
self
.
run_test
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_tile.py
View file @
dbe08e9b
...
@@ -26,7 +26,6 @@ import hypothesis.strategies as st
...
@@ -26,7 +26,6 @@ import hypothesis.strategies as st
class
TrtConvertTileTest
(
TrtLayerAutoScanTest
):
class
TrtConvertTileTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
inputs
=
program_config
.
inputs
inputs
=
program_config
.
inputs
attrs
=
[
attrs
=
[
...
@@ -39,38 +38,37 @@ class TrtConvertTileTest(TrtLayerAutoScanTest):
...
@@ -39,38 +38,37 @@ class TrtConvertTileTest(TrtLayerAutoScanTest):
return
True
return
True
def
sample_program_configs
(
self
,
*
args
,
**
kwargs
):
def
sample_program_configs
(
self
,
*
args
,
**
kwargs
):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
def
generate_input1
(
attrs
:
List
[
Dict
[
str
,
Any
]]):
return
np
.
ones
([
1
,
2
,
3
,
4
]).
astype
(
np
.
float32
)
return
np
.
ones
([
1
,
2
,
3
,
4
]).
astype
(
np
.
float32
)
dics
=
[{
"repeat_times"
:
kwargs
[
'repeat_times'
]}]
dics
=
[{
"repeat_times"
:
kwargs
[
'repeat_times'
]}]
ops_config
=
[{
ops_config
=
[
"op_type"
:
"tile"
,
{
"op_inputs"
:
{
"op_type"
:
"tile"
,
"X"
:
[
"input_data"
]
"op_inputs"
:
{
"X"
:
[
"input_data"
]},
},
"op_outputs"
:
{
"Out"
:
[
"tile_output_data"
]},
"op_outputs"
:
{
"op_attrs"
:
dics
[
0
],
"Out"
:
[
"tile_output_data"
]
}
},
]
"op_attrs"
:
dics
[
0
]
}]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input_data"
:
"input_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
generate_input1
,
dics
))
data_gen
=
partial
(
generate_input1
,
dics
)
)
},
},
outputs
=
[
"tile_output_data"
])
outputs
=
[
"tile_output_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
3
,
32
,
32
]}
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
3
,
32
,
32
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
4
,
3
,
64
,
64
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
4
,
3
,
64
,
64
]}
...
@@ -99,19 +97,23 @@ class TrtConvertTileTest(TrtLayerAutoScanTest):
...
@@ -99,19 +97,23 @@ class TrtConvertTileTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-4
attrs
,
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
]]))
@
given
(
repeat_times
=
st
.
sampled_from
([[
100
],
[
1
,
2
],
[
0
,
3
],
[
1
,
2
,
100
]]))
def
test
(
self
,
*
args
,
**
kwargs
):
def
test
(
self
,
*
args
,
**
kwargs
):
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_top_k.py
View file @
dbe08e9b
...
@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
...
@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
class
TrtConvertActivationTest
(
TrtLayerAutoScanTest
):
class
TrtConvertActivationTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
return
True
return
True
...
@@ -44,34 +43,37 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
...
@@ -44,34 +43,37 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
for
k
in
[
1
,
3
]:
for
k
in
[
1
,
3
]:
self
.
dims
=
dims
self
.
dims
=
dims
dics
=
[{
"k"
:
k
}]
dics
=
[{
"k"
:
k
}]
ops_config
=
[
{
ops_config
=
[
"op_type"
:
"top_k"
,
{
"op_inputs"
:
{
"op_type"
:
"top_k"
,
"X"
:
[
"input_data"
]
"op_inputs"
:
{
"X"
:
[
"input_data"
]
},
},
"op_outputs"
:
{
"op_outputs"
:
{
"Out"
:
[
"output_data"
],
"Out"
:
[
"output
_data"
],
"Indices"
:
[
"indices
_data"
],
"Indices"
:
[
"indices_data"
]
},
}
,
"op_attrs"
:
dics
[
0
]
,
"op_attrs"
:
dics
[
0
]
}
}
]
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input_data"
:
"input_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
data_gen
=
partial
(
generate_input1
,
dims
,
batch
,
dics
))
generate_input1
,
dims
,
batch
,
dics
)
)
},
},
outputs
=
[
"output_data"
,
"indices_data"
])
outputs
=
[
"output_data"
,
"indices_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
if
self
.
dims
==
1
:
if
self
.
dims
==
1
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
]}
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
]}
...
@@ -114,19 +116,23 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
...
@@ -114,19 +116,23 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
attrs
,
False
),
1e-3
## for dynamic_shape
## for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
attrs
,
True
),
1e-3
def
test
(
self
):
def
test
(
self
):
self
.
run_test
()
self
.
run_test
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_top_k_v2.py
View file @
dbe08e9b
...
@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
...
@@ -22,7 +22,6 @@ from typing import Optional, List, Callable, Dict, Any, Set
class
TrtConvertActivationTest
(
TrtLayerAutoScanTest
):
class
TrtConvertActivationTest
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
inputs
=
program_config
.
inputs
inputs
=
program_config
.
inputs
attrs
=
[
attrs
=
[
...
@@ -53,40 +52,48 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
...
@@ -53,40 +52,48 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
for
sort
in
[
True
,
False
]:
for
sort
in
[
True
,
False
]:
self
.
dims
=
dims
self
.
dims
=
dims
self
.
sort
=
sort
self
.
sort
=
sort
dics
=
[{
dics
=
[
"k"
:
k
,
{
"axis"
:
axis
,
"k"
:
k
,
"largest"
:
largest
,
"axis"
:
axis
,
"sorted"
:
sort
"largest"
:
largest
,
}]
"sorted"
:
sort
,
ops_config
=
[{
}
"op_type"
:
"top_k_v2"
,
]
"op_inputs"
:
{
ops_config
=
[
"X"
:
[
"input_data"
]
{
},
"op_type"
:
"top_k_v2"
,
"op_outputs"
:
{
"op_inputs"
:
{
"X"
:
[
"input_data"
]},
"Out"
:
[
"output_data"
],
"op_outputs"
:
{
"Indices"
:
[
"indices_data"
]
"Out"
:
[
"output_data"
],
},
"Indices"
:
[
"indices_data"
],
"op_attrs"
:
dics
[
0
]
},
}]
"op_attrs"
:
dics
[
0
],
}
]
ops
=
self
.
generate_op_config
(
ops_config
)
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
program_config
=
ProgramConfig
(
ops
=
ops
,
ops
=
ops
,
weights
=
{},
weights
=
{},
inputs
=
{
inputs
=
{
"input_data"
:
"input_data"
:
TensorConfig
(
TensorConfig
(
data_gen
=
partial
(
data_gen
=
partial
(
generate_input1
,
dims
,
batch
,
dics
))
generate_input1
,
dims
,
batch
,
dics
,
)
)
},
},
outputs
=
[
"output_data"
,
"indices_data"
])
outputs
=
[
"output_data"
,
"indices_data"
],
)
yield
program_config
yield
program_config
def
sample_predictor_configs
(
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
):
def
generate_dynamic_shape
(
attrs
):
if
self
.
dims
==
1
:
if
self
.
dims
==
1
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
]}
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
]}
...
@@ -131,19 +138,23 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
...
@@ -131,19 +138,23 @@ class TrtConvertActivationTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
attrs
,
False
),
1e-3
# for dynamic_shape
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
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
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
attrs
,
True
),
1e-3
def
test
(
self
):
def
test
(
self
):
self
.
run_test
()
self
.
run_test
()
...
...
Prev
1
…
8
9
10
11
12
13
14
15
16
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment