Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
eb097d64
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
eb097d64
编写于
8月 28, 2020
作者:
J
joanna.wozna.intel
提交者:
GitHub
8月 28, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix int8 performace drop cpu_quantize_placement_pass (#26715)
* Fix cpu quantize placement pass * Include string lib
上级
02083bda
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
56 addition
and
27 deletion
+56
-27
paddle/fluid/framework/ir/graph_pattern_detector.cc
paddle/fluid/framework/ir/graph_pattern_detector.cc
+13
-0
paddle/fluid/framework/ir/graph_pattern_detector.h
paddle/fluid/framework/ir/graph_pattern_detector.h
+9
-0
paddle/fluid/framework/ir/mkldnn/cpu_quantize_placement_pass.cc
.../fluid/framework/ir/mkldnn/cpu_quantize_placement_pass.cc
+26
-23
paddle/fluid/framework/ir/mkldnn/cpu_quantize_placement_pass.h
...e/fluid/framework/ir/mkldnn/cpu_quantize_placement_pass.h
+6
-2
paddle/fluid/framework/ir/mkldnn/cpu_quantize_placement_pass_tester.cc
...framework/ir/mkldnn/cpu_quantize_placement_pass_tester.cc
+2
-2
未找到文件。
paddle/fluid/framework/ir/graph_pattern_detector.cc
浏览文件 @
eb097d64
...
...
@@ -1879,6 +1879,19 @@ PDNode *patterns::MultipleQuantize::operator()() {
return
prev_out
;
}
PDNode
*
patterns
::
QuantizePlacement
::
operator
()(
const
std
::
unordered_set
<
std
::
string
>
&
quantize_enabled_op_types
)
{
std
::
unordered_set
<
std
::
string
>
supported_op_types
=
std
::
unordered_set
<
std
::
string
>
({
"concat"
,
"conv2d"
,
"elementwise_add"
,
"fc"
,
"matmul"
,
"pool2d"
,
"prior_box"
,
"relu"
,
"reshape2"
,
"transpose2"
});
if
(
!
quantize_enabled_op_types
.
empty
())
{
supported_op_types
=
quantize_enabled_op_types
;
}
auto
*
op
=
pattern
->
NewNode
(
op_repr
())
->
assert_is_ops
(
supported_op_types
);
return
op
;
}
PDNode
*
patterns
::
MKLDNNInPlace
::
operator
()()
{
const
std
::
unordered_set
<
std
::
string
>
&
supported_op_types
=
{
"abs"
,
...
...
paddle/fluid/framework/ir/graph_pattern_detector.h
浏览文件 @
eb097d64
...
...
@@ -1120,6 +1120,15 @@ struct MultipleQuantize : public PatternBase {
PATTERN_DECL_NODE
(
prev_out
);
};
struct
QuantizePlacement
:
public
PatternBase
{
QuantizePlacement
(
PDPattern
*
pattern
,
const
std
::
string
&
name_scope
)
:
PatternBase
(
pattern
,
name_scope
,
"quantize_placement"
)
{}
PDNode
*
operator
()(
const
std
::
unordered_set
<
std
::
string
>&
quantize_enabled_op_types
);
PATTERN_DECL_NODE
(
op
);
};
// Pattern used for enforcing inplace computation for in-place computation
// supporting DNNL ops. softmax, batch_norm and layer_norm
struct
MKLDNNInPlace
:
public
PatternBase
{
...
...
paddle/fluid/framework/ir/mkldnn/cpu_quantize_placement_pass.cc
浏览文件 @
eb097d64
...
...
@@ -26,27 +26,33 @@ void CPUQuantizePlacementPass::ApplyImpl(ir::Graph* graph) const {
Get
<
std
::
unordered_set
<
int
>>
(
"quantize_excluded_op_ids"
);
const
auto
&
op_types_list
=
Get
<
std
::
unordered_set
<
std
::
string
>>
(
"quantize_enabled_op_types"
);
for
(
const
Node
*
n
:
graph
->
Nodes
())
{
if
(
n
->
IsOp
())
{
if
(
std
::
find
(
excluded_ids_list
.
begin
(),
excluded_ids_list
.
end
(),
n
->
id
())
!=
excluded_ids_list
.
end
())
continue
;
auto
*
op
=
n
->
Op
();
if
(
op
->
HasAttr
(
"mkldnn_data_type"
)
||
op
->
HasProtoAttr
(
"mkldnn_data_type"
))
{
// use_quantizer is no longer used
// assign value for compatibility
if
(
op
->
GetAttrIfExists
<
bool
>
(
"use_quantizer"
))
{
op
->
SetAttr
(
"mkldnn_data_type"
,
std
::
string
(
"int8"
));
}
if
(
std
::
find
(
op_types_list
.
begin
(),
op_types_list
.
end
(),
op
->
Type
())
!=
op_types_list
.
end
())
{
op
->
SetAttr
(
"mkldnn_data_type"
,
std
::
string
(
"int8"
));
op
->
SetAttr
(
"use_quantizer"
,
true
);
}
Init
(
name_scope_
,
graph
);
GraphPatternDetector
gpd
;
patterns
::
QuantizePlacement
quantize_placement_pattern
{
gpd
.
mutable_pattern
(),
"quantize_placement"
};
quantize_placement_pattern
(
op_types_list
);
auto
handler
=
[
&
](
const
GraphPatternDetector
::
subgraph_t
&
subgraph
,
Graph
*
g
)
{
GET_IR_NODE_FROM_SUBGRAPH
(
op
,
op
,
quantize_placement_pattern
);
if
(
std
::
find
(
excluded_ids_list
.
begin
(),
excluded_ids_list
.
end
(),
op
->
id
())
!=
excluded_ids_list
.
end
())
{
return
;
}
if
(
op
->
Op
()
->
HasAttr
(
"mkldnn_data_type"
)
||
op
->
Op
()
->
HasProtoAttr
(
"mkldnn_data_type"
))
{
// use_quantizer is no longer used
// assign value for compatibility
if
(
op
->
Op
()
->
GetAttrIfExists
<
bool
>
(
"use_quantizer"
))
{
op
->
Op
()
->
SetAttr
(
"mkldnn_data_type"
,
std
::
string
(
"int8"
));
}
op
->
Op
()
->
SetAttr
(
"mkldnn_data_type"
,
std
::
string
(
"int8"
));
op
->
Op
()
->
SetAttr
(
"use_quantizer"
,
true
);
}
}
};
gpd
(
graph
,
handler
);
}
}
// namespace ir
...
...
@@ -58,10 +64,7 @@ REGISTER_PASS(cpu_quantize_placement_pass,
// a vector of operator type names to be quantized ("conv2d" etc.)
// the second param is the default value for this vector
.
DefaultPassAttr
(
"quantize_enabled_op_types"
,
new
std
::
unordered_set
<
std
::
string
>
(
{
"concat"
,
"conv2d"
,
"elementwise_add"
,
"fc"
,
"matmul"
,
"pool2d"
,
"prior_box"
,
"relu"
,
"reshape2"
,
"transpose2"
}))
new
std
::
unordered_set
<
std
::
string
>
())
// a vector of operator ids that are to be excluded from quantization
// the second param is the default value for this vector
.
DefaultPassAttr
(
"quantize_excluded_op_ids"
,
new
std
::
unordered_set
<
int
>
());
paddle/fluid/framework/ir/mkldnn/cpu_quantize_placement_pass.h
浏览文件 @
eb097d64
...
...
@@ -15,7 +15,10 @@ limitations under the License. */
#pragma once
#include <memory>
#include "paddle/fluid/framework/ir/pass.h"
#include <string>
#include "paddle/fluid/framework/ir/fuse_pass_base.h"
#include "paddle/fluid/framework/ir/graph.h"
#include "paddle/fluid/framework/ir/graph_pattern_detector.h"
namespace
paddle
{
namespace
framework
{
...
...
@@ -23,9 +26,10 @@ namespace ir {
/*
* Specifies which operators should be quantized.
*/
class
CPUQuantizePlacementPass
:
public
Pass
{
class
CPUQuantizePlacementPass
:
public
FusePassBase
{
protected:
void
ApplyImpl
(
ir
::
Graph
*
graph
)
const
override
;
const
std
::
string
name_scope_
{
"cpu_quantize_placement_pass"
};
};
}
// namespace ir
...
...
paddle/fluid/framework/ir/mkldnn/cpu_quantize_placement_pass_tester.cc
浏览文件 @
eb097d64
...
...
@@ -131,8 +131,8 @@ TEST(QuantizerPlacementPass, enabled_conv_excluded_one) {
}
TEST
(
QuantizerPlacementPass
,
empty_list
)
{
//
no operator
quantized
MainTest
({},
{},
0
);
//
all operators
quantized
MainTest
({},
{},
6
);
}
TEST
(
QuantizerPlacementPass
,
default_attr_value
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录