Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
e51d6f9d
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
大约 1 年 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e51d6f9d
编写于
11月 17, 2022
作者:
Z
zhouzj
提交者:
GitHub
11月 17, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Solve the OOM problem of ReconPTQ (#1523)
* Solve the 'oom' problem of QDrop. * Fix syntax.
上级
e94c69ce
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
20 addition
and
22 deletion
+20
-22
paddleslim/quant/reconstruction_quantization.py
paddleslim/quant/reconstruction_quantization.py
+20
-22
未找到文件。
paddleslim/quant/reconstruction_quantization.py
浏览文件 @
e51d6f9d
...
...
@@ -358,44 +358,42 @@ class ReconstructionQuanter(object):
def
_run
(
self
):
self
.
_preprocess
()
startup_program
=
paddle
.
static
.
Program
()
tmp_program
=
self
.
_student_program
.
clone
()
for
k
in
range
(
len
(
self
.
_regions
)):
region_
=
self
.
_regions
[
k
]
names
=
self
.
_region_weights_names
[
k
]
tmp_program
=
self
.
_student_program
.
clone
()
tmp_program
.
global_block
().
var
(
region_
[
0
]).
stop_gradient
=
True
quant_op_out_name
=
region_
[
1
]
with
paddle
.
static
.
program_guard
(
tmp_program
,
startup_program
):
names
=
self
.
_region_weights_names
[
k
]
_logger
.
info
(
f
"Current weights:
{
names
}
"
)
loss_function
=
ReconstructionQuanterLoss
(
program
=
tmp_program
,
weight_region_names
=
names
)
update_params
=
[
tmp_program
.
global_block
().
var
(
name
+
'.alpha'
)
for
name
in
names
]
with
paddle
.
static
.
program_guard
(
tmp_program
,
startup_program
):
student_var
=
tmp_program
.
global_block
().
var
(
quant_op_out_name
)
teacher_var
=
tmp_program
.
global_block
().
var
(
"teacher_"
+
quant_op_out_name
)
scheduler
=
paddle
.
optimizer
.
lr
.
CosineAnnealingDecay
(
learning_rate
=
20
,
eta_min
=
2
,
T_max
=
2000
,
verbose
=
True
,
)
total_loss
,
recon_loss
,
round_loss
=
loss_function
.
get_loss
(
student_var
,
teacher_var
,
scheduler
,
)
teacher_var
,
)
train_fetches_loss
=
{
"total_loss"
:
total_loss
,
"recon_loss"
:
recon_loss
,
"round_loss"
:
round_loss
,
}
optimizer
=
paddle
.
optimizer
.
Adam
(
learning_rate
=
self
.
_lr
)
optimizer
=
paddle
.
optimizer
.
Adam
(
learning_rate
=
self
.
_lr
,
parameters
=
update_params
)
optimizer
.
minimize
(
total_loss
)
self
.
_exe
.
run
(
startup_program
)
start_time
=
time
.
time
()
prev_start_time
=
start_time
loader
=
self
.
_data_loader
()
for
epoch
in
range
(
self
.
_epochs
):
for
i
,
data
in
(
enumerate
(
loader
)
if
(
isinstance
(
self
.
_data_loader
,
paddle
.
fluid
.
io
.
DataLoader
)
and
self
.
_data_loader
.
batch_size
==
1
)
else
enumerate
(
self
.
_data_loader
())):
for
i
,
data
in
(
enumerate
(
self
.
_data_loader
())):
prev_start_time
=
start_time
start_time
=
time
.
time
()
out
=
self
.
_exe
.
run
(
...
...
@@ -406,14 +404,14 @@ class ReconstructionQuanter(object):
],
return_numpy
=
True
,
)
_logger
.
info
(
"Iter {:d}, lr {}, total_loss {:.5f}, recon_loss {:.5f}, round_loss {:.5f}, time {:.5f}s"
.
format
(
epoch
,
self
.
_lr
,
"
Epoch {:d},
Iter {:d}, lr {}, total_loss {:.5f}, recon_loss {:.5f}, round_loss {:.5f}, time {:.5f}s"
.
format
(
epoch
,
i
,
self
.
_lr
,
np
.
mean
(
out
[
0
]),
np
.
mean
(
out
[
1
]),
np
.
mean
(
out
[
2
]),
start_time
-
prev_start_time
),
)
sys
.
stdout
.
flush
()
if
i
==
self
.
_num_iterations
:
if
i
+
1
==
self
.
_num_iterations
:
break
self
.
_update_scale
()
...
...
@@ -831,7 +829,7 @@ class ReconstructionQuanterLoss(object):
paddle
.
nn
.
functional
.
sigmoid
(
alpha_v
)
*
(
ZETA
-
GAMMA
)
+
GAMMA
,
0
,
1
)
def
get_loss
(
self
,
student_tensor
,
teacher_tensor
,
scheduler
):
def
get_loss
(
self
,
student_tensor
,
teacher_tensor
,
scheduler
=
None
):
if
self
.
rec_loss_type
==
'mse'
:
rec_loss
=
paddle
.
nn
.
functional
.
mse_loss
(
student_tensor
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录