Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
96e7d903
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
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看板
未验证
提交
96e7d903
编写于
8月 31, 2021
作者:
W
Wilber
提交者:
GitHub
8月 31, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update infer trt ut. (#35261)
上级
a2afcace
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
89 addition
and
22 deletion
+89
-22
python/paddle/fluid/tests/unittests/ir/inference/CMakeLists.txt
.../paddle/fluid/tests/unittests/ir/inference/CMakeLists.txt
+14
-1
python/paddle/fluid/tests/unittests/ir/inference/auto_scan_test.py
...ddle/fluid/tests/unittests/ir/inference/auto_scan_test.py
+27
-6
python/paddle/fluid/tests/unittests/ir/inference/program_config.py
...ddle/fluid/tests/unittests/ir/inference/program_config.py
+10
-8
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d.py
...d/tests/unittests/ir/inference/test_trt_convert_conv2d.py
+2
-2
python/paddle/fluid/tests/unittests/ir/inference/trt_layer_auto_scan_test.py
.../tests/unittests/ir/inference/trt_layer_auto_scan_test.py
+36
-5
未找到文件。
python/paddle/fluid/tests/unittests/ir/inference/CMakeLists.txt
浏览文件 @
96e7d903
...
...
@@ -3,15 +3,29 @@ string(REPLACE ".py" "" TEST_INFERENCE_IR_PASSES "${TEST_INFERENCE_IR_PASSES}")
file
(
GLOB TEST_TRT_IR_PASSES RELATIVE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
"
"test_trt_*.py"
)
string
(
REPLACE
".py"
""
TEST_TRT_IR_PASSES
"
${
TEST_TRT_IR_PASSES
}
"
)
file
(
GLOB TEST_TRT_CONVERTER RELATIVE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
"
"test_trt_convert_*.py"
)
string
(
REPLACE
".py"
""
TEST_TRT_CONVERTER
"
${
TEST_TRT_CONVERTER
}
"
)
foreach
(
TEST_INFERENCE_IR_PASS
${
TEST_TRT_IR_PASSES
}
)
list
(
REMOVE_ITEM TEST_INFERENCE_IR_PASSES
${
TEST_INFERENCE_IR_PASS
}
)
endforeach
()
if
(
WITH_GPU AND TENSORRT_FOUND
)
list
(
REMOVE_ITEM TEST_TRT_IR_PASSES test_trt_multiclass_nms_op
)
foreach
(
TRT_CONVERT
${
TEST_TRT_CONVERTER
}
)
list
(
REMOVE_ITEM TEST_TRT_IR_PASSES
${
TRT_CONVERT
}
)
endforeach
()
foreach
(
target
${
TEST_TRT_IR_PASSES
}
)
py_test_modules
(
${
target
}
MODULES
${
target
}
)
endforeach
()
foreach
(
target
${
TEST_TRT_CONVERTER
}
)
py_test_modules
(
${
target
}
MODULES
${
target
}
)
set_tests_properties
(
${
target
}
PROPERTIES TIMEOUT 100
)
endforeach
()
endif
()
file
(
GLOB TEST_MKLDNN_IR_PASSES RELATIVE
"
${
CMAKE_CURRENT_SOURCE_DIR
}
"
"test_mkldnn_*.py"
)
...
...
@@ -38,7 +52,6 @@ set_tests_properties(test_trt_dynamic_shape PROPERTIES TIMEOUT 120)
set_tests_properties
(
test_trt_pool_op PROPERTIES ENVIRONMENT FLAGS_fraction_of_gpu_memory_to_use=0.1 TIMEOUT 45
)
set_tests_properties
(
test_trt_reduce_mean_op PROPERTIES TIMEOUT 60
)
set_tests_properties
(
test_trt_tile_op PROPERTIES TIMEOUT 60
)
set_tests_properties
(
test_trt_convert_conv2d PROPERTIES TIMEOUT 100
)
set_tests_properties
(
test_trt_fc_fuse_quant_dequant_pass PROPERTIES TIMEOUT 100
)
set_tests_properties
(
test_trt_conv_quant_dequant_pass PROPERTIES TIMEOUT 100
)
set_tests_properties
(
test_trt_matmul_quant_dequant PROPERTIES TIMEOUT 100
)
...
...
python/paddle/fluid/tests/unittests/ir/inference/auto_scan_test.py
浏览文件 @
96e7d903
...
...
@@ -16,6 +16,7 @@ import numpy as np
import
unittest
import
abc
import
os
import
logging
import
paddle
import
paddle.fluid
as
fluid
from
paddle.fluid.initializer
import
NumpyArrayInitializer
...
...
@@ -25,6 +26,8 @@ import paddle.inference as paddle_infer
from
typing
import
Optional
,
List
,
Callable
,
Dict
,
Any
,
Set
from
program_config
import
TensorConfig
,
OpConfig
,
ProgramConfig
,
create_fake_model
,
create_quant_model
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
"%(message)s"
)
class
AutoScanTest
(
unittest
.
TestCase
):
def
__init__
(
self
,
methodName
=
'runTest'
):
...
...
@@ -53,7 +56,9 @@ class AutoScanTest(unittest.TestCase):
for
name
,
_
in
prog_config
.
inputs
.
items
():
input_tensor
=
predictor
.
get_input_handle
(
name
)
input_tensor
.
copy_from_cpu
(
feed_data
[
name
])
input_tensor
.
copy_from_cpu
(
feed_data
[
name
][
'shape'
])
if
feed_data
[
name
][
'lod'
]
is
not
None
:
input_tensor
.
set_lod
(
feed_data
[
name
][
'lod'
])
predictor
.
run
()
result
=
{}
for
out_name
,
o_name
in
zip
(
prog_config
.
outputs
,
...
...
@@ -97,22 +102,38 @@ class AutoScanTest(unittest.TestCase):
trt_engine_num
:
int
,
paddle_op_num
:
int
,
threshold
=
1e-5
,
quant
=
False
):
quant
=
False
,
error_msg
=
None
):
for
prog_config
in
self
.
sample_program_configs
():
model
,
params
=
create_fake_model
(
prog_config
)
if
quant
:
model
,
params
=
create_quant_model
(
model
,
params
)
for
batch_size
in
self
.
batch_size_set
:
feed_data
=
{}
log_str
=
' -- Input tensor info: '
for
name
,
tensor_config
in
prog_config
.
inputs
.
items
():
tensor_shape
=
tensor_config
.
shape
.
copy
()
tensor_shape
[
0
]
=
batch_size
feed_data
[
name
]
=
np
.
random
.
random
(
tensor_shape
).
astype
(
tensor_config
.
dtype
)
feed_data
[
name
]
=
{
'shape'
:
np
.
random
.
random
(
tensor_shape
).
astype
(
tensor_config
.
dtype
),
'lod'
:
tensor_config
.
lod
}
log_str
+=
str
({
name
:
{
'shape'
:
tensor_shape
,
'lod'
:
tensor_config
.
lod
}
})
logging
.
info
(
log_str
)
results
:
List
[
Dict
[
str
,
Tensor
]]
=
[]
for
pred_config
in
self
.
sample_predictor_configs
():
results
.
append
(
self
.
run_test_config
(
model
,
params
,
prog_config
,
pred_config
,
feed_data
))
self
.
assert_tensors_near
(
threshold
=
threshold
,
tensors
=
results
)
self
.
assert_op_size
(
trt_engine_num
,
paddle_op_num
)
try
:
self
.
assert_tensors_near
(
threshold
=
threshold
,
tensors
=
results
)
self
.
assert_op_size
(
trt_engine_num
,
paddle_op_num
)
except
:
logging
.
info
(
'ERROR OCCURED: '
+
error_msg
)
python/paddle/fluid/tests/unittests/ir/inference/program_config.py
浏览文件 @
96e7d903
...
...
@@ -37,7 +37,8 @@ class TensorConfig:
def
__init__
(
self
,
shape
:
[
List
[
int
]],
dtype
:
[
str
]
=
"float32"
,
data
:
Optional
[
np
.
array
]
=
None
):
data
:
Optional
[
np
.
array
]
=
None
,
lod
:
[
List
[
List
[
int
]]]
=
None
):
'''
shape: The shape of the tensor.
dtype: The data type of the tensor.
...
...
@@ -46,6 +47,7 @@ class TensorConfig:
self
.
shape
=
shape
self
.
dtype
=
dtype
self
.
data
=
data
self
.
lod
=
lod
class
OpConfig
:
...
...
@@ -186,13 +188,6 @@ def create_quant_model(model,
params_filename
=
params
)
graph
=
IrGraph
(
core
.
Graph
(
inference_program
.
desc
),
for_test
=
True
)
transform_pass
=
QuantizationTransformPass
(
scope
=
scope
,
place
=
place
,
activation_quantize_type
=
activation_quantize_type
,
weight_quantize_type
=
weight_quantize_type
)
transform_pass
.
apply
(
graph
)
out_scale_op_list
=
[
"conv2d"
,
"depthwise_conv2d"
,
...
...
@@ -299,6 +294,13 @@ def create_quant_model(model,
var_names
.
append
(
var_name
)
return
var_names
transform_pass
=
QuantizationTransformPass
(
scope
=
scope
,
place
=
place
,
activation_quantize_type
=
activation_quantize_type
,
weight_quantize_type
=
weight_quantize_type
)
transform_pass
.
apply
(
graph
)
op_nodes
=
graph
.
all_op_nodes
()
for
op_node
in
op_nodes
:
if
op_node
.
name
()
in
out_scale_op_list
:
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d.py
浏览文件 @
96e7d903
...
...
@@ -61,12 +61,12 @@ class TrtConvertConv2dTest(TrtLayerAutoScanTest):
self
.
program_outputs
=
[
"relu_output_data"
]
def
test_check_fp32_output
(
self
):
self
.
trt_param
.
precision
=
=
paddle_infer
.
PrecisionType
.
Float32
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Float32
# the fused tensorrt engine num is 1, and paddle op num is 2(feed and fetch).
self
.
run_test
(
trt_engine_num
=
1
,
paddle_op_num
=
2
,
threshold
=
1e-5
)
def
test_check_fp16_output
(
self
):
self
.
trt_param
.
precision
=
=
paddle_infer
.
PrecisionType
.
Half
self
.
trt_param
.
precision
=
paddle_infer
.
PrecisionType
.
Half
self
.
run_test
(
trt_engine_num
=
1
,
paddle_op_num
=
2
,
threshold
=
1e-2
)
def
test_dynamic_shape_fp32_check_output
(
self
):
...
...
python/paddle/fluid/tests/unittests/ir/inference/trt_layer_auto_scan_test.py
浏览文件 @
96e7d903
...
...
@@ -27,8 +27,7 @@ from typing import *
from
program_config
import
TensorConfig
,
OpConfig
,
ProgramConfig
from
auto_scan_test
import
AutoScanTest
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
"%(asctime)s - %(filename)s - %(message)s"
)
logging
.
basicConfig
(
level
=
logging
.
INFO
,
format
=
"%(message)s"
)
class
TrtLayerAutoScanTest
(
AutoScanTest
):
...
...
@@ -85,11 +84,19 @@ class TrtLayerAutoScanTest(AutoScanTest):
op_attr_list
=
[]
index
=
0
ops
=
[]
for
op_config
in
self
.
ops_config
:
log_str
=
'TEST_CASE: '
for
i
in
range
(
len
(
self
.
ops_config
)):
op_config
=
self
.
ops_config
[
i
]
op_attr
=
dict
(
zip
(
list
(
op_config
[
"op_attrs"
].
keys
()),
attrs_sample
[
index
:
index
+
len
(
op_config
[
"op_attrs"
])]))
if
i
!=
len
(
self
.
ops_config
)
-
1
:
log_str
+=
op_config
[
'op_type'
]
+
str
(
op_attr
)
+
' + '
else
:
log_str
+=
op_config
[
'op_type'
]
+
str
(
op_attr
)
op_attr_list
.
append
(
op_attr
)
index
=
index
+
len
(
op_config
[
"op_attrs"
])
ops
.
append
(
...
...
@@ -99,6 +106,7 @@ class TrtLayerAutoScanTest(AutoScanTest):
outputs
=
op_config
[
"op_outputs"
],
attrs
=
op_attr
))
logging
.
info
(
log_str
)
self
.
update_program_input_and_weight_with_attr
(
op_attr_list
)
# if no weight need to save, we create a place_holder to help seriazlie params.
if
not
self
.
program_weights
:
...
...
@@ -117,6 +125,7 @@ class TrtLayerAutoScanTest(AutoScanTest):
self
,
use_trt
=
True
,
precision_mode
=
paddle_infer
.
PrecisionType
.
Float32
):
config
=
paddle_infer
.
Config
()
config
.
disable_glog_info
()
config
.
enable_use_gpu
(
100
,
0
)
if
use_trt
:
config
.
switch_ir_debug
()
...
...
@@ -141,8 +150,30 @@ class TrtLayerAutoScanTest(AutoScanTest):
@
abc
.
abstractmethod
def
sample_predictor_configs
(
self
):
logging
.
info
(
'--------- gpu inference ---------'
)
def
precision_to_str
(
p
):
if
p
==
paddle_infer
.
PrecisionType
.
Float32
:
return
'float32'
elif
p
==
paddle_infer
.
PrecisionType
.
Half
:
return
'half'
elif
p
==
paddle_infer
.
PrecisionType
.
Int8
:
return
'int8'
else
:
raise
NotImplementedError
(
'not supported type.'
)
trt_log_str
=
''
if
len
(
self
.
dynamic_shape
.
min_input_shape
)
!=
0
and
self
.
dynamic_shape
.
min_input_shape
.
keys
(
)
==
self
.
dynamic_shape
.
max_input_shape
.
keys
(
)
and
self
.
dynamic_shape
.
min_input_shape
.
keys
(
)
==
self
.
dynamic_shape
.
opt_input_shape
.
keys
():
trt_log_str
+=
'dynamic_shape '
else
:
trt_log_str
+=
'static_shape '
trt_log_str
+=
precision_to_str
(
self
.
trt_param
.
precision
)
logging
.
info
(
' --------- gpu inference ---------'
)
yield
self
.
create_program_config
(
use_trt
=
False
)
logging
.
info
(
'--------- trt inference ---------'
)
logging
.
info
(
' --------- trt '
+
trt_log_str
+
' inference ---------'
)
yield
self
.
create_program_config
(
use_trt
=
True
,
precision_mode
=
self
.
trt_param
.
precision
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录