Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
dfa242e4
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看板
未验证
提交
dfa242e4
编写于
1月 18, 2022
作者:
J
JingZhuangzhuang
提交者:
GitHub
1月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix trt convert conv2d skip (#38999)
* fix trt convert conv2d skip * fix trt convert conv2d skip
上级
27f8460a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
41 addition
and
95 deletion
+41
-95
paddle/fluid/inference/tensorrt/convert/conv2d_op.cc
paddle/fluid/inference/tensorrt/convert/conv2d_op.cc
+8
-1
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+0
-30
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d.py
...d/tests/unittests/ir/inference/test_trt_convert_conv2d.py
+27
-49
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d_fusion.py
.../unittests/ir/inference/test_trt_convert_conv2d_fusion.py
+6
-15
未找到文件。
paddle/fluid/inference/tensorrt/convert/conv2d_op.cc
浏览文件 @
dfa242e4
...
...
@@ -76,12 +76,17 @@ void ConvertConv2d(TensorRTEngine* engine, const framework::proto::OpDesc& op,
BOOST_GET_CONST
(
std
::
vector
<
int
>
,
op_desc
.
GetAttr
(
"dilations"
));
const
std
::
vector
<
int
>
strides
=
BOOST_GET_CONST
(
std
::
vector
<
int
>
,
op_desc
.
GetAttr
(
"strides"
));
const
std
::
vector
<
int
>
paddings
=
std
::
vector
<
int
>
paddings
=
BOOST_GET_CONST
(
std
::
vector
<
int
>
,
op_desc
.
GetAttr
(
"paddings"
));
std
::
string
padding_algorithm
=
"EXPLICIT"
;
if
(
op_desc
.
HasAttr
(
"padding_algorithm"
))
padding_algorithm
=
BOOST_GET_CONST
(
std
::
string
,
op_desc
.
GetAttr
(
"padding_algorithm"
));
if
(
padding_algorithm
==
"VALID"
)
{
for
(
size_t
i
=
0
;
i
<
paddings
.
size
();
i
++
)
{
paddings
[
i
]
=
0
;
}
}
nvinfer1
::
DimsHW
nv_ksize
(
filter_h
,
filter_w
);
nvinfer1
::
DimsHW
nv_dilations
(
dilations
[
0
],
dilations
[
1
]);
...
...
@@ -139,6 +144,8 @@ void ConvertConv2d(TensorRTEngine* engine, const framework::proto::OpDesc& op,
layer
->
setNbGroups
(
groups
);
if
(
padding_algorithm
==
"SAME"
)
{
layer
->
setPaddingMode
(
nvinfer1
::
PaddingMode
::
kSAME_UPPER
);
nv_dilations
.
d
[
0
]
=
1
;
nv_dilations
.
d
[
1
]
=
1
;
}
// set dilations
fset_dilation
(
layer
,
nv_dilations
);
...
...
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
dfa242e4
...
...
@@ -271,36 +271,6 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
return
false
;
}
if
(
desc
.
HasAttr
(
"padding_algorithm"
))
{
auto
padding_algorithm
=
BOOST_GET_CONST
(
std
::
string
,
desc
.
GetAttr
(
"padding_algorithm"
));
if
(
padding_algorithm
==
"VALID"
)
{
return
false
;
}
if
(
padding_algorithm
==
"SAME"
)
{
if
(
desc
.
HasAttr
(
"dilations"
))
{
const
std
::
vector
<
int
>
dilations
=
BOOST_GET_CONST
(
std
::
vector
<
int
>
,
desc
.
GetAttr
(
"dilations"
));
if
(
dilations
[
0
]
!=
1
||
dilations
[
1
]
!=
1
)
{
VLOG
(
3
)
<<
"In Same mode, Dilations must be (1, 1) for "
"tensorRT, but given ("
<<
dilations
[
0
]
<<
", "
<<
dilations
[
1
]
<<
")"
;
return
false
;
}
}
}
}
if
(
use_no_calib_int8
)
{
if
(
desc
.
HasAttr
(
"padding_algorithm"
))
{
auto
padding_algorithm
=
BOOST_GET_CONST
(
std
::
string
,
desc
.
GetAttr
(
"padding_algorithm"
));
if
(
padding_algorithm
==
"SAME"
)
{
return
false
;
}
}
}
if
(
desc
.
HasAttr
(
"enable_int8"
))
{
if
(
op_type
==
"conv2d"
||
op_type
==
"conv2d_fusion"
)
{
if
(
!
desc
.
HasAttr
(
"Input_scale"
))
{
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d.py
浏览文件 @
dfa242e4
...
...
@@ -34,6 +34,12 @@ class TrtConvertConv2dTest(TrtLayerAutoScanTest):
1
]
*
attrs
[
0
][
'groups'
]:
return
False
ver
=
paddle_infer
.
get_trt_compile_version
()
if
ver
[
0
]
*
1000
+
ver
[
1
]
*
100
+
ver
[
0
]
*
10
<
7000
:
if
attrs
[
0
][
'padding_algorithm'
]
==
'SAME'
and
(
attrs
[
0
][
'strides'
][
0
]
>
1
or
attrs
[
0
][
'strides'
][
1
]
>
1
):
return
False
return
True
def
sample_program_configs
(
self
):
...
...
@@ -68,39 +74,27 @@ class TrtConvertConv2dTest(TrtLayerAutoScanTest):
"data_format"
:
data_format
},
{}]
if
padding_algorithm
==
'EXPLICIT'
:
ops_config
=
[{
"op_type"
:
"conv2d"
,
"op_inputs"
:
{
"Input"
:
[
"input_data"
],
"Filter"
:
[
"conv2d_weight"
]
},
"op_outputs"
:
{
"Output"
:
[
"conv_output_data"
]
},
"op_attrs"
:
dics
[
0
]
},
{
"op_type"
:
"relu"
,
"op_inputs"
:
{
"X"
:
[
"conv_output_data"
]
},
"op_outputs"
:
{
"Out"
:
[
"output_data"
]
},
"op_attrs"
:
dics
[
1
]
}]
else
:
ops_config
=
[{
"op_type"
:
"conv2d"
,
"op_inputs"
:
{
"Input"
:
[
"input_data"
],
"Filter"
:
[
"conv2d_weight"
]
},
"op_outputs"
:
{
"Output"
:
[
"output_data"
]
},
"op_attrs"
:
dics
[
0
]
}]
ops_config
=
[{
"op_type"
:
"conv2d"
,
"op_inputs"
:
{
"Input"
:
[
"input_data"
],
"Filter"
:
[
"conv2d_weight"
]
},
"op_outputs"
:
{
"Output"
:
[
"conv_output_data"
]
},
"op_attrs"
:
dics
[
0
]
},
{
"op_type"
:
"relu"
,
"op_inputs"
:
{
"X"
:
[
"conv_output_data"
]
},
"op_outputs"
:
{
"Out"
:
[
"output_data"
]
},
"op_attrs"
:
dics
[
1
]
}]
ops
=
self
.
generate_op_config
(
ops_config
)
program_config
=
ProgramConfig
(
...
...
@@ -188,7 +182,6 @@ class TrtConvertConv2dTest(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
,
...
...
@@ -200,25 +193,10 @@ class TrtConvertConv2dTest(TrtLayerAutoScanTest):
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
program_config
.
ops
[
0
].
attrs
[
'padding_algorithm'
]
==
"SAME"
or
program_config
.
ops
[
0
].
attrs
[
'padding_algorithm'
]
==
"VALID"
:
return
True
return
False
self
.
add_skip_case
(
teller1
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"When padding_algorithm is 'SAME' or 'VALID', Trt dose not support. In this case, trt build error is caused by scale op."
)
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
()
def
test_quant
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
(
quant
=
True
)
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_conv2d_fusion.py
浏览文件 @
dfa242e4
...
...
@@ -37,6 +37,12 @@ class TrtConvertConv2dFusionTest(TrtLayerAutoScanTest):
if
attrs
[
0
][
'groups'
]
<=
1
:
return
False
ver
=
paddle_infer
.
get_trt_compile_version
()
if
ver
[
0
]
*
1000
+
ver
[
1
]
*
100
+
ver
[
0
]
*
10
<
7000
:
if
attrs
[
0
][
'padding_algorithm'
]
==
'SAME'
and
(
attrs
[
0
][
'strides'
][
0
]
>
1
or
attrs
[
0
][
'strides'
][
1
]
>
1
):
return
False
return
True
def
sample_program_configs
(
self
):
...
...
@@ -184,25 +190,10 @@ class TrtConvertConv2dFusionTest(TrtLayerAutoScanTest):
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
program_config
.
ops
[
0
].
attrs
[
'padding_algorithm'
]
==
"SAME"
or
program_config
.
ops
[
0
].
attrs
[
'padding_algorithm'
]
==
"VALID"
:
return
True
return
False
self
.
add_skip_case
(
teller1
,
SkipReasons
.
TRT_NOT_IMPLEMENTED
,
"When padding_algorithm is 'SAME' or 'VALID', Trt dose not support. In this case, trt build error is caused by scale op."
)
def
test
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
()
def
test_quant
(
self
):
self
.
add_skip_trt_case
()
self
.
run_test
(
quant
=
True
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录