Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Fix bug bash of import data feature #1009

Merged
merged 4 commits into from
Apr 24, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,27 @@ 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 nni_params2tuner_params(in_x, parameter):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name of this function is a little weird? why we need the prefix "nni"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also confuse the name of this function. This function converts the form of hyperparameters in NNI into the form in TPE tuner. Do you have any suggestions for the name of this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to "params2tuner_params"

"""
change parameters in NNI format to parameters in hyperopt format.
For example, NNI 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}}
"""
tuner_params = dict()
for key in parameter.keys():
value = parameter[key]
_type = in_x[key][TYPE]
if _type == 'choice':
_idx = in_x[key][VALUE].index(value)
tuner_params[key] = {
INDEX: _idx,
VALUE: value
}
else:
tuner_params[key] = value
return tuner_params

def _split_index(params):
"""
Expand Down Expand Up @@ -375,6 +396,6 @@ def import_data(self, data):
_value = trial_info['value']
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] = nni_params2tuner_params(self.json, _params)
self.receive_trial_result(parameter_id=_parameter_id, parameters=_params, value=_value)
logger.info("Successfully import data to TPE/Anneal tuner.")