Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8fc9a19f
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看板
未验证
提交
8fc9a19f
编写于
3月 15, 2023
作者:
G
Guanghua Yu
提交者:
GitHub
3月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix quantization int8 weight save bug (#51500)
上级
c2b24166
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
7 addition
and
28 deletion
+7
-28
python/paddle/static/quantization/quantization_pass.py
python/paddle/static/quantization/quantization_pass.py
+7
-28
未找到文件。
python/paddle/static/quantization/quantization_pass.py
浏览文件 @
8fc9a19f
...
@@ -3150,7 +3150,7 @@ class QuantWeightPass:
...
@@ -3150,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
=
{}
self
.
_quantized_ops
=
set
()
def
apply
(
self
,
graph
):
def
apply
(
self
,
graph
):
assert
isinstance
(
assert
isinstance
(
...
@@ -3189,6 +3189,7 @@ class QuantWeightPass:
...
@@ -3189,6 +3189,7 @@ 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,30 +3212,10 @@ class QuantWeightPass:
...
@@ -3211,30 +3212,10 @@ class QuantWeightPass:
quantized_param_v
=
quantized_param_v
.
astype
(
quantized_param_v
=
quantized_param_v
.
astype
(
save_weight_dtype
save_weight_dtype
)
)
quant_weight_node
=
graph
.
create_persistable_node
(
self
.
_restore_var
(
x_node
.
name
(),
quantized_param_v
)
name
=
self
.
_quantized_var_name
(
x_node
.
name
()),
var_type
=
core
.
VarDesc
.
VarType
.
LOD_TENSOR
,
shape
=
x_node
.
shape
(),
var_dtype
=
core
.
VarDesc
.
VarType
.
INT8
,
)
_init_var_node
(
quant_weight_node
,
quantized_param_v
,
self
.
_scope
,
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
:
if
(
graph
.
update_input_link
(
out_node
,
x_node
,
next_op_node
)
self
.
_quantized_ops
[
x_node
.
name
()].
node
in
graph
.
graph
.
nodes
()
):
graph
.
update_input_link
(
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
)
...
@@ -3260,11 +3241,9 @@ class QuantWeightPass:
...
@@ -3260,11 +3241,9 @@ class QuantWeightPass:
def
_load_var
(
self
,
name
):
def
_load_var
(
self
,
name
):
return
np
.
array
(
self
.
_scope
.
find_var
(
name
).
get_tensor
())
return
np
.
array
(
self
.
_scope
.
find_var
(
name
).
get_tensor
())
def
_quantized_var_name
(
self
,
var_name
):
def
_restore_var
(
self
,
name
,
array
):
"""
tensor
=
self
.
_scope
.
find_var
(
name
).
get_tensor
()
Return quantized variable name for the input `var_name`.
tensor
.
set
(
array
,
self
.
_place
)
"""
return
"%s.quantized"
%
(
var_name
)
class
AddQuantDequantForInferencePass
:
class
AddQuantDequantForInferencePass
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录