Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
211cf208
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
211cf208
编写于
10月 26, 2021
作者:
W
Wilber
提交者:
GitHub
10月 26, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[cherry-pick] enable trt test check and fix trt ut error(3/3) (#36696)
上级
da6e5143
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
296 addition
and
90 deletion
+296
-90
paddle/fluid/framework/ir/graph_viz_pass.cc
paddle/fluid/framework/ir/graph_viz_pass.cc
+4
-0
paddle/fluid/inference/analysis/ir_pass_manager.cc
paddle/fluid/inference/analysis/ir_pass_manager.cc
+11
-3
paddle/fluid/inference/api/analysis_config.cc
paddle/fluid/inference/api/analysis_config.cc
+34
-11
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+5
-3
paddle/fluid/inference/tensorrt/plugin/elementwise_op_plugin.cu
.../fluid/inference/tensorrt/plugin/elementwise_op_plugin.cu
+0
-6
paddle/scripts/paddle_build.sh
paddle/scripts/paddle_build.sh
+23
-0
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d.py
...d/tests/unittests/ir/inference/test_trt_convert_conv2d.py
+1
-0
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d_transpose.py
...ittests/ir/inference/test_trt_convert_conv2d_transpose.py
+17
-4
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_depthwise_conv2d.py
...ittests/ir/inference/test_trt_convert_depthwise_conv2d.py
+15
-3
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_depthwise_conv2d_transpose.py
.../inference/test_trt_convert_depthwise_conv2d_transpose.py
+16
-3
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py
...ts/unittests/ir/inference/test_trt_convert_elementwise.py
+101
-34
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_group_norm.py
...sts/unittests/ir/inference/test_trt_convert_group_norm.py
+20
-6
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_pool2d.py
...d/tests/unittests/ir/inference/test_trt_convert_pool2d.py
+28
-0
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce_mean.py
...ts/unittests/ir/inference/test_trt_convert_reduce_mean.py
+8
-7
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce_sum.py
...sts/unittests/ir/inference/test_trt_convert_reduce_sum.py
+8
-7
python/paddle/fluid/tests/unittests/ir/inference/trt_layer_auto_scan_test.py
.../tests/unittests/ir/inference/trt_layer_auto_scan_test.py
+5
-3
未找到文件。
paddle/fluid/framework/ir/graph_viz_pass.cc
浏览文件 @
211cf208
...
...
@@ -62,10 +62,14 @@ void GraphVizPass::ApplyImpl(ir::Graph* graph) const {
}
}
}
const
std
::
string
&
optim_cache_dir
=
Get
<
std
::
string
>
(
"optim_cache_dir"
);
std
::
string
program_bytes
=
program_desc
.
Proto
()
->
SerializeAsString
();
// rename from "17_ir_fc_fuse_pass.dot" to "fc_fuse_pass.pdmodel"
program_path
=
graph_viz_path
.
substr
(
found1
+
4
,
found2
-
found1
-
4
)
+
".pdmodel"
;
if
(
!
optim_cache_dir
.
empty
())
{
program_path
=
optim_cache_dir
+
"/"
+
program_path
;
}
std
::
ofstream
file
(
program_path
.
c_str
(),
std
::
ios
::
binary
);
file
.
write
(
program_bytes
.
c_str
(),
program_bytes
.
size
());
file
.
close
();
...
...
paddle/fluid/inference/analysis/ir_pass_manager.cc
浏览文件 @
211cf208
...
...
@@ -56,10 +56,18 @@ void IRPassManager::CreatePasses(Argument *argument,
auto
pass
=
framework
::
ir
::
PassRegistry
::
Instance
().
Get
(
pass_name
);
if
(
pass_name
==
"graph_viz_pass"
)
{
std
::
string
dot_file_path
=
std
::
to_string
(
pass_num
)
+
"_ir_"
+
(
pre_pass
.
empty
()
?
"origin"
:
pre_pass
)
+
".dot"
;
std
::
string
optim_cache_dir
=
argument
->
optim_cache_dir
();
std
::
string
dot_file_path
;
if
(
optim_cache_dir
.
empty
())
{
dot_file_path
=
std
::
to_string
(
pass_num
)
+
"_ir_"
+
(
pre_pass
.
empty
()
?
"origin"
:
pre_pass
)
+
".dot"
;
}
else
{
dot_file_path
=
optim_cache_dir
+
"/"
+
std
::
to_string
(
pass_num
)
+
"_ir_"
+
(
pre_pass
.
empty
()
?
"origin"
:
pre_pass
)
+
".dot"
;
}
pass
->
Set
(
"graph_viz_path"
,
new
std
::
string
(
std
::
move
(
dot_file_path
)));
pass
->
Set
(
"optim_cache_dir"
,
new
std
::
string
(
std
::
move
(
optim_cache_dir
)));
pass_num
++
;
}
else
if
(
pass_name
==
"mkldnn_placement_pass"
)
{
pass
->
Set
(
"mkldnn_enabled_op_types"
,
...
...
paddle/fluid/inference/api/analysis_config.cc
浏览文件 @
211cf208
...
...
@@ -12,7 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <sstream>
#include <string>
#include <tuple>
#include "paddle/fluid/inference/api/paddle_analysis_config.h"
#include "paddle/fluid/inference/api/paddle_pass_builder.h"
#include "paddle/fluid/inference/utils/table_printer.h"
...
...
@@ -20,6 +22,10 @@
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/gpu_info.h"
#ifdef PADDLE_WITH_TENSORRT
#include "paddle/fluid/inference/tensorrt/helper.h"
#endif
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
DECLARE_uint64
(
initial_gpu_memory_in_mb
);
#endif
...
...
@@ -758,17 +764,6 @@ std::string AnalysisConfig::Summary() {
{
"mkldnn_cache_capacity"
,
std
::
to_string
(
mkldnn_cache_capacity_
)});
os
.
InsetDivider
();
auto
Precision2String
=
[](
paddle
::
AnalysisConfig
::
Precision
prec
)
->
std
::
string
{
if
(
prec
==
Precision
::
kFloat32
)
return
"fp32"
;
else
if
(
prec
==
Precision
::
kHalf
)
return
"fp16"
;
else
if
(
prec
==
Precision
::
kInt8
)
return
"int8"
;
else
return
"None"
;
};
// gpu info
os
.
InsertRow
({
"use_gpu"
,
use_gpu_
?
"true"
:
"false"
});
if
(
use_gpu_
)
{
...
...
@@ -780,6 +775,33 @@ std::string AnalysisConfig::Summary() {
os
.
InsertRow
({
"use_tensorrt"
,
use_tensorrt_
?
"true"
:
"false"
});
if
(
use_tensorrt_
)
{
#ifdef PADDLE_WITH_TENSORRT
auto
Precision2String
=
[](
paddle
::
AnalysisConfig
::
Precision
prec
)
->
std
::
string
{
if
(
prec
==
Precision
::
kFloat32
)
return
"fp32"
;
else
if
(
prec
==
Precision
::
kHalf
)
return
"fp16"
;
else
if
(
prec
==
Precision
::
kInt8
)
return
"int8"
;
else
return
"None"
;
};
auto
version2string
=
[](
const
std
::
tuple
<
int
,
int
,
int
>
&
ver
)
->
std
::
string
{
std
::
ostringstream
os
;
int
major
=
std
::
get
<
0
>
(
ver
);
int
minor
=
std
::
get
<
1
>
(
ver
);
int
patch
=
std
::
get
<
2
>
(
ver
);
os
<<
major
<<
"."
<<
minor
<<
"."
<<
patch
;
return
os
.
str
();
};
os
.
InsertRow
(
{
"trt_compile_version"
,
version2string
(
inference
::
tensorrt
::
GetTrtCompileVersion
())});
os
.
InsertRow
(
{
"trt_runtime_version"
,
version2string
(
inference
::
tensorrt
::
GetTrtRuntimeVersion
())});
os
.
InsertRow
({
"tensorrt_precision_mode"
,
Precision2String
(
tensorrt_precision_mode_
)});
os
.
InsertRow
({
"tensorrt_workspace_size"
,
...
...
@@ -805,6 +827,7 @@ std::string AnalysisConfig::Summary() {
if
(
trt_use_dla_
)
{
os
.
InsertRow
({
"tensorrt_dla_core"
,
std
::
to_string
(
trt_dla_core_
)});
}
#endif
}
}
os
.
InsetDivider
();
...
...
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
211cf208
...
...
@@ -48,9 +48,11 @@ struct SimpleOpTypeSetTeller : public Teller {
int8_teller_set
.
insert
(
"skip_layernorm"
);
int8_teller_set
.
insert
(
"slice"
);
#endif
#if IS_TRT_VERSION_GE(7130)
teller_set
.
insert
(
"group_norm"
);
#endif
// TODO(baoachun) The group_norm trt plugin will check input's dim
// not -1 failed when dynamic shape mode.
// #if IS_TRT_VERSION_GE(7130)
// teller_set.insert("group_norm");
// #endif
#if IS_TRT_VERSION_GE(7000)
teller_set
.
insert
(
"tile"
);
#endif
...
...
paddle/fluid/inference/tensorrt/plugin/elementwise_op_plugin.cu
浏览文件 @
211cf208
...
...
@@ -65,12 +65,6 @@ nvinfer1::Dims ElementWisePlugin::getOutputDimensions(
}
int
ElementWisePlugin
::
initialize
()
TRT_NOEXCEPT
{
PADDLE_ENFORCE_GT
(
dims_y_
.
nbDims
,
0
,
platform
::
errors
::
InvalidArgument
(
"The dimension of input Y of TRT elementwise op plugin "
"should be greater than 0, but got %d."
,
dims_y_
.
nbDims
));
axis_
=
(
axis_
==
-
1
)
?
dims_x_
.
nbDims
-
dims_y_
.
nbDims
:
axis_
;
int
trimed_nb_dims
=
dims_y_
.
nbDims
;
for
(;
trimed_nb_dims
>
0
;
--
trimed_nb_dims
)
{
...
...
paddle/scripts/paddle_build.sh
浏览文件 @
211cf208
...
...
@@ -2373,6 +2373,25 @@ function reuse_so_cache() {
fi
}
function
trt_convert_test
()
{
set
+e
cd
${
PADDLE_ROOT
}
result_num
=
0
export
PYTHONPATH
=
$PYTHONPATH
:
${
PADDLE_ROOT
}
/build/python
for
file_name
in
`
find python/
-name
'test_trt_convert*'
`
;
do
echo
"----- test trt ut:
$file_name
-----"
python
$file_name
res
=
$?
if
[
"
$res
"
!=
"0"
]
;
then
echo
"
$file_name
convert test failed "
>
&2
result_num
=
11
fi
done
if
[
"
$result_num
"
!=
"0"
]
;
then
exit
11
fi
}
function
find_temporary_files
()
{
set
+x
jsonData
=
`
curl
\
...
...
@@ -2639,6 +2658,10 @@ function main() {
test_model_benchmark
)
test_model_benchmark
;;
trt_convert_test
)
# only test trt convert.
trt_convert_test
;;
*
)
print_usage
exit
1
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d.py
浏览文件 @
211cf208
...
...
@@ -15,6 +15,7 @@
from
trt_layer_auto_scan_test
import
TrtLayerAutoScanTest
,
SkipReasons
from
program_config
import
TensorConfig
,
ProgramConfig
import
numpy
as
np
import
unittest
import
paddle.inference
as
paddle_infer
from
functools
import
partial
from
typing
import
Optional
,
List
,
Callable
,
Dict
,
Any
,
Set
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d_transpose.py
浏览文件 @
211cf208
...
...
@@ -15,6 +15,7 @@
from
trt_layer_auto_scan_test
import
TrtLayerAutoScanTest
,
SkipReasons
from
program_config
import
TensorConfig
,
ProgramConfig
import
numpy
as
np
import
unittest
import
paddle.inference
as
paddle_infer
from
functools
import
partial
from
typing
import
Optional
,
List
,
Callable
,
Dict
,
Any
,
Set
...
...
@@ -173,7 +174,7 @@ class TrtConvertConv2dTransposeTest(TrtLayerAutoScanTest):
attrs
,
False
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
(
1e-5
,
1e-
5
)
attrs
,
False
),
(
1e-5
,
1e-
3
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Int8
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
(
1e-5
,
1e-5
)
...
...
@@ -185,7 +186,7 @@ class TrtConvertConv2dTransposeTest(TrtLayerAutoScanTest):
True
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
(
1e-5
,
1e-
5
)
attrs
,
True
),
(
1e-5
,
1e-
3
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Int8
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
(
1e-5
,
1e-5
)
...
...
@@ -214,13 +215,25 @@ class TrtConvertConv2dTransposeTest(TrtLayerAutoScanTest):
"When dilations's element is not equal 1, there are different behaviors between Trt and Paddle."
)
def
teller3
(
program_config
,
predictor_config
):
if
self
.
trt_param
.
precision
==
paddle_infer
.
PrecisionType
.
Int8
:
return
True
return
False
self
.
add_skip_case
(
teller3
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"When precisionType is int8 without relu op, output is different between Trt and Paddle."
)
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
()
# TODO(inference): reopen the test
# self.run_test()
def
test_quant
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
(
quant
=
True
)
# TODO(inference): reopen the test
# self.run_test(quant=True)
if
__name__
==
"__main__"
:
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_depthwise_conv2d.py
浏览文件 @
211cf208
...
...
@@ -18,6 +18,7 @@ import numpy as np
import
paddle.inference
as
paddle_infer
from
functools
import
partial
from
typing
import
Optional
,
List
,
Callable
,
Dict
,
Any
,
Set
import
unittest
class
TrtConvertDepthwiseConv2dTest
(
TrtLayerAutoScanTest
):
...
...
@@ -165,7 +166,6 @@ class TrtConvertDepthwiseConv2dTest(TrtLayerAutoScanTest):
attrs
,
False
),
(
1e-5
,
1e-5
)
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
...
...
@@ -190,13 +190,25 @@ class TrtConvertDepthwiseConv2dTest(TrtLayerAutoScanTest):
"When padding_algorithm is 'SAME' or 'VALID', Trt dose not support. In this case, trt build error is caused by scale op."
)
def
teller2
(
program_config
,
predictor_config
):
if
self
.
trt_param
.
precision
==
paddle_infer
.
PrecisionType
.
Int8
:
return
True
return
False
self
.
add_skip_case
(
teller2
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"When precisionType is int8 without relu op, output is different between Trt and Paddle."
)
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
()
# TODO(inference): reopen the test
# self.run_test()
def
test_quant
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
(
quant
=
True
)
# TODO(inference): reopen the test
# self.run_test(quant=True)
if
__name__
==
"__main__"
:
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_depthwise_conv2d_transpose.py
浏览文件 @
211cf208
...
...
@@ -18,6 +18,7 @@ import numpy as np
import
paddle.inference
as
paddle_infer
from
functools
import
partial
from
typing
import
Optional
,
List
,
Callable
,
Dict
,
Any
,
Set
import
unittest
class
TrtConvertDepthwiseConv2dTransposeTest
(
TrtLayerAutoScanTest
):
...
...
@@ -137,7 +138,7 @@ class TrtConvertDepthwiseConv2dTransposeTest(TrtLayerAutoScanTest):
attrs
,
False
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
(
1e-5
,
1e-
5
)
attrs
,
False
),
(
1e-5
,
1e-
3
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Int8
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
(
1e-5
,
1e-5
)
...
...
@@ -178,13 +179,25 @@ class TrtConvertDepthwiseConv2dTransposeTest(TrtLayerAutoScanTest):
"When dilations's element is not equal 1, there are different behaviors between Trt and Paddle."
)
def
teller3
(
program_config
,
predictor_config
):
if
self
.
trt_param
.
precision
==
paddle_infer
.
PrecisionType
.
Int8
:
return
True
return
False
self
.
add_skip_case
(
teller3
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"When precisionType is int8 without relu op, output is different between Trt and Paddle."
)
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
()
# TODO(inference): reopen the test
# self.run_test()
def
test_quant
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
(
quant
=
True
)
# TODO(inference): reopen the test
# self.run_test(quant=True)
if
__name__
==
"__main__"
:
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_elementwise.py
浏览文件 @
211cf208
...
...
@@ -33,8 +33,8 @@ class TrtConvertElementwiseTest_one_input(TrtLayerAutoScanTest):
return
np
.
random
.
randn
(
32
).
astype
(
np
.
float32
)
for
batch
in
[
1
,
2
,
4
]:
for
shape
in
[[
32
],
[
batch
,
32
],
[
batch
,
64
,
32
],
[
batch
,
8
,
16
,
32
]]:
for
shape
in
[[
32
],
[
batch
,
32
],
[
batch
,
32
,
32
],
[
batch
,
32
,
16
,
32
]]:
for
op_type
in
[
"elementwise_add"
,
"elementwise_mul"
]:
for
axis
in
[
len
(
shape
)
-
1
,
-
1
]:
self
.
dims
=
len
(
shape
)
...
...
@@ -69,26 +69,27 @@ class TrtConvertElementwiseTest_one_input(TrtLayerAutoScanTest):
def
sample_predictor_configs
(
self
,
program_config
)
->
(
paddle_infer
.
Config
,
List
[
int
],
float
):
def
generate_dynamic_shape
(
attrs
):
# The input.dims[1] must be equal to the weight's length.
if
self
.
dims
==
1
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
4
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
256
]}
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data"
:
[
16
]}
elif
self
.
dims
==
2
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
4
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
4
,
256
]}
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data"
:
[
2
,
16
]}
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
32
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
4
,
32
]}
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data"
:
[
2
,
32
]}
elif
self
.
dims
==
3
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
4
,
4
]}
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
32
,
4
]}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
4
,
256
,
256
]
"input_data"
:
[
4
,
32
,
256
]
}
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data"
:
[
2
,
32
,
16
]}
elif
self
.
dims
==
4
:
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data"
:
[
1
,
4
,
4
,
4
]
"input_data"
:
[
1
,
32
,
4
,
4
]
}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data"
:
[
4
,
256
,
128
,
256
]
"input_data"
:
[
4
,
32
,
128
,
256
]
}
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data"
:
[
2
,
32
,
32
,
16
]
...
...
@@ -99,6 +100,11 @@ class TrtConvertElementwiseTest_one_input(TrtLayerAutoScanTest):
self
.
dynamic_shape
.
min_input_shape
=
{}
self
.
dynamic_shape
.
opt_input_shape
=
{}
def
generate_trt_nodes_num
(
attrs
,
dynamic_shape
):
if
self
.
dims
==
1
:
return
0
,
3
return
1
,
2
attrs
=
[
program_config
.
ops
[
i
].
attrs
for
i
in
range
(
len
(
program_config
.
ops
))
...
...
@@ -107,18 +113,52 @@ class TrtConvertElementwiseTest_one_input(TrtLayerAutoScanTest):
# for static_shape
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
0
,
3
),
1e-5
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
(
0
,
3
),
1e-5
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
1
,
2
),
1e-5
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
(
1
,
2
),
1e-5
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
def
add_skip_trt_case
(
self
):
def
teller1
(
program_config
,
predictor_config
):
if
self
.
dims
==
2
and
len
(
self
.
dynamic_shape
.
max_input_shape
)
==
0
:
return
True
return
False
self
.
add_skip_case
(
teller1
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"The output shape are not equal between gpu and tensorrt when input dim is 2."
)
def
teller2
(
program_config
,
predictor_config
):
if
self
.
dims
==
3
:
return
True
return
False
self
.
add_skip_case
(
teller2
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"The output has diff between gpu and tensorrt when input dim is 3."
)
def
teller3
(
program_config
,
predictor_config
):
if
self
.
dims
==
4
:
return
True
return
False
self
.
add_skip_case
(
teller3
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"The output has diff between gpu and tensorrt when input dim is 4."
)
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
()
...
...
@@ -246,15 +286,26 @@ class TrtConvertElementwiseTest_two_input_without_broadcast(
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
def
add_skip_trt_case
(
self
):
def
teller1
(
program_config
,
predictor_config
):
if
self
.
dims
==
2
:
return
True
return
False
self
.
add_skip_case
(
teller1
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"The output shape are not equal between gpu and tensorrt when input dim is 2."
)
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
()
class
TrtConvertElementwiseTest_two_input_with_broadcast
(
TrtLayerAutoScanTest
):
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
inputs
=
program_config
.
inputs
if
len
(
inputs
[
'input_data1'
].
shape
)
==
1
or
len
(
inputs
[
'input_data2'
]
.
shape
)
==
1
:
if
len
(
inputs
[
'input_data1'
].
shape
)
!=
len
(
inputs
[
'input_data2'
].
shape
):
return
False
return
True
...
...
@@ -265,24 +316,27 @@ class TrtConvertElementwiseTest_two_input_with_broadcast(TrtLayerAutoScanTest):
input1_shape_list
=
[[
4
,
32
],
[
2
,
4
,
32
],
[
4
,
2
,
4
,
32
]]
input2_shape1_list
=
[[
32
],
[
4
,
32
],
[
2
,
4
,
32
]]
input2_shape2_list
=
[[
1
,
32
],
[
1
,
1
,
32
],
[
1
,
1
,
1
,
32
]]
input2_shape3_list
=
[[
1
,
32
],
[
1
,
4
,
32
],
[
4
,
32
]]
input2_shape2_list
=
[[
4
,
1
],
[
2
,
4
,
1
],
[
4
,
2
,
4
,
1
]]
input2_shape3_list
=
[[
32
],
[
2
,
1
,
1
],
[
4
,
2
,
1
,
1
]]
input2_shape4_list
=
[[
32
],
[
4
,
32
],
[
4
,
1
,
1
,
1
]]
input2_shape_list
=
[
input2_shape1_list
,
input2_shape2_list
,
input2_shape3_list
input2_shape1_list
,
input2_shape2_list
,
input2_shape3_list
,
input2_shape4_list
]
axis1_list
=
[[
-
1
],
[
1
,
-
1
],
[
1
,
-
1
]]
axis2_list
=
[[
-
1
],
[
-
1
],
[
-
1
]]
axis3_list
=
[[
-
1
],
[
-
1
],
[
2
,
-
1
]]
axis_list
=
[
axis1_list
,
axis2_list
,
axis3_list
]
axis2_list
=
[[
-
1
],
[
0
],
[
0
]]
axis3_list
=
[[
-
1
],
[
0
],
[
0
]]
axis4_list
=
[[
-
1
],
[
-
1
],
[
0
]]
axis_list
=
[
axis1_list
,
axis2_list
,
axis3_list
,
axis4_list
]
for
i
in
range
(
3
):
input1_shape
=
input1_shape_list
[
i
]
for
j
in
range
(
3
):
for
j
in
range
(
4
):
input2_shape
=
input2_shape_list
[
j
][
i
]
for
op_type
in
[
"elementwise_add"
,
"elementwise_mul"
]:
for
axis
in
axis_list
[
j
][
i
]:
self
.
dims1
=
len
(
input1_shape
)
self
.
dims2
=
len
(
input2_shape
)
self
.
shape1
=
input1_shape
self
.
shape2
=
input2_shape
dics
=
[{
"axis"
:
axis
}]
ops_config
=
[{
"op_type"
:
op_type
,
...
...
@@ -319,16 +373,16 @@ class TrtConvertElementwiseTest_two_input_with_broadcast(TrtLayerAutoScanTest):
opt_shape
=
[[
32
],
[
32
,
32
],
[
32
,
32
,
32
],
[
32
,
32
,
32
,
32
]]
self
.
dynamic_shape
.
min_input_shape
=
{
"input_data1"
:
min_shape
[
self
.
dims1
-
1
],
"input_data2"
:
min_shape
[
self
.
dims2
-
1
]
"input_data1"
:
min_shape
[
len
(
self
.
shape1
)
-
1
],
"input_data2"
:
min_shape
[
len
(
self
.
shape2
)
-
1
]
}
self
.
dynamic_shape
.
max_input_shape
=
{
"input_data1"
:
max_shape
[
self
.
dims1
-
1
],
"input_data2"
:
max_shape
[
self
.
dims2
-
1
]
"input_data1"
:
max_shape
[
len
(
self
.
shape1
)
-
1
],
"input_data2"
:
max_shape
[
len
(
self
.
shape2
)
-
1
]
}
self
.
dynamic_shape
.
opt_input_shape
=
{
"input_data1"
:
opt_shape
[
self
.
dims1
-
1
],
"input_data2"
:
opt_shape
[
self
.
dims2
-
1
]
"input_data1"
:
opt_shape
[
len
(
self
.
shape1
)
-
1
],
"input_data2"
:
opt_shape
[
len
(
self
.
shape2
)
-
1
]
}
def
clear_dynamic_shape
():
...
...
@@ -343,10 +397,11 @@ class TrtConvertElementwiseTest_two_input_with_broadcast(TrtLayerAutoScanTest):
# for static_shape
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
if
self
.
shape1
[
0
]
==
self
.
shape2
[
0
]:
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
...
...
@@ -355,7 +410,19 @@ class TrtConvertElementwiseTest_two_input_with_broadcast(TrtLayerAutoScanTest):
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
(
1
,
3
),
1e-5
def
add_skip_trt_case
(
self
):
def
teller1
(
program_config
,
predictor_config
):
if
len
(
self
.
shape1
)
==
2
:
return
True
return
False
self
.
add_skip_case
(
teller1
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"The output shape are not equal between gpu and tensorrt when input dim is 2."
)
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_group_norm.py
浏览文件 @
211cf208
...
...
@@ -115,19 +115,33 @@ class TrtConvertGroupNormTest(TrtLayerAutoScanTest):
clear_dynamic_shape
()
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
attrs
,
False
),
(
1e-5
,
1e-5
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
attrs
,
False
),
(
1e-5
,
1e-5
)
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
# self.trt_param.precision = paddle_infer.PrecisionType.Float32
# yield self.create_inference_config(), generate_trt_nodes_num(attrs, True), 1e-5
# self.trt_param.precision = paddle_infer.PrecisionType.Half
# yield self.create_inference_config(), generate_trt_nodes_num(attrs, True), 1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
(
1e-5
,
1e-5
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
(
1e-5
,
1e-5
)
def
add_skip_trt_case
(
self
):
def
teller1
(
program_config
,
predictor_config
):
if
len
(
self
.
dynamic_shape
.
min_input_shape
)
!=
0
:
return
True
return
False
self
.
add_skip_case
(
teller1
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"The goup_norm plugin will check dim not -1 failed when dynamic fp16 mode."
)
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_pool2d.py
浏览文件 @
211cf208
...
...
@@ -18,6 +18,7 @@ import numpy as np
import
paddle.inference
as
paddle_infer
from
functools
import
partial
from
typing
import
Optional
,
List
,
Callable
,
Dict
,
Any
,
Set
import
unittest
class
TrtConvertPool2dTest
(
TrtLayerAutoScanTest
):
...
...
@@ -32,6 +33,10 @@ class TrtConvertPool2dTest(TrtLayerAutoScanTest):
for
index
in
range
(
len
(
ksize
)):
if
ksize
[
index
]
<=
paddings
[
index
]:
return
False
ver
=
paddle_infer
.
get_trt_compile_version
()
if
ver
[
0
]
*
1000
+
ver
[
1
]
*
100
+
ver
[
0
]
*
10
<
7000
:
if
program_config
.
ops
[
0
].
attrs
[
'pooling_type'
]
==
'avg'
:
return
False
return
True
def
is_program_valid
(
self
,
program_config
:
ProgramConfig
)
->
bool
:
...
...
@@ -157,6 +162,29 @@ class TrtConvertPool2dTest(TrtLayerAutoScanTest):
teller2
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"It is not support that global_pooling is true for trt now."
)
def
teller3
(
program_config
,
predictor_config
):
if
self
.
dynamic_shape
.
min_input_shape
==
{}
and
program_config
.
ops
[
0
].
attrs
[
'ceil_mode'
]
==
True
:
return
True
return
False
self
.
add_skip_case
(
teller3
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"It is not support that ceil_mode is true in static mode for trt now."
)
def
teller4
(
program_config
,
predictor_config
):
if
self
.
dynamic_shape
.
min_input_shape
!=
{}
and
(
program_config
.
ops
[
0
].
attrs
[
'strides'
]
==
[
1
,
2
]
or
program_config
.
ops
[
0
].
attrs
[
'strides'
]
==
[
2
,
2
]):
return
True
return
False
self
.
add_skip_case
(
teller4
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"It is not support that strides is not equal [1, 1] in dynamic mode for trt now."
)
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
()
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce_mean.py
浏览文件 @
211cf208
...
...
@@ -118,20 +118,21 @@ class TrtConvertReduceMeanTest(TrtLayerAutoScanTest):
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
(
1e-5
,
1e-5
)
# TODO(inference) : fix for ci
# self.trt_param.precision = paddle_infer.PrecisionType.Half
# yield self.create_inference_config(), generate_trt_nodes_num(
# attrs, False), (1e-4, 1e-4)
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-5
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
(
1e-5
,
1e-5
)
# TODO(inference) : fix for ci
# self.trt_param.precision = paddle_infer.PrecisionType.Half
# yield self.create_inference_config(), generate_trt_nodes_num(
pass
# attrs, True), (1e-4, 1e-4)
def
add_skip_trt_case
(
self
):
def
teller1
(
program_config
,
predictor_config
):
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_reduce_sum.py
浏览文件 @
211cf208
...
...
@@ -118,20 +118,21 @@ class TrtConvertReduceSumTest(TrtLayerAutoScanTest):
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
(
1e-5
,
1e-5
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
(
1e-5
,
1e-5
)
# TODO(inference) : fix for ci
# self.trt_param.precision = paddle_infer.PrecisionType.Half
# yield self.create_inference_config(), generate_trt_nodes_num(
# attrs, False), (1e-4, 1e-4)
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
(
1e-5
,
1e-5
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
(
1e-5
,
1e-5
)
# TODO(inference) : fix for ci
# self.trt_param.precision = paddle_infer.PrecisionType.Half
# yield self.create_inference_config(), generate_trt_nodes_num(
pass
# attrs, True), (1e-4, 1e-4)
def
add_skip_trt_case
(
self
):
def
teller1
(
program_config
,
predictor_config
):
...
...
python/paddle/fluid/tests/unittests/ir/inference/trt_layer_auto_scan_test.py
浏览文件 @
211cf208
...
...
@@ -122,7 +122,8 @@ class TrtLayerAutoScanTest(AutoScanTest):
"Output has diff between GPU and TensorRT. "
)
def
assert_op_size
(
self
,
trt_engine_num
,
paddle_op_num
):
last_passed_program
=
'transpose_flatten_concat_fuse_pass.pdmodel'
last_passed_program
=
os
.
path
.
join
(
self
.
trt_cache_dir
,
'transpose_flatten_concat_fuse_pass.pdmodel'
)
model_bytes
=
paddle
.
static
.
load_from_file
(
last_passed_program
)
pg
=
paddle
.
static
.
deserialize_program
(
model_bytes
)
main_block
=
pg
.
desc
.
block
(
0
)
...
...
@@ -179,7 +180,8 @@ class TrtLayerAutoScanTest(AutoScanTest):
def
run_test
(
self
,
quant
=
False
):
status
=
True
np
.
random
.
seed
(
int
(
1000
*
time
.
time
())
%
2
**
32
)
# Choose different tests by week
np
.
random
.
seed
(
int
(
time
.
strftime
(
"%W"
)))
run_flags
=
[]
for
prog_config
in
self
.
sample_program_configs
():
# In CI, only run 30% cases
...
...
@@ -283,4 +285,4 @@ class TrtLayerAutoScanTest(AutoScanTest):
self
.
success_log
(
'RUN '
+
str
(
prog_config
)
+
' vs '
+
self
.
inference_config_str
(
pred_config
))
#
self.assertTrue(status)
self
.
assertTrue
(
status
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录