Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7b5065ab
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
7b5065ab
编写于
4月 18, 2023
作者:
Z
zhouzj
提交者:
GitHub
4月 18, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the bug of quanting matmul (#52833)
上级
c3055d23
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
19 addition
and
23 deletion
+19
-23
python/paddle/static/quantization/post_training_quantization.py
.../paddle/static/quantization/post_training_quantization.py
+4
-0
python/paddle/static/quantization/quantization_pass.py
python/paddle/static/quantization/quantization_pass.py
+15
-23
未找到文件。
python/paddle/static/quantization/post_training_quantization.py
浏览文件 @
7b5065ab
...
...
@@ -701,6 +701,10 @@ class PostTrainingQuantization:
in
self
.
quant_config
.
activation_quant_operation_types
or
is_conv1d_quant
):
trans_y
=
(
op_type
==
'matmul_v2'
)
and
op
.
op
().
attr
(
'trans_y'
)
op_type
=
op_type
+
'_trans_y'
if
trans_y
else
op_type
collect_var_name
(
utils
.
_get_op_input_var_names
(
op
),
persistable_var_names
,
...
...
python/paddle/static/quantization/quantization_pass.py
浏览文件 @
7b5065ab
...
...
@@ -86,20 +86,6 @@ def _is_input_all_not_persistable(graph, op_node):
return
is_input_all_not_persistable
def
_check_grandchild_op_node
(
op_node
,
grandchild_op_name
):
'''
Check whether the fake_quant node has a grandchild op node named
grandchild_op_name.
'''
for
out1_var_node
in
op_node
.
outputs
:
for
out1_op_node
in
out1_var_node
.
outputs
:
for
out2_var_node
in
out1_op_node
.
outputs
:
for
out2_op_node
in
out2_var_node
.
outputs
:
if
out2_op_node
.
name
()
==
grandchild_op_name
:
return
True
return
False
class
QuantizationTransformPass
:
"""
Quantize the ops that have weights. Add quant and dequant ops for
...
...
@@ -360,9 +346,14 @@ class QuantizationTransformPass:
if
(
quant_type
==
'channel_wise_abs_max'
):
# Weight quantization
op_type
=
op
.
name
()
trans_y
=
(
op_type
==
'matmul_v2'
)
and
op
.
op
().
attr
(
'trans_y'
)
op_type
=
op_type
+
'_trans_y'
if
trans_y
else
op_type
quant_axis
=
(
1
if
op
.
name
()
in
utils
.
_channelwise_quant_axis1_ops
if
op
_type
in
utils
.
_channelwise_quant_axis1_ops
else
0
)
(
...
...
@@ -1184,13 +1175,9 @@ class QuantizationFreezePass:
# Quantize weight and restore
if
self
.
_round_type
==
'round'
:
param_v
=
self
.
_load_var
(
input_arg_name
)
if
any
(
_check_grandchild_op_node
(
op_node
,
op
)
for
op
in
utils
.
_channelwise_quant_axis1_ops
):
quant_axis
=
1
else
:
quant_axis
=
0
if
op_node
.
op
().
has_attr
(
'quant_axis'
):
quant_axis
=
op_node
.
op
().
attr
(
'quant_axis'
)
if
input_arg_name
not
in
self
.
_quantized_ops
:
self
.
_quantized_ops
.
add
(
input_arg_name
)
quantized_param_v
=
utils
.
quant_tensor
(
...
...
@@ -2605,9 +2592,14 @@ class QuantizationTransformPassV2(QuantizationTransformPass):
channel_wise
=
False
if
quant_type
==
'channel_wise_abs_max'
:
# Weight quantization
channel_wise
=
True
op_type
=
op
.
name
()
trans_y
=
(
op_type
==
'matmul_v2'
)
and
op
.
op
().
attr
(
'trans_y'
)
op_type
=
op_type
+
'_trans_y'
if
trans_y
else
op_type
quant_axis
=
(
1
if
op
.
name
()
in
utils
.
_channelwise_quant_axis1_ops
if
op
_type
in
utils
.
_channelwise_quant_axis1_ops
else
0
)
insert_quant_pass
=
InsertQuantizeLinear
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录