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
4ac1c3c5
"src/git@developer.sourcefind.cn:OpenDAS/nni.git" did not exist on "9e40371cb9a51c72c1472cf052bbf7cbaed8c345"
Unverified
Commit
4ac1c3c5
authored
May 27, 2019
by
QuanluZhang
Committed by
GitHub
May 27, 2019
Browse files
Fix smac import data (#1093)
fix smac import data
parent
d135d184
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
23 deletions
+91
-23
src/sdk/pynni/nni/batch_tuner/batch_tuner.py
src/sdk/pynni/nni/batch_tuner/batch_tuner.py
+37
-13
src/sdk/pynni/nni/smac_tuner/smac_tuner.py
src/sdk/pynni/nni/smac_tuner/smac_tuner.py
+51
-8
tools/nni_cmd/constants.py
tools/nni_cmd/constants.py
+3
-2
No files found.
src/sdk/pynni/nni/batch_tuner/batch_tuner.py
View file @
4ac1c3c5
...
@@ -22,11 +22,7 @@ batch_tuner.py including:
...
@@ -22,11 +22,7 @@ batch_tuner.py including:
class BatchTuner
class BatchTuner
"""
"""
import
copy
import
logging
from
enum
import
Enum
,
unique
import
random
import
numpy
as
np
import
nni
import
nni
from
nni.tuner
import
Tuner
from
nni.tuner
import
Tuner
...
@@ -35,6 +31,7 @@ TYPE = '_type'
...
@@ -35,6 +31,7 @@ TYPE = '_type'
CHOICE
=
'choice'
CHOICE
=
'choice'
VALUE
=
'_value'
VALUE
=
'_value'
logger
=
logging
.
getLogger
(
'batch_tuner_AutoML'
)
class
BatchTuner
(
Tuner
):
class
BatchTuner
(
Tuner
):
"""
"""
...
@@ -46,7 +43,7 @@ class BatchTuner(Tuner):
...
@@ -46,7 +43,7 @@ class BatchTuner(Tuner):
}
}
}
}
"""
"""
def
__init__
(
self
):
def
__init__
(
self
):
self
.
count
=
-
1
self
.
count
=
-
1
self
.
values
=
[]
self
.
values
=
[]
...
@@ -54,14 +51,14 @@ class BatchTuner(Tuner):
...
@@ -54,14 +51,14 @@ class BatchTuner(Tuner):
def
is_valid
(
self
,
search_space
):
def
is_valid
(
self
,
search_space
):
"""
"""
Check the search space is valid: only contains 'choice' type
Check the search space is valid: only contains 'choice' type
Parameters
Parameters
----------
----------
search_space : dict
search_space : dict
"""
"""
if
not
len
(
search_space
)
==
1
:
if
not
len
(
search_space
)
==
1
:
raise
RuntimeError
(
'BatchTuner only supprt one combined-paramreters key.'
)
raise
RuntimeError
(
'BatchTuner only supprt one combined-paramreters key.'
)
for
param
in
search_space
:
for
param
in
search_space
:
param_type
=
search_space
[
param
][
TYPE
]
param_type
=
search_space
[
param
][
TYPE
]
if
not
param_type
==
CHOICE
:
if
not
param_type
==
CHOICE
:
...
@@ -73,8 +70,8 @@ class BatchTuner(Tuner):
...
@@ -73,8 +70,8 @@ class BatchTuner(Tuner):
return
None
return
None
def
update_search_space
(
self
,
search_space
):
def
update_search_space
(
self
,
search_space
):
"""Update the search space
"""Update the search space
Parameters
Parameters
----------
----------
search_space : dict
search_space : dict
...
@@ -88,8 +85,8 @@ class BatchTuner(Tuner):
...
@@ -88,8 +85,8 @@ class BatchTuner(Tuner):
----------
----------
parameter_id : int
parameter_id : int
"""
"""
self
.
count
+=
1
self
.
count
+=
1
if
self
.
count
>
len
(
self
.
values
)
-
1
:
if
self
.
count
>
len
(
self
.
values
)
-
1
:
raise
nni
.
NoMoreTrialError
(
'no more parameters now.'
)
raise
nni
.
NoMoreTrialError
(
'no more parameters now.'
)
return
self
.
values
[
self
.
count
]
return
self
.
values
[
self
.
count
]
...
@@ -97,4 +94,31 @@ class BatchTuner(Tuner):
...
@@ -97,4 +94,31 @@ class BatchTuner(Tuner):
pass
pass
def
import_data
(
self
,
data
):
def
import_data
(
self
,
data
):
pass
"""Import additional data for tuning
Parameters
----------
data:
a list of dictionarys, each of which has at least two keys, 'parameter' and 'value'
"""
if
len
(
self
.
values
)
==
0
:
logger
.
info
(
"Search space has not been initialized, skip this data import"
)
return
self
.
values
=
self
.
values
[(
self
.
count
+
1
):]
self
.
count
=
-
1
_completed_num
=
0
for
trial_info
in
data
:
logger
.
info
(
"Importing data, current processing progress %s / %s"
,
_completed_num
,
len
(
data
))
# simply validate data format
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
_completed_num
+=
1
if
_params
in
self
.
values
:
self
.
values
.
remove
(
_params
)
logger
.
info
(
"Successfully import data to batch tuner, total data: %d, imported data: %d."
,
len
(
data
),
_completed_num
)
src/sdk/pynni/nni/smac_tuner/smac_tuner.py
View file @
4ac1c3c5
...
@@ -21,21 +21,21 @@
...
@@ -21,21 +21,21 @@
smac_tuner.py
smac_tuner.py
"""
"""
from
nni.tuner
import
Tuner
from
nni.utils
import
OptimizeMode
,
extract_scalar_reward
import
sys
import
sys
import
logging
import
logging
import
numpy
as
np
import
numpy
as
np
import
json_tricks
from
enum
import
Enum
,
unique
from
nni.tuner
import
Tuner
from
.convert_ss_to_scenario
import
generate_scenario
from
nni.utils
import
OptimizeMode
,
extract_scalar_reward
from
smac.utils.io.cmd_reader
import
CMDReader
from
smac.utils.io.cmd_reader
import
CMDReader
from
smac.scenario.scenario
import
Scenario
from
smac.scenario.scenario
import
Scenario
from
smac.facade.smac_facade
import
SMAC
from
smac.facade.smac_facade
import
SMAC
from
smac.facade.roar_facade
import
ROAR
from
smac.facade.roar_facade
import
ROAR
from
smac.facade.epils_facade
import
EPILS
from
smac.facade.epils_facade
import
EPILS
from
ConfigSpaceNNI
import
Configuration
from
.convert_ss_to_scenario
import
generate_scenario
class
SMACTuner
(
Tuner
):
class
SMACTuner
(
Tuner
):
...
@@ -57,6 +57,7 @@ class SMACTuner(Tuner):
...
@@ -57,6 +57,7 @@ class SMACTuner(Tuner):
self
.
update_ss_done
=
False
self
.
update_ss_done
=
False
self
.
loguniform_key
=
set
()
self
.
loguniform_key
=
set
()
self
.
categorical_dict
=
{}
self
.
categorical_dict
=
{}
self
.
cs
=
None
def
_main_cli
(
self
):
def
_main_cli
(
self
):
"""Main function of SMAC for CLI interface
"""Main function of SMAC for CLI interface
...
@@ -66,7 +67,7 @@ class SMACTuner(Tuner):
...
@@ -66,7 +67,7 @@ class SMACTuner(Tuner):
instance
instance
optimizer
optimizer
"""
"""
self
.
logger
.
info
(
"SMAC call: %s"
%
(
" "
.
join
(
sys
.
argv
))
)
self
.
logger
.
info
(
"SMAC call: %s"
,
" "
.
join
(
sys
.
argv
))
cmd_reader
=
CMDReader
()
cmd_reader
=
CMDReader
()
args
,
_
=
cmd_reader
.
read_cmd
()
args
,
_
=
cmd_reader
.
read_cmd
()
...
@@ -95,6 +96,7 @@ class SMACTuner(Tuner):
...
@@ -95,6 +96,7 @@ class SMACTuner(Tuner):
# Create scenario-object
# Create scenario-object
scen
=
Scenario
(
args
.
scenario_file
,
[])
scen
=
Scenario
(
args
.
scenario_file
,
[])
self
.
cs
=
scen
.
cs
if
args
.
mode
==
"SMAC"
:
if
args
.
mode
==
"SMAC"
:
optimizer
=
SMAC
(
optimizer
=
SMAC
(
...
@@ -258,4 +260,45 @@ class SMACTuner(Tuner):
...
@@ -258,4 +260,45 @@ class SMACTuner(Tuner):
return
params
return
params
def
import_data
(
self
,
data
):
def
import_data
(
self
,
data
):
pass
"""Import additional data for tuning
Parameters
----------
data:
a list of dictionarys, each of which has at least two keys, 'parameter' and 'value'
"""
_completed_num
=
0
for
trial_info
in
data
:
self
.
logger
.
info
(
"Importing data, current processing progress %s / %s"
,
_completed_num
,
len
(
data
))
# simply validate data format
assert
"parameter"
in
trial_info
_params
=
trial_info
[
"parameter"
]
assert
"value"
in
trial_info
_value
=
trial_info
[
'value'
]
if
not
_value
:
self
.
logger
.
info
(
"Useless trial data, value is %s, skip this trial data."
,
_value
)
continue
# convert the keys in loguniform and categorical types
valid_entry
=
True
for
key
,
value
in
_params
.
items
():
if
key
in
self
.
loguniform_key
:
_params
[
key
]
=
np
.
log
(
value
)
elif
key
in
self
.
categorical_dict
:
if
value
in
self
.
categorical_dict
[
key
]:
_params
[
key
]
=
self
.
categorical_dict
[
key
].
index
(
value
)
else
:
self
.
logger
.
info
(
"The value %s of key %s is not in search space."
,
str
(
value
),
key
)
valid_entry
=
False
break
if
not
valid_entry
:
continue
# start import this data entry
_completed_num
+=
1
config
=
Configuration
(
self
.
cs
,
values
=
_params
)
if
self
.
optimize_mode
is
OptimizeMode
.
Maximize
:
_value
=
-
_value
if
self
.
first_one
:
self
.
smbo_solver
.
nni_smac_receive_first_run
(
config
,
_value
)
self
.
first_one
=
False
else
:
self
.
smbo_solver
.
nni_smac_receive_runs
(
config
,
_value
)
self
.
logger
.
info
(
"Successfully import data to smac tuner, total data: %d, imported data: %d."
,
len
(
data
),
_completed_num
)
tools/nni_cmd/constants.py
View file @
4ac1c3c5
...
@@ -86,12 +86,13 @@ TUNERS_SUPPORTING_IMPORT_DATA = {
...
@@ -86,12 +86,13 @@ TUNERS_SUPPORTING_IMPORT_DATA = {
'Anneal'
,
'Anneal'
,
'GridSearch'
,
'GridSearch'
,
'MetisTuner'
,
'MetisTuner'
,
'BOHB'
'BOHB'
,
'SMAC'
,
'BatchTuner'
}
}
TUNERS_NO_NEED_TO_IMPORT_DATA
=
{
TUNERS_NO_NEED_TO_IMPORT_DATA
=
{
'Random'
,
'Random'
,
'Batch_tuner'
,
'Hyperband'
'Hyperband'
}
}
...
...
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