Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
3d647b1c
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
3d647b1c
编写于
10月 20, 2022
作者:
G
Guanghua Yu
提交者:
GitHub
10月 20, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix problem of persistable var saving in QAT (#47203)
上级
c2d344dd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
22 addition
and
15 deletion
+22
-15
python/paddle/fluid/contrib/slim/quantization/imperative/qat.py
.../paddle/fluid/contrib/slim/quantization/imperative/qat.py
+3
-0
python/paddle/fluid/contrib/slim/quantization/post_training_quantization.py
...d/contrib/slim/quantization/post_training_quantization.py
+1
-15
python/paddle/fluid/contrib/slim/quantization/utils.py
python/paddle/fluid/contrib/slim/quantization/utils.py
+18
-0
未找到文件。
python/paddle/fluid/contrib/slim/quantization/imperative/qat.py
浏览文件 @
3d647b1c
...
...
@@ -32,6 +32,7 @@ from paddle.fluid.io import load_inference_model, save_inference_model
from
..quantization_pass
import
ReplaceFakeQuantDequantPass
,
QuantWeightPass
from
paddle.fluid.log_helper
import
get_logger
from
..
import
quantization_pass
from
..utils
import
move_persistable_var_to_global_block
from
.
import
utils
from
.
import
fuse_utils
...
...
@@ -550,6 +551,8 @@ class ImperativeQuantizeOutputs(object):
clip_extra
=
True
move_persistable_var_to_global_block
(
infer_program
)
save_inference_model
(
dirname
=
dirname
,
feeded_var_names
=
feed_target_names
,
target_vars
=
fetch_targets
,
...
...
python/paddle/fluid/contrib/slim/quantization/post_training_quantization.py
浏览文件 @
3d647b1c
...
...
@@ -449,21 +449,7 @@ class PostTrainingQuantization(object):
self
.
_collect_dynamic_quantize_op_threshold
(
self
.
_dynamic_quantize_op_type
)
# Move sub blocks persistable var to global block
global_block
=
self
.
_program
.
global_block
()
for
_op
in
global_block
.
ops
:
if
_op
.
type
==
"while"
:
_block_id
=
_op
.
attr
(
"sub_block"
).
id
_block
=
self
.
_program
.
block
(
_block_id
)
persistables
=
[]
for
_name
,
_var
in
_block
.
vars
.
items
():
if
_var
.
persistable
:
global_block
.
_clone_variable
(
_var
)
persistables
.
append
(
_name
)
for
_name
in
persistables
:
_block
.
_remove_var
(
_name
)
persistables
.
extend
(
_op
.
input
(
'X'
))
_op
.
desc
.
set_input
(
"X"
,
persistables
)
utils
.
move_persistable_var_to_global_block
(
self
.
_program
)
if
not
self
.
_return_graph
:
return
self
.
_program
...
...
python/paddle/fluid/contrib/slim/quantization/utils.py
浏览文件 @
3d647b1c
...
...
@@ -433,6 +433,24 @@ def calculate_quant_cos_error(orig_tensor, qdq_tensor):
return
cos_sim
def
move_persistable_var_to_global_block
(
program
):
# Move sub blocks persistable var to global block
global_block
=
program
.
global_block
()
for
_op
in
global_block
.
ops
:
if
_op
.
type
==
"while"
:
_block_id
=
_op
.
attr
(
"sub_block"
).
id
_block
=
program
.
block
(
_block_id
)
persistables
=
[]
for
_name
,
_var
in
_block
.
vars
.
items
():
if
_var
.
persistable
:
global_block
.
_clone_variable
(
_var
)
persistables
.
append
(
_name
)
for
_name
in
persistables
:
_block
.
_remove_var
(
_name
)
persistables
.
extend
(
_op
.
input
(
'X'
))
_op
.
desc
.
set_input
(
"X"
,
persistables
)
def
l2_loss
(
gt
,
pred
):
return
((
gt
-
pred
)
**
2
).
mean
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录