From f1142232ebd56560f9ccac70cc44150b70a73ef8 Mon Sep 17 00:00:00 2001 From: ShufanHuang Date: Mon, 22 Apr 2019 19:39:12 +0800 Subject: [PATCH 1/4] fix import data in TPE tuner --- .../nni/hyperopt_tuner/hyperopt_tuner.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py b/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py index edcbaaa9a7..90e13f500b 100644 --- a/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py +++ b/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py @@ -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): + """ + 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): """ @@ -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(_params) self.receive_trial_result(parameter_id=_parameter_id, parameters=_params, value=_value) logger.info("Successfully import data to TPE/Anneal tuner.") From 4e542d467100a598106ecbfcb6469fd867bcb310 Mon Sep 17 00:00:00 2001 From: ShufanHuang Date: Mon, 22 Apr 2019 21:57:38 +0800 Subject: [PATCH 2/4] update --- src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py b/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py index 90e13f500b..31572717f7 100644 --- a/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py +++ b/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py @@ -396,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] = nni_params2tuner_params(_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.") From 7b33ca725b6243c2f10e9ec6e643a7faedf6b802 Mon Sep 17 00:00:00 2001 From: ShufanHuang Date: Wed, 24 Apr 2019 11:18:08 +0800 Subject: [PATCH 3/4] remove success info and handle null value --- src/sdk/pynni/nni/bohb_advisor/bohb_advisor.py | 3 +++ src/sdk/pynni/nni/gridsearch_tuner/gridsearch_tuner.py | 5 +++++ src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py | 3 +++ src/sdk/pynni/nni/metis_tuner/metis_tuner.py | 3 +++ tools/nni_cmd/updater.py | 2 +- 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/sdk/pynni/nni/bohb_advisor/bohb_advisor.py b/src/sdk/pynni/nni/bohb_advisor/bohb_advisor.py index 0341be9656..881c0439cc 100644 --- a/src/sdk/pynni/nni/bohb_advisor/bohb_advisor.py +++ b/src/sdk/pynni/nni/bohb_advisor/bohb_advisor.py @@ -595,6 +595,9 @@ def handle_import_data(self, data): _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 budget_exist_flag = False barely_params = dict() for keys in _params: diff --git a/src/sdk/pynni/nni/gridsearch_tuner/gridsearch_tuner.py b/src/sdk/pynni/nni/gridsearch_tuner/gridsearch_tuner.py index 317d9f0ff0..80c8a9ecd2 100644 --- a/src/sdk/pynni/nni/gridsearch_tuner/gridsearch_tuner.py +++ b/src/sdk/pynni/nni/gridsearch_tuner/gridsearch_tuner.py @@ -164,6 +164,11 @@ def import_data(self, data): _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.") diff --git a/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py b/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py index 31572717f7..126b2cdc30 100644 --- a/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py +++ b/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py @@ -394,6 +394,9 @@ def import_data(self, data): _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] = nni_params2tuner_params(self.json, _params) diff --git a/src/sdk/pynni/nni/metis_tuner/metis_tuner.py b/src/sdk/pynni/nni/metis_tuner/metis_tuner.py index e0e2c2248c..8716fc497c 100644 --- a/src/sdk/pynni/nni/metis_tuner/metis_tuner.py +++ b/src/sdk/pynni/nni/metis_tuner/metis_tuner.py @@ -417,6 +417,9 @@ def import_data(self, data): _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) diff --git a/tools/nni_cmd/updater.py b/tools/nni_cmd/updater.py index 4a285e4b24..831ea69272 100644 --- a/tools/nni_cmd/updater.py +++ b/tools/nni_cmd/updater.py @@ -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): - print_normal('Import data success!') + pass else: print_error('Import data failed!') From 7d96bc3632584fee75fecb6435528c0a37522872 Mon Sep 17 00:00:00 2001 From: ShufanHuang Date: Wed, 24 Apr 2019 11:32:52 +0800 Subject: [PATCH 4/4] rename function --- src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py b/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py index 126b2cdc30..c92ed5440f 100644 --- a/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py +++ b/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py @@ -139,7 +139,7 @@ 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): +def params2tuner_params(in_x, parameter): """ change parameters in NNI format to parameters in hyperopt format. For example, NNI receive parameters like: @@ -399,6 +399,6 @@ def import_data(self, data): continue self.supplement_data_num += 1 _parameter_id = '_'.join(["ImportData", str(self.supplement_data_num)]) - self.total_data[_parameter_id] = nni_params2tuner_params(self.json, _params) + self.total_data[_parameter_id] = 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.")