Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
03619037
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看板
未验证
提交
03619037
编写于
2月 01, 2023
作者:
G
Guanghua Yu
提交者:
GitHub
2月 01, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Skip the int input operator when inserting a quant node & fix some bug (#49926)
上级
3a73d348
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
53 addition
and
33 deletion
+53
-33
python/paddle/static/quantization/quantization_pass.py
python/paddle/static/quantization/quantization_pass.py
+53
-33
未找到文件。
python/paddle/static/quantization/quantization_pass.py
浏览文件 @
03619037
...
@@ -2890,6 +2890,19 @@ class AddQuantDequantPassV2:
...
@@ -2890,6 +2890,19 @@ class AddQuantDequantPassV2:
)
)
if
in_node
.
persistable
():
if
in_node
.
persistable
():
continue
continue
if
in_node
.
dtype
()
not
in
[
paddle
.
float64
,
paddle
.
float32
,
paddle
.
float16
,
]:
_logger
.
warning
(
"Since the {} contains an input of type INT, the quantization of this layer is skipped."
.
format
(
op_node
.
name
()
)
)
break
if
arg_name
in
dequantized_vars_map
:
if
arg_name
in
dequantized_vars_map
:
dequant_var_node
=
dequantized_vars_map
[
arg_name
]
dequant_var_node
=
dequantized_vars_map
[
arg_name
]
else
:
else
:
...
@@ -3137,7 +3150,7 @@ class QuantWeightPass:
...
@@ -3137,7 +3150,7 @@ class QuantWeightPass:
self
.
_save_int_weight
=
save_int_weight
self
.
_save_int_weight
=
save_int_weight
assert
self
.
_scope
is
not
None
,
"scope must not be None."
assert
self
.
_scope
is
not
None
,
"scope must not be None."
assert
self
.
_place
is
not
None
,
"place must not be None."
assert
self
.
_place
is
not
None
,
"place must not be None."
self
.
_quantized_ops
=
set
()
self
.
_quantized_ops
=
{}
def
apply
(
self
,
graph
):
def
apply
(
self
,
graph
):
assert
isinstance
(
assert
isinstance
(
...
@@ -3176,7 +3189,6 @@ class QuantWeightPass:
...
@@ -3176,7 +3189,6 @@ class QuantWeightPass:
quant_axis
=
_op
.
op
().
attr
(
"quant_axis"
)
quant_axis
=
_op
.
op
().
attr
(
"quant_axis"
)
bits_length
=
_op
.
op
().
attr
(
"bit_length"
)
bits_length
=
_op
.
op
().
attr
(
"bit_length"
)
if
x_node
.
name
()
not
in
self
.
_quantized_ops
:
if
x_node
.
name
()
not
in
self
.
_quantized_ops
:
self
.
_quantized_ops
.
add
(
x_node
.
name
())
quantized_param_v
=
utils
.
quant_tensor
(
quantized_param_v
=
utils
.
quant_tensor
(
param_v
.
copy
(),
param_v
.
copy
(),
scale_v
,
scale_v
,
...
@@ -3211,10 +3223,13 @@ class QuantWeightPass:
...
@@ -3211,10 +3223,13 @@ class QuantWeightPass:
self
.
_scope
,
self
.
_scope
,
self
.
_place
,
self
.
_place
,
)
)
self
.
_quantized_ops
[
x_node
.
name
()]
=
quant_weight_node
for
next_op_node
in
out_node
.
outputs
:
for
next_op_node
in
out_node
.
outputs
:
graph
.
update_input_link
(
graph
.
update_input_link
(
out_node
,
quant_weight_node
,
next_op_node
out_node
,
self
.
_quantized_ops
[
x_node
.
name
()],
next_op_node
,
)
)
graph
.
safe_remove_nodes
(
_op
)
graph
.
safe_remove_nodes
(
_op
)
self
.
_remove_unused_var_nodes
(
graph
)
self
.
_remove_unused_var_nodes
(
graph
)
...
@@ -3298,9 +3313,9 @@ class AddQuantDequantForInferencePass:
...
@@ -3298,9 +3313,9 @@ class AddQuantDequantForInferencePass:
op_node
.
outputs
,
var_name
op_node
.
outputs
,
var_name
)
)
if
out_node
.
dtype
()
not
in
[
if
out_node
.
dtype
()
not
in
[
core
.
VarDesc
.
VarType
.
FP
64
,
paddle
.
float
64
,
core
.
VarDesc
.
VarType
.
FP
32
,
paddle
.
float
32
,
core
.
VarDesc
.
VarType
.
FP
16
,
paddle
.
float
16
,
]:
]:
continue
continue
if
var_name
in
dequantized_vars_map
:
if
var_name
in
dequantized_vars_map
:
...
@@ -3319,7 +3334,10 @@ class AddQuantDequantForInferencePass:
...
@@ -3319,7 +3334,10 @@ class AddQuantDequantForInferencePass:
else
:
else
:
var_names
=
utils
.
_get_op_input_var_names
(
op_node
)
var_names
=
utils
.
_get_op_input_var_names
(
op_node
)
for
var_name
in
var_names
:
for
var_name
in
var_names
:
if
var_name
in
dequant_node_map
:
if
(
var_name
in
dequant_node_map
and
dequant_node_map
[
var_name
]
):
in_node
=
graph
.
_find_node_by_name
(
in_node
=
graph
.
_find_node_by_name
(
op_node
.
inputs
,
var_name
op_node
.
inputs
,
var_name
)
)
...
@@ -3345,19 +3363,16 @@ class AddQuantDequantForInferencePass:
...
@@ -3345,19 +3363,16 @@ class AddQuantDequantForInferencePass:
shape
=
var_node
.
shape
(),
shape
=
var_node
.
shape
(),
var_dtype
=
var_node
.
dtype
(),
var_dtype
=
var_node
.
dtype
(),
)
)
if
not
self
.
_calibration_range_dict
:
try
:
try
:
scale_var_node
=
graph
.
_find_node_by_name
(
scale_var_node
=
graph
.
_find_node_by_name
(
graph
.
all_persistable_nodes
(),
self
.
_scale_name
(
var_name
)
graph
.
all_persistable_nodes
(),
self
.
_scale_name
(
var_name
)
)
)
except
:
except
:
_logger
.
warning
(
if
(
"Cannot find the target node {} in scope, so skip adding quant node."
.
format
(
self
.
_calibration_range_dict
var_name
and
var_name
in
self
.
_calibration_range_dict
)
):
)
return
None
elif
var_name
in
self
.
_calibration_range_dict
:
scale_value
=
self
.
_calibration_range_dict
[
var_name
]
scale_value
=
self
.
_calibration_range_dict
[
var_name
]
scale_var_node
=
graph
.
create_persistable_node
(
scale_var_node
=
graph
.
create_persistable_node
(
name
=
self
.
_scale_name
(
var_name
),
name
=
self
.
_scale_name
(
var_name
),
...
@@ -3377,6 +3392,11 @@ class AddQuantDequantForInferencePass:
...
@@ -3377,6 +3392,11 @@ class AddQuantDequantForInferencePass:
self
.
_place
,
self
.
_place
,
)
)
else
:
else
:
_logger
.
warning
(
"Cannot find the target node {} in scope, so skip adding quant node."
.
format
(
var_name
)
)
return
None
return
None
try
:
try
:
zero_point_node
=
graph
.
_find_node_by_name
(
zero_point_node
=
graph
.
_find_node_by_name
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录