Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
7d0e73e8
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看板
提交
7d0e73e8
编写于
11月 21, 2019
作者:
L
lvmengsi
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'refine_nas' into 'develop'
Remove unnecessary arguments in sa nas API See merge request
!36
上级
2f91e8e2
9a1cf454
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
9 addition
and
39 deletion
+9
-39
demo/nas/sa_nas_mobilenetv2_cifar10.py
demo/nas/sa_nas_mobilenetv2_cifar10.py
+1
-1
paddleslim/nas/sa_nas.py
paddleslim/nas/sa_nas.py
+7
-36
tests/test_sa_nas.py
tests/test_sa_nas.py
+1
-2
未找到文件。
demo/nas/sa_nas_mobilenetv2_cifar10.py
浏览文件 @
7d0e73e8
...
...
@@ -39,7 +39,7 @@ def init_sa_nas(config):
search_steps
=
10000000
### start a server and a client
sa_nas
=
SANAS
(
config
,
max_flops
=
base_flops
,
search_steps
=
search_steps
)
sa_nas
=
SANAS
(
config
,
search_steps
=
search_steps
,
is_server
=
True
)
### start a client, server_addr is server address
#sa_nas = SANAS(config, max_flops = base_flops, server_addr=("10.255.125.38", 18607), search_steps = search_steps, is_server=False)
...
...
paddleslim/nas/sa_nas.py
浏览文件 @
7d0e73e8
...
...
@@ -33,40 +33,31 @@ _logger = get_logger(__name__, level=logging.INFO)
class
SANAS
(
object
):
def
__init__
(
self
,
configs
,
max_flops
=
None
,
max_latency
=
None
,
server_addr
=
(
""
,
0
),
server_addr
=
(
""
,
8881
),
init_temperature
=
100
,
reduce_rate
=
0.85
,
max_try_number
=
300
,
max_client_num
=
10
,
search_steps
=
300
,
key
=
"sa_nas"
,
is_server
=
Tru
e
):
is_server
=
Fals
e
):
"""
Search a group of ratios used to prune program.
Args:
configs(list<tuple>): A list of search space configuration with format (key, input_size, output_size, block_num).
`key` is the name of search space with data type str. `input_size` and `output_size` are
input size and output size of searched sub-network. `block_num` is the number of blocks in searched network.
max_flops(int): The max flops of searched network. None means no constrains. Default: None.
max_latency(float): The max latency of searched network. None means no constrains. Default: None.
server_addr(tuple): A tuple of server ip and server port for controller server.
init_temperature(float): The init temperature used in simulated annealing search strategy.
reduce_rate(float): The decay rate used in simulated annealing search strategy.
max_try_number(int): The max number of trying to generate legal tokens.
max_client_num(int): The max number of connections of controller server.
search_steps(int): The steps of searching.
key(str): Identity used in communication between controller server and clients.
is_server(bool): Whether current host is controller server. Default: True.
"""
if
not
is_server
:
assert
server_addr
[
0
]
!=
""
,
"You should set the IP and port of server when is_server is False."
self
.
_reduce_rate
=
reduce_rate
self
.
_init_temperature
=
init_temperature
self
.
_max_try_number
=
max_try_number
self
.
_is_server
=
is_server
self
.
_max_flops
=
max_flops
self
.
_max_latency
=
max_latency
self
.
_configs
=
configs
...
...
@@ -75,9 +66,7 @@ class SANAS(object):
init_tokens
=
self
.
_search_space
.
init_tokens
()
range_table
=
self
.
_search_space
.
range_table
()
range_table
=
(
len
(
range_table
)
*
[
0
],
range_table
)
print
range_table
_logger
.
info
(
"range table: {}"
.
format
(
range_table
))
controller
=
SAController
(
range_table
,
self
.
_reduce_rate
,
self
.
_init_temperature
,
self
.
_max_try_number
,
init_tokens
,
self
.
_constrain_func
)
...
...
@@ -85,7 +74,7 @@ class SANAS(object):
server_ip
,
server_port
=
server_addr
if
server_ip
==
None
or
server_ip
==
""
:
server_ip
=
self
.
_get_host_ip
()
max_client_num
=
100
self
.
_controller_server
=
ControllerServer
(
controller
=
controller
,
address
=
(
server_ip
,
server_port
),
...
...
@@ -107,24 +96,6 @@ class SANAS(object):
def
_get_host_ip
(
self
):
return
socket
.
gethostbyname
(
socket
.
gethostname
())
def
_constrain_func
(
self
,
tokens
):
if
(
self
.
_max_flops
is
None
)
and
(
self
.
_max_latency
is
None
):
return
True
archs
=
self
.
_search_space
.
token2arch
(
tokens
)
main_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
main_program
,
startup_program
):
i
=
0
for
config
,
arch
in
zip
(
self
.
_configs
,
archs
):
input_size
=
config
[
1
][
"input_size"
]
input
=
fluid
.
data
(
name
=
"data_{}"
.
format
(
i
),
shape
=
[
None
,
3
,
input_size
,
input_size
],
dtype
=
"float32"
)
output
=
arch
(
input
)
i
+=
1
return
flops
(
main_program
)
<
self
.
_max_flops
def
next_archs
(
self
):
"""
Get next network architectures.
...
...
tests/test_sa_nas.py
浏览文件 @
7d0e73e8
...
...
@@ -40,8 +40,7 @@ class TestSANAS(unittest.TestCase):
base_flops
=
flops
(
main_program
)
search_steps
=
3
sa_nas
=
SANAS
(
configs
,
max_flops
=
base_flops
,
search_steps
=
search_steps
)
sa_nas
=
SANAS
(
configs
,
search_steps
=
search_steps
,
is_server
=
True
)
for
i
in
range
(
search_steps
):
archs
=
sa_nas
.
next_archs
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录