Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a76b77a5
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
a76b77a5
编写于
11月 12, 2021
作者:
W
Wangzheee
提交者:
GitHub
11月 12, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add_fc_convert_layers_name (#37157)
上级
f584d378
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
4 deletion
+23
-4
paddle/fluid/inference/tensorrt/convert/fc_op.cc
paddle/fluid/inference/tensorrt/convert/fc_op.cc
+23
-4
未找到文件。
paddle/fluid/inference/tensorrt/convert/fc_op.cc
浏览文件 @
a76b77a5
...
@@ -34,8 +34,8 @@ namespace tensorrt {
...
@@ -34,8 +34,8 @@ namespace tensorrt {
class
FcOpConverter
:
public
OpConverter
{
class
FcOpConverter
:
public
OpConverter
{
public:
public:
nvinfer1
::
ILayer
*
reshape_before_fc
(
nvinfer1
::
ITensor
*
before_fc
,
nvinfer1
::
ILayer
*
reshape_before_fc
(
nvinfer1
::
ITensor
*
before_fc
,
nvinfer1
::
Dims
x_dim
,
nvinfer1
::
Dims
x_dim
,
int
x_num_col_dims
,
int
x_num_col_dims
)
{
std
::
string
output_name
)
{
// add shuffle before fc
// add shuffle before fc
nvinfer1
::
Dims
reshape_before_fc_dim
;
nvinfer1
::
Dims
reshape_before_fc_dim
;
reshape_before_fc_dim
.
nbDims
=
x_num_col_dims
+
3
;
reshape_before_fc_dim
.
nbDims
=
x_num_col_dims
+
3
;
...
@@ -57,6 +57,9 @@ class FcOpConverter : public OpConverter {
...
@@ -57,6 +57,9 @@ class FcOpConverter : public OpConverter {
auto
*
reshape_before_fc_layer
=
auto
*
reshape_before_fc_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Shuffle
,
*
before_fc
);
TRT_ENGINE_ADD_LAYER
(
engine_
,
Shuffle
,
*
before_fc
);
reshape_before_fc_layer
->
setReshapeDimensions
(
reshape_before_fc_dim
);
reshape_before_fc_layer
->
setReshapeDimensions
(
reshape_before_fc_dim
);
reshape_before_fc_layer
->
setName
(
(
"fc_op_reshape_before_fc: Shuffle (Output: "
+
output_name
+
")"
)
.
c_str
());
return
reshape_before_fc_layer
;
return
reshape_before_fc_layer
;
}
}
...
@@ -164,17 +167,25 @@ class FcOpConverter : public OpConverter {
...
@@ -164,17 +167,25 @@ class FcOpConverter : public OpConverter {
auto
*
fc_layer_int8
=
auto
*
fc_layer_int8
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Convolution
,
*
inputs
,
n_output
,
TRT_ENGINE_ADD_LAYER
(
engine_
,
Convolution
,
*
inputs
,
n_output
,
nv_ksize
,
weight
.
get
(),
bias
.
get
());
nv_ksize
,
weight
.
get
(),
bias
.
get
());
fc_layer_int8
->
setName
(
(
"fc_op_int8_conv1x1: Convolution (Output: "
+
output_name
+
")"
)
.
c_str
());
engine_
->
SetTensorDynamicRange
(
fc_layer_int8
->
getOutput
(
0
),
out_scale
);
engine_
->
SetTensorDynamicRange
(
fc_layer_int8
->
getOutput
(
0
),
out_scale
);
auto
*
fc_after_reshape_int8
=
reshape_after_fc
(
auto
*
fc_after_reshape_int8
=
reshape_after_fc
(
fc_layer_int8
->
getOutput
(
0
),
x_dim
,
x_num_col_dims
);
fc_layer_int8
->
getOutput
(
0
),
x_dim
,
x_num_col_dims
);
if
(
activation_type
==
"relu"
)
{
if
(
activation_type
==
"relu"
)
{
fc_after_reshape_int8
->
setName
(
(
"fc_op_int8_reshape_after_fc: Shuffle (Output: "
+
output_name
+
")"
)
.
c_str
());
nvinfer1
::
IActivationLayer
*
relu_layer_int8
=
TRT_ENGINE_ADD_LAYER
(
nvinfer1
::
IActivationLayer
*
relu_layer_int8
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Activation
,
*
(
fc_after_reshape_int8
->
getOutput
(
0
)),
engine_
,
Activation
,
*
(
fc_after_reshape_int8
->
getOutput
(
0
)),
nvinfer1
::
ActivationType
::
kRELU
);
nvinfer1
::
ActivationType
::
kRELU
);
RreplenishLayerAndOutput
(
relu_layer_int8
,
"relu_after_fc_shuffle"
,
RreplenishLayerAndOutput
(
relu_layer_int8
,
"relu_after_fc_shuffle"
,
{
output_name
},
test_mode
);
{
output_name
},
test_mode
);
}
else
{
}
else
{
RreplenishLayerAndOutput
(
fc_after_reshape_int8
,
"shuffle_after_fc"
,
RreplenishLayerAndOutput
(
fc_after_reshape_int8
,
"fc_op_int8_reshape_after_fc: Shuffle"
,
{
output_name
},
test_mode
);
{
output_name
},
test_mode
);
}
}
}
else
{
}
else
{
...
@@ -182,9 +193,16 @@ class FcOpConverter : public OpConverter {
...
@@ -182,9 +193,16 @@ class FcOpConverter : public OpConverter {
auto
*
fc_layer_float
=
auto
*
fc_layer_float
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
FullyConnected
,
*
inputs
,
n_output
,
TRT_ENGINE_ADD_LAYER
(
engine_
,
FullyConnected
,
*
inputs
,
n_output
,
weight
.
get
(),
bias
.
get
());
weight
.
get
(),
bias
.
get
());
fc_layer_float
->
setName
(
(
"fc_op_float: FullyConnected (Output: "
+
output_name
+
")"
)
.
c_str
());
auto
*
fc_after_reshape_float
=
reshape_after_fc
(
auto
*
fc_after_reshape_float
=
reshape_after_fc
(
fc_layer_float
->
getOutput
(
0
),
x_dim
,
x_num_col_dims
);
fc_layer_float
->
getOutput
(
0
),
x_dim
,
x_num_col_dims
);
if
(
activation_type
==
"relu"
)
{
if
(
activation_type
==
"relu"
)
{
fc_after_reshape_float
->
setName
(
(
"fc_op_float_reshape_after_fc: Shuffle (Output: "
+
output_name
+
")"
)
.
c_str
());
nvinfer1
::
IActivationLayer
*
relu_layer_float
=
TRT_ENGINE_ADD_LAYER
(
nvinfer1
::
IActivationLayer
*
relu_layer_float
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Activation
,
*
(
fc_after_reshape_float
->
getOutput
(
0
)),
engine_
,
Activation
,
*
(
fc_after_reshape_float
->
getOutput
(
0
)),
nvinfer1
::
ActivationType
::
kRELU
);
nvinfer1
::
ActivationType
::
kRELU
);
...
@@ -234,7 +252,8 @@ class FcOpConverter : public OpConverter {
...
@@ -234,7 +252,8 @@ class FcOpConverter : public OpConverter {
"converter expects x_dim.nbDims > x_num_col_dims, but "
"converter expects x_dim.nbDims > x_num_col_dims, but "
"x_dim.nbDims : %d, x_num_col_dims : %d."
,
"x_dim.nbDims : %d, x_num_col_dims : %d."
,
x_dim
.
nbDims
,
x_num_col_dims
));
x_dim
.
nbDims
,
x_num_col_dims
));
auto
*
reshape_before_fc_layer
=
reshape_before_fc
(
X
,
x_dim
,
x_num_col_dims
);
auto
*
reshape_before_fc_layer
=
reshape_before_fc
(
X
,
x_dim
,
x_num_col_dims
,
output_name
);
auto
*
reshape_itensor
=
reshape_before_fc_layer
->
getOutput
(
0
);
auto
*
reshape_itensor
=
reshape_before_fc_layer
->
getOutput
(
0
);
if
(
enable_int8
)
{
if
(
enable_int8
)
{
engine_
->
SetTensorDynamicRange
(
reshape_itensor
,
in_scale
);
engine_
->
SetTensorDynamicRange
(
reshape_itensor
,
in_scale
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录