partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | _split_index | Delete index infromation from params | src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py | def _split_index(params):
"""
Delete index infromation from params
"""
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... | def _split_index(params):
"""
Delete index infromation from params
"""
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... | [
"Delete",
"index",
"infromation",
"from",
"params"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py#L171-L185 | [
"def",
"_split_index",
"(",
"params",
")",
":",
"if",
"isinstance",
"(",
"params",
",",
"list",
")",
":",
"return",
"[",
"params",
"[",
"0",
"]",
",",
"_split_index",
"(",
"params",
"[",
"1",
"]",
")",
"]",
"elif",
"isinstance",
"(",
"params",
",",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | HyperoptTuner._choose_tuner | Parameters
----------
algorithm_name : str
algorithm_name includes "tpe", "random_search" and anneal" | src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py | def _choose_tuner(self, algorithm_name):
"""
Parameters
----------
algorithm_name : str
algorithm_name includes "tpe", "random_search" and anneal"
"""
if algorithm_name == 'tpe':
return hp.tpe.suggest
if algorithm_name == 'random_search':
... | def _choose_tuner(self, algorithm_name):
"""
Parameters
----------
algorithm_name : str
algorithm_name includes "tpe", "random_search" and anneal"
"""
if algorithm_name == 'tpe':
return hp.tpe.suggest
if algorithm_name == 'random_search':
... | [
"Parameters",
"----------",
"algorithm_name",
":",
"str",
"algorithm_name",
"includes",
"tpe",
"random_search",
"and",
"anneal"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py#L208-L221 | [
"def",
"_choose_tuner",
"(",
"self",
",",
"algorithm_name",
")",
":",
"if",
"algorithm_name",
"==",
"'tpe'",
":",
"return",
"hp",
".",
"tpe",
".",
"suggest",
"if",
"algorithm_name",
"==",
"'random_search'",
":",
"return",
"hp",
".",
"rand",
".",
"suggest",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | HyperoptTuner.update_search_space | Update search space definition in tuner by search_space in parameters.
Will called when first setup experiemnt or update search space in WebUI.
Parameters
----------
search_space : dict | src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py | def update_search_space(self, search_space):
"""
Update search space definition in tuner by search_space in parameters.
Will called when first setup experiemnt or update search space in WebUI.
Parameters
----------
search_space : dict
"""
self.json = sea... | def update_search_space(self, search_space):
"""
Update search space definition in tuner by search_space in parameters.
Will called when first setup experiemnt or update search space in WebUI.
Parameters
----------
search_space : dict
"""
self.json = sea... | [
"Update",
"search",
"space",
"definition",
"in",
"tuner",
"by",
"search_space",
"in",
"parameters",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py#L223-L242 | [
"def",
"update_search_space",
"(",
"self",
",",
"search_space",
")",
":",
"self",
".",
"json",
"=",
"search_space",
"search_space_instance",
"=",
"json2space",
"(",
"self",
".",
"json",
")",
"rstate",
"=",
"np",
".",
"random",
".",
"RandomState",
"(",
")",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | HyperoptTuner.generate_parameters | Returns a set of trial (hyper-)parameters, as a serializable object.
Parameters
----------
parameter_id : int
Returns
-------
params : dict | src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py | def generate_parameters(self, parameter_id):
"""
Returns a set of trial (hyper-)parameters, as a serializable object.
Parameters
----------
parameter_id : int
Returns
-------
params : dict
"""
total_params = self.get_suggestion(random_sea... | def generate_parameters(self, parameter_id):
"""
Returns a set of trial (hyper-)parameters, as a serializable object.
Parameters
----------
parameter_id : int
Returns
-------
params : dict
"""
total_params = self.get_suggestion(random_sea... | [
"Returns",
"a",
"set",
"of",
"trial",
"(",
"hyper",
"-",
")",
"parameters",
"as",
"a",
"serializable",
"object",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py#L244-L263 | [
"def",
"generate_parameters",
"(",
"self",
",",
"parameter_id",
")",
":",
"total_params",
"=",
"self",
".",
"get_suggestion",
"(",
"random_search",
"=",
"False",
")",
"# avoid generating same parameter with concurrent trials because hyperopt doesn't support parallel mode",
"if"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | HyperoptTuner.receive_trial_result | Record an observation of the objective function
Parameters
----------
parameter_id : int
parameters : dict
value : dict/float
if value is dict, it should have "default" key.
value is final metrics of the trial. | src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py | def receive_trial_result(self, parameter_id, parameters, value):
"""
Record an observation of the objective function
Parameters
----------
parameter_id : int
parameters : dict
value : dict/float
if value is dict, it should have "default" key.
... | def receive_trial_result(self, parameter_id, parameters, value):
"""
Record an observation of the objective function
Parameters
----------
parameter_id : int
parameters : dict
value : dict/float
if value is dict, it should have "default" key.
... | [
"Record",
"an",
"observation",
"of",
"the",
"objective",
"function"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py#L265-L319 | [
"def",
"receive_trial_result",
"(",
"self",
",",
"parameter_id",
",",
"parameters",
",",
"value",
")",
":",
"reward",
"=",
"extract_scalar_reward",
"(",
"value",
")",
"# restore the paramsters contains '_index'",
"if",
"parameter_id",
"not",
"in",
"self",
".",
"tota... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | HyperoptTuner.miscs_update_idxs_vals | Unpack the idxs-vals format into the list of dictionaries that is
`misc`.
Parameters
----------
idxs_map : dict
idxs_map is a dictionary of id->id mappings so that the misc['idxs'] can
contain different numbers than the idxs argument. | src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py | def miscs_update_idxs_vals(self, miscs, idxs, vals,
assert_all_vals_used=True,
idxs_map=None):
"""
Unpack the idxs-vals format into the list of dictionaries that is
`misc`.
Parameters
----------
idxs_map : dic... | def miscs_update_idxs_vals(self, miscs, idxs, vals,
assert_all_vals_used=True,
idxs_map=None):
"""
Unpack the idxs-vals format into the list of dictionaries that is
`misc`.
Parameters
----------
idxs_map : dic... | [
"Unpack",
"the",
"idxs",
"-",
"vals",
"format",
"into",
"the",
"list",
"of",
"dictionaries",
"that",
"is",
"misc",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py#L321-L350 | [
"def",
"miscs_update_idxs_vals",
"(",
"self",
",",
"miscs",
",",
"idxs",
",",
"vals",
",",
"assert_all_vals_used",
"=",
"True",
",",
"idxs_map",
"=",
"None",
")",
":",
"if",
"idxs_map",
"is",
"None",
":",
"idxs_map",
"=",
"{",
"}",
"assert",
"set",
"(",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | HyperoptTuner.get_suggestion | get suggestion from hyperopt
Parameters
----------
random_search : bool
flag to indicate random search or not (default: {False})
Returns
----------
total_params : dict
parameter suggestion | src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py | def get_suggestion(self, random_search=False):
"""get suggestion from hyperopt
Parameters
----------
random_search : bool
flag to indicate random search or not (default: {False})
Returns
----------
total_params : dict
parameter suggestion... | def get_suggestion(self, random_search=False):
"""get suggestion from hyperopt
Parameters
----------
random_search : bool
flag to indicate random search or not (default: {False})
Returns
----------
total_params : dict
parameter suggestion... | [
"get",
"suggestion",
"from",
"hyperopt"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py#L352-L387 | [
"def",
"get_suggestion",
"(",
"self",
",",
"random_search",
"=",
"False",
")",
":",
"rval",
"=",
"self",
".",
"rval",
"trials",
"=",
"rval",
".",
"trials",
"algorithm",
"=",
"rval",
".",
"algo",
"new_ids",
"=",
"rval",
".",
"trials",
".",
"new_trial_ids"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | HyperoptTuner.import_data | Import additional data for tuning
Parameters
----------
data:
a list of dictionarys, each of which has at least two keys, 'parameter' and 'value' | src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py | def import_data(self, data):
"""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:
logger.info("I... | def import_data(self, data):
"""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:
logger.info("I... | [
"Import",
"additional",
"data",
"for",
"tuning"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperopt_tuner/hyperopt_tuner.py#L389-L414 | [
"def",
"import_data",
"(",
"self",
",",
"data",
")",
":",
"_completed_num",
"=",
"0",
"for",
"trial_info",
"in",
"data",
":",
"logger",
".",
"info",
"(",
"\"Importing data, current processing progress %s / %s\"",
"%",
"(",
"_completed_num",
",",
"len",
"(",
"dat... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | next_hyperparameter_lowest_mu | "Lowest Mu" acquisition function | src/sdk/pynni/nni/metis_tuner/lib_acquisition_function.py | def next_hyperparameter_lowest_mu(fun_prediction,
fun_prediction_args,
x_bounds, x_types,
minimize_starting_points,
minimize_constraints_fun=None):
'''
"Lowest Mu" acquisition ... | def next_hyperparameter_lowest_mu(fun_prediction,
fun_prediction_args,
x_bounds, x_types,
minimize_starting_points,
minimize_constraints_fun=None):
'''
"Lowest Mu" acquisition ... | [
"Lowest",
"Mu",
"acquisition",
"function"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/metis_tuner/lib_acquisition_function.py#L154-L187 | [
"def",
"next_hyperparameter_lowest_mu",
"(",
"fun_prediction",
",",
"fun_prediction_args",
",",
"x_bounds",
",",
"x_types",
",",
"minimize_starting_points",
",",
"minimize_constraints_fun",
"=",
"None",
")",
":",
"best_x",
"=",
"None",
"best_acquisition_value",
"=",
"No... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | _lowest_mu | Calculate the lowest mu | src/sdk/pynni/nni/metis_tuner/lib_acquisition_function.py | def _lowest_mu(x, fun_prediction, fun_prediction_args,
x_bounds, x_types, minimize_constraints_fun):
'''
Calculate the lowest mu
'''
# This is only for step-wise optimization
x = lib_data.match_val_type(x, x_bounds, x_types)
mu = sys.maxsize
if (minimize_constraints_fun is No... | def _lowest_mu(x, fun_prediction, fun_prediction_args,
x_bounds, x_types, minimize_constraints_fun):
'''
Calculate the lowest mu
'''
# This is only for step-wise optimization
x = lib_data.match_val_type(x, x_bounds, x_types)
mu = sys.maxsize
if (minimize_constraints_fun is No... | [
"Calculate",
"the",
"lowest",
"mu"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/metis_tuner/lib_acquisition_function.py#L190-L201 | [
"def",
"_lowest_mu",
"(",
"x",
",",
"fun_prediction",
",",
"fun_prediction_args",
",",
"x_bounds",
",",
"x_types",
",",
"minimize_constraints_fun",
")",
":",
"# This is only for step-wise optimization",
"x",
"=",
"lib_data",
".",
"match_val_type",
"(",
"x",
",",
"x_... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | GAG.build_char_states | Build char embedding network for the QA model. | examples/trials/weight_sharing/ga_squad/train_model.py | def build_char_states(self, char_embed, is_training, reuse, char_ids, char_lengths):
"""Build char embedding network for the QA model."""
max_char_length = self.cfg.max_char_length
inputs = dropout(tf.nn.embedding_lookup(char_embed, char_ids),
self.cfg.dropout, is_train... | def build_char_states(self, char_embed, is_training, reuse, char_ids, char_lengths):
"""Build char embedding network for the QA model."""
max_char_length = self.cfg.max_char_length
inputs = dropout(tf.nn.embedding_lookup(char_embed, char_ids),
self.cfg.dropout, is_train... | [
"Build",
"char",
"embedding",
"network",
"for",
"the",
"QA",
"model",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/train_model.py#L234-L263 | [
"def",
"build_char_states",
"(",
"self",
",",
"char_embed",
",",
"is_training",
",",
"reuse",
",",
"char_ids",
",",
"char_lengths",
")",
":",
"max_char_length",
"=",
"self",
".",
"cfg",
".",
"max_char_length",
"inputs",
"=",
"dropout",
"(",
"tf",
".",
"nn",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MsgDispatcher.handle_report_metric_data | data: a dict received from nni_manager, which contains:
- 'parameter_id': id of the trial
- 'value': metric value reported by nni.report_final_result()
- 'type': report type, support {'FINAL', 'PERIODICAL'} | src/sdk/pynni/nni/msg_dispatcher.py | def handle_report_metric_data(self, data):
"""
data: a dict received from nni_manager, which contains:
- 'parameter_id': id of the trial
- 'value': metric value reported by nni.report_final_result()
- 'type': report type, support {'FINAL', 'PERIODICAL'}
... | def handle_report_metric_data(self, data):
"""
data: a dict received from nni_manager, which contains:
- 'parameter_id': id of the trial
- 'value': metric value reported by nni.report_final_result()
- 'type': report type, support {'FINAL', 'PERIODICAL'}
... | [
"data",
":",
"a",
"dict",
"received",
"from",
"nni_manager",
"which",
"contains",
":",
"-",
"parameter_id",
":",
"id",
"of",
"the",
"trial",
"-",
"value",
":",
"metric",
"value",
"reported",
"by",
"nni",
".",
"report_final_result",
"()",
"-",
"type",
":",
... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/msg_dispatcher.py#L124-L139 | [
"def",
"handle_report_metric_data",
"(",
"self",
",",
"data",
")",
":",
"if",
"data",
"[",
"'type'",
"]",
"==",
"'FINAL'",
":",
"self",
".",
"_handle_final_metric_data",
"(",
"data",
")",
"elif",
"data",
"[",
"'type'",
"]",
"==",
"'PERIODICAL'",
":",
"if",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MsgDispatcher.handle_trial_end | data: it has three keys: trial_job_id, event, hyper_params
- trial_job_id: the id generated by training service
- event: the job's state
- hyper_params: the hyperparameters generated and returned by tuner | src/sdk/pynni/nni/msg_dispatcher.py | def handle_trial_end(self, data):
"""
data: it has three keys: trial_job_id, event, hyper_params
- trial_job_id: the id generated by training service
- event: the job's state
- hyper_params: the hyperparameters generated and returned by tuner
"""
tr... | def handle_trial_end(self, data):
"""
data: it has three keys: trial_job_id, event, hyper_params
- trial_job_id: the id generated by training service
- event: the job's state
- hyper_params: the hyperparameters generated and returned by tuner
"""
tr... | [
"data",
":",
"it",
"has",
"three",
"keys",
":",
"trial_job_id",
"event",
"hyper_params",
"-",
"trial_job_id",
":",
"the",
"id",
"generated",
"by",
"training",
"service",
"-",
"event",
":",
"the",
"job",
"s",
"state",
"-",
"hyper_params",
":",
"the",
"hyper... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/msg_dispatcher.py#L141-L155 | [
"def",
"handle_trial_end",
"(",
"self",
",",
"data",
")",
":",
"trial_job_id",
"=",
"data",
"[",
"'trial_job_id'",
"]",
"_ended_trials",
".",
"add",
"(",
"trial_job_id",
")",
"if",
"trial_job_id",
"in",
"_trial_history",
":",
"_trial_history",
".",
"pop",
"(",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MsgDispatcher._handle_final_metric_data | Call tuner to process final results | src/sdk/pynni/nni/msg_dispatcher.py | def _handle_final_metric_data(self, data):
"""Call tuner to process final results
"""
id_ = data['parameter_id']
value = data['value']
if id_ in _customized_parameter_ids:
self.tuner.receive_customized_trial_result(id_, _trial_params[id_], value)
else:
... | def _handle_final_metric_data(self, data):
"""Call tuner to process final results
"""
id_ = data['parameter_id']
value = data['value']
if id_ in _customized_parameter_ids:
self.tuner.receive_customized_trial_result(id_, _trial_params[id_], value)
else:
... | [
"Call",
"tuner",
"to",
"process",
"final",
"results"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/msg_dispatcher.py#L157-L165 | [
"def",
"_handle_final_metric_data",
"(",
"self",
",",
"data",
")",
":",
"id_",
"=",
"data",
"[",
"'parameter_id'",
"]",
"value",
"=",
"data",
"[",
"'value'",
"]",
"if",
"id_",
"in",
"_customized_parameter_ids",
":",
"self",
".",
"tuner",
".",
"receive_custom... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MsgDispatcher._handle_intermediate_metric_data | Call assessor to process intermediate results | src/sdk/pynni/nni/msg_dispatcher.py | def _handle_intermediate_metric_data(self, data):
"""Call assessor to process intermediate results
"""
if data['type'] != 'PERIODICAL':
return
if self.assessor is None:
return
trial_job_id = data['trial_job_id']
if trial_job_id in _ended_trials:
... | def _handle_intermediate_metric_data(self, data):
"""Call assessor to process intermediate results
"""
if data['type'] != 'PERIODICAL':
return
if self.assessor is None:
return
trial_job_id = data['trial_job_id']
if trial_job_id in _ended_trials:
... | [
"Call",
"assessor",
"to",
"process",
"intermediate",
"results"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/msg_dispatcher.py#L167-L204 | [
"def",
"_handle_intermediate_metric_data",
"(",
"self",
",",
"data",
")",
":",
"if",
"data",
"[",
"'type'",
"]",
"!=",
"'PERIODICAL'",
":",
"return",
"if",
"self",
".",
"assessor",
"is",
"None",
":",
"return",
"trial_job_id",
"=",
"data",
"[",
"'trial_job_id... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MsgDispatcher._earlystop_notify_tuner | Send last intermediate result as final result to tuner in case the
trial is early stopped. | src/sdk/pynni/nni/msg_dispatcher.py | def _earlystop_notify_tuner(self, data):
"""Send last intermediate result as final result to tuner in case the
trial is early stopped.
"""
_logger.debug('Early stop notify tuner data: [%s]', data)
data['type'] = 'FINAL'
if multi_thread_enabled():
self._handle_... | def _earlystop_notify_tuner(self, data):
"""Send last intermediate result as final result to tuner in case the
trial is early stopped.
"""
_logger.debug('Early stop notify tuner data: [%s]', data)
data['type'] = 'FINAL'
if multi_thread_enabled():
self._handle_... | [
"Send",
"last",
"intermediate",
"result",
"as",
"final",
"result",
"to",
"tuner",
"in",
"case",
"the",
"trial",
"is",
"early",
"stopped",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/msg_dispatcher.py#L206-L215 | [
"def",
"_earlystop_notify_tuner",
"(",
"self",
",",
"data",
")",
":",
"_logger",
".",
"debug",
"(",
"'Early stop notify tuner data: [%s]'",
",",
"data",
")",
"data",
"[",
"'type'",
"]",
"=",
"'FINAL'",
"if",
"multi_thread_enabled",
"(",
")",
":",
"self",
".",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | parse_rev_args | parse reveive msgs to global variable | examples/trials/network_morphism/FashionMNIST/FashionMNIST_keras.py | def parse_rev_args(receive_msg):
""" parse reveive msgs to global variable
"""
global trainloader
global testloader
global net
# Loading Data
logger.debug("Preparing data..")
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
y_train = to_categorical(y_train, 10)
... | def parse_rev_args(receive_msg):
""" parse reveive msgs to global variable
"""
global trainloader
global testloader
global net
# Loading Data
logger.debug("Preparing data..")
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()
y_train = to_categorical(y_train, 10)
... | [
"parse",
"reveive",
"msgs",
"to",
"global",
"variable"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/network_morphism/FashionMNIST/FashionMNIST_keras.py#L90-L140 | [
"def",
"parse_rev_args",
"(",
"receive_msg",
")",
":",
"global",
"trainloader",
"global",
"testloader",
"global",
"net",
"# Loading Data",
"logger",
".",
"debug",
"(",
"\"Preparing data..\"",
")",
"(",
"x_train",
",",
"y_train",
")",
",",
"(",
"x_test",
",",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | train_eval | train and eval the model | examples/trials/network_morphism/FashionMNIST/FashionMNIST_keras.py | def train_eval():
""" train and eval the model
"""
global trainloader
global testloader
global net
(x_train, y_train) = trainloader
(x_test, y_test) = testloader
# train procedure
net.fit(
x=x_train,
y=y_train,
batch_size=args.batch_size,
validation... | def train_eval():
""" train and eval the model
"""
global trainloader
global testloader
global net
(x_train, y_train) = trainloader
(x_test, y_test) = testloader
# train procedure
net.fit(
x=x_train,
y=y_train,
batch_size=args.batch_size,
validation... | [
"train",
"and",
"eval",
"the",
"model"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/network_morphism/FashionMNIST/FashionMNIST_keras.py#L159-L188 | [
"def",
"train_eval",
"(",
")",
":",
"global",
"trainloader",
"global",
"testloader",
"global",
"net",
"(",
"x_train",
",",
"y_train",
")",
"=",
"trainloader",
"(",
"x_test",
",",
"y_test",
")",
"=",
"testloader",
"# train procedure",
"net",
".",
"fit",
"(",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | SendMetrics.on_epoch_end | Run on end of each epoch | examples/trials/network_morphism/FashionMNIST/FashionMNIST_keras.py | def on_epoch_end(self, epoch, logs=None):
"""
Run on end of each epoch
"""
if logs is None:
logs = dict()
logger.debug(logs)
nni.report_intermediate_result(logs["val_acc"]) | def on_epoch_end(self, epoch, logs=None):
"""
Run on end of each epoch
"""
if logs is None:
logs = dict()
logger.debug(logs)
nni.report_intermediate_result(logs["val_acc"]) | [
"Run",
"on",
"end",
"of",
"each",
"epoch"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/network_morphism/FashionMNIST/FashionMNIST_keras.py#L148-L155 | [
"def",
"on_epoch_end",
"(",
"self",
",",
"epoch",
",",
"logs",
"=",
"None",
")",
":",
"if",
"logs",
"is",
"None",
":",
"logs",
"=",
"dict",
"(",
")",
"logger",
".",
"debug",
"(",
"logs",
")",
"nni",
".",
"report_intermediate_result",
"(",
"logs",
"["... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | create_bracket_parameter_id | Create a full id for a specific bracket's hyperparameter configuration
Parameters
----------
brackets_id: int
brackets id
brackets_curr_decay:
brackets curr decay
increased_id: int
increased id
Returns
-------
int
params id | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def create_bracket_parameter_id(brackets_id, brackets_curr_decay, increased_id=-1):
"""Create a full id for a specific bracket's hyperparameter configuration
Parameters
----------
brackets_id: int
brackets id
brackets_curr_decay:
brackets curr decay
increased_id: int
... | def create_bracket_parameter_id(brackets_id, brackets_curr_decay, increased_id=-1):
"""Create a full id for a specific bracket's hyperparameter configuration
Parameters
----------
brackets_id: int
brackets id
brackets_curr_decay:
brackets curr decay
increased_id: int
... | [
"Create",
"a",
"full",
"id",
"for",
"a",
"specific",
"bracket",
"s",
"hyperparameter",
"configuration",
"Parameters",
"----------",
"brackets_id",
":",
"int",
"brackets",
"id",
"brackets_curr_decay",
":",
"brackets",
"curr",
"decay",
"increased_id",
":",
"int",
"i... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L61-L83 | [
"def",
"create_bracket_parameter_id",
"(",
"brackets_id",
",",
"brackets_curr_decay",
",",
"increased_id",
"=",
"-",
"1",
")",
":",
"if",
"increased_id",
"==",
"-",
"1",
":",
"increased_id",
"=",
"str",
"(",
"create_parameter_id",
"(",
")",
")",
"params_id",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | json2paramater | Randomly generate values for hyperparameters from hyperparameter space i.e., x.
Parameters
----------
ss_spec:
hyperparameter space
random_state:
random operator to generate random values
Returns
-------
Parameter:
Parameters in this experiment | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def json2paramater(ss_spec, random_state):
"""Randomly generate values for hyperparameters from hyperparameter space i.e., x.
Parameters
----------
ss_spec:
hyperparameter space
random_state:
random operator to generate random values
Returns
-------
Parameter:
... | def json2paramater(ss_spec, random_state):
"""Randomly generate values for hyperparameters from hyperparameter space i.e., x.
Parameters
----------
ss_spec:
hyperparameter space
random_state:
random operator to generate random values
Returns
-------
Parameter:
... | [
"Randomly",
"generate",
"values",
"for",
"hyperparameters",
"from",
"hyperparameter",
"space",
"i",
".",
"e",
".",
"x",
".",
"Parameters",
"----------",
"ss_spec",
":",
"hyperparameter",
"space",
"random_state",
":",
"random",
"operator",
"to",
"generate",
"random... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L85-L120 | [
"def",
"json2paramater",
"(",
"ss_spec",
",",
"random_state",
")",
":",
"if",
"isinstance",
"(",
"ss_spec",
",",
"dict",
")",
":",
"if",
"'_type'",
"in",
"ss_spec",
".",
"keys",
"(",
")",
":",
"_type",
"=",
"ss_spec",
"[",
"'_type'",
"]",
"_value",
"="... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Bracket.get_n_r | return the values of n and r for the next round | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def get_n_r(self):
"""return the values of n and r for the next round"""
return math.floor(self.n / self.eta**self.i + _epsilon), math.floor(self.r * self.eta**self.i + _epsilon) | def get_n_r(self):
"""return the values of n and r for the next round"""
return math.floor(self.n / self.eta**self.i + _epsilon), math.floor(self.r * self.eta**self.i + _epsilon) | [
"return",
"the",
"values",
"of",
"n",
"and",
"r",
"for",
"the",
"next",
"round"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L159-L161 | [
"def",
"get_n_r",
"(",
"self",
")",
":",
"return",
"math",
".",
"floor",
"(",
"self",
".",
"n",
"/",
"self",
".",
"eta",
"**",
"self",
".",
"i",
"+",
"_epsilon",
")",
",",
"math",
".",
"floor",
"(",
"self",
".",
"r",
"*",
"self",
".",
"eta",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Bracket.increase_i | i means the ith round. Increase i by 1 | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def increase_i(self):
"""i means the ith round. Increase i by 1"""
self.i += 1
if self.i > self.bracket_id:
self.no_more_trial = True | def increase_i(self):
"""i means the ith round. Increase i by 1"""
self.i += 1
if self.i > self.bracket_id:
self.no_more_trial = True | [
"i",
"means",
"the",
"ith",
"round",
".",
"Increase",
"i",
"by",
"1"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L163-L167 | [
"def",
"increase_i",
"(",
"self",
")",
":",
"self",
".",
"i",
"+=",
"1",
"if",
"self",
".",
"i",
">",
"self",
".",
"bracket_id",
":",
"self",
".",
"no_more_trial",
"=",
"True"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Bracket.set_config_perf | update trial's latest result with its sequence number, e.g., epoch number or batch number
Parameters
----------
i: int
the ith round
parameter_id: int
the id of the trial/parameter
seq: int
sequence number, e.g., epoch number or batch ... | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def set_config_perf(self, i, parameter_id, seq, value):
"""update trial's latest result with its sequence number, e.g., epoch number or batch number
Parameters
----------
i: int
the ith round
parameter_id: int
the id of the trial/parameter
... | def set_config_perf(self, i, parameter_id, seq, value):
"""update trial's latest result with its sequence number, e.g., epoch number or batch number
Parameters
----------
i: int
the ith round
parameter_id: int
the id of the trial/parameter
... | [
"update",
"trial",
"s",
"latest",
"result",
"with",
"its",
"sequence",
"number",
"e",
".",
"g",
".",
"epoch",
"number",
"or",
"batch",
"number",
"Parameters",
"----------",
"i",
":",
"int",
"the",
"ith",
"round",
"parameter_id",
":",
"int",
"the",
"id",
... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L169-L191 | [
"def",
"set_config_perf",
"(",
"self",
",",
"i",
",",
"parameter_id",
",",
"seq",
",",
"value",
")",
":",
"if",
"parameter_id",
"in",
"self",
".",
"configs_perf",
"[",
"i",
"]",
":",
"if",
"self",
".",
"configs_perf",
"[",
"i",
"]",
"[",
"parameter_id"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Bracket.inform_trial_end | If the trial is finished and the corresponding round (i.e., i) has all its trials finished,
it will choose the top k trials for the next round (i.e., i+1)
Parameters
----------
i: int
the ith round | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def inform_trial_end(self, i):
"""If the trial is finished and the corresponding round (i.e., i) has all its trials finished,
it will choose the top k trials for the next round (i.e., i+1)
Parameters
----------
i: int
the ith round
"""
global _KEY # p... | def inform_trial_end(self, i):
"""If the trial is finished and the corresponding round (i.e., i) has all its trials finished,
it will choose the top k trials for the next round (i.e., i+1)
Parameters
----------
i: int
the ith round
"""
global _KEY # p... | [
"If",
"the",
"trial",
"is",
"finished",
"and",
"the",
"corresponding",
"round",
"(",
"i",
".",
"e",
".",
"i",
")",
"has",
"all",
"its",
"trials",
"finished",
"it",
"will",
"choose",
"the",
"top",
"k",
"trials",
"for",
"the",
"next",
"round",
"(",
"i"... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L194-L229 | [
"def",
"inform_trial_end",
"(",
"self",
",",
"i",
")",
":",
"global",
"_KEY",
"# pylint: disable=global-statement",
"self",
".",
"num_finished_configs",
"[",
"i",
"]",
"+=",
"1",
"_logger",
".",
"debug",
"(",
"'bracket id: %d, round: %d %d, finished: %d, all: %d'",
",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Bracket.get_hyperparameter_configurations | Randomly generate num hyperparameter configurations from search space
Parameters
----------
num: int
the number of hyperparameter configurations
Returns
-------
list
a list of hyperparameter configurations. Format: [[key1, value1], [key2,... | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def get_hyperparameter_configurations(self, num, r, searchspace_json, random_state): # pylint: disable=invalid-name
"""Randomly generate num hyperparameter configurations from search space
Parameters
----------
num: int
the number of hyperparameter configurations
... | def get_hyperparameter_configurations(self, num, r, searchspace_json, random_state): # pylint: disable=invalid-name
"""Randomly generate num hyperparameter configurations from search space
Parameters
----------
num: int
the number of hyperparameter configurations
... | [
"Randomly",
"generate",
"num",
"hyperparameter",
"configurations",
"from",
"search",
"space"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L231-L253 | [
"def",
"get_hyperparameter_configurations",
"(",
"self",
",",
"num",
",",
"r",
",",
"searchspace_json",
",",
"random_state",
")",
":",
"# pylint: disable=invalid-name",
"global",
"_KEY",
"# pylint: disable=global-statement",
"assert",
"self",
".",
"i",
"==",
"0",
"hyp... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Bracket._record_hyper_configs | after generating one round of hyperconfigs, this function records the generated hyperconfigs,
creates a dict to record the performance when those hyperconifgs are running, set the number of finished configs
in this round to be 0, and increase the round number.
Parameters
----------
... | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def _record_hyper_configs(self, hyper_configs):
"""after generating one round of hyperconfigs, this function records the generated hyperconfigs,
creates a dict to record the performance when those hyperconifgs are running, set the number of finished configs
in this round to be 0, and increase th... | def _record_hyper_configs(self, hyper_configs):
"""after generating one round of hyperconfigs, this function records the generated hyperconfigs,
creates a dict to record the performance when those hyperconifgs are running, set the number of finished configs
in this round to be 0, and increase th... | [
"after",
"generating",
"one",
"round",
"of",
"hyperconfigs",
"this",
"function",
"records",
"the",
"generated",
"hyperconfigs",
"creates",
"a",
"dict",
"to",
"record",
"the",
"performance",
"when",
"those",
"hyperconifgs",
"are",
"running",
"set",
"the",
"number",... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L255-L269 | [
"def",
"_record_hyper_configs",
"(",
"self",
",",
"hyper_configs",
")",
":",
"self",
".",
"hyper_configs",
".",
"append",
"(",
"hyper_configs",
")",
"self",
".",
"configs_perf",
".",
"append",
"(",
"dict",
"(",
")",
")",
"self",
".",
"num_finished_configs",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Hyperband._request_one_trial_job | get one trial job, i.e., one hyperparameter configuration. | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def _request_one_trial_job(self):
"""get one trial job, i.e., one hyperparameter configuration."""
if not self.generated_hyper_configs:
if self.curr_s < 0:
self.curr_s = self.s_max
_logger.debug('create a new bracket, self.curr_s=%d', self.curr_s)
self... | def _request_one_trial_job(self):
"""get one trial job, i.e., one hyperparameter configuration."""
if not self.generated_hyper_configs:
if self.curr_s < 0:
self.curr_s = self.s_max
_logger.debug('create a new bracket, self.curr_s=%d', self.curr_s)
self... | [
"get",
"one",
"trial",
"job",
"i",
".",
"e",
".",
"one",
"hyperparameter",
"configuration",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L331-L354 | [
"def",
"_request_one_trial_job",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"generated_hyper_configs",
":",
"if",
"self",
".",
"curr_s",
"<",
"0",
":",
"self",
".",
"curr_s",
"=",
"self",
".",
"s_max",
"_logger",
".",
"debug",
"(",
"'create a new bra... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Hyperband.handle_update_search_space | data: JSON object, which is search space
Parameters
----------
data: int
number of trial jobs | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def handle_update_search_space(self, data):
"""data: JSON object, which is search space
Parameters
----------
data: int
number of trial jobs
"""
self.searchspace_json = data
self.random_state = np.random.RandomState() | def handle_update_search_space(self, data):
"""data: JSON object, which is search space
Parameters
----------
data: int
number of trial jobs
"""
self.searchspace_json = data
self.random_state = np.random.RandomState() | [
"data",
":",
"JSON",
"object",
"which",
"is",
"search",
"space",
"Parameters",
"----------",
"data",
":",
"int",
"number",
"of",
"trial",
"jobs"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L356-L365 | [
"def",
"handle_update_search_space",
"(",
"self",
",",
"data",
")",
":",
"self",
".",
"searchspace_json",
"=",
"data",
"self",
".",
"random_state",
"=",
"np",
".",
"random",
".",
"RandomState",
"(",
")"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Hyperband.handle_trial_end | Parameters
----------
data: dict()
it has three keys: trial_job_id, event, hyper_params
trial_job_id: the id generated by training service
event: the job's state
hyper_params: the hyperparameters (a string) generated and returned by tuner | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def handle_trial_end(self, data):
"""
Parameters
----------
data: dict()
it has three keys: trial_job_id, event, hyper_params
trial_job_id: the id generated by training service
event: the job's state
hyper_params: the hyperparameters (a str... | def handle_trial_end(self, data):
"""
Parameters
----------
data: dict()
it has three keys: trial_job_id, event, hyper_params
trial_job_id: the id generated by training service
event: the job's state
hyper_params: the hyperparameters (a str... | [
"Parameters",
"----------",
"data",
":",
"dict",
"()",
"it",
"has",
"three",
"keys",
":",
"trial_job_id",
"event",
"hyper_params",
"trial_job_id",
":",
"the",
"id",
"generated",
"by",
"training",
"service",
"event",
":",
"the",
"job",
"s",
"state",
"hyper_para... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L367-L393 | [
"def",
"handle_trial_end",
"(",
"self",
",",
"data",
")",
":",
"hyper_params",
"=",
"json_tricks",
".",
"loads",
"(",
"data",
"[",
"'hyper_params'",
"]",
")",
"bracket_id",
",",
"i",
",",
"_",
"=",
"hyper_params",
"[",
"'parameter_id'",
"]",
".",
"split",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Hyperband.handle_report_metric_data | Parameters
----------
data:
it is an object which has keys 'parameter_id', 'value', 'trial_job_id', 'type', 'sequence'.
Raises
------
ValueError
Data type not supported | src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py | def handle_report_metric_data(self, data):
"""
Parameters
----------
data:
it is an object which has keys 'parameter_id', 'value', 'trial_job_id', 'type', 'sequence'.
Raises
------
ValueError
Data type not supported
"""
... | def handle_report_metric_data(self, data):
"""
Parameters
----------
data:
it is an object which has keys 'parameter_id', 'value', 'trial_job_id', 'type', 'sequence'.
Raises
------
ValueError
Data type not supported
"""
... | [
"Parameters",
"----------",
"data",
":",
"it",
"is",
"an",
"object",
"which",
"has",
"keys",
"parameter_id",
"value",
"trial_job_id",
"type",
"sequence",
".",
"Raises",
"------",
"ValueError",
"Data",
"type",
"not",
"supported"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py#L395-L418 | [
"def",
"handle_report_metric_data",
"(",
"self",
",",
"data",
")",
":",
"value",
"=",
"extract_scalar_reward",
"(",
"data",
"[",
"'value'",
"]",
")",
"bracket_id",
",",
"i",
",",
"_",
"=",
"data",
"[",
"'parameter_id'",
"]",
".",
"split",
"(",
"'_'",
")"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | CustomerTuner.generate_parameters | Returns a set of trial graph config, as a serializable object.
parameter_id : int | examples/tuners/ga_customer_tuner/customer_tuner.py | def generate_parameters(self, parameter_id):
"""Returns a set of trial graph config, as a serializable object.
parameter_id : int
"""
if len(self.population) <= 0:
logger.debug("the len of poplution lower than zero.")
raise Exception('The population is empty')
... | def generate_parameters(self, parameter_id):
"""Returns a set of trial graph config, as a serializable object.
parameter_id : int
"""
if len(self.population) <= 0:
logger.debug("the len of poplution lower than zero.")
raise Exception('The population is empty')
... | [
"Returns",
"a",
"set",
"of",
"trial",
"graph",
"config",
"as",
"a",
"serializable",
"object",
".",
"parameter_id",
":",
"int"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/tuners/ga_customer_tuner/customer_tuner.py#L82-L109 | [
"def",
"generate_parameters",
"(",
"self",
",",
"parameter_id",
")",
":",
"if",
"len",
"(",
"self",
".",
"population",
")",
"<=",
"0",
":",
"logger",
".",
"debug",
"(",
"\"the len of poplution lower than zero.\"",
")",
"raise",
"Exception",
"(",
"'The population... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | CustomerTuner.receive_trial_result | Record an observation of the objective function
parameter_id : int
parameters : dict of parameters
value: final metrics of the trial, including reward | examples/tuners/ga_customer_tuner/customer_tuner.py | def receive_trial_result(self, parameter_id, parameters, value):
'''
Record an observation of the objective function
parameter_id : int
parameters : dict of parameters
value: final metrics of the trial, including reward
'''
reward = extract_scalar_reward(value)
... | def receive_trial_result(self, parameter_id, parameters, value):
'''
Record an observation of the objective function
parameter_id : int
parameters : dict of parameters
value: final metrics of the trial, including reward
'''
reward = extract_scalar_reward(value)
... | [
"Record",
"an",
"observation",
"of",
"the",
"objective",
"function",
"parameter_id",
":",
"int",
"parameters",
":",
"dict",
"of",
"parameters",
"value",
":",
"final",
"metrics",
"of",
"the",
"trial",
"including",
"reward"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/tuners/ga_customer_tuner/customer_tuner.py#L112-L129 | [
"def",
"receive_trial_result",
"(",
"self",
",",
"parameter_id",
",",
"parameters",
",",
"value",
")",
":",
"reward",
"=",
"extract_scalar_reward",
"(",
"value",
")",
"if",
"self",
".",
"optimize_mode",
"is",
"OptimizeMode",
".",
"Minimize",
":",
"reward",
"="... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | CnnGenerator.generate | Generates a CNN.
Args:
model_len: An integer. Number of convolutional layers.
model_width: An integer. Number of filters for the convolutional layers.
Returns:
An instance of the class Graph. Represents the neural architecture graph of the generated model. | src/sdk/pynni/nni/networkmorphism_tuner/nn.py | def generate(self, model_len=None, model_width=None):
"""Generates a CNN.
Args:
model_len: An integer. Number of convolutional layers.
model_width: An integer. Number of filters for the convolutional layers.
Returns:
An instance of the class Graph. Represents ... | def generate(self, model_len=None, model_width=None):
"""Generates a CNN.
Args:
model_len: An integer. Number of convolutional layers.
model_width: An integer. Number of filters for the convolutional layers.
Returns:
An instance of the class Graph. Represents ... | [
"Generates",
"a",
"CNN",
".",
"Args",
":",
"model_len",
":",
"An",
"integer",
".",
"Number",
"of",
"convolutional",
"layers",
".",
"model_width",
":",
"An",
"integer",
".",
"Number",
"of",
"filters",
"for",
"the",
"convolutional",
"layers",
".",
"Returns",
... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/nn.py#L74-L115 | [
"def",
"generate",
"(",
"self",
",",
"model_len",
"=",
"None",
",",
"model_width",
"=",
"None",
")",
":",
"if",
"model_len",
"is",
"None",
":",
"model_len",
"=",
"Constant",
".",
"MODEL_LEN",
"if",
"model_width",
"is",
"None",
":",
"model_width",
"=",
"C... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MlpGenerator.generate | Generates a Multi-Layer Perceptron.
Args:
model_len: An integer. Number of hidden layers.
model_width: An integer or a list of integers of length `model_len`. If it is a list, it represents the
number of nodes in each hidden layer. If it is an integer, all hidden layers h... | src/sdk/pynni/nni/networkmorphism_tuner/nn.py | def generate(self, model_len=None, model_width=None):
"""Generates a Multi-Layer Perceptron.
Args:
model_len: An integer. Number of hidden layers.
model_width: An integer or a list of integers of length `model_len`. If it is a list, it represents the
number of nod... | def generate(self, model_len=None, model_width=None):
"""Generates a Multi-Layer Perceptron.
Args:
model_len: An integer. Number of hidden layers.
model_width: An integer or a list of integers of length `model_len`. If it is a list, it represents the
number of nod... | [
"Generates",
"a",
"Multi",
"-",
"Layer",
"Perceptron",
".",
"Args",
":",
"model_len",
":",
"An",
"integer",
".",
"Number",
"of",
"hidden",
"layers",
".",
"model_width",
":",
"An",
"integer",
"or",
"a",
"list",
"of",
"integers",
"of",
"length",
"model_len",... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/nn.py#L133-L166 | [
"def",
"generate",
"(",
"self",
",",
"model_len",
"=",
"None",
",",
"model_width",
"=",
"None",
")",
":",
"if",
"model_len",
"is",
"None",
":",
"model_len",
"=",
"Constant",
".",
"MODEL_LEN",
"if",
"model_width",
"is",
"None",
":",
"model_width",
"=",
"C... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | generate_search_space | Generate search space from Python source code.
Return a serializable search space object.
code_dir: directory path of source files (str) | tools/nni_annotation/__init__.py | def generate_search_space(code_dir):
"""Generate search space from Python source code.
Return a serializable search space object.
code_dir: directory path of source files (str)
"""
search_space = {}
if code_dir.endswith(slash):
code_dir = code_dir[:-1]
for subdir, _, files in o... | def generate_search_space(code_dir):
"""Generate search space from Python source code.
Return a serializable search space object.
code_dir: directory path of source files (str)
"""
search_space = {}
if code_dir.endswith(slash):
code_dir = code_dir[:-1]
for subdir, _, files in o... | [
"Generate",
"search",
"space",
"from",
"Python",
"source",
"code",
".",
"Return",
"a",
"serializable",
"search",
"space",
"object",
".",
"code_dir",
":",
"directory",
"path",
"of",
"source",
"files",
"(",
"str",
")"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_annotation/__init__.py#L36-L61 | [
"def",
"generate_search_space",
"(",
"code_dir",
")",
":",
"search_space",
"=",
"{",
"}",
"if",
"code_dir",
".",
"endswith",
"(",
"slash",
")",
":",
"code_dir",
"=",
"code_dir",
"[",
":",
"-",
"1",
"]",
"for",
"subdir",
",",
"_",
",",
"files",
"in",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | expand_annotations | Expand annotations in user code.
Return dst_dir if annotation detected; return src_dir if not.
src_dir: directory path of user code (str)
dst_dir: directory to place generated files (str) | tools/nni_annotation/__init__.py | def expand_annotations(src_dir, dst_dir):
"""Expand annotations in user code.
Return dst_dir if annotation detected; return src_dir if not.
src_dir: directory path of user code (str)
dst_dir: directory to place generated files (str)
"""
if src_dir[-1] == slash:
src_dir = src_dir[:-1]
... | def expand_annotations(src_dir, dst_dir):
"""Expand annotations in user code.
Return dst_dir if annotation detected; return src_dir if not.
src_dir: directory path of user code (str)
dst_dir: directory to place generated files (str)
"""
if src_dir[-1] == slash:
src_dir = src_dir[:-1]
... | [
"Expand",
"annotations",
"in",
"user",
"code",
".",
"Return",
"dst_dir",
"if",
"annotation",
"detected",
";",
"return",
"src_dir",
"if",
"not",
".",
"src_dir",
":",
"directory",
"path",
"of",
"user",
"code",
"(",
"str",
")",
"dst_dir",
":",
"directory",
"t... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_annotation/__init__.py#L77-L107 | [
"def",
"expand_annotations",
"(",
"src_dir",
",",
"dst_dir",
")",
":",
"if",
"src_dir",
"[",
"-",
"1",
"]",
"==",
"slash",
":",
"src_dir",
"=",
"src_dir",
"[",
":",
"-",
"1",
"]",
"if",
"dst_dir",
"[",
"-",
"1",
"]",
"==",
"slash",
":",
"dst_dir",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | gen_send_stdout_url | Generate send stdout url | tools/nni_trial_tool/url_utils.py | def gen_send_stdout_url(ip, port):
'''Generate send stdout url'''
return '{0}:{1}{2}{3}/{4}/{5}'.format(BASE_URL.format(ip), port, API_ROOT_URL, STDOUT_API, NNI_EXP_ID, NNI_TRIAL_JOB_ID) | def gen_send_stdout_url(ip, port):
'''Generate send stdout url'''
return '{0}:{1}{2}{3}/{4}/{5}'.format(BASE_URL.format(ip), port, API_ROOT_URL, STDOUT_API, NNI_EXP_ID, NNI_TRIAL_JOB_ID) | [
"Generate",
"send",
"stdout",
"url"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_trial_tool/url_utils.py#L23-L25 | [
"def",
"gen_send_stdout_url",
"(",
"ip",
",",
"port",
")",
":",
"return",
"'{0}:{1}{2}{3}/{4}/{5}'",
".",
"format",
"(",
"BASE_URL",
".",
"format",
"(",
"ip",
")",
",",
"port",
",",
"API_ROOT_URL",
",",
"STDOUT_API",
",",
"NNI_EXP_ID",
",",
"NNI_TRIAL_JOB_ID",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | gen_send_version_url | Generate send error url | tools/nni_trial_tool/url_utils.py | def gen_send_version_url(ip, port):
'''Generate send error url'''
return '{0}:{1}{2}{3}/{4}/{5}'.format(BASE_URL.format(ip), port, API_ROOT_URL, VERSION_API, NNI_EXP_ID, NNI_TRIAL_JOB_ID) | def gen_send_version_url(ip, port):
'''Generate send error url'''
return '{0}:{1}{2}{3}/{4}/{5}'.format(BASE_URL.format(ip), port, API_ROOT_URL, VERSION_API, NNI_EXP_ID, NNI_TRIAL_JOB_ID) | [
"Generate",
"send",
"error",
"url"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_trial_tool/url_utils.py#L27-L29 | [
"def",
"gen_send_version_url",
"(",
"ip",
",",
"port",
")",
":",
"return",
"'{0}:{1}{2}{3}/{4}/{5}'",
".",
"format",
"(",
"BASE_URL",
".",
"format",
"(",
"ip",
")",
",",
"port",
",",
"API_ROOT_URL",
",",
"VERSION_API",
",",
"NNI_EXP_ID",
",",
"NNI_TRIAL_JOB_ID... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | validate_digit | validate if a digit is valid | tools/nni_cmd/updater.py | def validate_digit(value, start, end):
'''validate if a digit is valid'''
if not str(value).isdigit() or int(value) < start or int(value) > end:
raise ValueError('%s must be a digit from %s to %s' % (value, start, end)) | def validate_digit(value, start, end):
'''validate if a digit is valid'''
if not str(value).isdigit() or int(value) < start or int(value) > end:
raise ValueError('%s must be a digit from %s to %s' % (value, start, end)) | [
"validate",
"if",
"a",
"digit",
"is",
"valid"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/updater.py#L32-L35 | [
"def",
"validate_digit",
"(",
"value",
",",
"start",
",",
"end",
")",
":",
"if",
"not",
"str",
"(",
"value",
")",
".",
"isdigit",
"(",
")",
"or",
"int",
"(",
"value",
")",
"<",
"start",
"or",
"int",
"(",
"value",
")",
">",
"end",
":",
"raise",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | validate_dispatcher | validate if the dispatcher of the experiment supports importing data | tools/nni_cmd/updater.py | def validate_dispatcher(args):
'''validate if the dispatcher of the experiment supports importing data'''
nni_config = Config(get_config_filename(args)).get_config('experimentConfig')
if nni_config.get('tuner') and nni_config['tuner'].get('builtinTunerName'):
dispatcher_name = nni_config['tuner']['b... | def validate_dispatcher(args):
'''validate if the dispatcher of the experiment supports importing data'''
nni_config = Config(get_config_filename(args)).get_config('experimentConfig')
if nni_config.get('tuner') and nni_config['tuner'].get('builtinTunerName'):
dispatcher_name = nni_config['tuner']['b... | [
"validate",
"if",
"the",
"dispatcher",
"of",
"the",
"experiment",
"supports",
"importing",
"data"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/updater.py#L42-L57 | [
"def",
"validate_dispatcher",
"(",
"args",
")",
":",
"nni_config",
"=",
"Config",
"(",
"get_config_filename",
"(",
"args",
")",
")",
".",
"get_config",
"(",
"'experimentConfig'",
")",
"if",
"nni_config",
".",
"get",
"(",
"'tuner'",
")",
"and",
"nni_config",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | load_search_space | load search space content | tools/nni_cmd/updater.py | def load_search_space(path):
'''load search space content'''
content = json.dumps(get_json_content(path))
if not content:
raise ValueError('searchSpace file should not be empty')
return content | def load_search_space(path):
'''load search space content'''
content = json.dumps(get_json_content(path))
if not content:
raise ValueError('searchSpace file should not be empty')
return content | [
"load",
"search",
"space",
"content"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/updater.py#L59-L64 | [
"def",
"load_search_space",
"(",
"path",
")",
":",
"content",
"=",
"json",
".",
"dumps",
"(",
"get_json_content",
"(",
"path",
")",
")",
"if",
"not",
"content",
":",
"raise",
"ValueError",
"(",
"'searchSpace file should not be empty'",
")",
"return",
"content"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | update_experiment_profile | call restful server to update experiment profile | tools/nni_cmd/updater.py | def update_experiment_profile(args, key, value):
'''call restful server to update experiment profile'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
running, _ = check_rest_server_quick(rest_port)
if running:
response = rest_get(experimen... | def update_experiment_profile(args, key, value):
'''call restful server to update experiment profile'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
running, _ = check_rest_server_quick(rest_port)
if running:
response = rest_get(experimen... | [
"call",
"restful",
"server",
"to",
"update",
"experiment",
"profile"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/updater.py#L77-L92 | [
"def",
"update_experiment_profile",
"(",
"args",
",",
"key",
",",
"value",
")",
":",
"nni_config",
"=",
"Config",
"(",
"get_config_filename",
"(",
"args",
")",
")",
"rest_port",
"=",
"nni_config",
".",
"get_config",
"(",
"'restServerPort'",
")",
"running",
","... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | import_data | import additional data to the experiment | tools/nni_cmd/updater.py | def import_data(args):
'''import additional data to the experiment'''
validate_file(args.filename)
validate_dispatcher(args)
content = load_search_space(args.filename)
args.port = get_experiment_port(args)
if args.port is not None:
if import_data_to_restful_server(args, content):
... | def import_data(args):
'''import additional data to the experiment'''
validate_file(args.filename)
validate_dispatcher(args)
content = load_search_space(args.filename)
args.port = get_experiment_port(args)
if args.port is not None:
if import_data_to_restful_server(args, content):
... | [
"import",
"additional",
"data",
"to",
"the",
"experiment"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/updater.py#L131-L141 | [
"def",
"import_data",
"(",
"args",
")",
":",
"validate_file",
"(",
"args",
".",
"filename",
")",
"validate_dispatcher",
"(",
"args",
")",
"content",
"=",
"load_search_space",
"(",
"args",
".",
"filename",
")",
"args",
".",
"port",
"=",
"get_experiment_port",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | import_data_to_restful_server | call restful server to import data to the experiment | tools/nni_cmd/updater.py | def import_data_to_restful_server(args, content):
'''call restful server to import data to the experiment'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
running, _ = check_rest_server_quick(rest_port)
if running:
response = rest_post(imp... | def import_data_to_restful_server(args, content):
'''call restful server to import data to the experiment'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
running, _ = check_rest_server_quick(rest_port)
if running:
response = rest_post(imp... | [
"call",
"restful",
"server",
"to",
"import",
"data",
"to",
"the",
"experiment"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/updater.py#L143-L154 | [
"def",
"import_data_to_restful_server",
"(",
"args",
",",
"content",
")",
":",
"nni_config",
"=",
"Config",
"(",
"get_config_filename",
"(",
"args",
")",
")",
"rest_port",
"=",
"nni_config",
".",
"get_config",
"(",
"'restServerPort'",
")",
"running",
",",
"_",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | setType | check key type | tools/nni_cmd/config_schema.py | def setType(key, type):
'''check key type'''
return And(type, error=SCHEMA_TYPE_ERROR % (key, type.__name__)) | def setType(key, type):
'''check key type'''
return And(type, error=SCHEMA_TYPE_ERROR % (key, type.__name__)) | [
"check",
"key",
"type"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/config_schema.py#L26-L28 | [
"def",
"setType",
"(",
"key",
",",
"type",
")",
":",
"return",
"And",
"(",
"type",
",",
"error",
"=",
"SCHEMA_TYPE_ERROR",
"%",
"(",
"key",
",",
"type",
".",
"__name__",
")",
")"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | setChoice | check choice | tools/nni_cmd/config_schema.py | def setChoice(key, *args):
'''check choice'''
return And(lambda n: n in args, error=SCHEMA_RANGE_ERROR % (key, str(args))) | def setChoice(key, *args):
'''check choice'''
return And(lambda n: n in args, error=SCHEMA_RANGE_ERROR % (key, str(args))) | [
"check",
"choice"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/config_schema.py#L30-L32 | [
"def",
"setChoice",
"(",
"key",
",",
"*",
"args",
")",
":",
"return",
"And",
"(",
"lambda",
"n",
":",
"n",
"in",
"args",
",",
"error",
"=",
"SCHEMA_RANGE_ERROR",
"%",
"(",
"key",
",",
"str",
"(",
"args",
")",
")",
")"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | setNumberRange | check number range | tools/nni_cmd/config_schema.py | def setNumberRange(key, keyType, start, end):
'''check number range'''
return And(
And(keyType, error=SCHEMA_TYPE_ERROR % (key, keyType.__name__)),
And(lambda n: start <= n <= end, error=SCHEMA_RANGE_ERROR % (key, '(%s,%s)' % (start, end))),
) | def setNumberRange(key, keyType, start, end):
'''check number range'''
return And(
And(keyType, error=SCHEMA_TYPE_ERROR % (key, keyType.__name__)),
And(lambda n: start <= n <= end, error=SCHEMA_RANGE_ERROR % (key, '(%s,%s)' % (start, end))),
) | [
"check",
"number",
"range"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/config_schema.py#L34-L39 | [
"def",
"setNumberRange",
"(",
"key",
",",
"keyType",
",",
"start",
",",
"end",
")",
":",
"return",
"And",
"(",
"And",
"(",
"keyType",
",",
"error",
"=",
"SCHEMA_TYPE_ERROR",
"%",
"(",
"key",
",",
"keyType",
".",
"__name__",
")",
")",
",",
"And",
"(",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | keras_dropout | keras dropout layer. | src/sdk/pynni/nni/networkmorphism_tuner/layers.py | def keras_dropout(layer, rate):
'''keras dropout layer.
'''
from keras import layers
input_dim = len(layer.input.shape)
if input_dim == 2:
return layers.SpatialDropout1D(rate)
elif input_dim == 3:
return layers.SpatialDropout2D(rate)
elif input_dim == 4:
return laye... | def keras_dropout(layer, rate):
'''keras dropout layer.
'''
from keras import layers
input_dim = len(layer.input.shape)
if input_dim == 2:
return layers.SpatialDropout1D(rate)
elif input_dim == 3:
return layers.SpatialDropout2D(rate)
elif input_dim == 4:
return laye... | [
"keras",
"dropout",
"layer",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/layers.py#L530-L544 | [
"def",
"keras_dropout",
"(",
"layer",
",",
"rate",
")",
":",
"from",
"keras",
"import",
"layers",
"input_dim",
"=",
"len",
"(",
"layer",
".",
"input",
".",
"shape",
")",
"if",
"input_dim",
"==",
"2",
":",
"return",
"layers",
".",
"SpatialDropout1D",
"(",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | to_real_keras_layer | real keras layer. | src/sdk/pynni/nni/networkmorphism_tuner/layers.py | def to_real_keras_layer(layer):
''' real keras layer.
'''
from keras import layers
if is_layer(layer, "Dense"):
return layers.Dense(layer.units, input_shape=(layer.input_units,))
if is_layer(layer, "Conv"):
return layers.Conv2D(
layer.filters,
layer.kernel_si... | def to_real_keras_layer(layer):
''' real keras layer.
'''
from keras import layers
if is_layer(layer, "Dense"):
return layers.Dense(layer.units, input_shape=(layer.input_units,))
if is_layer(layer, "Conv"):
return layers.Conv2D(
layer.filters,
layer.kernel_si... | [
"real",
"keras",
"layer",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/layers.py#L547-L578 | [
"def",
"to_real_keras_layer",
"(",
"layer",
")",
":",
"from",
"keras",
"import",
"layers",
"if",
"is_layer",
"(",
"layer",
",",
"\"Dense\"",
")",
":",
"return",
"layers",
".",
"Dense",
"(",
"layer",
".",
"units",
",",
"input_shape",
"=",
"(",
"layer",
".... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | is_layer | judge the layer type.
Returns:
boolean -- True or False | src/sdk/pynni/nni/networkmorphism_tuner/layers.py | def is_layer(layer, layer_type):
'''judge the layer type.
Returns:
boolean -- True or False
'''
if layer_type == "Input":
return isinstance(layer, StubInput)
elif layer_type == "Conv":
return isinstance(layer, StubConv)
elif layer_type == "Dense":
return isinstan... | def is_layer(layer, layer_type):
'''judge the layer type.
Returns:
boolean -- True or False
'''
if layer_type == "Input":
return isinstance(layer, StubInput)
elif layer_type == "Conv":
return isinstance(layer, StubConv)
elif layer_type == "Dense":
return isinstan... | [
"judge",
"the",
"layer",
"type",
".",
"Returns",
":",
"boolean",
"--",
"True",
"or",
"False"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/layers.py#L581-L610 | [
"def",
"is_layer",
"(",
"layer",
",",
"layer_type",
")",
":",
"if",
"layer_type",
"==",
"\"Input\"",
":",
"return",
"isinstance",
"(",
"layer",
",",
"StubInput",
")",
"elif",
"layer_type",
"==",
"\"Conv\"",
":",
"return",
"isinstance",
"(",
"layer",
",",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | layer_description_extractor | get layer description. | src/sdk/pynni/nni/networkmorphism_tuner/layers.py | def layer_description_extractor(layer, node_to_id):
'''get layer description.
'''
layer_input = layer.input
layer_output = layer.output
if layer_input is not None:
if isinstance(layer_input, Iterable):
layer_input = list(map(lambda x: node_to_id[x], layer_input))
else:
... | def layer_description_extractor(layer, node_to_id):
'''get layer description.
'''
layer_input = layer.input
layer_output = layer.output
if layer_input is not None:
if isinstance(layer_input, Iterable):
layer_input = list(map(lambda x: node_to_id[x], layer_input))
else:
... | [
"get",
"layer",
"description",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/layers.py#L613-L661 | [
"def",
"layer_description_extractor",
"(",
"layer",
",",
"node_to_id",
")",
":",
"layer_input",
"=",
"layer",
".",
"input",
"layer_output",
"=",
"layer",
".",
"output",
"if",
"layer_input",
"is",
"not",
"None",
":",
"if",
"isinstance",
"(",
"layer_input",
",",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | layer_description_builder | build layer from description. | src/sdk/pynni/nni/networkmorphism_tuner/layers.py | def layer_description_builder(layer_information, id_to_node):
'''build layer from description.
'''
# pylint: disable=W0123
layer_type = layer_information[0]
layer_input_ids = layer_information[1]
if isinstance(layer_input_ids, Iterable):
layer_input = list(map(lambda x: id_to_node[x], l... | def layer_description_builder(layer_information, id_to_node):
'''build layer from description.
'''
# pylint: disable=W0123
layer_type = layer_information[0]
layer_input_ids = layer_information[1]
if isinstance(layer_input_ids, Iterable):
layer_input = list(map(lambda x: id_to_node[x], l... | [
"build",
"layer",
"from",
"description",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/layers.py#L664-L700 | [
"def",
"layer_description_builder",
"(",
"layer_information",
",",
"id_to_node",
")",
":",
"# pylint: disable=W0123",
"layer_type",
"=",
"layer_information",
"[",
"0",
"]",
"layer_input_ids",
"=",
"layer_information",
"[",
"1",
"]",
"if",
"isinstance",
"(",
"layer_inp... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | layer_width | get layer width. | src/sdk/pynni/nni/networkmorphism_tuner/layers.py | def layer_width(layer):
'''get layer width.
'''
if is_layer(layer, "Dense"):
return layer.units
if is_layer(layer, "Conv"):
return layer.filters
raise TypeError("The layer should be either Dense or Conv layer.") | def layer_width(layer):
'''get layer width.
'''
if is_layer(layer, "Dense"):
return layer.units
if is_layer(layer, "Conv"):
return layer.filters
raise TypeError("The layer should be either Dense or Conv layer.") | [
"get",
"layer",
"width",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/layers.py#L703-L711 | [
"def",
"layer_width",
"(",
"layer",
")",
":",
"if",
"is_layer",
"(",
"layer",
",",
"\"Dense\"",
")",
":",
"return",
"layer",
".",
"units",
"if",
"is_layer",
"(",
"layer",
",",
"\"Conv\"",
")",
":",
"return",
"layer",
".",
"filters",
"raise",
"TypeError",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | GRU.define_params | Define parameters. | examples/trials/weight_sharing/ga_squad/rnn.py | def define_params(self):
'''
Define parameters.
'''
input_dim = self.input_dim
hidden_dim = self.hidden_dim
prefix = self.name
self.w_matrix = tf.Variable(tf.random_normal([input_dim, 3 * hidden_dim], stddev=0.1),
name='/'.join(... | def define_params(self):
'''
Define parameters.
'''
input_dim = self.input_dim
hidden_dim = self.hidden_dim
prefix = self.name
self.w_matrix = tf.Variable(tf.random_normal([input_dim, 3 * hidden_dim], stddev=0.1),
name='/'.join(... | [
"Define",
"parameters",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/rnn.py#L38-L51 | [
"def",
"define_params",
"(",
"self",
")",
":",
"input_dim",
"=",
"self",
".",
"input_dim",
"hidden_dim",
"=",
"self",
".",
"hidden_dim",
"prefix",
"=",
"self",
".",
"name",
"self",
".",
"w_matrix",
"=",
"tf",
".",
"Variable",
"(",
"tf",
".",
"random_norm... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | GRU.build | Build the GRU cell. | examples/trials/weight_sharing/ga_squad/rnn.py | def build(self, x, h, mask=None):
'''
Build the GRU cell.
'''
xw = tf.split(tf.matmul(x, self.w_matrix) + self.bias, 3, 1)
hu = tf.split(tf.matmul(h, self.U), 3, 1)
r = tf.sigmoid(xw[0] + hu[0])
z = tf.sigmoid(xw[1] + hu[1])
h1 = tf.tanh(xw[2] + r * hu[2])... | def build(self, x, h, mask=None):
'''
Build the GRU cell.
'''
xw = tf.split(tf.matmul(x, self.w_matrix) + self.bias, 3, 1)
hu = tf.split(tf.matmul(h, self.U), 3, 1)
r = tf.sigmoid(xw[0] + hu[0])
z = tf.sigmoid(xw[1] + hu[1])
h1 = tf.tanh(xw[2] + r * hu[2])... | [
"Build",
"the",
"GRU",
"cell",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/rnn.py#L53-L65 | [
"def",
"build",
"(",
"self",
",",
"x",
",",
"h",
",",
"mask",
"=",
"None",
")",
":",
"xw",
"=",
"tf",
".",
"split",
"(",
"tf",
".",
"matmul",
"(",
"x",
",",
"self",
".",
"w_matrix",
")",
"+",
"self",
".",
"bias",
",",
"3",
",",
"1",
")",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | GRU.build_sequence | Build GRU sequence. | examples/trials/weight_sharing/ga_squad/rnn.py | def build_sequence(self, xs, masks, init, is_left_to_right):
'''
Build GRU sequence.
'''
states = []
last = init
if is_left_to_right:
for i, xs_i in enumerate(xs):
h = self.build(xs_i, last, masks[i])
states.append(h)
... | def build_sequence(self, xs, masks, init, is_left_to_right):
'''
Build GRU sequence.
'''
states = []
last = init
if is_left_to_right:
for i, xs_i in enumerate(xs):
h = self.build(xs_i, last, masks[i])
states.append(h)
... | [
"Build",
"GRU",
"sequence",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/rnn.py#L67-L83 | [
"def",
"build_sequence",
"(",
"self",
",",
"xs",
",",
"masks",
",",
"init",
",",
"is_left_to_right",
")",
":",
"states",
"=",
"[",
"]",
"last",
"=",
"init",
"if",
"is_left_to_right",
":",
"for",
"i",
",",
"xs_i",
"in",
"enumerate",
"(",
"xs",
")",
":... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | conv2d | conv2d returns a 2d convolution layer with full stride. | tools/nni_annotation/examples/mnist_without_annotation.py | def conv2d(x_input, w_matrix):
"""conv2d returns a 2d convolution layer with full stride."""
return tf.nn.conv2d(x_input, w_matrix, strides=[1, 1, 1, 1], padding='SAME') | def conv2d(x_input, w_matrix):
"""conv2d returns a 2d convolution layer with full stride."""
return tf.nn.conv2d(x_input, w_matrix, strides=[1, 1, 1, 1], padding='SAME') | [
"conv2d",
"returns",
"a",
"2d",
"convolution",
"layer",
"with",
"full",
"stride",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_annotation/examples/mnist_without_annotation.py#L149-L151 | [
"def",
"conv2d",
"(",
"x_input",
",",
"w_matrix",
")",
":",
"return",
"tf",
".",
"nn",
".",
"conv2d",
"(",
"x_input",
",",
"w_matrix",
",",
"strides",
"=",
"[",
"1",
",",
"1",
",",
"1",
",",
"1",
"]",
",",
"padding",
"=",
"'SAME'",
")"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | max_pool | max_pool downsamples a feature map by 2X. | tools/nni_annotation/examples/mnist_without_annotation.py | def max_pool(x_input, pool_size):
"""max_pool downsamples a feature map by 2X."""
return tf.nn.max_pool(x_input, ksize=[1, pool_size, pool_size, 1],
strides=[1, pool_size, pool_size, 1], padding='SAME') | def max_pool(x_input, pool_size):
"""max_pool downsamples a feature map by 2X."""
return tf.nn.max_pool(x_input, ksize=[1, pool_size, pool_size, 1],
strides=[1, pool_size, pool_size, 1], padding='SAME') | [
"max_pool",
"downsamples",
"a",
"feature",
"map",
"by",
"2X",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_annotation/examples/mnist_without_annotation.py#L154-L157 | [
"def",
"max_pool",
"(",
"x_input",
",",
"pool_size",
")",
":",
"return",
"tf",
".",
"nn",
".",
"max_pool",
"(",
"x_input",
",",
"ksize",
"=",
"[",
"1",
",",
"pool_size",
",",
"pool_size",
",",
"1",
"]",
",",
"strides",
"=",
"[",
"1",
",",
"pool_siz... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | main | Main function, build mnist network, run and send result to NNI. | tools/nni_annotation/examples/mnist_without_annotation.py | def main(params):
'''
Main function, build mnist network, run and send result to NNI.
'''
# Import data
mnist = download_mnist_retry(params['data_dir'])
print('Mnist download data done.')
logger.debug('Mnist download data done.')
# Create the model
# Build the graph for the deep net... | def main(params):
'''
Main function, build mnist network, run and send result to NNI.
'''
# Import data
mnist = download_mnist_retry(params['data_dir'])
print('Mnist download data done.')
logger.debug('Mnist download data done.')
# Create the model
# Build the graph for the deep net... | [
"Main",
"function",
"build",
"mnist",
"network",
"run",
"and",
"send",
"result",
"to",
"NNI",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_annotation/examples/mnist_without_annotation.py#L185-L237 | [
"def",
"main",
"(",
"params",
")",
":",
"# Import data",
"mnist",
"=",
"download_mnist_retry",
"(",
"params",
"[",
"'data_dir'",
"]",
")",
"print",
"(",
"'Mnist download data done.'",
")",
"logger",
".",
"debug",
"(",
"'Mnist download data done.'",
")",
"# Create ... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | GAG.build_net | Build the whole neural network for the QA model. | examples/trials/ga_squad/train_model.py | def build_net(self, is_training):
"""Build the whole neural network for the QA model."""
cfg = self.cfg
with tf.device('/cpu:0'):
word_embed = tf.get_variable(
name='word_embed', initializer=self.embed, dtype=tf.float32, trainable=False)
char_embed = tf.ge... | def build_net(self, is_training):
"""Build the whole neural network for the QA model."""
cfg = self.cfg
with tf.device('/cpu:0'):
word_embed = tf.get_variable(
name='word_embed', initializer=self.embed, dtype=tf.float32, trainable=False)
char_embed = tf.ge... | [
"Build",
"the",
"whole",
"neural",
"network",
"for",
"the",
"QA",
"model",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/ga_squad/train_model.py#L87-L233 | [
"def",
"build_net",
"(",
"self",
",",
"is_training",
")",
":",
"cfg",
"=",
"self",
".",
"cfg",
"with",
"tf",
".",
"device",
"(",
"'/cpu:0'",
")",
":",
"word_embed",
"=",
"tf",
".",
"get_variable",
"(",
"name",
"=",
"'word_embed'",
",",
"initializer",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | check_output_command | call check_output command to read content from a file | tools/nni_cmd/command_utils.py | def check_output_command(file_path, head=None, tail=None):
'''call check_output command to read content from a file'''
if os.path.exists(file_path):
if sys.platform == 'win32':
cmds = ['powershell.exe', 'type', file_path]
if head:
cmds += ['|', 'select', '-first',... | def check_output_command(file_path, head=None, tail=None):
'''call check_output command to read content from a file'''
if os.path.exists(file_path):
if sys.platform == 'win32':
cmds = ['powershell.exe', 'type', file_path]
if head:
cmds += ['|', 'select', '-first',... | [
"call",
"check_output",
"command",
"to",
"read",
"content",
"from",
"a",
"file"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/command_utils.py#L8-L27 | [
"def",
"check_output_command",
"(",
"file_path",
",",
"head",
"=",
"None",
",",
"tail",
"=",
"None",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"file_path",
")",
":",
"if",
"sys",
".",
"platform",
"==",
"'win32'",
":",
"cmds",
"=",
"[",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | kill_command | kill command | tools/nni_cmd/command_utils.py | def kill_command(pid):
'''kill command'''
if sys.platform == 'win32':
process = psutil.Process(pid=pid)
process.send_signal(signal.CTRL_BREAK_EVENT)
else:
cmds = ['kill', str(pid)]
call(cmds) | def kill_command(pid):
'''kill command'''
if sys.platform == 'win32':
process = psutil.Process(pid=pid)
process.send_signal(signal.CTRL_BREAK_EVENT)
else:
cmds = ['kill', str(pid)]
call(cmds) | [
"kill",
"command"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/command_utils.py#L29-L36 | [
"def",
"kill_command",
"(",
"pid",
")",
":",
"if",
"sys",
".",
"platform",
"==",
"'win32'",
":",
"process",
"=",
"psutil",
".",
"Process",
"(",
"pid",
"=",
"pid",
")",
"process",
".",
"send_signal",
"(",
"signal",
".",
"CTRL_BREAK_EVENT",
")",
"else",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | install_package_command | install python package from pip | tools/nni_cmd/command_utils.py | def install_package_command(package_name):
'''install python package from pip'''
#TODO refactor python logic
if sys.platform == "win32":
cmds = 'python -m pip install --user {0}'.format(package_name)
else:
cmds = 'python3 -m pip install --user {0}'.format(package_name)
call(cmds, she... | def install_package_command(package_name):
'''install python package from pip'''
#TODO refactor python logic
if sys.platform == "win32":
cmds = 'python -m pip install --user {0}'.format(package_name)
else:
cmds = 'python3 -m pip install --user {0}'.format(package_name)
call(cmds, she... | [
"install",
"python",
"package",
"from",
"pip"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/command_utils.py#L38-L45 | [
"def",
"install_package_command",
"(",
"package_name",
")",
":",
"#TODO refactor python logic",
"if",
"sys",
".",
"platform",
"==",
"\"win32\"",
":",
"cmds",
"=",
"'python -m pip install --user {0}'",
".",
"format",
"(",
"package_name",
")",
"else",
":",
"cmds",
"="... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | install_requirements_command | install requirements.txt | tools/nni_cmd/command_utils.py | def install_requirements_command(requirements_path):
'''install requirements.txt'''
cmds = 'cd ' + requirements_path + ' && {0} -m pip install --user -r requirements.txt'
#TODO refactor python logic
if sys.platform == "win32":
cmds = cmds.format('python')
else:
cmds = cmds.format('py... | def install_requirements_command(requirements_path):
'''install requirements.txt'''
cmds = 'cd ' + requirements_path + ' && {0} -m pip install --user -r requirements.txt'
#TODO refactor python logic
if sys.platform == "win32":
cmds = cmds.format('python')
else:
cmds = cmds.format('py... | [
"install",
"requirements",
".",
"txt"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/command_utils.py#L47-L55 | [
"def",
"install_requirements_command",
"(",
"requirements_path",
")",
":",
"cmds",
"=",
"'cd '",
"+",
"requirements_path",
"+",
"' && {0} -m pip install --user -r requirements.txt'",
"#TODO refactor python logic",
"if",
"sys",
".",
"platform",
"==",
"\"win32\"",
":",
"cmds"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_params | Get parameters from command line | examples/trials/mnist-advisor/mnist.py | def get_params():
''' Get parameters from command line '''
parser = argparse.ArgumentParser()
parser.add_argument("--data_dir", type=str, default='/tmp/tensorflow/mnist/input_data', help="data directory")
parser.add_argument("--dropout_rate", type=float, default=0.5, help="dropout rate")
parser.add_... | def get_params():
''' Get parameters from command line '''
parser = argparse.ArgumentParser()
parser.add_argument("--data_dir", type=str, default='/tmp/tensorflow/mnist/input_data', help="data directory")
parser.add_argument("--dropout_rate", type=float, default=0.5, help="dropout rate")
parser.add_... | [
"Get",
"parameters",
"from",
"command",
"line"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/mnist-advisor/mnist.py#L211-L226 | [
"def",
"get_params",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"\"--data_dir\"",
",",
"type",
"=",
"str",
",",
"default",
"=",
"'/tmp/tensorflow/mnist/input_data'",
",",
"help",
"=",
"\"data ... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MnistNetwork.build_network | Building network for mnist | examples/trials/mnist-advisor/mnist.py | def build_network(self):
'''
Building network for mnist
'''
# Reshape to use within a convolutional neural net.
# Last dimension is for "features" - there is only one here, since images are
# grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.
with tf.n... | def build_network(self):
'''
Building network for mnist
'''
# Reshape to use within a convolutional neural net.
# Last dimension is for "features" - there is only one here, since images are
# grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.
with tf.n... | [
"Building",
"network",
"for",
"mnist"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/mnist-advisor/mnist.py#L48-L122 | [
"def",
"build_network",
"(",
"self",
")",
":",
"# Reshape to use within a convolutional neural net.",
"# Last dimension is for \"features\" - there is only one here, since images are",
"# grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.",
"with",
"tf",
".",
"name_scope",
"(",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_experiment_time | get the startTime and endTime of an experiment | tools/nni_cmd/nnictl_utils.py | def get_experiment_time(port):
'''get the startTime and endTime of an experiment'''
response = rest_get(experiment_url(port), REST_TIME_OUT)
if response and check_response(response):
content = convert_time_stamp_to_date(json.loads(response.text))
return content.get('startTime'), content.get(... | def get_experiment_time(port):
'''get the startTime and endTime of an experiment'''
response = rest_get(experiment_url(port), REST_TIME_OUT)
if response and check_response(response):
content = convert_time_stamp_to_date(json.loads(response.text))
return content.get('startTime'), content.get(... | [
"get",
"the",
"startTime",
"and",
"endTime",
"of",
"an",
"experiment"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L36-L42 | [
"def",
"get_experiment_time",
"(",
"port",
")",
":",
"response",
"=",
"rest_get",
"(",
"experiment_url",
"(",
"port",
")",
",",
"REST_TIME_OUT",
")",
"if",
"response",
"and",
"check_response",
"(",
"response",
")",
":",
"content",
"=",
"convert_time_stamp_to_dat... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_experiment_status | get the status of an experiment | tools/nni_cmd/nnictl_utils.py | def get_experiment_status(port):
'''get the status of an experiment'''
result, response = check_rest_server_quick(port)
if result:
return json.loads(response.text).get('status')
return None | def get_experiment_status(port):
'''get the status of an experiment'''
result, response = check_rest_server_quick(port)
if result:
return json.loads(response.text).get('status')
return None | [
"get",
"the",
"status",
"of",
"an",
"experiment"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L44-L49 | [
"def",
"get_experiment_status",
"(",
"port",
")",
":",
"result",
",",
"response",
"=",
"check_rest_server_quick",
"(",
"port",
")",
"if",
"result",
":",
"return",
"json",
".",
"loads",
"(",
"response",
".",
"text",
")",
".",
"get",
"(",
"'status'",
")",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | update_experiment | Update the experiment status in config file | tools/nni_cmd/nnictl_utils.py | def update_experiment():
'''Update the experiment status in config file'''
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
if not experiment_dict:
return None
for key in experiment_dict.keys():
if isinstance(experiment_dict[key], dict):
... | def update_experiment():
'''Update the experiment status in config file'''
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
if not experiment_dict:
return None
for key in experiment_dict.keys():
if isinstance(experiment_dict[key], dict):
... | [
"Update",
"the",
"experiment",
"status",
"in",
"config",
"file"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L51-L73 | [
"def",
"update_experiment",
"(",
")",
":",
"experiment_config",
"=",
"Experiments",
"(",
")",
"experiment_dict",
"=",
"experiment_config",
".",
"get_all_experiments",
"(",
")",
"if",
"not",
"experiment_dict",
":",
"return",
"None",
"for",
"key",
"in",
"experiment_... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | check_experiment_id | check if the id is valid | tools/nni_cmd/nnictl_utils.py | def check_experiment_id(args):
'''check if the id is valid
'''
update_experiment()
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
if not experiment_dict:
print_normal('There is no experiment running...')
return None
if not args.id:... | def check_experiment_id(args):
'''check if the id is valid
'''
update_experiment()
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
if not experiment_dict:
print_normal('There is no experiment running...')
return None
if not args.id:... | [
"check",
"if",
"the",
"id",
"is",
"valid"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L75-L110 | [
"def",
"check_experiment_id",
"(",
"args",
")",
":",
"update_experiment",
"(",
")",
"experiment_config",
"=",
"Experiments",
"(",
")",
"experiment_dict",
"=",
"experiment_config",
".",
"get_all_experiments",
"(",
")",
"if",
"not",
"experiment_dict",
":",
"print_norm... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | parse_ids | Parse the arguments for nnictl stop
1.If there is an id specified, return the corresponding id
2.If there is no id specified, and there is an experiment running, return the id, or return Error
3.If the id matches an experiment, nnictl will return the id.
4.If the id ends with *, nnictl will match all id... | tools/nni_cmd/nnictl_utils.py | def parse_ids(args):
'''Parse the arguments for nnictl stop
1.If there is an id specified, return the corresponding id
2.If there is no id specified, and there is an experiment running, return the id, or return Error
3.If the id matches an experiment, nnictl will return the id.
4.If the id ends with... | def parse_ids(args):
'''Parse the arguments for nnictl stop
1.If there is an id specified, return the corresponding id
2.If there is no id specified, and there is an experiment running, return the id, or return Error
3.If the id matches an experiment, nnictl will return the id.
4.If the id ends with... | [
"Parse",
"the",
"arguments",
"for",
"nnictl",
"stop",
"1",
".",
"If",
"there",
"is",
"an",
"id",
"specified",
"return",
"the",
"corresponding",
"id",
"2",
".",
"If",
"there",
"is",
"no",
"id",
"specified",
"and",
"there",
"is",
"an",
"experiment",
"runni... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L112-L166 | [
"def",
"parse_ids",
"(",
"args",
")",
":",
"update_experiment",
"(",
")",
"experiment_config",
"=",
"Experiments",
"(",
")",
"experiment_dict",
"=",
"experiment_config",
".",
"get_all_experiments",
"(",
")",
"if",
"not",
"experiment_dict",
":",
"print_normal",
"("... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_config_filename | get the file name of config file | tools/nni_cmd/nnictl_utils.py | def get_config_filename(args):
'''get the file name of config file'''
experiment_id = check_experiment_id(args)
if experiment_id is None:
print_error('Please set the experiment id!')
exit(1)
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
... | def get_config_filename(args):
'''get the file name of config file'''
experiment_id = check_experiment_id(args)
if experiment_id is None:
print_error('Please set the experiment id!')
exit(1)
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
... | [
"get",
"the",
"file",
"name",
"of",
"config",
"file"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L168-L176 | [
"def",
"get_config_filename",
"(",
"args",
")",
":",
"experiment_id",
"=",
"check_experiment_id",
"(",
"args",
")",
"if",
"experiment_id",
"is",
"None",
":",
"print_error",
"(",
"'Please set the experiment id!'",
")",
"exit",
"(",
"1",
")",
"experiment_config",
"=... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | convert_time_stamp_to_date | Convert time stamp to date time format | tools/nni_cmd/nnictl_utils.py | def convert_time_stamp_to_date(content):
'''Convert time stamp to date time format'''
start_time_stamp = content.get('startTime')
end_time_stamp = content.get('endTime')
if start_time_stamp:
start_time = datetime.datetime.utcfromtimestamp(start_time_stamp // 1000).strftime("%Y/%m/%d %H:%M:%S")
... | def convert_time_stamp_to_date(content):
'''Convert time stamp to date time format'''
start_time_stamp = content.get('startTime')
end_time_stamp = content.get('endTime')
if start_time_stamp:
start_time = datetime.datetime.utcfromtimestamp(start_time_stamp // 1000).strftime("%Y/%m/%d %H:%M:%S")
... | [
"Convert",
"time",
"stamp",
"to",
"date",
"time",
"format"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L188-L198 | [
"def",
"convert_time_stamp_to_date",
"(",
"content",
")",
":",
"start_time_stamp",
"=",
"content",
".",
"get",
"(",
"'startTime'",
")",
"end_time_stamp",
"=",
"content",
".",
"get",
"(",
"'endTime'",
")",
"if",
"start_time_stamp",
":",
"start_time",
"=",
"dateti... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | check_rest | check if restful server is running | tools/nni_cmd/nnictl_utils.py | def check_rest(args):
'''check if restful server is running'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
running, _ = check_rest_server_quick(rest_port)
if not running:
print_normal('Restful server is running...')
else:
pri... | def check_rest(args):
'''check if restful server is running'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
running, _ = check_rest_server_quick(rest_port)
if not running:
print_normal('Restful server is running...')
else:
pri... | [
"check",
"if",
"restful",
"server",
"is",
"running"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L200-L208 | [
"def",
"check_rest",
"(",
"args",
")",
":",
"nni_config",
"=",
"Config",
"(",
"get_config_filename",
"(",
"args",
")",
")",
"rest_port",
"=",
"nni_config",
".",
"get_config",
"(",
"'restServerPort'",
")",
"running",
",",
"_",
"=",
"check_rest_server_quick",
"(... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | stop_experiment | Stop the experiment which is running | tools/nni_cmd/nnictl_utils.py | def stop_experiment(args):
'''Stop the experiment which is running'''
experiment_id_list = parse_ids(args)
if experiment_id_list:
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
for experiment_id in experiment_id_list:
print_nor... | def stop_experiment(args):
'''Stop the experiment which is running'''
experiment_id_list = parse_ids(args)
if experiment_id_list:
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
for experiment_id in experiment_id_list:
print_nor... | [
"Stop",
"the",
"experiment",
"which",
"is",
"running"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L210-L234 | [
"def",
"stop_experiment",
"(",
"args",
")",
":",
"experiment_id_list",
"=",
"parse_ids",
"(",
"args",
")",
"if",
"experiment_id_list",
":",
"experiment_config",
"=",
"Experiments",
"(",
")",
"experiment_dict",
"=",
"experiment_config",
".",
"get_all_experiments",
"(... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | trial_ls | List trial | tools/nni_cmd/nnictl_utils.py | def trial_ls(args):
'''List trial'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
rest_pid = nni_config.get_config('restServerPid')
if not detect_process(rest_pid):
print_error('Experiment is not running...')
return
running, r... | def trial_ls(args):
'''List trial'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
rest_pid = nni_config.get_config('restServerPid')
if not detect_process(rest_pid):
print_error('Experiment is not running...')
return
running, r... | [
"List",
"trial"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L236-L255 | [
"def",
"trial_ls",
"(",
"args",
")",
":",
"nni_config",
"=",
"Config",
"(",
"get_config_filename",
"(",
"args",
")",
")",
"rest_port",
"=",
"nni_config",
".",
"get_config",
"(",
"'restServerPort'",
")",
"rest_pid",
"=",
"nni_config",
".",
"get_config",
"(",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | trial_kill | List trial | tools/nni_cmd/nnictl_utils.py | def trial_kill(args):
'''List trial'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
rest_pid = nni_config.get_config('restServerPid')
if not detect_process(rest_pid):
print_error('Experiment is not running...')
return
running,... | def trial_kill(args):
'''List trial'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
rest_pid = nni_config.get_config('restServerPid')
if not detect_process(rest_pid):
print_error('Experiment is not running...')
return
running,... | [
"List",
"trial"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L257-L273 | [
"def",
"trial_kill",
"(",
"args",
")",
":",
"nni_config",
"=",
"Config",
"(",
"get_config_filename",
"(",
"args",
")",
")",
"rest_port",
"=",
"nni_config",
".",
"get_config",
"(",
"'restServerPort'",
")",
"rest_pid",
"=",
"nni_config",
".",
"get_config",
"(",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | list_experiment | Get experiment information | tools/nni_cmd/nnictl_utils.py | def list_experiment(args):
'''Get experiment information'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
rest_pid = nni_config.get_config('restServerPid')
if not detect_process(rest_pid):
print_error('Experiment is not running...')
... | def list_experiment(args):
'''Get experiment information'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
rest_pid = nni_config.get_config('restServerPid')
if not detect_process(rest_pid):
print_error('Experiment is not running...')
... | [
"Get",
"experiment",
"information"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L275-L292 | [
"def",
"list_experiment",
"(",
"args",
")",
":",
"nni_config",
"=",
"Config",
"(",
"get_config_filename",
"(",
"args",
")",
")",
"rest_port",
"=",
"nni_config",
".",
"get_config",
"(",
"'restServerPort'",
")",
"rest_pid",
"=",
"nni_config",
".",
"get_config",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | experiment_status | Show the status of experiment | tools/nni_cmd/nnictl_utils.py | def experiment_status(args):
'''Show the status of experiment'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
result, response = check_rest_server_quick(rest_port)
if not result:
print_normal('Restful server is not running...')
else:
... | def experiment_status(args):
'''Show the status of experiment'''
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
result, response = check_rest_server_quick(rest_port)
if not result:
print_normal('Restful server is not running...')
else:
... | [
"Show",
"the",
"status",
"of",
"experiment"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L294-L302 | [
"def",
"experiment_status",
"(",
"args",
")",
":",
"nni_config",
"=",
"Config",
"(",
"get_config_filename",
"(",
"args",
")",
")",
"rest_port",
"=",
"nni_config",
".",
"get_config",
"(",
"'restServerPort'",
")",
"result",
",",
"response",
"=",
"check_rest_server... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | log_internal | internal function to call get_log_content | tools/nni_cmd/nnictl_utils.py | def log_internal(args, filetype):
'''internal function to call get_log_content'''
file_name = get_config_filename(args)
if filetype == 'stdout':
file_full_path = os.path.join(NNICTL_HOME_DIR, file_name, 'stdout')
else:
file_full_path = os.path.join(NNICTL_HOME_DIR, file_name, 'stderr')
... | def log_internal(args, filetype):
'''internal function to call get_log_content'''
file_name = get_config_filename(args)
if filetype == 'stdout':
file_full_path = os.path.join(NNICTL_HOME_DIR, file_name, 'stdout')
else:
file_full_path = os.path.join(NNICTL_HOME_DIR, file_name, 'stderr')
... | [
"internal",
"function",
"to",
"call",
"get_log_content"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L304-L311 | [
"def",
"log_internal",
"(",
"args",
",",
"filetype",
")",
":",
"file_name",
"=",
"get_config_filename",
"(",
"args",
")",
"if",
"filetype",
"==",
"'stdout'",
":",
"file_full_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"NNICTL_HOME_DIR",
",",
"file_name"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | log_trial | get trial log path | tools/nni_cmd/nnictl_utils.py | def log_trial(args):
''''get trial log path'''
trial_id_path_dict = {}
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
rest_pid = nni_config.get_config('restServerPid')
if not detect_process(rest_pid):
print_error('Experiment is not runn... | def log_trial(args):
''''get trial log path'''
trial_id_path_dict = {}
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
rest_pid = nni_config.get_config('restServerPid')
if not detect_process(rest_pid):
print_error('Experiment is not runn... | [
"get",
"trial",
"log",
"path"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L321-L352 | [
"def",
"log_trial",
"(",
"args",
")",
":",
"trial_id_path_dict",
"=",
"{",
"}",
"nni_config",
"=",
"Config",
"(",
"get_config_filename",
"(",
"args",
")",
")",
"rest_port",
"=",
"nni_config",
".",
"get_config",
"(",
"'restServerPort'",
")",
"rest_pid",
"=",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | webui_url | show the url of web ui | tools/nni_cmd/nnictl_utils.py | def webui_url(args):
'''show the url of web ui'''
nni_config = Config(get_config_filename(args))
print_normal('{0} {1}'.format('Web UI url:', ' '.join(nni_config.get_config('webuiUrl')))) | def webui_url(args):
'''show the url of web ui'''
nni_config = Config(get_config_filename(args))
print_normal('{0} {1}'.format('Web UI url:', ' '.join(nni_config.get_config('webuiUrl')))) | [
"show",
"the",
"url",
"of",
"web",
"ui"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L359-L362 | [
"def",
"webui_url",
"(",
"args",
")",
":",
"nni_config",
"=",
"Config",
"(",
"get_config_filename",
"(",
"args",
")",
")",
"print_normal",
"(",
"'{0} {1}'",
".",
"format",
"(",
"'Web UI url:'",
",",
"' '",
".",
"join",
"(",
"nni_config",
".",
"get_config",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | experiment_list | get the information of all experiments | tools/nni_cmd/nnictl_utils.py | def experiment_list(args):
'''get the information of all experiments'''
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
if not experiment_dict:
print('There is no experiment running...')
exit(1)
update_experiment()
experiment_id_list = ... | def experiment_list(args):
'''get the information of all experiments'''
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
if not experiment_dict:
print('There is no experiment running...')
exit(1)
update_experiment()
experiment_id_list = ... | [
"get",
"the",
"information",
"of",
"all",
"experiments"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L364-L387 | [
"def",
"experiment_list",
"(",
"args",
")",
":",
"experiment_config",
"=",
"Experiments",
"(",
")",
"experiment_dict",
"=",
"experiment_config",
".",
"get_all_experiments",
"(",
")",
"if",
"not",
"experiment_dict",
":",
"print",
"(",
"'There is no experiment running..... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_time_interval | get the interval of two times | tools/nni_cmd/nnictl_utils.py | def get_time_interval(time1, time2):
'''get the interval of two times'''
try:
#convert time to timestamp
time1 = time.mktime(time.strptime(time1, '%Y/%m/%d %H:%M:%S'))
time2 = time.mktime(time.strptime(time2, '%Y/%m/%d %H:%M:%S'))
seconds = (datetime.datetime.fromtimestamp(time2)... | def get_time_interval(time1, time2):
'''get the interval of two times'''
try:
#convert time to timestamp
time1 = time.mktime(time.strptime(time1, '%Y/%m/%d %H:%M:%S'))
time2 = time.mktime(time.strptime(time2, '%Y/%m/%d %H:%M:%S'))
seconds = (datetime.datetime.fromtimestamp(time2)... | [
"get",
"the",
"interval",
"of",
"two",
"times"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L389-L405 | [
"def",
"get_time_interval",
"(",
"time1",
",",
"time2",
")",
":",
"try",
":",
"#convert time to timestamp",
"time1",
"=",
"time",
".",
"mktime",
"(",
"time",
".",
"strptime",
"(",
"time1",
",",
"'%Y/%m/%d %H:%M:%S'",
")",
")",
"time2",
"=",
"time",
".",
"m... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | show_experiment_info | show experiment information in monitor | tools/nni_cmd/nnictl_utils.py | def show_experiment_info():
'''show experiment information in monitor'''
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
if not experiment_dict:
print('There is no experiment running...')
exit(1)
update_experiment()
experiment_id_list =... | def show_experiment_info():
'''show experiment information in monitor'''
experiment_config = Experiments()
experiment_dict = experiment_config.get_all_experiments()
if not experiment_dict:
print('There is no experiment running...')
exit(1)
update_experiment()
experiment_id_list =... | [
"show",
"experiment",
"information",
"in",
"monitor"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L407-L434 | [
"def",
"show_experiment_info",
"(",
")",
":",
"experiment_config",
"=",
"Experiments",
"(",
")",
"experiment_dict",
"=",
"experiment_config",
".",
"get_all_experiments",
"(",
")",
"if",
"not",
"experiment_dict",
":",
"print",
"(",
"'There is no experiment running...'",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | monitor_experiment | monitor the experiment | tools/nni_cmd/nnictl_utils.py | def monitor_experiment(args):
'''monitor the experiment'''
if args.time <= 0:
print_error('please input a positive integer as time interval, the unit is second.')
exit(1)
while True:
try:
os.system('clear')
update_experiment()
show_experiment_info(... | def monitor_experiment(args):
'''monitor the experiment'''
if args.time <= 0:
print_error('please input a positive integer as time interval, the unit is second.')
exit(1)
while True:
try:
os.system('clear')
update_experiment()
show_experiment_info(... | [
"monitor",
"the",
"experiment"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L436-L451 | [
"def",
"monitor_experiment",
"(",
"args",
")",
":",
"if",
"args",
".",
"time",
"<=",
"0",
":",
"print_error",
"(",
"'please input a positive integer as time interval, the unit is second.'",
")",
"exit",
"(",
"1",
")",
"while",
"True",
":",
"try",
":",
"os",
".",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | parse_trial_data | output: List[Dict] | tools/nni_cmd/nnictl_utils.py | def parse_trial_data(content):
"""output: List[Dict]"""
trial_records = []
for trial_data in content:
for phase_i in range(len(trial_data['hyperParameters'])):
hparam = json.loads(trial_data['hyperParameters'][phase_i])['parameters']
hparam['id'] = trial_data['id']
... | def parse_trial_data(content):
"""output: List[Dict]"""
trial_records = []
for trial_data in content:
for phase_i in range(len(trial_data['hyperParameters'])):
hparam = json.loads(trial_data['hyperParameters'][phase_i])['parameters']
hparam['id'] = trial_data['id']
... | [
"output",
":",
"List",
"[",
"Dict",
"]"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L454-L472 | [
"def",
"parse_trial_data",
"(",
"content",
")",
":",
"trial_records",
"=",
"[",
"]",
"for",
"trial_data",
"in",
"content",
":",
"for",
"phase_i",
"in",
"range",
"(",
"len",
"(",
"trial_data",
"[",
"'hyperParameters'",
"]",
")",
")",
":",
"hparam",
"=",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | export_trials_data | export experiment metadata to csv | tools/nni_cmd/nnictl_utils.py | def export_trials_data(args):
"""export experiment metadata to csv
"""
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
rest_pid = nni_config.get_config('restServerPid')
if not detect_process(rest_pid):
print_error('Experiment is not runn... | def export_trials_data(args):
"""export experiment metadata to csv
"""
nni_config = Config(get_config_filename(args))
rest_port = nni_config.get_config('restServerPort')
rest_pid = nni_config.get_config('restServerPid')
if not detect_process(rest_pid):
print_error('Experiment is not runn... | [
"export",
"experiment",
"metadata",
"to",
"csv"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/nnictl_utils.py#L474-L507 | [
"def",
"export_trials_data",
"(",
"args",
")",
":",
"nni_config",
"=",
"Config",
"(",
"get_config_filename",
"(",
"args",
")",
")",
"rest_port",
"=",
"nni_config",
".",
"get_config",
"(",
"'restServerPort'",
")",
"rest_pid",
"=",
"nni_config",
".",
"get_config",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | copy_remote_directory_to_local | copy remote directory to local machine | tools/nni_cmd/ssh_utils.py | def copy_remote_directory_to_local(sftp, remote_path, local_path):
'''copy remote directory to local machine'''
try:
os.makedirs(local_path, exist_ok=True)
files = sftp.listdir(remote_path)
for file in files:
remote_full_path = os.path.join(remote_path, file)
loca... | def copy_remote_directory_to_local(sftp, remote_path, local_path):
'''copy remote directory to local machine'''
try:
os.makedirs(local_path, exist_ok=True)
files = sftp.listdir(remote_path)
for file in files:
remote_full_path = os.path.join(remote_path, file)
loca... | [
"copy",
"remote",
"directory",
"to",
"local",
"machine"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/ssh_utils.py#L33-L47 | [
"def",
"copy_remote_directory_to_local",
"(",
"sftp",
",",
"remote_path",
",",
"local_path",
")",
":",
"try",
":",
"os",
".",
"makedirs",
"(",
"local_path",
",",
"exist_ok",
"=",
"True",
")",
"files",
"=",
"sftp",
".",
"listdir",
"(",
"remote_path",
")",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | create_ssh_sftp_client | create ssh client | tools/nni_cmd/ssh_utils.py | def create_ssh_sftp_client(host_ip, port, username, password):
'''create ssh client'''
try:
check_environment()
import paramiko
conn = paramiko.Transport(host_ip, port)
conn.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(conn)
... | def create_ssh_sftp_client(host_ip, port, username, password):
'''create ssh client'''
try:
check_environment()
import paramiko
conn = paramiko.Transport(host_ip, port)
conn.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(conn)
... | [
"create",
"ssh",
"client"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/ssh_utils.py#L49-L59 | [
"def",
"create_ssh_sftp_client",
"(",
"host_ip",
",",
"port",
",",
"username",
",",
"password",
")",
":",
"try",
":",
"check_environment",
"(",
")",
"import",
"paramiko",
"conn",
"=",
"paramiko",
".",
"Transport",
"(",
"host_ip",
",",
"port",
")",
"conn",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | json2space | Change search space from json format to hyperopt format | src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py | def json2space(x, oldy=None, name=NodeType.Root.value):
"""Change search space from json format to hyperopt format
"""
y = list()
if isinstance(x, dict):
if NodeType.Type.value in x.keys():
_type = x[NodeType.Type.value]
name = name + '-' + _type
if _type == '... | def json2space(x, oldy=None, name=NodeType.Root.value):
"""Change search space from json format to hyperopt format
"""
y = list()
if isinstance(x, dict):
if NodeType.Type.value in x.keys():
_type = x[NodeType.Type.value]
name = name + '-' + _type
if _type == '... | [
"Change",
"search",
"space",
"from",
"json",
"format",
"to",
"hyperopt",
"format"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py#L61-L87 | [
"def",
"json2space",
"(",
"x",
",",
"oldy",
"=",
"None",
",",
"name",
"=",
"NodeType",
".",
"Root",
".",
"value",
")",
":",
"y",
"=",
"list",
"(",
")",
"if",
"isinstance",
"(",
"x",
",",
"dict",
")",
":",
"if",
"NodeType",
".",
"Type",
".",
"va... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | json2paramater | Json to pramaters. | src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py | def json2paramater(x, is_rand, random_state, oldy=None, Rand=False, name=NodeType.Root.value):
"""Json to pramaters.
"""
if isinstance(x, dict):
if NodeType.Type.value in x.keys():
_type = x[NodeType.Type.value]
_value = x[NodeType.Value.value]
name = name + '-' +... | def json2paramater(x, is_rand, random_state, oldy=None, Rand=False, name=NodeType.Root.value):
"""Json to pramaters.
"""
if isinstance(x, dict):
if NodeType.Type.value in x.keys():
_type = x[NodeType.Type.value]
_value = x[NodeType.Value.value]
name = name + '-' +... | [
"Json",
"to",
"pramaters",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py#L90-L128 | [
"def",
"json2paramater",
"(",
"x",
",",
"is_rand",
",",
"random_state",
",",
"oldy",
"=",
"None",
",",
"Rand",
"=",
"False",
",",
"name",
"=",
"NodeType",
".",
"Root",
".",
"value",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"dict",
")",
":",
"if... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | _split_index | Delete index information from params
Parameters
----------
params : dict
Returns
-------
result : dict | src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py | def _split_index(params):
"""Delete index information from params
Parameters
----------
params : dict
Returns
-------
result : dict
"""
result = {}
for key in params:
if isinstance(params[key], dict):
value = params[key]['_value']
else:
v... | def _split_index(params):
"""Delete index information from params
Parameters
----------
params : dict
Returns
-------
result : dict
"""
result = {}
for key in params:
if isinstance(params[key], dict):
value = params[key]['_value']
else:
v... | [
"Delete",
"index",
"information",
"from",
"params"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py#L131-L149 | [
"def",
"_split_index",
"(",
"params",
")",
":",
"result",
"=",
"{",
"}",
"for",
"key",
"in",
"params",
":",
"if",
"isinstance",
"(",
"params",
"[",
"key",
"]",
",",
"dict",
")",
":",
"value",
"=",
"params",
"[",
"key",
"]",
"[",
"'_value'",
"]",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Individual.mutation | Parameters
----------
config : str
info : str
save_dir : str | src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py | def mutation(self, config=None, info=None, save_dir=None):
"""
Parameters
----------
config : str
info : str
save_dir : str
"""
self.result = None
self.config = config
self.restore_dir = self.save_dir
self.save_dir = save_dir
... | def mutation(self, config=None, info=None, save_dir=None):
"""
Parameters
----------
config : str
info : str
save_dir : str
"""
self.result = None
self.config = config
self.restore_dir = self.save_dir
self.save_dir = save_dir
... | [
"Parameters",
"----------",
"config",
":",
"str",
"info",
":",
"str",
"save_dir",
":",
"str"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py#L176-L188 | [
"def",
"mutation",
"(",
"self",
",",
"config",
"=",
"None",
",",
"info",
"=",
"None",
",",
"save_dir",
"=",
"None",
")",
":",
"self",
".",
"result",
"=",
"None",
"self",
".",
"config",
"=",
"config",
"self",
".",
"restore_dir",
"=",
"self",
".",
"s... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | EvolutionTuner.update_search_space | Update search space.
Search_space contains the information that user pre-defined.
Parameters
----------
search_space : dict | src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py | def update_search_space(self, search_space):
"""Update search space.
Search_space contains the information that user pre-defined.
Parameters
----------
search_space : dict
"""
self.searchspace_json = search_space
self.space = json2space(self.searchspace_... | def update_search_space(self, search_space):
"""Update search space.
Search_space contains the information that user pre-defined.
Parameters
----------
search_space : dict
"""
self.searchspace_json = search_space
self.space = json2space(self.searchspace_... | [
"Update",
"search",
"space",
".",
"Search_space",
"contains",
"the",
"information",
"that",
"user",
"pre",
"-",
"defined",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py#L215-L234 | [
"def",
"update_search_space",
"(",
"self",
",",
"search_space",
")",
":",
"self",
".",
"searchspace_json",
"=",
"search_space",
"self",
".",
"space",
"=",
"json2space",
"(",
"self",
".",
"searchspace_json",
")",
"self",
".",
"random_state",
"=",
"np",
".",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | EvolutionTuner.generate_parameters | Returns a dict of trial (hyper-)parameters, as a serializable object.
Parameters
----------
parameter_id : int
Returns
-------
config : dict | src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py | def generate_parameters(self, parameter_id):
"""Returns a dict of trial (hyper-)parameters, as a serializable object.
Parameters
----------
parameter_id : int
Returns
-------
config : dict
"""
if not self.population:
raise Runtime... | def generate_parameters(self, parameter_id):
"""Returns a dict of trial (hyper-)parameters, as a serializable object.
Parameters
----------
parameter_id : int
Returns
-------
config : dict
"""
if not self.population:
raise Runtime... | [
"Returns",
"a",
"dict",
"of",
"trial",
"(",
"hyper",
"-",
")",
"parameters",
"as",
"a",
"serializable",
"object",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py#L236-L278 | [
"def",
"generate_parameters",
"(",
"self",
",",
"parameter_id",
")",
":",
"if",
"not",
"self",
".",
"population",
":",
"raise",
"RuntimeError",
"(",
"'The population is empty'",
")",
"pos",
"=",
"-",
"1",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | EvolutionTuner.receive_trial_result | Record the result from a trial
Parameters
----------
parameters: dict
value : dict/float
if value is dict, it should have "default" key.
value is final metrics of the trial. | src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py | def receive_trial_result(self, parameter_id, parameters, value):
'''Record the result from a trial
Parameters
----------
parameters: dict
value : dict/float
if value is dict, it should have "default" key.
value is final metrics of the trial.
'''
... | def receive_trial_result(self, parameter_id, parameters, value):
'''Record the result from a trial
Parameters
----------
parameters: dict
value : dict/float
if value is dict, it should have "default" key.
value is final metrics of the trial.
'''
... | [
"Record",
"the",
"result",
"from",
"a",
"trial"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/evolution_tuner/evolution_tuner.py#L280-L300 | [
"def",
"receive_trial_result",
"(",
"self",
",",
"parameter_id",
",",
"parameters",
",",
"value",
")",
":",
"reward",
"=",
"extract_scalar_reward",
"(",
"value",
")",
"if",
"parameter_id",
"not",
"in",
"self",
".",
"total_data",
":",
"raise",
"RuntimeError",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_json_content | Load json file content
Parameters
----------
file_path:
path to the file
Raises
------
TypeError
Error with the file path | src/sdk/pynni/nni/smac_tuner/convert_ss_to_scenario.py | def get_json_content(file_path):
"""Load json file content
Parameters
----------
file_path:
path to the file
Raises
------
TypeError
Error with the file path
"""
try:
with open(file_path, 'r') as file:
return json.load(file)
except Ty... | def get_json_content(file_path):
"""Load json file content
Parameters
----------
file_path:
path to the file
Raises
------
TypeError
Error with the file path
"""
try:
with open(file_path, 'r') as file:
return json.load(file)
except Ty... | [
"Load",
"json",
"file",
"content",
"Parameters",
"----------",
"file_path",
":",
"path",
"to",
"the",
"file",
"Raises",
"------",
"TypeError",
"Error",
"with",
"the",
"file",
"path"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/smac_tuner/convert_ss_to_scenario.py#L25-L43 | [
"def",
"get_json_content",
"(",
"file_path",
")",
":",
"try",
":",
"with",
"open",
"(",
"file_path",
",",
"'r'",
")",
"as",
"file",
":",
"return",
"json",
".",
"load",
"(",
"file",
")",
"except",
"TypeError",
"as",
"err",
":",
"print",
"(",
"'Error: '"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | generate_pcs | Generate the Parameter Configuration Space (PCS) which defines the
legal ranges of the parameters to be optimized and their default values.
Generally, the format is:
# parameter_name categorical {value_1, ..., value_N} [default value]
# parameter_name ordinal {value_1, ..., value_N} [default value... | src/sdk/pynni/nni/smac_tuner/convert_ss_to_scenario.py | def generate_pcs(nni_search_space_content):
"""Generate the Parameter Configuration Space (PCS) which defines the
legal ranges of the parameters to be optimized and their default values.
Generally, the format is:
# parameter_name categorical {value_1, ..., value_N} [default value]
# parameter_... | def generate_pcs(nni_search_space_content):
"""Generate the Parameter Configuration Space (PCS) which defines the
legal ranges of the parameters to be optimized and their default values.
Generally, the format is:
# parameter_name categorical {value_1, ..., value_N} [default value]
# parameter_... | [
"Generate",
"the",
"Parameter",
"Configuration",
"Space",
"(",
"PCS",
")",
"which",
"defines",
"the",
"legal",
"ranges",
"of",
"the",
"parameters",
"to",
"be",
"optimized",
"and",
"their",
"default",
"values",
".",
"Generally",
"the",
"format",
"is",
":",
"#... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/smac_tuner/convert_ss_to_scenario.py#L45-L122 | [
"def",
"generate_pcs",
"(",
"nni_search_space_content",
")",
":",
"categorical_dict",
"=",
"{",
"}",
"search_space",
"=",
"nni_search_space_content",
"with",
"open",
"(",
"'param_config_space.pcs'",
",",
"'w'",
")",
"as",
"pcs_fd",
":",
"if",
"isinstance",
"(",
"s... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.