Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f8681ffc
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
f8681ffc
编写于
6月 21, 2022
作者:
J
joanna.wozna.intel
提交者:
lidanqing-intel
6月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correct elementwise quantization (#43693)
上级
ae7192a8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
9 deletion
+41
-9
paddle/fluid/framework/ir/graph_pattern_detector.cc
paddle/fluid/framework/ir/graph_pattern_detector.cc
+14
-0
paddle/fluid/framework/ir/graph_pattern_detector.h
paddle/fluid/framework/ir/graph_pattern_detector.h
+13
-0
paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass.cc
paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass.cc
+14
-9
未找到文件。
paddle/fluid/framework/ir/graph_pattern_detector.cc
浏览文件 @
f8681ffc
...
@@ -2069,6 +2069,20 @@ PDNode *patterns::Elementwise::operator()(PDNode *x_var, PDNode *y_var,
...
@@ -2069,6 +2069,20 @@ PDNode *patterns::Elementwise::operator()(PDNode *x_var, PDNode *y_var,
return
out_var
;
return
out_var
;
}
}
PDNode
*
patterns
::
ElementwiseOp
::
operator
()(
const
std
::
string
elementwise_type
)
{
auto
elementwise_op
=
pattern
->
NewNode
(
elementwise_op_repr
())
->
assert_is_op
(
elementwise_type
);
auto
out_var
=
pattern
->
NewNode
(
elementwise_out_repr
())
->
AsOutput
()
->
assert_is_op_output
(
elementwise_type
,
"Out"
);
elementwise_op
->
LinksTo
({
out_var
});
return
out_var
;
}
PDNode
*
patterns
::
ResidualElementwise
::
operator
()(
PDNode
*
patterns
::
ResidualElementwise
::
operator
()(
PDNode
*
op_var
,
PDNode
*
residual_var
,
const
std
::
string
elementwise_type
,
PDNode
*
op_var
,
PDNode
*
residual_var
,
const
std
::
string
elementwise_type
,
bool
as_x
)
{
bool
as_x
)
{
...
...
paddle/fluid/framework/ir/graph_pattern_detector.h
浏览文件 @
f8681ffc
...
@@ -1071,6 +1071,19 @@ struct Elementwise : public PatternBase {
...
@@ -1071,6 +1071,19 @@ struct Elementwise : public PatternBase {
PATTERN_DECL_NODE
(
elementwise_out
);
PATTERN_DECL_NODE
(
elementwise_out
);
};
};
// Elementwise ops
// Forward pass for element-wise operators
// elementwise_out is the result of the operator
struct
ElementwiseOp
:
public
PatternBase
{
ElementwiseOp
(
PDPattern
*
pattern
,
const
std
::
string
&
name_scope
)
:
PatternBase
(
pattern
,
name_scope
,
"elementwise"
)
{}
PDNode
*
operator
()(
const
std
::
string
elementwise_type
);
PATTERN_DECL_NODE
(
elementwise_op
);
PATTERN_DECL_NODE
(
elementwise_out
);
};
// Residual Elementwise ops
// Residual Elementwise ops
// This pattern allows operator output to be X or Y
// This pattern allows operator output to be X or Y
// and residual data Y or X, based on as_x flag
// and residual data Y or X, based on as_x flag
...
...
paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass.cc
浏览文件 @
f8681ffc
...
@@ -819,12 +819,9 @@ void CPUQuantizePass::QuantizeElementwise(
...
@@ -819,12 +819,9 @@ void CPUQuantizePass::QuantizeElementwise(
Graph
*
graph
,
const
std
::
string
elementwise_type
)
const
{
Graph
*
graph
,
const
std
::
string
elementwise_type
)
const
{
GraphPatternDetector
gpd
;
GraphPatternDetector
gpd
;
auto
pattern
=
gpd
.
mutable_pattern
();
auto
pattern
=
gpd
.
mutable_pattern
();
patterns
::
Elementwise
elementwise_pattern
{
pattern
,
name_scope_
};
patterns
::
Elementwise
Op
elementwise_pattern
{
pattern
,
name_scope_
};
elementwise_pattern
(
elementwise_pattern
(
elementwise_type
);
pattern
->
NewNode
(
elementwise_pattern
.
elementwise_x_repr
()),
pattern
->
NewNode
(
elementwise_pattern
.
elementwise_y_repr
()),
elementwise_type
);
int
quantize_elementwise_count
=
0
;
int
quantize_elementwise_count
=
0
;
auto
handler
=
[
&
](
const
GraphPatternDetector
::
subgraph_t
&
subgraph
,
auto
handler
=
[
&
](
const
GraphPatternDetector
::
subgraph_t
&
subgraph
,
...
@@ -839,10 +836,18 @@ void CPUQuantizePass::QuantizeElementwise(
...
@@ -839,10 +836,18 @@ void CPUQuantizePass::QuantizeElementwise(
return
;
return
;
}
}
GET_IR_NODE_FROM_SUBGRAPH
(
elementwise_x
,
elementwise_x
,
auto
x_name
=
elementwise_op
->
Op
()
->
Input
(
"X"
);
elementwise_pattern
);
auto
y_name
=
elementwise_op
->
Op
()
->
Input
(
"Y"
);
GET_IR_NODE_FROM_SUBGRAPH
(
elementwise_y
,
elementwise_y
,
Node
*
elementwise_x
,
*
elementwise_y
;
elementwise_pattern
);
for
(
auto
&
input
:
elementwise_op
->
inputs
)
{
if
(
input
->
Name
()
==
x_name
[
0
])
elementwise_x
=
input
;
if
(
input
->
Name
()
==
y_name
[
0
])
elementwise_y
=
input
;
}
if
(
!
elementwise_x
||
!
elementwise_y
)
{
return
;
}
GET_IR_NODE_FROM_SUBGRAPH
(
elementwise_out
,
elementwise_out
,
GET_IR_NODE_FROM_SUBGRAPH
(
elementwise_out
,
elementwise_out
,
elementwise_pattern
);
elementwise_pattern
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录