Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
b6a33ceb
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看板
提交
b6a33ceb
编写于
11月 21, 2019
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix iter.
上级
c5d3eeb4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
13 addition
and
10 deletion
+13
-10
paddleslim/common/controller_client.py
paddleslim/common/controller_client.py
+3
-3
paddleslim/common/controller_server.py
paddleslim/common/controller_server.py
+3
-2
paddleslim/common/sa_controller.py
paddleslim/common/sa_controller.py
+4
-3
paddleslim/nas/sa_nas.py
paddleslim/nas/sa_nas.py
+2
-1
paddleslim/prune/auto_pruner.py
paddleslim/prune/auto_pruner.py
+1
-1
未找到文件。
paddleslim/common/controller_client.py
浏览文件 @
b6a33ceb
...
...
@@ -38,7 +38,7 @@ class ControllerClient(object):
self
.
socket_client
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
_key
=
key
def
update
(
self
,
tokens
,
reward
):
def
update
(
self
,
tokens
,
reward
,
iter
):
"""
Update the controller according to latest tokens and reward.
Args:
...
...
@@ -48,8 +48,8 @@ class ControllerClient(object):
socket_client
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
socket_client
.
connect
((
self
.
server_ip
,
self
.
server_port
))
tokens
=
","
.
join
([
str
(
token
)
for
token
in
tokens
])
socket_client
.
send
(
"{}
\t
{}
\t
{}
"
.
format
(
self
.
_key
,
tokens
,
reward
)
.
encode
())
socket_client
.
send
(
"{}
\t
{}
\t
{}
\t
{}"
.
format
(
self
.
_key
,
tokens
,
reward
,
iter
)
.
encode
())
response
=
socket_client
.
recv
(
1024
).
decode
()
if
response
.
strip
(
'
\n
'
).
split
(
"
\t
"
)
==
"ok"
:
return
True
...
...
paddleslim/common/controller_server.py
浏览文件 @
b6a33ceb
...
...
@@ -93,14 +93,15 @@ class ControllerServer(object):
_logger
.
debug
(
"recv message from {}: [{}]"
.
format
(
addr
,
message
))
messages
=
message
.
strip
(
'
\n
'
).
split
(
"
\t
"
)
if
(
len
(
messages
)
<
3
)
or
(
messages
[
0
]
!=
self
.
_key
):
if
(
len
(
messages
)
<
4
)
or
(
messages
[
0
]
!=
self
.
_key
):
_logger
.
debug
(
"recv noise from {}: [{}]"
.
format
(
addr
,
message
))
continue
tokens
=
messages
[
1
]
reward
=
messages
[
2
]
iter
=
messages
[
3
]
tokens
=
[
int
(
token
)
for
token
in
tokens
.
split
(
","
)]
self
.
_controller
.
update
(
tokens
,
float
(
reward
))
self
.
_controller
.
update
(
tokens
,
float
(
reward
)
,
iter
)
response
=
"ok"
conn
.
send
(
response
.
encode
())
_logger
.
debug
(
"send message to {}: [{}]"
.
format
(
addr
,
...
...
paddleslim/common/sa_controller.py
浏览文件 @
b6a33ceb
...
...
@@ -65,15 +65,16 @@ class SAController(EvolutionaryController):
d
[
key
]
=
self
.
__dict__
[
key
]
return
d
def
update
(
self
,
tokens
,
reward
):
def
update
(
self
,
tokens
,
reward
,
iter
):
"""
Update the controller according to latest tokens and reward.
Args:
tokens(list<int>): The tokens generated in last step.
reward(float): The reward of tokens.
"""
self
.
_iter
+=
1
temperature
=
self
.
_init_temperature
*
self
.
_reduce_rate
**
self
.
_iter
if
iter
>
self
.
_iter
:
self
.
_iter
=
iter
temperature
=
self
.
_init_temperature
*
self
.
_reduce_rate
**
self
.
_iter
if
(
reward
>
self
.
_reward
)
or
(
np
.
random
.
random
()
<=
math
.
exp
(
(
reward
-
self
.
_reward
)
/
temperature
)):
self
.
_reward
=
reward
...
...
paddleslim/nas/sa_nas.py
浏览文件 @
b6a33ceb
...
...
@@ -112,4 +112,5 @@ class SANAS(object):
bool: True means updating successfully while false means failure.
"""
self
.
_iter
+=
1
return
self
.
_controller_client
.
update
(
self
.
_current_tokens
,
score
)
return
self
.
_controller_client
.
update
(
self
.
_current_tokens
,
score
,
self
.
_iter
)
paddleslim/prune/auto_pruner.py
浏览文件 @
b6a33ceb
...
...
@@ -212,7 +212,7 @@ class AutoPruner(object):
self
.
_restore
(
self
.
_scope
)
self
.
_param_backup
=
{}
tokens
=
self
.
_ratios2tokens
(
self
.
_current_ratios
)
self
.
_controller_client
.
update
(
tokens
,
score
)
self
.
_controller_client
.
update
(
tokens
,
score
,
self
.
_iter
)
self
.
_iter
+=
1
def
_restore
(
self
,
scope
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录