Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
bf983c2f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2307
Star
20932
Fork
5423
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
bf983c2f
编写于
9月 14, 2021
作者:
W
Wilber
提交者:
GitHub
9月 14, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
trt ut add serialize and deserialize (#35645)
上级
efeec79b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
62 addition
and
11 deletion
+62
-11
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+9
-0
paddle/scripts/paddle_build.sh
paddle/scripts/paddle_build.sh
+2
-0
python/paddle/fluid/tests/unittests/ir/inference/program_config.py
...ddle/fluid/tests/unittests/ir/inference/program_config.py
+2
-0
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d.py
...d/tests/unittests/ir/inference/test_trt_convert_conv2d.py
+6
-6
python/paddle/fluid/tests/unittests/ir/inference/trt_layer_auto_scan_test.py
.../tests/unittests/ir/inference/trt_layer_auto_scan_test.py
+43
-5
未找到文件。
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
bf983c2f
...
...
@@ -582,6 +582,15 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
<<
desc
.
Output
(
"Out"
).
size
()
<<
"."
;
return
false
;
}
auto
*
block
=
desc
.
Block
();
auto
*
x_var_desc
=
block
->
FindVar
(
desc
.
Input
(
"X"
)[
0
]);
auto
*
y_var_desc
=
block
->
FindVar
(
desc
.
Input
(
"Y"
)[
0
]);
const
auto
x_shape
=
x_var_desc
->
GetShape
();
const
auto
y_shape
=
y_var_desc
->
GetShape
();
if
(
x_shape
.
size
()
==
1
&&
y_shape
.
size
()
==
1
)
{
VLOG
(
3
)
<<
"Now trt may not support two 1d tensor elementwise op."
;
return
false
;
}
}
if
(
op_type
==
"stack"
)
{
...
...
paddle/scripts/paddle_build.sh
浏览文件 @
bf983c2f
...
...
@@ -1155,6 +1155,8 @@ function parallel_test_base_gpu() {
EOF
set
-x
# set trt_convert ut to run 30% cases.
export
TEST_NUM_PERCENT_CASES
=
0.3
precison_cases
=
""
bash
$PADDLE_ROOT
/tools/check_added_ut.sh
if
[
${
PRECISION_TEST
:-
OFF
}
==
"ON"
]
;
then
...
...
python/paddle/fluid/tests/unittests/ir/inference/program_config.py
浏览文件 @
bf983c2f
...
...
@@ -102,6 +102,8 @@ class ProgramConfig:
log_str
+=
' -- '
for
t
,
v
in
self
.
inputs
.
items
():
log_str
+=
'['
+
t
+
': '
+
str
(
v
)
+
']'
for
t
,
v
in
self
.
weights
.
items
():
log_str
+=
'['
+
t
+
': '
+
str
(
v
)
+
']'
return
log_str
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d.py
浏览文件 @
bf983c2f
...
...
@@ -163,10 +163,10 @@ class TrtConvertConv2dTest(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-2
attrs
,
False
),
(
1e-5
,
1e-5
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Int8
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
False
),
1e-1
attrs
,
False
),
(
1e-5
,
1e-5
)
# for dynamic_shape
generate_dynamic_shape
(
attrs
)
...
...
@@ -174,11 +174,11 @@ class TrtConvertConv2dTest(TrtLayerAutoScanTest):
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-2
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
(
1e-5
,
1e-5
)
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Int8
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
1e-1
yield
self
.
create_inference_config
(),
generate_trt_nodes_num
(
attrs
,
True
),
(
1e-5
,
1e-5
)
def
add_skip_trt_case
(
self
):
# TODO(wilber): This is just the example to illustrate the skip usage.
...
...
python/paddle/fluid/tests/unittests/ir/inference/trt_layer_auto_scan_test.py
浏览文件 @
bf983c2f
...
...
@@ -17,7 +17,10 @@ import unittest
import
itertools
import
abc
import
enum
import
sys
import
os
import
logging
import
time
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid.core
as
core
...
...
@@ -65,14 +68,18 @@ class TrtLayerAutoScanTest(AutoScanTest):
max_batch_size
=
4
,
min_subgraph_size
=
0
,
precision
=
paddle_infer
.
PrecisionType
.
Float32
,
use_static
=
Fals
e
,
use_static
=
Tru
e
,
use_calib_mode
=
False
)
self
.
dynamic_shape
=
self
.
DynamicShapeParam
({},
{},
{},
False
)
self
.
num_percent_cases
=
float
(
os
.
getenv
(
'TEST_NUM_PERCENT_CASES'
,
default
=
'1.0'
))
def
create_inference_config
(
self
,
use_trt
=
True
)
->
paddle_infer
.
Config
:
config
=
paddle_infer
.
Config
()
config
.
disable_glog_info
()
config
.
enable_use_gpu
(
100
,
0
)
config
.
set_optim_cache_dir
(
'trt_convert_cache_dir'
)
if
use_trt
:
config
.
switch_ir_debug
()
config
.
enable_tensorrt_engine
(
...
...
@@ -95,7 +102,8 @@ class TrtLayerAutoScanTest(AutoScanTest):
return
config
def
assert_tensors_near
(
self
,
threshold
:
float
,
atol
:
float
,
rtol
:
float
,
tensor
:
Dict
[
str
,
np
.
array
],
baseline
:
Dict
[
str
,
np
.
array
]):
for
key
,
arr
in
tensor
.
items
():
...
...
@@ -104,7 +112,7 @@ class TrtLayerAutoScanTest(AutoScanTest):
"The output shape of GPU and TensorRT are not equal."
)
self
.
assertTrue
(
np
.
allclose
(
baseline
[
key
],
arr
,
atol
=
threshold
),
baseline
[
key
],
arr
,
atol
=
atol
,
rtol
=
rtol
),
"Output has diff between GPU and TensorRT. "
)
def
assert_op_size
(
self
,
trt_engine_num
,
paddle_op_num
):
...
...
@@ -165,8 +173,21 @@ class TrtLayerAutoScanTest(AutoScanTest):
def
run_test
(
self
,
quant
=
False
):
status
=
True
np
.
random
.
seed
(
int
(
1000
*
time
.
time
())
%
2
**
32
)
run_flags
=
[]
for
prog_config
in
self
.
sample_program_configs
():
# In CI, only run 30% cases
if
np
.
random
.
rand
()
<
self
.
num_percent_cases
:
run_flags
.
append
(
True
)
else
:
run_flags
.
append
(
False
)
np
.
random
.
seed
(
1024
)
for
prog_config
,
run_flags
in
zip
(
self
.
sample_program_configs
(),
run_flags
):
if
not
run_flags
:
continue
# if program is invalid, we should skip that cases.
if
not
self
.
is_program_valid
(
prog_config
):
continue
...
...
@@ -194,6 +215,17 @@ class TrtLayerAutoScanTest(AutoScanTest):
for
pred_config
,
nodes_num
,
threshold
in
self
.
sample_predictor_configs
(
prog_config
):
if
isinstance
(
threshold
,
float
):
atol
=
threshold
rtol
=
1e-8
elif
isinstance
(
threshold
,
list
)
or
isinstance
(
threshold
,
tuple
):
atol
=
threshold
[
0
]
rtol
=
threshold
[
1
]
else
:
raise
NotImplementedError
if
quant
and
pred_config
.
tensorrt_precision_mode
(
)
!=
paddle_infer
.
PrecisionType
.
Int8
:
continue
...
...
@@ -218,12 +250,18 @@ class TrtLayerAutoScanTest(AutoScanTest):
break
try
:
pred_config_deserialize
=
paddle_infer
.
Config
(
pred_config
)
results
.
append
(
self
.
run_test_config
(
model
,
params
,
prog_config
,
pred_config
,
feed_data
))
self
.
assert_tensors_near
(
threshold
,
results
[
-
1
],
results
[
0
])
self
.
assert_tensors_near
(
atol
,
rtol
,
results
[
-
1
],
results
[
0
])
if
not
skip_flag
:
self
.
assert_op_size
(
nodes_num
[
0
],
nodes_num
[
1
])
# deserialize test
if
nodes_num
[
0
]
>
0
:
self
.
run_test_config
(
model
,
params
,
prog_config
,
pred_config_deserialize
,
feed_data
)
except
Exception
as
e
:
self
.
fail_log
(
str
(
prog_config
)
+
' vs '
+
self
.
inference_config_str
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录