Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
d4372a1e
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看板
未验证
提交
d4372a1e
编写于
7月 11, 2022
作者:
Z
Zuza Gawrysiak
提交者:
GitHub
7月 11, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Quantize shape operator (#44124)
* Quantize shape operator * Add shape op to propagate scales pass
上级
ab57cbf6
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
22 addition
and
9 deletion
+22
-9
paddle/fluid/framework/ir/graph_pattern_detector.h
paddle/fluid/framework/ir/graph_pattern_detector.h
+1
-1
paddle/fluid/framework/ir/mkldnn/compute_propagate_scales_mkldnn_pass.cc
...amework/ir/mkldnn/compute_propagate_scales_mkldnn_pass.cc
+2
-1
paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass.cc
paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass.cc
+1
-0
paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass_tester.cc
paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass_tester.cc
+7
-3
paddle/fluid/inference/api/mkldnn_quantizer.cc
paddle/fluid/inference/api/mkldnn_quantizer.cc
+1
-1
paddle/fluid/inference/api/mkldnn_quantizer_config.cc
paddle/fluid/inference/api/mkldnn_quantizer_config.cc
+7
-0
python/paddle/fluid/contrib/slim/quantization/quant2_int8_mkldnn_pass.py
...luid/contrib/slim/quantization/quant2_int8_mkldnn_pass.py
+3
-3
未找到文件。
paddle/fluid/framework/ir/graph_pattern_detector.h
浏览文件 @
d4372a1e
...
...
@@ -1056,7 +1056,7 @@ struct ResidualElementwise : public PatternBase {
};
// General struct for immutable ops:
// reshape, transpose, slice, nearest-interp
// reshape, transpose, slice,
shape,
nearest-interp
// Forward pass for no weights-op.
// immutable_out is a result of the operator.
struct
Immutable
:
public
PatternBase
{
...
...
paddle/fluid/framework/ir/mkldnn/compute_propagate_scales_mkldnn_pass.cc
浏览文件 @
d4372a1e
...
...
@@ -372,7 +372,7 @@ std::unordered_set<std::string> ComputePropagateScalesMkldnnPass::UpdateScales(
const
auto
op_name
=
op_node
->
Name
();
if
(
scale_immutable_ops
.
count
(
op_name
))
{
std
::
string
input_name
;
if
(
op_name
==
"slice"
)
{
if
(
op_name
==
"slice"
||
op_name
==
"shape"
)
{
input_name
=
op_node
->
Op
()
->
Input
(
"Input"
)[
0
];
}
else
{
input_name
=
op_node
->
Op
()
->
Input
(
"X"
)[
0
];
...
...
@@ -445,6 +445,7 @@ void ComputePropagateScalesMkldnnPass::ApplyImpl(ir::Graph* graph) const {
"reshape2"
,
"pool2d"
,
"slice"
,
"shape"
,
"nearest_interp"
,
"nearest_interp_v2"
};
...
...
paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass.cc
浏览文件 @
d4372a1e
...
...
@@ -1136,6 +1136,7 @@ void CPUQuantizePass::ApplyImpl(ir::Graph* graph) const {
QuantizeImmutable
(
graph
,
"reshape2"
,
"X"
);
QuantizeImmutable
(
graph
,
"transpose2"
,
"X"
);
QuantizeImmutable
(
graph
,
"slice"
,
"Input"
);
QuantizeImmutable
(
graph
,
"shape"
,
"Input"
);
QuantizeImmutable
(
graph
,
"nearest_interp"
,
"X"
);
QuantizeImmutable
(
graph
,
"nearest_interp_v2"
,
"X"
);
QuantizeElementwise
(
graph
,
"elementwise_add"
);
...
...
paddle/fluid/framework/ir/mkldnn/cpu_quantize_pass_tester.cc
浏览文件 @
d4372a1e
...
...
@@ -66,7 +66,7 @@ void SetOp(ProgramDesc* prog,
type
==
"nearest_interp"
||
type
==
"nearest_interp_v2"
)
{
op
->
SetInput
(
"X"
,
{
inputs
[
0
]});
op
->
SetOutput
(
"Out"
,
{
outputs
[
0
]});
}
else
if
(
type
==
"slice"
)
{
}
else
if
(
type
==
"slice"
||
type
==
"shape"
)
{
op
->
SetInput
(
"Input"
,
{
inputs
[
0
]});
op
->
SetOutput
(
"Out"
,
{
outputs
[
0
]});
}
else
if
(
type
==
"dropout"
)
{
...
...
@@ -550,8 +550,12 @@ void TestImmutableOpWithManyOutputs(const std::string tested_op) {
SCALE
*
S8_MAX
);
}
const
std
::
vector
<
std
::
string
>
immutables
=
{
"reshape2"
,
"transpose2"
,
"slice"
,
"nearest_interp"
,
"nearest_interp_v2"
};
const
std
::
vector
<
std
::
string
>
immutables
=
{
"reshape2"
,
"transpose2"
,
"slice"
,
"shape"
,
"nearest_interp"
,
"nearest_interp_v2"
};
class
TestImmutables
:
public
testing
::
TestWithParam
<
std
::
string
>
{};
...
...
paddle/fluid/inference/api/mkldnn_quantizer.cc
浏览文件 @
d4372a1e
...
...
@@ -142,7 +142,7 @@ void AnalysisPredictor::MkldnnQuantizer::CalculateScalesForOpOutputs(
scales_
[
var_name
]
=
scales_
[
input_var_name
];
}
compute_scale
=
false
;
}
else
if
(
op
->
Type
()
==
"slice"
)
{
}
else
if
(
op
->
Type
()
==
"slice"
||
op
->
Type
()
==
"shape"
)
{
auto
input_var_name
=
op
->
Input
(
"Input"
)[
0
];
PADDLE_ENFORCE_NE
(
scales_
.
find
(
input_var_name
),
scales_
.
end
(),
...
...
paddle/fluid/inference/api/mkldnn_quantizer_config.cc
浏览文件 @
d4372a1e
...
...
@@ -45,6 +45,9 @@ MkldnnQuantizerConfig::MkldnnQuantizerConfig() {
rules_
[
"slice"
][
"Input"
]
=
ScaleAlgo
::
KL
;
rules_
[
"slice"
][
"Out"
]
=
ScaleAlgo
::
NONE
;
rules_
[
"shape"
][
"Input"
]
=
ScaleAlgo
::
KL
;
rules_
[
"shape"
][
"Out"
]
=
ScaleAlgo
::
NONE
;
rules_
[
"fc"
][
"Input"
]
=
ScaleAlgo
::
KL
;
rules_
[
"fc"
][
"W"
]
=
ScaleAlgo
::
MAX_CH_T
;
rules_
[
"fc"
][
"Bias"
]
=
ScaleAlgo
::
NONE
;
...
...
@@ -62,6 +65,10 @@ MkldnnQuantizerConfig::MkldnnQuantizerConfig() {
rules_
[
"elementwise_mul"
][
"Y"
]
=
ScaleAlgo
::
KL
;
rules_
[
"elementwise_mul"
][
"Out"
]
=
ScaleAlgo
::
KL
;
rules_
[
"elementwise_sub"
][
"X"
]
=
ScaleAlgo
::
KL
;
rules_
[
"elementwise_sub"
][
"Y"
]
=
ScaleAlgo
::
KL
;
rules_
[
"elementwise_sub"
][
"Out"
]
=
ScaleAlgo
::
KL
;
// Reshape2 does not perform calculation on the data and shapes are not
// changed. Scale is calculated on input data and assign to Quantize and
// Dequantize scale.
...
...
python/paddle/fluid/contrib/slim/quantization/quant2_int8_mkldnn_pass.py
浏览文件 @
d4372a1e
...
...
@@ -63,8 +63,8 @@ class Quant2Int8MkldnnPass(object):
self
.
_op_ids_to_skip
=
_op_ids_to_skip
if
_op_ids_to_skip
is
not
None
else
set
(
[
-
1
])
self
.
_scale_immutable_ops
=
[
'transpose2'
,
'reshape2'
,
'pool2d'
,
'slice'
,
'
nearest_interp
'
,
'nearest_interp_v2'
'transpose2'
,
'reshape2'
,
'pool2d'
,
'slice'
,
'
shape
'
,
'nearest_interp
'
,
'nearest_interp
_v2'
]
self
.
_scale_ops
=
[
'scale'
]
self
.
_conv_ops
=
[
'conv2d'
,
'depthwise_conv2d'
]
...
...
@@ -247,7 +247,7 @@ class Quant2Int8MkldnnPass(object):
waiting_for_scale
=
set
()
for
op
in
graph
.
all_op_nodes
():
if
op
.
name
()
in
self
.
_scale_immutable_ops
:
if
op
.
name
()
==
'slice'
:
if
op
.
name
()
==
'slice'
or
op
.
name
()
==
'shape'
:
input_name
=
op
.
input
(
"Input"
)[
0
]
else
:
input_name
=
op
.
input
(
"X"
)[
0
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录