Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
14737e19
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
14737e19
编写于
2月 10, 2020
作者:
Z
Zhaolong Xing
提交者:
GitHub
2月 10, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[cherry-pick] [Refine Paddle-TRT INT8]: Support PaddleSlim's Resnet50 (#22485)
test=develop
上级
d2d4a02c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
40 addition
and
26 deletion
+40
-26
paddle/fluid/inference/analysis/ir_passes/tensorrt_subgraph_pass.cc
...id/inference/analysis/ir_passes/tensorrt_subgraph_pass.cc
+6
-3
paddle/fluid/inference/tensorrt/convert/pool2d_op.cc
paddle/fluid/inference/tensorrt/convert/pool2d_op.cc
+8
-8
paddle/fluid/inference/tensorrt/convert/softmax_op.cc
paddle/fluid/inference/tensorrt/convert/softmax_op.cc
+2
-6
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+20
-7
paddle/fluid/inference/tensorrt/op_teller.h
paddle/fluid/inference/tensorrt/op_teller.h
+4
-2
未找到文件。
paddle/fluid/inference/analysis/ir_passes/tensorrt_subgraph_pass.cc
浏览文件 @
14737e19
...
@@ -34,10 +34,13 @@ using framework::ir::Node;
...
@@ -34,10 +34,13 @@ using framework::ir::Node;
void
analysis
::
TensorRtSubgraphPass
::
ApplyImpl
(
void
analysis
::
TensorRtSubgraphPass
::
ApplyImpl
(
framework
::
ir
::
Graph
*
graph
)
const
{
framework
::
ir
::
Graph
*
graph
)
const
{
framework
::
ir
::
FusePassBase
::
Init
(
"tensorrt_subgraph_pass"
,
graph
);
framework
::
ir
::
FusePassBase
::
Init
(
"tensorrt_subgraph_pass"
,
graph
);
auto
enable_int8
=
Get
<
bool
>
(
"enable_int8"
);
auto
teller
=
[](
const
framework
::
ir
::
Node
*
node
)
{
auto
use_calib_mode
=
Get
<
bool
>
(
"use_calib_mode"
);
bool
no_calib_int8
=
enable_int8
&&
!
(
use_calib_mode
);
auto
teller
=
[
&
](
const
framework
::
ir
::
Node
*
node
)
{
if
(
!
node
->
IsOp
()
||
!
node
->
Op
())
return
false
;
if
(
!
node
->
IsOp
()
||
!
node
->
Op
())
return
false
;
return
tensorrt
::
OpTeller
::
Global
().
Tell
(
node
->
Op
()
->
Type
(),
*
node
->
Op
());
return
tensorrt
::
OpTeller
::
Global
().
Tell
(
node
->
Op
()
->
Type
(),
*
node
->
Op
(),
no_calib_int8
);
};
};
framework
::
ir
::
SubGraphFuser
fuser
(
framework
::
ir
::
SubGraphFuser
fuser
(
...
...
paddle/fluid/inference/tensorrt/convert/pool2d_op.cc
浏览文件 @
14737e19
...
@@ -98,6 +98,14 @@ class Pool2dOpConverter : public OpConverter {
...
@@ -98,6 +98,14 @@ class Pool2dOpConverter : public OpConverter {
nvinfer1
::
ILayer
*
layer
=
nullptr
;
nvinfer1
::
ILayer
*
layer
=
nullptr
;
if
(
op_desc
.
HasAttr
(
"enable_int8"
))
{
#if IS_TRT_VERSION_GE(5000)
CHECK
(
op_desc
.
HasAttr
(
"X_scale"
));
float
input_scale
=
boost
::
get
<
float
>
(
op_desc
.
GetAttr
(
"X_scale"
));
engine_
->
SetTensorDynamicRange
(
input1
,
input_scale
);
#endif
}
if
(
global_pooling
==
true
)
{
if
(
global_pooling
==
true
)
{
nv_ksize
.
d
[
0
]
=
input_shape
.
d
[
input_dims
-
2
];
nv_ksize
.
d
[
0
]
=
input_shape
.
d
[
input_dims
-
2
];
nv_ksize
.
d
[
1
]
=
input_shape
.
d
[
input_dims
-
1
];
nv_ksize
.
d
[
1
]
=
input_shape
.
d
[
input_dims
-
1
];
...
@@ -159,14 +167,6 @@ class Pool2dOpConverter : public OpConverter {
...
@@ -159,14 +167,6 @@ class Pool2dOpConverter : public OpConverter {
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
RreplenishLayerAndOutput
(
layer
,
"pool2d"
,
{
output_name
},
test_mode
);
RreplenishLayerAndOutput
(
layer
,
"pool2d"
,
{
output_name
},
test_mode
);
if
(
op_desc
.
HasAttr
(
"enable_int8"
))
{
#if IS_TRT_VERSION_GE(5000)
CHECK
(
op_desc
.
HasAttr
(
"X_scale"
));
float
input_scale
=
boost
::
get
<
float
>
(
op_desc
.
GetAttr
(
"X_scale"
));
engine_
->
SetTensorDynamicRange
(
input1
,
input_scale
);
#endif
}
}
}
};
};
...
...
paddle/fluid/inference/tensorrt/convert/softmax_op.cc
浏览文件 @
14737e19
...
@@ -36,12 +36,8 @@ class SoftMaxOpConverter : public OpConverter {
...
@@ -36,12 +36,8 @@ class SoftMaxOpConverter : public OpConverter {
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
RreplenishLayerAndOutput
(
layer
,
"softmax"
,
{
output_name
},
test_mode
);
RreplenishLayerAndOutput
(
layer
,
"softmax"
,
{
output_name
},
test_mode
);
if
(
op_desc
.
HasAttr
(
"out_scale"
))
{
// The trt will not run int for softmax.
#if IS_TRT_VERSION_GE(5000)
engine_
->
SetTensorDynamicRange
(
input1
,
1.0
);
float
out_scale
=
boost
::
get
<
float
>
(
op_desc
.
GetAttr
(
"out_scale"
));
engine_
->
SetTensorDynamicRange
(
layer
->
getOutput
(
0
),
out_scale
);
#endif
}
}
}
};
};
...
...
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
14737e19
...
@@ -26,9 +26,13 @@ struct SimpleOpTypeSetTeller : public Teller {
...
@@ -26,9 +26,13 @@ struct SimpleOpTypeSetTeller : public Teller {
#endif
#endif
}
}
bool
operator
()(
const
std
::
string
&
op_type
,
bool
operator
()(
const
std
::
string
&
op_type
,
const
framework
::
OpDesc
&
desc
,
const
framework
::
OpDesc
&
desc
)
override
{
bool
use_no_calib_int8
)
override
{
return
teller_set
.
count
(
op_type
);
if
(
use_no_calib_int8
)
{
return
int8_teller_set
.
count
(
op_type
);
}
else
{
return
teller_set
.
count
(
op_type
);
}
}
}
private:
private:
...
@@ -59,13 +63,22 @@ struct SimpleOpTypeSetTeller : public Teller {
...
@@ -59,13 +63,22 @@ struct SimpleOpTypeSetTeller : public Teller {
"layer_norm"
,
"layer_norm"
,
"multihead_matmul"
,
"multihead_matmul"
,
}};
}};
// use this set for no calib int8.
std
::
unordered_set
<
std
::
string
>
int8_teller_set
{
{
"mul"
,
"conv2d"
,
"pool2d"
,
"relu"
,
"depthwise_conv2d"
,
"softmax"
,
"batch_norm"
,
"elementwise_add"
,
"leaky_relu"
,
"fc"
}};
};
};
bool
OpTeller
::
Tell
(
const
std
::
string
&
op_type
,
const
framework
::
OpDesc
&
desc
)
{
bool
OpTeller
::
Tell
(
const
std
::
string
&
op_type
,
const
framework
::
OpDesc
&
desc
,
bool
use_no_calib_int8
)
{
// do not support the op which is labeled the `skip_quant`
// do not support the op which is labeled the `skip_quant`
if
(
desc
.
HasAttr
(
"op_namescope"
)
&&
if
((
desc
.
HasAttr
(
"namescope"
)
&&
boost
::
get
<
std
::
string
>
(
desc
.
GetAttr
(
"op_namescope"
))
==
"/skip_quant_2/"
)
boost
::
get
<
std
::
string
>
(
desc
.
GetAttr
(
"op_namescope"
))
==
"/skip_quant_2/"
)
||
desc
.
HasAttr
(
"skip_quant"
))
return
false
;
return
false
;
for
(
auto
&
teller
:
tellers_
)
{
for
(
auto
&
teller
:
tellers_
)
{
if
(
op_type
==
"pool2d"
||
op_type
==
"conv2d"
||
if
(
op_type
==
"pool2d"
||
op_type
==
"conv2d"
||
op_type
==
"depthwise_conv2d"
||
op_type
==
"conv2d_transpose"
)
{
op_type
==
"depthwise_conv2d"
||
op_type
==
"conv2d_transpose"
)
{
...
@@ -73,7 +86,7 @@ bool OpTeller::Tell(const std::string& op_type, const framework::OpDesc& desc) {
...
@@ -73,7 +86,7 @@ bool OpTeller::Tell(const std::string& op_type, const framework::OpDesc& desc) {
boost
::
get
<
std
::
vector
<
int
>>
(
desc
.
GetAttr
(
"paddings"
));
boost
::
get
<
std
::
vector
<
int
>>
(
desc
.
GetAttr
(
"paddings"
));
if
(
paddings
.
size
()
>
2
)
return
false
;
if
(
paddings
.
size
()
>
2
)
return
false
;
}
}
if
((
*
teller
)(
op_type
,
desc
))
return
true
;
if
((
*
teller
)(
op_type
,
desc
,
use_no_calib_int8
))
return
true
;
}
}
return
false
;
return
false
;
}
}
...
...
paddle/fluid/inference/tensorrt/op_teller.h
浏览文件 @
14737e19
...
@@ -31,7 +31,8 @@ namespace tensorrt {
...
@@ -31,7 +31,8 @@ namespace tensorrt {
*/
*/
struct
Teller
{
struct
Teller
{
virtual
bool
operator
()(
const
std
::
string
&
op_type
,
virtual
bool
operator
()(
const
std
::
string
&
op_type
,
const
framework
::
OpDesc
&
desc
)
=
0
;
const
framework
::
OpDesc
&
desc
,
bool
use_no_calib_int8
)
=
0
;
virtual
~
Teller
()
=
default
;
virtual
~
Teller
()
=
default
;
};
};
...
@@ -57,7 +58,8 @@ class OpTeller {
...
@@ -57,7 +58,8 @@ class OpTeller {
return
*
x
;
return
*
x
;
}
}
bool
Tell
(
const
std
::
string
&
op_type
,
const
framework
::
OpDesc
&
desc
);
bool
Tell
(
const
std
::
string
&
op_type
,
const
framework
::
OpDesc
&
desc
,
bool
use_no_calib_int8
=
false
);
private:
private:
OpTeller
();
OpTeller
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录