Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
e68da187
P
Paddle
项目概览
Crayon鑫
/
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看板
未验证
提交
e68da187
编写于
4月 10, 2022
作者:
B
baoachun
提交者:
GitHub
4月 10, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add mkldnn int8 pass [step1] (#41579)
* add mkldnn int8 pass * add mkldnn int8 pass * update pass
上级
7a07c4a5
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
751 addition
and
0 deletion
+751
-0
paddle/fluid/framework/ir/CMakeLists.txt
paddle/fluid/framework/ir/CMakeLists.txt
+1
-0
paddle/fluid/framework/ir/mkldnn/mkldnn_pass_util.h
paddle/fluid/framework/ir/mkldnn/mkldnn_pass_util.h
+77
-0
paddle/fluid/framework/ir/mkldnn/quant_dequant_mkldnn_pass.cc
...le/fluid/framework/ir/mkldnn/quant_dequant_mkldnn_pass.cc
+582
-0
paddle/fluid/framework/ir/mkldnn/quant_dequant_mkldnn_pass.h
paddle/fluid/framework/ir/mkldnn/quant_dequant_mkldnn_pass.h
+91
-0
未找到文件。
paddle/fluid/framework/ir/CMakeLists.txt
浏览文件 @
e68da187
...
...
@@ -140,6 +140,7 @@ if(WITH_MKLDNN)
pass_library
(
batch_norm_act_fuse_pass inference DIR mkldnn
)
pass_library
(
multi_gru_fuse_pass inference DIR mkldnn
)
pass_library
(
multi_gru_seq_fuse_pass inference DIR mkldnn
)
pass_library
(
quant_dequant_mkldnn_pass inference DIR mkldnn
)
endif
()
if
(
WITH_IPU
)
...
...
paddle/fluid/framework/ir/mkldnn/mkldnn_pass_util.h
0 → 100644
浏览文件 @
e68da187
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <string>
#include "paddle/fluid/framework/ir/graph_helper.h"
namespace
paddle
{
namespace
framework
{
namespace
ir
{
static
void
SaveInfoInTheFirstOp
(
ir
::
Graph
*
graph
,
const
std
::
string
&
flag
,
const
std
::
string
&
key_suffix
,
const
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
float
>>&
info_map
)
{
VLOG
(
3
)
<<
"save variables in the first op's attr"
;
const
std
::
string
suffix
=
"_"
+
key_suffix
+
"_"
+
flag
;
for
(
auto
*
op_node
:
ir
::
TopologyVarientSort
(
*
graph
,
static_cast
<
ir
::
SortKind
>
(
0
)))
{
if
(
!
op_node
->
IsOp
()
||
op_node
->
Op
()
->
Type
()
==
"feed"
||
op_node
->
Op
()
->
Type
()
==
"fetch"
)
continue
;
op_node
->
Op
()
->
SetAttr
(
flag
,
true
);
for
(
auto
iter
=
info_map
.
begin
();
iter
!=
info_map
.
end
();
++
iter
)
{
op_node
->
Op
()
->
SetAttr
(
iter
->
first
+
suffix
,
iter
->
second
);
}
break
;
}
}
static
void
GetInfoFromTheFirstOp
(
ir
::
Graph
*
graph
,
const
std
::
string
&
flag
,
const
std
::
string
&
key_suffix
,
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
float
>>*
info_map
)
{
VLOG
(
3
)
<<
"get variables from the first op's attr"
;
const
std
::
string
suffix
=
"_"
+
key_suffix
+
"_"
+
flag
;
for
(
auto
*
op_node
:
ir
::
TopologyVarientSort
(
*
graph
,
static_cast
<
ir
::
SortKind
>
(
0
)))
{
if
(
!
op_node
->
IsOp
()
||
op_node
->
Op
()
->
Type
()
==
"feed"
||
op_node
->
Op
()
->
Type
()
==
"fetch"
)
continue
;
auto
*
op_desc
=
op_node
->
Op
();
if
(
op_desc
->
GetAttrIfExists
<
bool
>
(
flag
))
{
op_desc
->
RemoveAttr
(
flag
);
std
::
vector
<
std
::
string
>
attr_names
=
op_desc
->
AttrNames
();
for
(
auto
fake_name
:
attr_names
)
{
size_t
pos
=
fake_name
.
find
(
suffix
);
if
(
pos
!=
std
::
string
::
npos
)
{
std
::
string
name
=
fake_name
.
substr
(
0
,
pos
);
auto
scales_vector
=
BOOST_GET_CONST
(
std
::
vector
<
float
>
,
op_desc
->
GetAttr
(
fake_name
));
info_map
->
insert
(
std
::
make_pair
(
name
,
scales_vector
));
op_desc
->
RemoveAttr
(
fake_name
);
}
}
break
;
}
}
}
}
// namespace ir
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/ir/mkldnn/quant_dequant_mkldnn_pass.cc
0 → 100644
浏览文件 @
e68da187
此差异已折叠。
点击以展开。
paddle/fluid/framework/ir/mkldnn/quant_dequant_mkldnn_pass.h
0 → 100644
浏览文件 @
e68da187
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <string>
#include "paddle/fluid/framework/ir/fuse_pass_base.h"
namespace
paddle
{
namespace
framework
{
namespace
ir
{
class
QuantDequantMkldnnPass
:
public
FusePassBase
{
public:
QuantDequantMkldnnPass
()
=
default
;
virtual
~
QuantDequantMkldnnPass
()
{}
protected:
void
ApplyImpl
(
ir
::
Graph
*
graph
)
const
override
;
private:
void
MarkSkipQuantizedOps
(
ir
::
Graph
*
graph
,
const
std
::
unordered_set
<
std
::
string
>&
skip_ops
)
const
;
void
MarkSkipQuantizedPool2d
(
ir
::
Graph
*
graph
)
const
;
void
CollectInfoFromFake
(
ir
::
Graph
*
graph
,
Scope
*
scope
,
const
std
::
unordered_set
<
std
::
string
>&
fake_dequantize_types
,
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
float
>>*
weight_thresholds
)
const
;
void
CollectInputScalesFromFake
(
ir
::
Graph
*
graph
,
Scope
*
scope
,
const
std
::
unordered_set
<
std
::
string
>&
fake_quantize_types
,
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
float
>>*
var_quant_scales
)
const
;
void
CollectOutputScalesFromAttr
(
ir
::
Graph
*
graph
,
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
float
>>*
var_quant_scales
)
const
;
void
CollectFakeQuantizeOps
(
ir
::
Graph
*
graph
,
Node
*
op_node
,
std
::
unordered_set
<
const
Node
*>*
nodes2rm
)
const
;
void
CollectFakeDequantizeOps
(
ir
::
Graph
*
graph
,
Node
*
op_node
,
std
::
unordered_set
<
const
Node
*>*
nodes2rm
)
const
;
void
RemoveFakeOps
(
ir
::
Graph
*
graph
,
const
std
::
unordered_set
<
std
::
string
>&
fake_quantize_types
,
const
std
::
unordered_set
<
std
::
string
>&
fake_dequantize_types
,
const
std
::
unordered_set
<
std
::
string
>&
fake_quantize_dequantize_types
)
const
;
bool
IsInt8Weight
(
Node
*
op_node
,
Scope
*
scope
,
const
std
::
string
&
weight_name
)
const
;
void
TransposeWeight
(
Tensor
*
input
)
const
;
void
DequantizeOpWeights
(
Node
*
op_node
,
Scope
*
scope
,
const
std
::
string
&
weight_name
,
const
std
::
string
&
output_name
,
const
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
float
>>&
weight_thresholds
)
const
;
void
DequantizeWeights
(
ir
::
Graph
*
graph
,
Scope
*
scope
,
const
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
float
>>&
weight_thresholds
)
const
;
void
UpdateActivations
(
ir
::
Graph
*
graph
)
const
;
void
RemoveCtrlVars
(
ir
::
Graph
*
graph
)
const
;
};
}
// namespace ir
}
// namespace framework
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录