Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
d5081f7d
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
接近 2 年 前同步成功
通知
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看板
提交
d5081f7d
编写于
12月 03, 2019
作者:
C
ceci3
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add save_load for sanas
上级
477d503b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
7 deletion
+30
-7
paddleslim/common/sa_controller.py
paddleslim/common/sa_controller.py
+30
-7
未找到文件。
paddleslim/common/sa_controller.py
浏览文件 @
d5081f7d
...
@@ -17,6 +17,7 @@ import copy
...
@@ -17,6 +17,7 @@ import copy
import
math
import
math
import
logging
import
logging
import
numpy
as
np
import
numpy
as
np
import
json
from
.controller
import
EvolutionaryController
from
.controller
import
EvolutionaryController
from
log_helper
import
get_logger
from
log_helper
import
get_logger
...
@@ -34,7 +35,12 @@ class SAController(EvolutionaryController):
...
@@ -34,7 +35,12 @@ class SAController(EvolutionaryController):
init_temperature
=
1024
,
init_temperature
=
1024
,
max_try_times
=
None
,
max_try_times
=
None
,
init_tokens
=
None
,
init_tokens
=
None
,
constrain_func
=
None
):
reward
=-
1
,
max_reward
=-
1
,
iters
=
0
,
best_tokens
=
None
,
constrain_func
=
None
,
checkpoints
=
None
):
"""Initialize.
"""Initialize.
Args:
Args:
range_table(list<int>): Range table.
range_table(list<int>): Range table.
...
@@ -43,6 +49,7 @@ class SAController(EvolutionaryController):
...
@@ -43,6 +49,7 @@ class SAController(EvolutionaryController):
max_try_times(int): max try times before get legal tokens.
max_try_times(int): max try times before get legal tokens.
init_tokens(list<int>): The initial tokens.
init_tokens(list<int>): The initial tokens.
constrain_func(function): The callback function used to check whether the tokens meet constraint. None means there is no constraint. Default: None.
constrain_func(function): The callback function used to check whether the tokens meet constraint. None means there is no constraint. Default: None.
checkpoints(str): if checkpoint is None, donnot save checkpoints, else save scene to checkpoints file.
"""
"""
super
(
SAController
,
self
).
__init__
()
super
(
SAController
,
self
).
__init__
()
self
.
_range_table
=
range_table
self
.
_range_table
=
range_table
...
@@ -51,12 +58,13 @@ class SAController(EvolutionaryController):
...
@@ -51,12 +58,13 @@ class SAController(EvolutionaryController):
self
.
_reduce_rate
=
reduce_rate
self
.
_reduce_rate
=
reduce_rate
self
.
_init_temperature
=
init_temperature
self
.
_init_temperature
=
init_temperature
self
.
_max_try_times
=
max_try_times
self
.
_max_try_times
=
max_try_times
self
.
_reward
=
-
1
self
.
_reward
=
reward
self
.
_tokens
=
init_tokens
self
.
_tokens
=
init_tokens
self
.
_constrain_func
=
constrain_func
self
.
_constrain_func
=
constrain_func
self
.
_max_reward
=
-
1
self
.
_max_reward
=
max_reward
self
.
_best_tokens
=
None
self
.
_best_tokens
=
best_tokens
self
.
_iter
=
0
self
.
_iter
=
iters
self
.
_checkpoints
=
checkpoints
def
__getstate__
(
self
):
def
__getstate__
(
self
):
d
=
{}
d
=
{}
...
@@ -84,8 +92,12 @@ class SAController(EvolutionaryController):
...
@@ -84,8 +92,12 @@ class SAController(EvolutionaryController):
self
.
_max_reward
=
reward
self
.
_max_reward
=
reward
self
.
_best_tokens
=
tokens
self
.
_best_tokens
=
tokens
_logger
.
info
(
_logger
.
info
(
"Controller - iter: {}; current_reward: {}; current tokens: {}"
.
"Controller - iter: {}; best_reward: {}, best tokens: {}, current_reward: {}; current tokens: {}"
.
format
(
self
.
_iter
,
self
.
_reward
,
self
.
_tokens
))
format
(
self
.
_iter
,
self
.
_reward
,
self
.
_tokens
,
reward
,
tokens
))
if
self
.
_checkpoints
!=
None
:
self
.
_save_checkpoint
(
self
.
_checkpoints
)
def
next_tokens
(
self
,
control_token
=
None
):
def
next_tokens
(
self
,
control_token
=
None
):
"""
"""
...
@@ -113,3 +125,14 @@ class SAController(EvolutionaryController):
...
@@ -113,3 +125,14 @@ class SAController(EvolutionaryController):
else
:
else
:
break
break
return
new_tokens
return
new_tokens
def
_save_checkpoint
(
self
,
output_file
):
scene
=
dict
()
for
key
in
self
.
__dict__
():
if
key
in
[
'_checkpoints'
]:
continue
scene
[
key
]
=
self
.
__dict__
[
key
]
f
=
open
(
output_file
,
'w'
)
json
.
dump
(
scene
)
f
.
close
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录