Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
nni
Commits
c577553d
Unverified
Commit
c577553d
authored
May 05, 2019
by
SparkSnail
Committed by
GitHub
May 05, 2019
Browse files
Merge pull request #166 from Microsoft/master
merge master
parents
50326948
c7cc8db3
Changes
29
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
89 additions
and
32 deletions
+89
-32
src/sdk/pynni/nni/gridsearch_tuner/gridsearch_tuner.py
src/sdk/pynni/nni/gridsearch_tuner/gridsearch_tuner.py
+5
-0
src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py
src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py
+43
-9
src/sdk/pynni/nni/metis_tuner/metis_tuner.py
src/sdk/pynni/nni/metis_tuner/metis_tuner.py
+4
-1
src/sdk/pynni/nni/msg_dispatcher_base.py
src/sdk/pynni/nni/msg_dispatcher_base.py
+2
-0
src/webui/src/components/trial-detail/DefaultMetricPoint.tsx
src/webui/src/components/trial-detail/DefaultMetricPoint.tsx
+9
-7
tools/nni_cmd/common_utils.py
tools/nni_cmd/common_utils.py
+7
-4
tools/nni_cmd/launcher.py
tools/nni_cmd/launcher.py
+5
-2
tools/nni_cmd/updater.py
tools/nni_cmd/updater.py
+1
-1
tools/nni_gpu_tool/gpu_metrics_collector.py
tools/nni_gpu_tool/gpu_metrics_collector.py
+13
-8
No files found.
src/sdk/pynni/nni/gridsearch_tuner/gridsearch_tuner.py
View file @
c577553d
...
...
@@ -164,6 +164,11 @@ class GridSearchTuner(Tuner):
_completed_num
+=
1
assert
"parameter"
in
trial_info
_params
=
trial_info
[
"parameter"
]
assert
"value"
in
trial_info
_value
=
trial_info
[
'value'
]
if
not
_value
:
logger
.
info
(
"Useless trial data, value is %s, skip this trial data."
%
_value
)
continue
_params_tuple
=
convert_dict2tuple
(
_params
)
self
.
supplement_data
[
_params_tuple
]
=
True
logger
.
info
(
"Successfully import data to grid search tuner."
)
src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py
View file @
c577553d
...
...
@@ -139,19 +139,50 @@ def json2vals(in_x, vals, out_y, name=ROOT):
for
i
,
temp
in
enumerate
(
in_x
):
json2vals
(
temp
,
vals
[
i
],
out_y
,
name
+
'[%d]'
%
i
)
def
_add_index
(
in_x
,
parameter
):
"""
change parameters in NNI format to parameters in hyperopt format(This function also support nested dict.).
For example, receive parameters like:
{'dropout_rate': 0.8, 'conv_size': 3, 'hidden_size': 512}
Will change to format in hyperopt, like:
{'dropout_rate': 0.8, 'conv_size': {'_index': 1, '_value': 3}, 'hidden_size': {'_index': 1, '_value': 512}}
"""
if
TYPE
not
in
in_x
:
# if at the top level
out_y
=
dict
()
for
key
,
value
in
parameter
.
items
():
out_y
[
key
]
=
_add_index
(
in_x
[
key
],
value
)
return
out_y
elif
isinstance
(
in_x
,
dict
):
value_type
=
in_x
[
TYPE
]
value_format
=
in_x
[
VALUE
]
if
value_type
==
"choice"
:
choice_name
=
parameter
[
0
]
if
isinstance
(
parameter
,
list
)
else
parameter
for
pos
,
item
in
enumerate
(
value_format
):
# here value_format is a list
if
isinstance
(
item
,
list
):
# this format is ["choice_key", format_dict]
choice_key
=
item
[
0
]
choice_value_format
=
item
[
1
]
if
choice_key
==
choice_name
:
return
{
INDEX
:
pos
,
VALUE
:
[
choice_name
,
_add_index
(
choice_value_format
,
parameter
[
1
])]}
elif
choice_name
==
item
:
return
{
INDEX
:
pos
,
VALUE
:
item
}
else
:
return
parameter
def
_split_index
(
params
):
"""
Delete index infromation from params
"""
result
=
{}
for
key
in
params
:
if
isinstance
(
params
[
key
],
dict
):
value
=
params
[
key
][
VALUE
]
else
:
value
=
params
[
key
]
result
[
key
]
=
value
return
result
if
isinstance
(
params
,
list
):
return
[
params
[
0
],
_split_index
(
params
[
1
])]
elif
isinstance
(
params
,
dict
):
if
INDEX
in
params
.
keys
():
return
_split_index
(
params
[
VALUE
])
result
=
dict
()
for
key
in
params
:
result
[
key
]
=
_split_index
(
params
[
key
])
return
result
else
:
return
params
class
HyperoptTuner
(
Tuner
):
...
...
@@ -373,8 +404,11 @@ class HyperoptTuner(Tuner):
_params
=
trial_info
[
"parameter"
]
assert
"value"
in
trial_info
_value
=
trial_info
[
'value'
]
if
not
_value
:
logger
.
info
(
"Useless trial data, value is %s, skip this trial data."
%
_value
)
continue
self
.
supplement_data_num
+=
1
_parameter_id
=
'_'
.
join
([
"ImportData"
,
str
(
self
.
supplement_data_num
)])
self
.
total_data
[
_parameter_id
]
=
_params
self
.
total_data
[
_parameter_id
]
=
_add_index
(
in_x
=
self
.
json
,
parameter
=
_params
)
self
.
receive_trial_result
(
parameter_id
=
_parameter_id
,
parameters
=
_params
,
value
=
_value
)
logger
.
info
(
"Successfully import data to TPE/Anneal tuner."
)
src/sdk/pynni/nni/metis_tuner/metis_tuner.py
View file @
c577553d
...
...
@@ -65,7 +65,7 @@ class MetisTuner(Tuner):
https://www.microsoft.com/en-us/research/publication/metis-robustly-tuning-tail-latencies-cloud-systems/
"""
def
__init__
(
self
,
optimize_mode
=
"maximize"
,
no_resampling
=
True
,
no_candidates
=
Tru
e
,
def
__init__
(
self
,
optimize_mode
=
"maximize"
,
no_resampling
=
True
,
no_candidates
=
Fals
e
,
selection_num_starting_points
=
600
,
cold_start_num
=
10
,
exploration_probability
=
0.9
):
"""
Parameters
...
...
@@ -417,6 +417,9 @@ class MetisTuner(Tuner):
_params
=
trial_info
[
"parameter"
]
assert
"value"
in
trial_info
_value
=
trial_info
[
'value'
]
if
not
_value
:
logger
.
info
(
"Useless trial data, value is %s, skip this trial data."
%
_value
)
continue
self
.
supplement_data_num
+=
1
_parameter_id
=
'_'
.
join
([
"ImportData"
,
str
(
self
.
supplement_data_num
)])
self
.
total_data
.
append
(
_params
)
...
...
src/sdk/pynni/nni/msg_dispatcher_base.py
View file @
c577553d
...
...
@@ -77,6 +77,8 @@ class MsgDispatcherBase(Recoverable):
break
else
:
self
.
enqueue_command
(
command
,
data
)
if
self
.
worker_exceptions
:
break
_logger
.
info
(
'Dispatcher exiting...'
)
self
.
stopping
=
True
...
...
src/webui/src/components/trial-detail/DefaultMetricPoint.tsx
View file @
c577553d
...
...
@@ -30,13 +30,15 @@ class DefaultPoint extends React.Component<DefaultPointProps, DefaultPointState>
const
accSource
:
Array
<
DetailAccurPoint
>
=
[];
Object
.
keys
(
showSource
).
map
(
item
=>
{
const
temp
=
showSource
[
item
];
if
(
temp
.
status
===
'
SUCCEEDED
'
&&
temp
.
acc
.
default
!==
undefined
)
{
const
searchSpace
=
temp
.
description
.
parameters
;
accSource
.
push
({
acc
:
temp
.
acc
.
default
,
index
:
temp
.
sequenceId
,
searchSpace
:
JSON
.
stringify
(
searchSpace
)
});
if
(
temp
.
status
===
'
SUCCEEDED
'
&&
temp
.
acc
!==
undefined
)
{
if
(
temp
.
acc
.
default
!==
undefined
)
{
const
searchSpace
=
temp
.
description
.
parameters
;
accSource
.
push
({
acc
:
temp
.
acc
.
default
,
index
:
temp
.
sequenceId
,
searchSpace
:
JSON
.
stringify
(
searchSpace
)
});
}
}
});
const
resultList
:
Array
<
number
|
string
>
[]
=
[];
...
...
tools/nni_cmd/common_utils.py
View file @
c577553d
...
...
@@ -32,9 +32,12 @@ def get_yml_content(file_path):
try
:
with
open
(
file_path
,
'r'
)
as
file
:
return
yaml
.
load
(
file
,
Loader
=
yaml
.
Loader
)
except
TypeError
as
err
:
print
(
'Error: '
,
err
)
return
None
except
yaml
.
scanner
.
ScannerError
as
err
:
print_error
(
'yaml file format error!'
)
exit
(
1
)
except
Exception
as
exception
:
print_error
(
exception
)
exit
(
1
)
def
get_json_content
(
file_path
):
'''Load json file content'''
...
...
@@ -42,7 +45,7 @@ def get_json_content(file_path):
with
open
(
file_path
,
'r'
)
as
file
:
return
json
.
load
(
file
)
except
TypeError
as
err
:
print
(
'E
rror
: '
,
err
)
print
_e
rror
(
'json file format error!'
)
return
None
def
print_error
(
content
):
...
...
tools/nni_cmd/launcher.py
View file @
c577553d
...
...
@@ -113,8 +113,11 @@ def start_rest_server(port, platform, mode, config_file_name, experiment_id=None
entry_dir
=
get_nni_installation_path
()
entry_file
=
os
.
path
.
join
(
entry_dir
,
'main.js'
)
cmds
=
[
'node'
,
entry_file
,
'--port'
,
str
(
port
),
'--mode'
,
platform
,
'--start_mode'
,
mode
]
node_command
=
'node'
if
sys
.
platform
==
'win32'
:
node_command
=
os
.
path
.
join
(
entry_dir
[:
-
3
],
'Scripts'
,
'node.exe'
)
cmds
=
[
node_command
,
entry_file
,
'--port'
,
str
(
port
),
'--mode'
,
platform
,
'--start_mode'
,
mode
]
if
log_dir
is
not
None
:
cmds
+=
[
'--log_dir'
,
log_dir
]
if
log_level
is
not
None
:
...
...
tools/nni_cmd/updater.py
View file @
c577553d
...
...
@@ -136,7 +136,7 @@ def import_data(args):
args
.
port
=
get_experiment_port
(
args
)
if
args
.
port
is
not
None
:
if
import_data_to_restful_server
(
args
,
content
):
p
rint_normal
(
'Import data success!'
)
p
ass
else
:
print_error
(
'Import data failed!'
)
...
...
tools/nni_gpu_tool/gpu_metrics_collector.py
View file @
c577553d
...
...
@@ -25,15 +25,20 @@ import time
from
xml.dom
import
minidom
def
check_ready_to_run
():
#TODO check process in windows
if
sys
.
platform
==
'win32'
:
return
True
pgrep_output
=
subprocess
.
check_output
(
'pgrep -fx
\'
python3 -m nni_gpu_tool.gpu_metrics_collector
\'
'
,
shell
=
True
)
pidList
=
[]
for
pid
in
pgrep_output
.
splitlines
():
pidList
.
append
(
int
(
pid
))
pidList
.
remove
(
os
.
getpid
())
return
len
(
pidList
)
==
0
pgrep_output
=
subprocess
.
check_output
(
'wmic process where "CommandLine like
\'
%nni_gpu_tool.gpu_metrics_collector%
\'
and name like
\'
%python%
\'
" get processId'
)
pidList
=
pgrep_output
.
decode
(
"utf-8"
).
strip
().
split
()
pidList
.
pop
(
0
)
# remove the key word 'ProcessId'
pidList
=
list
(
map
(
int
,
pidList
))
pidList
.
remove
(
os
.
getpid
())
return
len
(
pidList
)
==
0
else
:
pgrep_output
=
subprocess
.
check_output
(
'pgrep -fx
\'
python3 -m nni_gpu_tool.gpu_metrics_collector
\'
'
,
shell
=
True
)
pidList
=
[]
for
pid
in
pgrep_output
.
splitlines
():
pidList
.
append
(
int
(
pid
))
pidList
.
remove
(
os
.
getpid
())
return
len
(
pidList
)
==
0
def
main
(
argv
):
metrics_output_dir
=
os
.
environ
[
'METRIC_OUTPUT_DIR'
]
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment