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 | generate_scenario | Generate the scenario. The scenario-object (smac.scenario.scenario.Scenario) is used to configure SMAC and
can be constructed either by providing an actual scenario-object, or by specifing the options in a scenario file.
Reference: https://automl.github.io/SMAC3/stable/options.html
The format of the ... | src/sdk/pynni/nni/smac_tuner/convert_ss_to_scenario.py | def generate_scenario(ss_content):
"""Generate the scenario. The scenario-object (smac.scenario.scenario.Scenario) is used to configure SMAC and
can be constructed either by providing an actual scenario-object, or by specifing the options in a scenario file.
Reference: https://automl.github.io/SMAC3/s... | def generate_scenario(ss_content):
"""Generate the scenario. The scenario-object (smac.scenario.scenario.Scenario) is used to configure SMAC and
can be constructed either by providing an actual scenario-object, or by specifing the options in a scenario file.
Reference: https://automl.github.io/SMAC3/s... | [
"Generate",
"the",
"scenario",
".",
"The",
"scenario",
"-",
"object",
"(",
"smac",
".",
"scenario",
".",
"scenario",
".",
"Scenario",
")",
"is",
"used",
"to",
"configure",
"SMAC",
"and",
"can",
"be",
"constructed",
"either",
"by",
"providing",
"an",
"actua... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/smac_tuner/convert_ss_to_scenario.py#L124-L210 | [
"def",
"generate_scenario",
"(",
"ss_content",
")",
":",
"with",
"open",
"(",
"'scenario.txt'",
",",
"'w'",
")",
"as",
"sce_fd",
":",
"sce_fd",
".",
"write",
"(",
"'deterministic = 0\\n'",
")",
"#sce_fd.write('output_dir = \\n')",
"sce_fd",
".",
"write",
"(",
"'... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | load_data | Load or create dataset | examples/trials/auto-gbdt/main.py | def load_data(train_path='./data/regression.train', test_path='./data/regression.test'):
'''
Load or create dataset
'''
print('Load data...')
df_train = pd.read_csv(train_path, header=None, sep='\t')
df_test = pd.read_csv(test_path, header=None, sep='\t')
num = len(df_train)
split_num = ... | def load_data(train_path='./data/regression.train', test_path='./data/regression.test'):
'''
Load or create dataset
'''
print('Load data...')
df_train = pd.read_csv(train_path, header=None, sep='\t')
df_test = pd.read_csv(test_path, header=None, sep='\t')
num = len(df_train)
split_num = ... | [
"Load",
"or",
"create",
"dataset"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/auto-gbdt/main.py#L48-L72 | [
"def",
"load_data",
"(",
"train_path",
"=",
"'./data/regression.train'",
",",
"test_path",
"=",
"'./data/regression.test'",
")",
":",
"print",
"(",
"'Load data...'",
")",
"df_train",
"=",
"pd",
".",
"read_csv",
"(",
"train_path",
",",
"header",
"=",
"None",
",",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | layer_distance | The distance between two layers. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def layer_distance(a, b):
"""The distance between two layers."""
# pylint: disable=unidiomatic-typecheck
if type(a) != type(b):
return 1.0
if is_layer(a, "Conv"):
att_diff = [
(a.filters, b.filters),
(a.kernel_size, b.kernel_size),
(a.stride, b.stride)... | def layer_distance(a, b):
"""The distance between two layers."""
# pylint: disable=unidiomatic-typecheck
if type(a) != type(b):
return 1.0
if is_layer(a, "Conv"):
att_diff = [
(a.filters, b.filters),
(a.kernel_size, b.kernel_size),
(a.stride, b.stride)... | [
"The",
"distance",
"between",
"two",
"layers",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L37-L56 | [
"def",
"layer_distance",
"(",
"a",
",",
"b",
")",
":",
"# pylint: disable=unidiomatic-typecheck",
"if",
"type",
"(",
"a",
")",
"!=",
"type",
"(",
"b",
")",
":",
"return",
"1.0",
"if",
"is_layer",
"(",
"a",
",",
"\"Conv\"",
")",
":",
"att_diff",
"=",
"[... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | attribute_difference | The attribute distance. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def attribute_difference(att_diff):
''' The attribute distance.
'''
ret = 0
for a_value, b_value in att_diff:
if max(a_value, b_value) == 0:
ret += 0
else:
ret += abs(a_value - b_value) * 1.0 / max(a_value, b_value)
return ret * 1.0 / len(att_diff) | def attribute_difference(att_diff):
''' The attribute distance.
'''
ret = 0
for a_value, b_value in att_diff:
if max(a_value, b_value) == 0:
ret += 0
else:
ret += abs(a_value - b_value) * 1.0 / max(a_value, b_value)
return ret * 1.0 / len(att_diff) | [
"The",
"attribute",
"distance",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L59-L69 | [
"def",
"attribute_difference",
"(",
"att_diff",
")",
":",
"ret",
"=",
"0",
"for",
"a_value",
",",
"b_value",
"in",
"att_diff",
":",
"if",
"max",
"(",
"a_value",
",",
"b_value",
")",
"==",
"0",
":",
"ret",
"+=",
"0",
"else",
":",
"ret",
"+=",
"abs",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | layers_distance | The distance between the layers of two neural networks. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def layers_distance(list_a, list_b):
"""The distance between the layers of two neural networks."""
len_a = len(list_a)
len_b = len(list_b)
f = np.zeros((len_a + 1, len_b + 1))
f[-1][-1] = 0
for i in range(-1, len_a):
f[i][-1] = i + 1
for j in range(-1, len_b):
f[-1][j] = j + ... | def layers_distance(list_a, list_b):
"""The distance between the layers of two neural networks."""
len_a = len(list_a)
len_b = len(list_b)
f = np.zeros((len_a + 1, len_b + 1))
f[-1][-1] = 0
for i in range(-1, len_a):
f[i][-1] = i + 1
for j in range(-1, len_b):
f[-1][j] = j + ... | [
"The",
"distance",
"between",
"the",
"layers",
"of",
"two",
"neural",
"networks",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L72-L89 | [
"def",
"layers_distance",
"(",
"list_a",
",",
"list_b",
")",
":",
"len_a",
"=",
"len",
"(",
"list_a",
")",
"len_b",
"=",
"len",
"(",
"list_b",
")",
"f",
"=",
"np",
".",
"zeros",
"(",
"(",
"len_a",
"+",
"1",
",",
"len_b",
"+",
"1",
")",
")",
"f"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | skip_connection_distance | The distance between two skip-connections. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def skip_connection_distance(a, b):
"""The distance between two skip-connections."""
if a[2] != b[2]:
return 1.0
len_a = abs(a[1] - a[0])
len_b = abs(b[1] - b[0])
return (abs(a[0] - b[0]) + abs(len_a - len_b)) / (max(a[0], b[0]) + max(len_a, len_b)) | def skip_connection_distance(a, b):
"""The distance between two skip-connections."""
if a[2] != b[2]:
return 1.0
len_a = abs(a[1] - a[0])
len_b = abs(b[1] - b[0])
return (abs(a[0] - b[0]) + abs(len_a - len_b)) / (max(a[0], b[0]) + max(len_a, len_b)) | [
"The",
"distance",
"between",
"two",
"skip",
"-",
"connections",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L92-L98 | [
"def",
"skip_connection_distance",
"(",
"a",
",",
"b",
")",
":",
"if",
"a",
"[",
"2",
"]",
"!=",
"b",
"[",
"2",
"]",
":",
"return",
"1.0",
"len_a",
"=",
"abs",
"(",
"a",
"[",
"1",
"]",
"-",
"a",
"[",
"0",
"]",
")",
"len_b",
"=",
"abs",
"(",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | skip_connections_distance | The distance between the skip-connections of two neural networks. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def skip_connections_distance(list_a, list_b):
"""The distance between the skip-connections of two neural networks."""
distance_matrix = np.zeros((len(list_a), len(list_b)))
for i, a in enumerate(list_a):
for j, b in enumerate(list_b):
distance_matrix[i][j] = skip_connection_distance(a, ... | def skip_connections_distance(list_a, list_b):
"""The distance between the skip-connections of two neural networks."""
distance_matrix = np.zeros((len(list_a), len(list_b)))
for i, a in enumerate(list_a):
for j, b in enumerate(list_b):
distance_matrix[i][j] = skip_connection_distance(a, ... | [
"The",
"distance",
"between",
"the",
"skip",
"-",
"connections",
"of",
"two",
"neural",
"networks",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L101-L109 | [
"def",
"skip_connections_distance",
"(",
"list_a",
",",
"list_b",
")",
":",
"distance_matrix",
"=",
"np",
".",
"zeros",
"(",
"(",
"len",
"(",
"list_a",
")",
",",
"len",
"(",
"list_b",
")",
")",
")",
"for",
"i",
",",
"a",
"in",
"enumerate",
"(",
"list... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | edit_distance | The distance between two neural networks.
Args:
x: An instance of NetworkDescriptor.
y: An instance of NetworkDescriptor
Returns:
The edit-distance between x and y. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def edit_distance(x, y):
"""The distance between two neural networks.
Args:
x: An instance of NetworkDescriptor.
y: An instance of NetworkDescriptor
Returns:
The edit-distance between x and y.
"""
ret = layers_distance(x.layers, y.layers)
ret += Constant.KERNEL_LAMBDA * ... | def edit_distance(x, y):
"""The distance between two neural networks.
Args:
x: An instance of NetworkDescriptor.
y: An instance of NetworkDescriptor
Returns:
The edit-distance between x and y.
"""
ret = layers_distance(x.layers, y.layers)
ret += Constant.KERNEL_LAMBDA * ... | [
"The",
"distance",
"between",
"two",
"neural",
"networks",
".",
"Args",
":",
"x",
":",
"An",
"instance",
"of",
"NetworkDescriptor",
".",
"y",
":",
"An",
"instance",
"of",
"NetworkDescriptor",
"Returns",
":",
"The",
"edit",
"-",
"distance",
"between",
"x",
... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L112-L125 | [
"def",
"edit_distance",
"(",
"x",
",",
"y",
")",
":",
"ret",
"=",
"layers_distance",
"(",
"x",
".",
"layers",
",",
"y",
".",
"layers",
")",
"ret",
"+=",
"Constant",
".",
"KERNEL_LAMBDA",
"*",
"skip_connections_distance",
"(",
"x",
".",
"skip_connections",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | edit_distance_matrix | Calculate the edit distance.
Args:
train_x: A list of neural architectures.
train_y: A list of neural architectures.
Returns:
An edit-distance matrix. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def edit_distance_matrix(train_x, train_y=None):
"""Calculate the edit distance.
Args:
train_x: A list of neural architectures.
train_y: A list of neural architectures.
Returns:
An edit-distance matrix.
"""
if train_y is None:
ret = np.zeros((train_x.shape[0], train_x... | def edit_distance_matrix(train_x, train_y=None):
"""Calculate the edit distance.
Args:
train_x: A list of neural architectures.
train_y: A list of neural architectures.
Returns:
An edit-distance matrix.
"""
if train_y is None:
ret = np.zeros((train_x.shape[0], train_x... | [
"Calculate",
"the",
"edit",
"distance",
".",
"Args",
":",
"train_x",
":",
"A",
"list",
"of",
"neural",
"architectures",
".",
"train_y",
":",
"A",
"list",
"of",
"neural",
"architectures",
".",
"Returns",
":",
"An",
"edit",
"-",
"distance",
"matrix",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L243-L266 | [
"def",
"edit_distance_matrix",
"(",
"train_x",
",",
"train_y",
"=",
"None",
")",
":",
"if",
"train_y",
"is",
"None",
":",
"ret",
"=",
"np",
".",
"zeros",
"(",
"(",
"train_x",
".",
"shape",
"[",
"0",
"]",
",",
"train_x",
".",
"shape",
"[",
"0",
"]",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | vector_distance | The Euclidean distance between two vectors. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def vector_distance(a, b):
"""The Euclidean distance between two vectors."""
a = np.array(a)
b = np.array(b)
return np.linalg.norm(a - b) | def vector_distance(a, b):
"""The Euclidean distance between two vectors."""
a = np.array(a)
b = np.array(b)
return np.linalg.norm(a - b) | [
"The",
"Euclidean",
"distance",
"between",
"two",
"vectors",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L269-L273 | [
"def",
"vector_distance",
"(",
"a",
",",
"b",
")",
":",
"a",
"=",
"np",
".",
"array",
"(",
"a",
")",
"b",
"=",
"np",
".",
"array",
"(",
"b",
")",
"return",
"np",
".",
"linalg",
".",
"norm",
"(",
"a",
"-",
"b",
")"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | bourgain_embedding_matrix | Use Bourgain algorithm to embed the neural architectures based on their edit-distance.
Args:
distance_matrix: A matrix of edit-distances.
Returns:
A matrix of distances after embedding. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def bourgain_embedding_matrix(distance_matrix):
"""Use Bourgain algorithm to embed the neural architectures based on their edit-distance.
Args:
distance_matrix: A matrix of edit-distances.
Returns:
A matrix of distances after embedding.
"""
distance_matrix = np.array(distance_matrix)... | def bourgain_embedding_matrix(distance_matrix):
"""Use Bourgain algorithm to embed the neural architectures based on their edit-distance.
Args:
distance_matrix: A matrix of edit-distances.
Returns:
A matrix of distances after embedding.
"""
distance_matrix = np.array(distance_matrix)... | [
"Use",
"Bourgain",
"algorithm",
"to",
"embed",
"the",
"neural",
"architectures",
"based",
"on",
"their",
"edit",
"-",
"distance",
".",
"Args",
":",
"distance_matrix",
":",
"A",
"matrix",
"of",
"edit",
"-",
"distances",
".",
"Returns",
":",
"A",
"matrix",
"... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L276-L303 | [
"def",
"bourgain_embedding_matrix",
"(",
"distance_matrix",
")",
":",
"distance_matrix",
"=",
"np",
".",
"array",
"(",
"distance_matrix",
")",
"n",
"=",
"len",
"(",
"distance_matrix",
")",
"if",
"n",
"==",
"1",
":",
"return",
"distance_matrix",
"np",
".",
"r... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | contain | Check if the target descriptor is in the descriptors. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def contain(descriptors, target_descriptor):
"""Check if the target descriptor is in the descriptors."""
for descriptor in descriptors:
if edit_distance(descriptor, target_descriptor) < 1e-5:
return True
return False | def contain(descriptors, target_descriptor):
"""Check if the target descriptor is in the descriptors."""
for descriptor in descriptors:
if edit_distance(descriptor, target_descriptor) < 1e-5:
return True
return False | [
"Check",
"if",
"the",
"target",
"descriptor",
"is",
"in",
"the",
"descriptors",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L449-L454 | [
"def",
"contain",
"(",
"descriptors",
",",
"target_descriptor",
")",
":",
"for",
"descriptor",
"in",
"descriptors",
":",
"if",
"edit_distance",
"(",
"descriptor",
",",
"target_descriptor",
")",
"<",
"1e-5",
":",
"return",
"True",
"return",
"False"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | IncrementalGaussianProcess.fit | Fit the regressor with more data.
Args:
train_x: A list of NetworkDescriptor.
train_y: A list of metric values. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def fit(self, train_x, train_y):
""" Fit the regressor with more data.
Args:
train_x: A list of NetworkDescriptor.
train_y: A list of metric values.
"""
if self.first_fitted:
self.incremental_fit(train_x, train_y)
else:
self.first_f... | def fit(self, train_x, train_y):
""" Fit the regressor with more data.
Args:
train_x: A list of NetworkDescriptor.
train_y: A list of metric values.
"""
if self.first_fitted:
self.incremental_fit(train_x, train_y)
else:
self.first_f... | [
"Fit",
"the",
"regressor",
"with",
"more",
"data",
".",
"Args",
":",
"train_x",
":",
"A",
"list",
"of",
"NetworkDescriptor",
".",
"train_y",
":",
"A",
"list",
"of",
"metric",
"values",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L149-L158 | [
"def",
"fit",
"(",
"self",
",",
"train_x",
",",
"train_y",
")",
":",
"if",
"self",
".",
"first_fitted",
":",
"self",
".",
"incremental_fit",
"(",
"train_x",
",",
"train_y",
")",
"else",
":",
"self",
".",
"first_fit",
"(",
"train_x",
",",
"train_y",
")"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | IncrementalGaussianProcess.incremental_fit | Incrementally fit the regressor. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def incremental_fit(self, train_x, train_y):
""" Incrementally fit the regressor. """
if not self._first_fitted:
raise ValueError("The first_fit function needs to be called first.")
train_x, train_y = np.array(train_x), np.array(train_y)
# Incrementally compute K
up... | def incremental_fit(self, train_x, train_y):
""" Incrementally fit the regressor. """
if not self._first_fitted:
raise ValueError("The first_fit function needs to be called first.")
train_x, train_y = np.array(train_x), np.array(train_y)
# Incrementally compute K
up... | [
"Incrementally",
"fit",
"the",
"regressor",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L160-L190 | [
"def",
"incremental_fit",
"(",
"self",
",",
"train_x",
",",
"train_y",
")",
":",
"if",
"not",
"self",
".",
"_first_fitted",
":",
"raise",
"ValueError",
"(",
"\"The first_fit function needs to be called first.\"",
")",
"train_x",
",",
"train_y",
"=",
"np",
".",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | IncrementalGaussianProcess.first_fit | Fit the regressor for the first time. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def first_fit(self, train_x, train_y):
""" Fit the regressor for the first time. """
train_x, train_y = np.array(train_x), np.array(train_y)
self._x = np.copy(train_x)
self._y = np.copy(train_y)
self._distance_matrix = edit_distance_matrix(self._x)
k_matrix = bourgain_e... | def first_fit(self, train_x, train_y):
""" Fit the regressor for the first time. """
train_x, train_y = np.array(train_x), np.array(train_y)
self._x = np.copy(train_x)
self._y = np.copy(train_y)
self._distance_matrix = edit_distance_matrix(self._x)
k_matrix = bourgain_e... | [
"Fit",
"the",
"regressor",
"for",
"the",
"first",
"time",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L198-L214 | [
"def",
"first_fit",
"(",
"self",
",",
"train_x",
",",
"train_y",
")",
":",
"train_x",
",",
"train_y",
"=",
"np",
".",
"array",
"(",
"train_x",
")",
",",
"np",
".",
"array",
"(",
"train_y",
")",
"self",
".",
"_x",
"=",
"np",
".",
"copy",
"(",
"tra... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | IncrementalGaussianProcess.predict | Predict the result.
Args:
train_x: A list of NetworkDescriptor.
Returns:
y_mean: The predicted mean.
y_std: The predicted standard deviation. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def predict(self, train_x):
"""Predict the result.
Args:
train_x: A list of NetworkDescriptor.
Returns:
y_mean: The predicted mean.
y_std: The predicted standard deviation.
"""
k_trans = np.exp(-np.power(edit_distance_matrix(train_x, self._x), ... | def predict(self, train_x):
"""Predict the result.
Args:
train_x: A list of NetworkDescriptor.
Returns:
y_mean: The predicted mean.
y_std: The predicted standard deviation.
"""
k_trans = np.exp(-np.power(edit_distance_matrix(train_x, self._x), ... | [
"Predict",
"the",
"result",
".",
"Args",
":",
"train_x",
":",
"A",
"list",
"of",
"NetworkDescriptor",
".",
"Returns",
":",
"y_mean",
":",
"The",
"predicted",
"mean",
".",
"y_std",
":",
"The",
"predicted",
"standard",
"deviation",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L216-L240 | [
"def",
"predict",
"(",
"self",
",",
"train_x",
")",
":",
"k_trans",
"=",
"np",
".",
"exp",
"(",
"-",
"np",
".",
"power",
"(",
"edit_distance_matrix",
"(",
"train_x",
",",
"self",
".",
"_x",
")",
",",
"2",
")",
")",
"y_mean",
"=",
"k_trans",
".",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | BayesianOptimizer.generate | Generate new architecture.
Args:
descriptors: All the searched neural architectures.
Returns:
graph: An instance of Graph. A morphed neural network with weights.
father_id: The father node ID in the search tree. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def generate(self, descriptors):
"""Generate new architecture.
Args:
descriptors: All the searched neural architectures.
Returns:
graph: An instance of Graph. A morphed neural network with weights.
father_id: The father node ID in the search tree.
"""
... | def generate(self, descriptors):
"""Generate new architecture.
Args:
descriptors: All the searched neural architectures.
Returns:
graph: An instance of Graph. A morphed neural network with weights.
father_id: The father node ID in the search tree.
"""
... | [
"Generate",
"new",
"architecture",
".",
"Args",
":",
"descriptors",
":",
"All",
"the",
"searched",
"neural",
"architectures",
".",
"Returns",
":",
"graph",
":",
"An",
"instance",
"of",
"Graph",
".",
"A",
"morphed",
"neural",
"network",
"with",
"weights",
"."... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L333-L394 | [
"def",
"generate",
"(",
"self",
",",
"descriptors",
")",
":",
"model_ids",
"=",
"self",
".",
"search_tree",
".",
"adj_list",
".",
"keys",
"(",
")",
"target_graph",
"=",
"None",
"father_id",
"=",
"None",
"descriptors",
"=",
"deepcopy",
"(",
"descriptors",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | BayesianOptimizer.acq | estimate the value of generated graph | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def acq(self, graph):
''' estimate the value of generated graph
'''
mean, std = self.gpr.predict(np.array([graph.extract_descriptor()]))
if self.optimizemode is OptimizeMode.Maximize:
return mean + self.beta * std
return mean - self.beta * std | def acq(self, graph):
''' estimate the value of generated graph
'''
mean, std = self.gpr.predict(np.array([graph.extract_descriptor()]))
if self.optimizemode is OptimizeMode.Maximize:
return mean + self.beta * std
return mean - self.beta * std | [
"estimate",
"the",
"value",
"of",
"generated",
"graph"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L396-L402 | [
"def",
"acq",
"(",
"self",
",",
"graph",
")",
":",
"mean",
",",
"std",
"=",
"self",
".",
"gpr",
".",
"predict",
"(",
"np",
".",
"array",
"(",
"[",
"graph",
".",
"extract_descriptor",
"(",
")",
"]",
")",
")",
"if",
"self",
".",
"optimizemode",
"is... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | SearchTree.add_child | add child to search tree itself.
Arguments:
u {int} -- father id
v {int} -- child id | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def add_child(self, u, v):
''' add child to search tree itself.
Arguments:
u {int} -- father id
v {int} -- child id
'''
if u == -1:
self.root = v
self.adj_list[v] = []
return
if v not in self.adj_list[u]:
s... | def add_child(self, u, v):
''' add child to search tree itself.
Arguments:
u {int} -- father id
v {int} -- child id
'''
if u == -1:
self.root = v
self.adj_list[v] = []
return
if v not in self.adj_list[u]:
s... | [
"add",
"child",
"to",
"search",
"tree",
"itself",
".",
"Arguments",
":",
"u",
"{",
"int",
"}",
"--",
"father",
"id",
"v",
"{",
"int",
"}",
"--",
"child",
"id"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L464-L478 | [
"def",
"add_child",
"(",
"self",
",",
"u",
",",
"v",
")",
":",
"if",
"u",
"==",
"-",
"1",
":",
"self",
".",
"root",
"=",
"v",
"self",
".",
"adj_list",
"[",
"v",
"]",
"=",
"[",
"]",
"return",
"if",
"v",
"not",
"in",
"self",
".",
"adj_list",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | SearchTree.get_dict | A recursive function to return the content of the tree in a dict. | src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py | def get_dict(self, u=None):
""" A recursive function to return the content of the tree in a dict."""
if u is None:
return self.get_dict(self.root)
children = []
for v in self.adj_list[u]:
children.append(self.get_dict(v))
ret = {"name": u, "children": chil... | def get_dict(self, u=None):
""" A recursive function to return the content of the tree in a dict."""
if u is None:
return self.get_dict(self.root)
children = []
for v in self.adj_list[u]:
children.append(self.get_dict(v))
ret = {"name": u, "children": chil... | [
"A",
"recursive",
"function",
"to",
"return",
"the",
"content",
"of",
"the",
"tree",
"in",
"a",
"dict",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/bayesian.py#L480-L488 | [
"def",
"get_dict",
"(",
"self",
",",
"u",
"=",
"None",
")",
":",
"if",
"u",
"is",
"None",
":",
"return",
"self",
".",
"get_dict",
"(",
"self",
".",
"root",
")",
"children",
"=",
"[",
"]",
"for",
"v",
"in",
"self",
".",
"adj_list",
"[",
"u",
"]"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | train_with_graph | Train a network from a specific graph. | examples/trials/weight_sharing/ga_squad/trial.py | def train_with_graph(p_graph, qp_pairs, dev_qp_pairs):
'''
Train a network from a specific graph.
'''
global sess
with tf.Graph().as_default():
train_model = GAG(cfg, embed, p_graph)
train_model.build_net(is_training=True)
tf.get_variable_scope().reuse_variables()
dev... | def train_with_graph(p_graph, qp_pairs, dev_qp_pairs):
'''
Train a network from a specific graph.
'''
global sess
with tf.Graph().as_default():
train_model = GAG(cfg, embed, p_graph)
train_model.build_net(is_training=True)
tf.get_variable_scope().reuse_variables()
dev... | [
"Train",
"a",
"network",
"from",
"a",
"specific",
"graph",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/trial.py#L301-L377 | [
"def",
"train_with_graph",
"(",
"p_graph",
",",
"qp_pairs",
",",
"dev_qp_pairs",
")",
":",
"global",
"sess",
"with",
"tf",
".",
"Graph",
"(",
")",
".",
"as_default",
"(",
")",
":",
"train_model",
"=",
"GAG",
"(",
"cfg",
",",
"embed",
",",
"p_graph",
")... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Tuner.generate_multiple_parameters | Returns multiple sets of trial (hyper-)parameters, as iterable of serializable objects.
Call 'generate_parameters()' by 'count' times by default.
User code must override either this function or 'generate_parameters()'.
If there's no more trial, user should raise nni.NoMoreTrialError exception in... | src/sdk/pynni/nni/tuner.py | def generate_multiple_parameters(self, parameter_id_list):
"""Returns multiple sets of trial (hyper-)parameters, as iterable of serializable objects.
Call 'generate_parameters()' by 'count' times by default.
User code must override either this function or 'generate_parameters()'.
If ther... | def generate_multiple_parameters(self, parameter_id_list):
"""Returns multiple sets of trial (hyper-)parameters, as iterable of serializable objects.
Call 'generate_parameters()' by 'count' times by default.
User code must override either this function or 'generate_parameters()'.
If ther... | [
"Returns",
"multiple",
"sets",
"of",
"trial",
"(",
"hyper",
"-",
")",
"parameters",
"as",
"iterable",
"of",
"serializable",
"objects",
".",
"Call",
"generate_parameters",
"()",
"by",
"count",
"times",
"by",
"default",
".",
"User",
"code",
"must",
"override",
... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/tuner.py#L40-L56 | [
"def",
"generate_multiple_parameters",
"(",
"self",
",",
"parameter_id_list",
")",
":",
"result",
"=",
"[",
"]",
"for",
"parameter_id",
"in",
"parameter_id_list",
":",
"try",
":",
"_logger",
".",
"debug",
"(",
"\"generating param for {}\"",
".",
"format",
"(",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | graph_loads | Load graph | examples/trials/weight_sharing/ga_squad/graph.py | def graph_loads(graph_json):
'''
Load graph
'''
layers = []
for layer in graph_json['layers']:
layer_info = Layer(layer['graph_type'], layer['input'], layer['output'], layer['size'], layer['hash_id'])
layer_info.is_delete = layer['is_delete']
_logger.debug('append layer {}'.f... | def graph_loads(graph_json):
'''
Load graph
'''
layers = []
for layer in graph_json['layers']:
layer_info = Layer(layer['graph_type'], layer['input'], layer['output'], layer['size'], layer['hash_id'])
layer_info.is_delete = layer['is_delete']
_logger.debug('append layer {}'.f... | [
"Load",
"graph"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/graph.py#L131-L144 | [
"def",
"graph_loads",
"(",
"graph_json",
")",
":",
"layers",
"=",
"[",
"]",
"for",
"layer",
"in",
"graph_json",
"[",
"'layers'",
"]",
":",
"layer_info",
"=",
"Layer",
"(",
"layer",
"[",
"'graph_type'",
"]",
",",
"layer",
"[",
"'input'",
"]",
",",
"laye... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Layer.update_hash | Calculation of `hash_id` of Layer. Which is determined by the properties of itself, and the `hash_id`s of input layers | examples/trials/weight_sharing/ga_squad/graph.py | def update_hash(self, layers: Iterable):
"""
Calculation of `hash_id` of Layer. Which is determined by the properties of itself, and the `hash_id`s of input layers
"""
if self.graph_type == LayerType.input.value:
return
hasher = hashlib.md5()
hasher.update(Lay... | def update_hash(self, layers: Iterable):
"""
Calculation of `hash_id` of Layer. Which is determined by the properties of itself, and the `hash_id`s of input layers
"""
if self.graph_type == LayerType.input.value:
return
hasher = hashlib.md5()
hasher.update(Lay... | [
"Calculation",
"of",
"hash_id",
"of",
"Layer",
".",
"Which",
"is",
"determined",
"by",
"the",
"properties",
"of",
"itself",
"and",
"the",
"hash_id",
"s",
"of",
"input",
"layers"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/graph.py#L83-L96 | [
"def",
"update_hash",
"(",
"self",
",",
"layers",
":",
"Iterable",
")",
":",
"if",
"self",
".",
"graph_type",
"==",
"LayerType",
".",
"input",
".",
"value",
":",
"return",
"hasher",
"=",
"hashlib",
".",
"md5",
"(",
")",
"hasher",
".",
"update",
"(",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph.update_hash | update hash id of each layer, in topological order/recursively
hash id will be used in weight sharing | examples/trials/weight_sharing/ga_squad/graph.py | def update_hash(self):
"""
update hash id of each layer, in topological order/recursively
hash id will be used in weight sharing
"""
_logger.debug('update hash')
layer_in_cnt = [len(layer.input) for layer in self.layers]
topo_queue = deque([i for i, layer in enume... | def update_hash(self):
"""
update hash id of each layer, in topological order/recursively
hash id will be used in weight sharing
"""
_logger.debug('update hash')
layer_in_cnt = [len(layer.input) for layer in self.layers]
topo_queue = deque([i for i, layer in enume... | [
"update",
"hash",
"id",
"of",
"each",
"layer",
"in",
"topological",
"order",
"/",
"recursively",
"hash",
"id",
"will",
"be",
"used",
"in",
"weight",
"sharing"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/graph.py#L239-L253 | [
"def",
"update_hash",
"(",
"self",
")",
":",
"_logger",
".",
"debug",
"(",
"'update hash'",
")",
"layer_in_cnt",
"=",
"[",
"len",
"(",
"layer",
".",
"input",
")",
"for",
"layer",
"in",
"self",
".",
"layers",
"]",
"topo_queue",
"=",
"deque",
"(",
"[",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | init_logger | Initialize root logger.
This will redirect anything from logging.getLogger() as well as stdout to specified file.
logger_file_path: path of logger file (path-like object). | src/sdk/pynni/nni/common.py | def init_logger(logger_file_path, log_level_name='info'):
"""Initialize root logger.
This will redirect anything from logging.getLogger() as well as stdout to specified file.
logger_file_path: path of logger file (path-like object).
"""
log_level = log_level_map.get(log_level_name, logging.INFO)
... | def init_logger(logger_file_path, log_level_name='info'):
"""Initialize root logger.
This will redirect anything from logging.getLogger() as well as stdout to specified file.
logger_file_path: path of logger file (path-like object).
"""
log_level = log_level_map.get(log_level_name, logging.INFO)
... | [
"Initialize",
"root",
"logger",
".",
"This",
"will",
"redirect",
"anything",
"from",
"logging",
".",
"getLogger",
"()",
"as",
"well",
"as",
"stdout",
"to",
"specified",
"file",
".",
"logger_file_path",
":",
"path",
"of",
"logger",
"file",
"(",
"path",
"-",
... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/common.py#L49-L69 | [
"def",
"init_logger",
"(",
"logger_file_path",
",",
"log_level_name",
"=",
"'info'",
")",
":",
"log_level",
"=",
"log_level_map",
".",
"get",
"(",
"log_level_name",
",",
"logging",
".",
"INFO",
")",
"logger_file",
"=",
"open",
"(",
"logger_file_path",
",",
"'w... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | create_mnist_model | Create simple convolutional model | examples/trials/mnist-batch-tune-keras/mnist-keras.py | def create_mnist_model(hyper_params, input_shape=(H, W, 1), num_classes=NUM_CLASSES):
'''
Create simple convolutional model
'''
layers = [
Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_shape),
Conv2D(64, (3, 3), activation='relu'),
MaxPooling2D(pool_size=(2,... | def create_mnist_model(hyper_params, input_shape=(H, W, 1), num_classes=NUM_CLASSES):
'''
Create simple convolutional model
'''
layers = [
Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_shape),
Conv2D(64, (3, 3), activation='relu'),
MaxPooling2D(pool_size=(2,... | [
"Create",
"simple",
"convolutional",
"model"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/mnist-batch-tune-keras/mnist-keras.py#L39-L60 | [
"def",
"create_mnist_model",
"(",
"hyper_params",
",",
"input_shape",
"=",
"(",
"H",
",",
"W",
",",
"1",
")",
",",
"num_classes",
"=",
"NUM_CLASSES",
")",
":",
"layers",
"=",
"[",
"Conv2D",
"(",
"32",
",",
"kernel_size",
"=",
"(",
"3",
",",
"3",
")",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | load_mnist_data | Load MNIST dataset | examples/trials/mnist-batch-tune-keras/mnist-keras.py | def load_mnist_data(args):
'''
Load MNIST dataset
'''
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = (np.expand_dims(x_train, -1).astype(np.float) / 255.)[:args.num_train]
x_test = (np.expand_dims(x_test, -1).astype(np.float) / 255.)[:args.num_test]
y_train = keras.utils... | def load_mnist_data(args):
'''
Load MNIST dataset
'''
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = (np.expand_dims(x_train, -1).astype(np.float) / 255.)[:args.num_train]
x_test = (np.expand_dims(x_test, -1).astype(np.float) / 255.)[:args.num_test]
y_train = keras.utils... | [
"Load",
"MNIST",
"dataset"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/mnist-batch-tune-keras/mnist-keras.py#L62-L76 | [
"def",
"load_mnist_data",
"(",
"args",
")",
":",
"(",
"x_train",
",",
"y_train",
")",
",",
"(",
"x_test",
",",
"y_test",
")",
"=",
"mnist",
".",
"load_data",
"(",
")",
"x_train",
"=",
"(",
"np",
".",
"expand_dims",
"(",
"x_train",
",",
"-",
"1",
")... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | train | Train model | examples/trials/mnist-batch-tune-keras/mnist-keras.py | def train(args, params):
'''
Train model
'''
x_train, y_train, x_test, y_test = load_mnist_data(args)
model = create_mnist_model(params)
# nni
model.fit(x_train, y_train, batch_size=args.batch_size, epochs=args.epochs, verbose=1,
validation_data=(x_test, y_test), callbacks=[SendMet... | def train(args, params):
'''
Train model
'''
x_train, y_train, x_test, y_test = load_mnist_data(args)
model = create_mnist_model(params)
# nni
model.fit(x_train, y_train, batch_size=args.batch_size, epochs=args.epochs, verbose=1,
validation_data=(x_test, y_test), callbacks=[SendMet... | [
"Train",
"model"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/mnist-batch-tune-keras/mnist-keras.py#L89-L102 | [
"def",
"train",
"(",
"args",
",",
"params",
")",
":",
"x_train",
",",
"y_train",
",",
"x_test",
",",
"y_test",
"=",
"load_mnist_data",
"(",
"args",
")",
"model",
"=",
"create_mnist_model",
"(",
"params",
")",
"# nni ",
"model",
".",
"fit",
"(",
"x_train"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | SendMetrics.on_epoch_end | Run on end of each epoch | examples/trials/mnist-batch-tune-keras/mnist-keras.py | def on_epoch_end(self, epoch, logs={}):
'''
Run on end of each epoch
'''
LOG.debug(logs)
nni.report_intermediate_result(logs["val_acc"]) | def on_epoch_end(self, epoch, logs={}):
'''
Run on end of each epoch
'''
LOG.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/mnist-batch-tune-keras/mnist-keras.py#L82-L87 | [
"def",
"on_epoch_end",
"(",
"self",
",",
"epoch",
",",
"logs",
"=",
"{",
"}",
")",
":",
"LOG",
".",
"debug",
"(",
"logs",
")",
"nni",
".",
"report_intermediate_result",
"(",
"logs",
"[",
"\"val_acc\"",
"]",
")"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Config.get_all_config | get all of config values | tools/nni_cmd/config_utils.py | def get_all_config(self):
'''get all of config values'''
return json.dumps(self.config, indent=4, sort_keys=True, separators=(',', ':')) | def get_all_config(self):
'''get all of config values'''
return json.dumps(self.config, indent=4, sort_keys=True, separators=(',', ':')) | [
"get",
"all",
"of",
"config",
"values"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/config_utils.py#L35-L37 | [
"def",
"get_all_config",
"(",
"self",
")",
":",
"return",
"json",
".",
"dumps",
"(",
"self",
".",
"config",
",",
"indent",
"=",
"4",
",",
"sort_keys",
"=",
"True",
",",
"separators",
"=",
"(",
"','",
",",
"':'",
")",
")"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Config.set_config | set {key:value} paris to self.config | tools/nni_cmd/config_utils.py | def set_config(self, key, value):
'''set {key:value} paris to self.config'''
self.config = self.read_file()
self.config[key] = value
self.write_file() | def set_config(self, key, value):
'''set {key:value} paris to self.config'''
self.config = self.read_file()
self.config[key] = value
self.write_file() | [
"set",
"{",
"key",
":",
"value",
"}",
"paris",
"to",
"self",
".",
"config"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/config_utils.py#L39-L43 | [
"def",
"set_config",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"self",
".",
"config",
"=",
"self",
".",
"read_file",
"(",
")",
"self",
".",
"config",
"[",
"key",
"]",
"=",
"value",
"self",
".",
"write_file",
"(",
")"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Config.write_file | save config to local file | tools/nni_cmd/config_utils.py | def write_file(self):
'''save config to local file'''
if self.config:
try:
with open(self.config_file, 'w') as file:
json.dump(self.config, file)
except IOError as error:
print('Error:', error)
return | def write_file(self):
'''save config to local file'''
if self.config:
try:
with open(self.config_file, 'w') as file:
json.dump(self.config, file)
except IOError as error:
print('Error:', error)
return | [
"save",
"config",
"to",
"local",
"file"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/config_utils.py#L49-L57 | [
"def",
"write_file",
"(",
"self",
")",
":",
"if",
"self",
".",
"config",
":",
"try",
":",
"with",
"open",
"(",
"self",
".",
"config_file",
",",
"'w'",
")",
"as",
"file",
":",
"json",
".",
"dump",
"(",
"self",
".",
"config",
",",
"file",
")",
"exc... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Experiments.add_experiment | set {key:value} paris to self.experiment | tools/nni_cmd/config_utils.py | def add_experiment(self, id, port, time, file_name, platform):
'''set {key:value} paris to self.experiment'''
self.experiments[id] = {}
self.experiments[id]['port'] = port
self.experiments[id]['startTime'] = time
self.experiments[id]['endTime'] = 'N/A'
self.experiments[id... | def add_experiment(self, id, port, time, file_name, platform):
'''set {key:value} paris to self.experiment'''
self.experiments[id] = {}
self.experiments[id]['port'] = port
self.experiments[id]['startTime'] = time
self.experiments[id]['endTime'] = 'N/A'
self.experiments[id... | [
"set",
"{",
"key",
":",
"value",
"}",
"paris",
"to",
"self",
".",
"experiment"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/config_utils.py#L76-L85 | [
"def",
"add_experiment",
"(",
"self",
",",
"id",
",",
"port",
",",
"time",
",",
"file_name",
",",
"platform",
")",
":",
"self",
".",
"experiments",
"[",
"id",
"]",
"=",
"{",
"}",
"self",
".",
"experiments",
"[",
"id",
"]",
"[",
"'port'",
"]",
"=",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Experiments.update_experiment | Update experiment | tools/nni_cmd/config_utils.py | def update_experiment(self, id, key, value):
'''Update experiment'''
if id not in self.experiments:
return False
self.experiments[id][key] = value
self.write_file()
return True | def update_experiment(self, id, key, value):
'''Update experiment'''
if id not in self.experiments:
return False
self.experiments[id][key] = value
self.write_file()
return True | [
"Update",
"experiment"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/config_utils.py#L87-L93 | [
"def",
"update_experiment",
"(",
"self",
",",
"id",
",",
"key",
",",
"value",
")",
":",
"if",
"id",
"not",
"in",
"self",
".",
"experiments",
":",
"return",
"False",
"self",
".",
"experiments",
"[",
"id",
"]",
"[",
"key",
"]",
"=",
"value",
"self",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Experiments.remove_experiment | remove an experiment by id | tools/nni_cmd/config_utils.py | def remove_experiment(self, id):
'''remove an experiment by id'''
if id in self.experiments:
self.experiments.pop(id)
self.write_file() | def remove_experiment(self, id):
'''remove an experiment by id'''
if id in self.experiments:
self.experiments.pop(id)
self.write_file() | [
"remove",
"an",
"experiment",
"by",
"id"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/config_utils.py#L95-L99 | [
"def",
"remove_experiment",
"(",
"self",
",",
"id",
")",
":",
"if",
"id",
"in",
"self",
".",
"experiments",
":",
"self",
".",
"experiments",
".",
"pop",
"(",
"id",
")",
"self",
".",
"write_file",
"(",
")"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Experiments.write_file | save config to local file | tools/nni_cmd/config_utils.py | def write_file(self):
'''save config to local file'''
try:
with open(self.experiment_file, 'w') as file:
json.dump(self.experiments, file)
except IOError as error:
print('Error:', error)
return | def write_file(self):
'''save config to local file'''
try:
with open(self.experiment_file, 'w') as file:
json.dump(self.experiments, file)
except IOError as error:
print('Error:', error)
return | [
"save",
"config",
"to",
"local",
"file"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/config_utils.py#L105-L112 | [
"def",
"write_file",
"(",
"self",
")",
":",
"try",
":",
"with",
"open",
"(",
"self",
".",
"experiment_file",
",",
"'w'",
")",
"as",
"file",
":",
"json",
".",
"dump",
"(",
"self",
".",
"experiments",
",",
"file",
")",
"except",
"IOError",
"as",
"error... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Experiments.read_file | load config from local file | tools/nni_cmd/config_utils.py | def read_file(self):
'''load config from local file'''
if os.path.exists(self.experiment_file):
try:
with open(self.experiment_file, 'r') as file:
return json.load(file)
except ValueError:
return {}
return {} | def read_file(self):
'''load config from local file'''
if os.path.exists(self.experiment_file):
try:
with open(self.experiment_file, 'r') as file:
return json.load(file)
except ValueError:
return {}
return {} | [
"load",
"config",
"from",
"local",
"file"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_cmd/config_utils.py#L114-L122 | [
"def",
"read_file",
"(",
"self",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"experiment_file",
")",
":",
"try",
":",
"with",
"open",
"(",
"self",
".",
"experiment_file",
",",
"'r'",
")",
"as",
"file",
":",
"return",
"json",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | load_from_file | load data from file | examples/trials/weight_sharing/ga_squad/data.py | def load_from_file(path, fmt=None, is_training=True):
'''
load data from file
'''
if fmt is None:
fmt = 'squad'
assert fmt in ['squad', 'csv'], 'input format must be squad or csv'
qp_pairs = []
if fmt == 'squad':
with open(path) as data_file:
data = json.load(data... | def load_from_file(path, fmt=None, is_training=True):
'''
load data from file
'''
if fmt is None:
fmt = 'squad'
assert fmt in ['squad', 'csv'], 'input format must be squad or csv'
qp_pairs = []
if fmt == 'squad':
with open(path) as data_file:
data = json.load(data... | [
"load",
"data",
"from",
"file"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/data.py#L67-L104 | [
"def",
"load_from_file",
"(",
"path",
",",
"fmt",
"=",
"None",
",",
"is_training",
"=",
"True",
")",
":",
"if",
"fmt",
"is",
"None",
":",
"fmt",
"=",
"'squad'",
"assert",
"fmt",
"in",
"[",
"'squad'",
",",
"'csv'",
"]",
",",
"'input format must be squad o... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | tokenize | tokenize function. | examples/trials/weight_sharing/ga_squad/data.py | def tokenize(qp_pair, tokenizer=None, is_training=False):
'''
tokenize function.
'''
question_tokens = tokenizer.tokenize(qp_pair['question'])
passage_tokens = tokenizer.tokenize(qp_pair['passage'])
if is_training:
question_tokens = question_tokens[:300]
passage_tokens = passage_... | def tokenize(qp_pair, tokenizer=None, is_training=False):
'''
tokenize function.
'''
question_tokens = tokenizer.tokenize(qp_pair['question'])
passage_tokens = tokenizer.tokenize(qp_pair['passage'])
if is_training:
question_tokens = question_tokens[:300]
passage_tokens = passage_... | [
"tokenize",
"function",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/data.py#L107-L121 | [
"def",
"tokenize",
"(",
"qp_pair",
",",
"tokenizer",
"=",
"None",
",",
"is_training",
"=",
"False",
")",
":",
"question_tokens",
"=",
"tokenizer",
".",
"tokenize",
"(",
"qp_pair",
"[",
"'question'",
"]",
")",
"passage_tokens",
"=",
"tokenizer",
".",
"tokeniz... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | collect_vocab | Build the vocab from corpus. | examples/trials/weight_sharing/ga_squad/data.py | def collect_vocab(qp_pairs):
'''
Build the vocab from corpus.
'''
vocab = set()
for qp_pair in qp_pairs:
for word in qp_pair['question_tokens']:
vocab.add(word['word'])
for word in qp_pair['passage_tokens']:
vocab.add(word['word'])
return vocab | def collect_vocab(qp_pairs):
'''
Build the vocab from corpus.
'''
vocab = set()
for qp_pair in qp_pairs:
for word in qp_pair['question_tokens']:
vocab.add(word['word'])
for word in qp_pair['passage_tokens']:
vocab.add(word['word'])
return vocab | [
"Build",
"the",
"vocab",
"from",
"corpus",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/data.py#L124-L134 | [
"def",
"collect_vocab",
"(",
"qp_pairs",
")",
":",
"vocab",
"=",
"set",
"(",
")",
"for",
"qp_pair",
"in",
"qp_pairs",
":",
"for",
"word",
"in",
"qp_pair",
"[",
"'question_tokens'",
"]",
":",
"vocab",
".",
"add",
"(",
"word",
"[",
"'word'",
"]",
")",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | shuffle_step | Shuffle the step | examples/trials/weight_sharing/ga_squad/data.py | def shuffle_step(entries, step):
'''
Shuffle the step
'''
answer = []
for i in range(0, len(entries), step):
sub = entries[i:i+step]
shuffle(sub)
answer += sub
return answer | def shuffle_step(entries, step):
'''
Shuffle the step
'''
answer = []
for i in range(0, len(entries), step):
sub = entries[i:i+step]
shuffle(sub)
answer += sub
return answer | [
"Shuffle",
"the",
"step"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/data.py#L137-L146 | [
"def",
"shuffle_step",
"(",
"entries",
",",
"step",
")",
":",
"answer",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"entries",
")",
",",
"step",
")",
":",
"sub",
"=",
"entries",
"[",
"i",
":",
"i",
"+",
"step",
"]",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_batches | Get batches data and shuffle. | examples/trials/weight_sharing/ga_squad/data.py | def get_batches(qp_pairs, batch_size, need_sort=True):
'''
Get batches data and shuffle.
'''
if need_sort:
qp_pairs = sorted(qp_pairs, key=lambda qp: (
len(qp['passage_tokens']), qp['id']), reverse=True)
batches = [{'qp_pairs': qp_pairs[i:(i + batch_size)]}
for i i... | def get_batches(qp_pairs, batch_size, need_sort=True):
'''
Get batches data and shuffle.
'''
if need_sort:
qp_pairs = sorted(qp_pairs, key=lambda qp: (
len(qp['passage_tokens']), qp['id']), reverse=True)
batches = [{'qp_pairs': qp_pairs[i:(i + batch_size)]}
for i i... | [
"Get",
"batches",
"data",
"and",
"shuffle",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/data.py#L149-L159 | [
"def",
"get_batches",
"(",
"qp_pairs",
",",
"batch_size",
",",
"need_sort",
"=",
"True",
")",
":",
"if",
"need_sort",
":",
"qp_pairs",
"=",
"sorted",
"(",
"qp_pairs",
",",
"key",
"=",
"lambda",
"qp",
":",
"(",
"len",
"(",
"qp",
"[",
"'passage_tokens'",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_char_input | Get char input. | examples/trials/weight_sharing/ga_squad/data.py | def get_char_input(data, char_dict, max_char_length):
'''
Get char input.
'''
batch_size = len(data)
sequence_length = max(len(d) for d in data)
char_id = np.zeros((max_char_length, sequence_length,
batch_size), dtype=np.int32)
char_lengths = np.zeros((sequence_length... | def get_char_input(data, char_dict, max_char_length):
'''
Get char input.
'''
batch_size = len(data)
sequence_length = max(len(d) for d in data)
char_id = np.zeros((max_char_length, sequence_length,
batch_size), dtype=np.int32)
char_lengths = np.zeros((sequence_length... | [
"Get",
"char",
"input",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/data.py#L162-L179 | [
"def",
"get_char_input",
"(",
"data",
",",
"char_dict",
",",
"max_char_length",
")",
":",
"batch_size",
"=",
"len",
"(",
"data",
")",
"sequence_length",
"=",
"max",
"(",
"len",
"(",
"d",
")",
"for",
"d",
"in",
"data",
")",
"char_id",
"=",
"np",
".",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_word_input | Get word input. | examples/trials/weight_sharing/ga_squad/data.py | def get_word_input(data, word_dict, embed, embed_dim):
'''
Get word input.
'''
batch_size = len(data)
max_sequence_length = max(len(d) for d in data)
sequence_length = max_sequence_length
word_input = np.zeros((max_sequence_length, batch_size,
embed_dim), dtype=np.... | def get_word_input(data, word_dict, embed, embed_dim):
'''
Get word input.
'''
batch_size = len(data)
max_sequence_length = max(len(d) for d in data)
sequence_length = max_sequence_length
word_input = np.zeros((max_sequence_length, batch_size,
embed_dim), dtype=np.... | [
"Get",
"word",
"input",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/data.py#L182-L208 | [
"def",
"get_word_input",
"(",
"data",
",",
"word_dict",
",",
"embed",
",",
"embed_dim",
")",
":",
"batch_size",
"=",
"len",
"(",
"data",
")",
"max_sequence_length",
"=",
"max",
"(",
"len",
"(",
"d",
")",
"for",
"d",
"in",
"data",
")",
"sequence_length",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_word_index | Given word return word index. | examples/trials/weight_sharing/ga_squad/data.py | def get_word_index(tokens, char_index):
'''
Given word return word index.
'''
for (i, token) in enumerate(tokens):
if token['char_end'] == 0:
continue
if token['char_begin'] <= char_index and char_index <= token['char_end']:
return i
return 0 | def get_word_index(tokens, char_index):
'''
Given word return word index.
'''
for (i, token) in enumerate(tokens):
if token['char_end'] == 0:
continue
if token['char_begin'] <= char_index and char_index <= token['char_end']:
return i
return 0 | [
"Given",
"word",
"return",
"word",
"index",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/data.py#L211-L220 | [
"def",
"get_word_index",
"(",
"tokens",
",",
"char_index",
")",
":",
"for",
"(",
"i",
",",
"token",
")",
"in",
"enumerate",
"(",
"tokens",
")",
":",
"if",
"token",
"[",
"'char_end'",
"]",
"==",
"0",
":",
"continue",
"if",
"token",
"[",
"'char_begin'",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_answer_begin_end | Get answer's index of begin and end. | examples/trials/weight_sharing/ga_squad/data.py | def get_answer_begin_end(data):
'''
Get answer's index of begin and end.
'''
begin = []
end = []
for qa_pair in data:
tokens = qa_pair['passage_tokens']
char_begin = qa_pair['answer_begin']
char_end = qa_pair['answer_end']
word_begin = get_word_index(tokens, char_... | def get_answer_begin_end(data):
'''
Get answer's index of begin and end.
'''
begin = []
end = []
for qa_pair in data:
tokens = qa_pair['passage_tokens']
char_begin = qa_pair['answer_begin']
char_end = qa_pair['answer_end']
word_begin = get_word_index(tokens, char_... | [
"Get",
"answer",
"s",
"index",
"of",
"begin",
"and",
"end",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/data.py#L223-L237 | [
"def",
"get_answer_begin_end",
"(",
"data",
")",
":",
"begin",
"=",
"[",
"]",
"end",
"=",
"[",
"]",
"for",
"qa_pair",
"in",
"data",
":",
"tokens",
"=",
"qa_pair",
"[",
"'passage_tokens'",
"]",
"char_begin",
"=",
"qa_pair",
"[",
"'answer_begin'",
"]",
"ch... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_buckets | Get bucket by length. | examples/trials/weight_sharing/ga_squad/data.py | def get_buckets(min_length, max_length, bucket_count):
'''
Get bucket by length.
'''
if bucket_count <= 0:
return [max_length]
unit_length = int((max_length - min_length) // (bucket_count))
buckets = [min_length + unit_length *
(i + 1) for i in range(0, bucket_count)]
... | def get_buckets(min_length, max_length, bucket_count):
'''
Get bucket by length.
'''
if bucket_count <= 0:
return [max_length]
unit_length = int((max_length - min_length) // (bucket_count))
buckets = [min_length + unit_length *
(i + 1) for i in range(0, bucket_count)]
... | [
"Get",
"bucket",
"by",
"length",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/data.py#L249-L259 | [
"def",
"get_buckets",
"(",
"min_length",
",",
"max_length",
",",
"bucket_count",
")",
":",
"if",
"bucket_count",
"<=",
"0",
":",
"return",
"[",
"max_length",
"]",
"unit_length",
"=",
"int",
"(",
"(",
"max_length",
"-",
"min_length",
")",
"//",
"(",
"bucket... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | WhitespaceTokenizer.tokenize | tokenize function in Tokenizer. | examples/trials/weight_sharing/ga_squad/data.py | def tokenize(self, text):
'''
tokenize function in Tokenizer.
'''
start = -1
tokens = []
for i, character in enumerate(text):
if character == ' ' or character == '\t':
if start >= 0:
word = text[start:i]
... | def tokenize(self, text):
'''
tokenize function in Tokenizer.
'''
start = -1
tokens = []
for i, character in enumerate(text):
if character == ' ' or character == '\t':
if start >= 0:
word = text[start:i]
... | [
"tokenize",
"function",
"in",
"Tokenizer",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/weight_sharing/ga_squad/data.py#L38-L64 | [
"def",
"tokenize",
"(",
"self",
",",
"text",
")",
":",
"start",
"=",
"-",
"1",
"tokens",
"=",
"[",
"]",
"for",
"i",
",",
"character",
"in",
"enumerate",
"(",
"text",
")",
":",
"if",
"character",
"==",
"' '",
"or",
"character",
"==",
"'\\t'",
":",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | CustomerTuner.generate_new_id | generate new id and event hook for new Individual | examples/tuners/weight_sharing/ga_customer_tuner/customer_tuner.py | def generate_new_id(self):
"""
generate new id and event hook for new Individual
"""
self.events.append(Event())
indiv_id = self.indiv_counter
self.indiv_counter += 1
return indiv_id | def generate_new_id(self):
"""
generate new id and event hook for new Individual
"""
self.events.append(Event())
indiv_id = self.indiv_counter
self.indiv_counter += 1
return indiv_id | [
"generate",
"new",
"id",
"and",
"event",
"hook",
"for",
"new",
"Individual"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/tuners/weight_sharing/ga_customer_tuner/customer_tuner.py#L84-L91 | [
"def",
"generate_new_id",
"(",
"self",
")",
":",
"self",
".",
"events",
".",
"append",
"(",
"Event",
"(",
")",
")",
"indiv_id",
"=",
"self",
".",
"indiv_counter",
"self",
".",
"indiv_counter",
"+=",
"1",
"return",
"indiv_id"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | CustomerTuner.init_population | initialize populations for evolution tuner | examples/tuners/weight_sharing/ga_customer_tuner/customer_tuner.py | def init_population(self, population_size, graph_max_layer, graph_min_layer):
"""
initialize populations for evolution tuner
"""
population = []
graph = Graph(max_layer_num=graph_max_layer, min_layer_num=graph_min_layer,
inputs=[Layer(LayerType.input.value, ... | def init_population(self, population_size, graph_max_layer, graph_min_layer):
"""
initialize populations for evolution tuner
"""
population = []
graph = Graph(max_layer_num=graph_max_layer, min_layer_num=graph_min_layer,
inputs=[Layer(LayerType.input.value, ... | [
"initialize",
"populations",
"for",
"evolution",
"tuner"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/tuners/weight_sharing/ga_customer_tuner/customer_tuner.py#L99-L113 | [
"def",
"init_population",
"(",
"self",
",",
"population_size",
",",
"graph_max_layer",
",",
"graph_min_layer",
")",
":",
"population",
"=",
"[",
"]",
"graph",
"=",
"Graph",
"(",
"max_layer_num",
"=",
"graph_max_layer",
",",
"min_layer_num",
"=",
"graph_min_layer",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | CustomerTuner.generate_parameters | Returns a set of trial graph config, as a serializable object.
An example configuration:
```json
{
"shared_id": [
"4a11b2ef9cb7211590dfe81039b27670",
"370af04de24985e5ea5b3d72b12644c9",
"11f646e9f650f5f3fedc12b6349ec60f",
... | examples/tuners/weight_sharing/ga_customer_tuner/customer_tuner.py | def generate_parameters(self, parameter_id):
"""Returns a set of trial graph config, as a serializable object.
An example configuration:
```json
{
"shared_id": [
"4a11b2ef9cb7211590dfe81039b27670",
"370af04de24985e5ea5b3d72b12644c9",
... | def generate_parameters(self, parameter_id):
"""Returns a set of trial graph config, as a serializable object.
An example configuration:
```json
{
"shared_id": [
"4a11b2ef9cb7211590dfe81039b27670",
"370af04de24985e5ea5b3d72b12644c9",
... | [
"Returns",
"a",
"set",
"of",
"trial",
"graph",
"config",
"as",
"a",
"serializable",
"object",
".",
"An",
"example",
"configuration",
":",
"json",
"{",
"shared_id",
":",
"[",
"4a11b2ef9cb7211590dfe81039b27670",
"370af04de24985e5ea5b3d72b12644c9",
"11f646e9f650f5f3fedc12b... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/tuners/weight_sharing/ga_customer_tuner/customer_tuner.py#L115-L197 | [
"def",
"generate_parameters",
"(",
"self",
",",
"parameter_id",
")",
":",
"logger",
".",
"debug",
"(",
"'acquiring lock for param {}'",
".",
"format",
"(",
"parameter_id",
")",
")",
"self",
".",
"thread_lock",
".",
"acquire",
"(",
")",
"logger",
".",
"debug",
... | 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/weight_sharing/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
'''
logger.debug('acquiring lock for param {... | 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
'''
logger.debug('acquiring lock for param {... | [
"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/weight_sharing/ga_customer_tuner/customer_tuner.py#L199-L222 | [
"def",
"receive_trial_result",
"(",
"self",
",",
"parameter_id",
",",
"parameters",
",",
"value",
")",
":",
"logger",
".",
"debug",
"(",
"'acquiring lock for param {}'",
".",
"format",
"(",
"parameter_id",
")",
")",
"self",
".",
"thread_lock",
".",
"acquire",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MedianstopAssessor._update_data | update data
Parameters
----------
trial_job_id: int
trial job id
trial_history: list
The history performance matrix of each trial | src/sdk/pynni/nni/medianstop_assessor/medianstop_assessor.py | def _update_data(self, trial_job_id, trial_history):
"""update data
Parameters
----------
trial_job_id: int
trial job id
trial_history: list
The history performance matrix of each trial
"""
if trial_job_id not in self.running_history:
... | def _update_data(self, trial_job_id, trial_history):
"""update data
Parameters
----------
trial_job_id: int
trial job id
trial_history: list
The history performance matrix of each trial
"""
if trial_job_id not in self.running_history:
... | [
"update",
"data"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/medianstop_assessor/medianstop_assessor.py#L47-L59 | [
"def",
"_update_data",
"(",
"self",
",",
"trial_job_id",
",",
"trial_history",
")",
":",
"if",
"trial_job_id",
"not",
"in",
"self",
".",
"running_history",
":",
"self",
".",
"running_history",
"[",
"trial_job_id",
"]",
"=",
"[",
"]",
"self",
".",
"running_hi... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MedianstopAssessor.trial_end | trial_end
Parameters
----------
trial_job_id: int
trial job id
success: bool
True if succssfully finish the experiment, False otherwise | src/sdk/pynni/nni/medianstop_assessor/medianstop_assessor.py | def trial_end(self, trial_job_id, success):
"""trial_end
Parameters
----------
trial_job_id: int
trial job id
success: bool
True if succssfully finish the experiment, False otherwise
"""
if trial_job_id in self.running_history:
... | def trial_end(self, trial_job_id, success):
"""trial_end
Parameters
----------
trial_job_id: int
trial job id
success: bool
True if succssfully finish the experiment, False otherwise
"""
if trial_job_id in self.running_history:
... | [
"trial_end",
"Parameters",
"----------",
"trial_job_id",
":",
"int",
"trial",
"job",
"id",
"success",
":",
"bool",
"True",
"if",
"succssfully",
"finish",
"the",
"experiment",
"False",
"otherwise"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/medianstop_assessor/medianstop_assessor.py#L61-L82 | [
"def",
"trial_end",
"(",
"self",
",",
"trial_job_id",
",",
"success",
")",
":",
"if",
"trial_job_id",
"in",
"self",
".",
"running_history",
":",
"if",
"success",
":",
"cnt",
"=",
"0",
"history_sum",
"=",
"0",
"self",
".",
"completed_avg_history",
"[",
"tri... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MedianstopAssessor.assess_trial | assess_trial
Parameters
----------
trial_job_id: int
trial job id
trial_history: list
The history performance matrix of each trial
Returns
-------
bool
AssessResult.Good or AssessResult.Bad
Raises
----... | src/sdk/pynni/nni/medianstop_assessor/medianstop_assessor.py | def assess_trial(self, trial_job_id, trial_history):
"""assess_trial
Parameters
----------
trial_job_id: int
trial job id
trial_history: list
The history performance matrix of each trial
Returns
-------
bool
As... | def assess_trial(self, trial_job_id, trial_history):
"""assess_trial
Parameters
----------
trial_job_id: int
trial job id
trial_history: list
The history performance matrix of each trial
Returns
-------
bool
As... | [
"assess_trial",
"Parameters",
"----------",
"trial_job_id",
":",
"int",
"trial",
"job",
"id",
"trial_history",
":",
"list",
"The",
"history",
"performance",
"matrix",
"of",
"each",
"trial"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/medianstop_assessor/medianstop_assessor.py#L84-L136 | [
"def",
"assess_trial",
"(",
"self",
",",
"trial_job_id",
",",
"trial_history",
")",
":",
"curr_step",
"=",
"len",
"(",
"trial_history",
")",
"if",
"curr_step",
"<",
"self",
".",
"start_step",
":",
"return",
"AssessResult",
".",
"Good",
"try",
":",
"num_trial... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | copyHdfsDirectoryToLocal | Copy directory from HDFS to local | tools/nni_trial_tool/hdfsClientUtility.py | def copyHdfsDirectoryToLocal(hdfsDirectory, localDirectory, hdfsClient):
'''Copy directory from HDFS to local'''
if not os.path.exists(localDirectory):
os.makedirs(localDirectory)
try:
listing = hdfsClient.list_status(hdfsDirectory)
except Exception as exception:
nni_log(LogType.... | def copyHdfsDirectoryToLocal(hdfsDirectory, localDirectory, hdfsClient):
'''Copy directory from HDFS to local'''
if not os.path.exists(localDirectory):
os.makedirs(localDirectory)
try:
listing = hdfsClient.list_status(hdfsDirectory)
except Exception as exception:
nni_log(LogType.... | [
"Copy",
"directory",
"from",
"HDFS",
"to",
"local"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_trial_tool/hdfsClientUtility.py#L26-L46 | [
"def",
"copyHdfsDirectoryToLocal",
"(",
"hdfsDirectory",
",",
"localDirectory",
",",
"hdfsClient",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"localDirectory",
")",
":",
"os",
".",
"makedirs",
"(",
"localDirectory",
")",
"try",
":",
"listi... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | copyHdfsFileToLocal | Copy file from HDFS to local | tools/nni_trial_tool/hdfsClientUtility.py | def copyHdfsFileToLocal(hdfsFilePath, localFilePath, hdfsClient, override=True):
'''Copy file from HDFS to local'''
if not hdfsClient.exists(hdfsFilePath):
raise Exception('HDFS file {} does not exist!'.format(hdfsFilePath))
try:
file_status = hdfsClient.get_file_status(hdfsFilePath)
... | def copyHdfsFileToLocal(hdfsFilePath, localFilePath, hdfsClient, override=True):
'''Copy file from HDFS to local'''
if not hdfsClient.exists(hdfsFilePath):
raise Exception('HDFS file {} does not exist!'.format(hdfsFilePath))
try:
file_status = hdfsClient.get_file_status(hdfsFilePath)
... | [
"Copy",
"file",
"from",
"HDFS",
"to",
"local"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_trial_tool/hdfsClientUtility.py#L48-L67 | [
"def",
"copyHdfsFileToLocal",
"(",
"hdfsFilePath",
",",
"localFilePath",
",",
"hdfsClient",
",",
"override",
"=",
"True",
")",
":",
"if",
"not",
"hdfsClient",
".",
"exists",
"(",
"hdfsFilePath",
")",
":",
"raise",
"Exception",
"(",
"'HDFS file {} does not exist!'"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | copyDirectoryToHdfs | Copy directory from local to HDFS | tools/nni_trial_tool/hdfsClientUtility.py | def copyDirectoryToHdfs(localDirectory, hdfsDirectory, hdfsClient):
'''Copy directory from local to HDFS'''
if not os.path.exists(localDirectory):
raise Exception('Local Directory does not exist!')
hdfsClient.mkdirs(hdfsDirectory)
result = True
for file in os.listdir(localDirectory):
... | def copyDirectoryToHdfs(localDirectory, hdfsDirectory, hdfsClient):
'''Copy directory from local to HDFS'''
if not os.path.exists(localDirectory):
raise Exception('Local Directory does not exist!')
hdfsClient.mkdirs(hdfsDirectory)
result = True
for file in os.listdir(localDirectory):
... | [
"Copy",
"directory",
"from",
"local",
"to",
"HDFS"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_trial_tool/hdfsClientUtility.py#L69-L91 | [
"def",
"copyDirectoryToHdfs",
"(",
"localDirectory",
",",
"hdfsDirectory",
",",
"hdfsClient",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"localDirectory",
")",
":",
"raise",
"Exception",
"(",
"'Local Directory does not exist!'",
")",
"hdfsClient... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | copyFileToHdfs | Copy a local file to HDFS directory | tools/nni_trial_tool/hdfsClientUtility.py | def copyFileToHdfs(localFilePath, hdfsFilePath, hdfsClient, override=True):
'''Copy a local file to HDFS directory'''
if not os.path.exists(localFilePath):
raise Exception('Local file Path does not exist!')
if os.path.isdir(localFilePath):
raise Exception('localFile should not a directory!')... | def copyFileToHdfs(localFilePath, hdfsFilePath, hdfsClient, override=True):
'''Copy a local file to HDFS directory'''
if not os.path.exists(localFilePath):
raise Exception('Local file Path does not exist!')
if os.path.isdir(localFilePath):
raise Exception('localFile should not a directory!')... | [
"Copy",
"a",
"local",
"file",
"to",
"HDFS",
"directory"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/tools/nni_trial_tool/hdfsClientUtility.py#L93-L109 | [
"def",
"copyFileToHdfs",
"(",
"localFilePath",
",",
"hdfsFilePath",
",",
"hdfsClient",
",",
"override",
"=",
"True",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"localFilePath",
")",
":",
"raise",
"Exception",
"(",
"'Local file Path does not ... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | load_data | Load dataset, use boston dataset | examples/trials/sklearn/regression/main.py | def load_data():
'''Load dataset, use boston dataset'''
boston = load_boston()
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target, random_state=99, test_size=0.25)
#normalize data
ss_X = StandardScaler()
ss_y = StandardScaler()
X_train = ss_X.fit_transform(X_trai... | def load_data():
'''Load dataset, use boston dataset'''
boston = load_boston()
X_train, X_test, y_train, y_test = train_test_split(boston.data, boston.target, random_state=99, test_size=0.25)
#normalize data
ss_X = StandardScaler()
ss_y = StandardScaler()
X_train = ss_X.fit_transform(X_trai... | [
"Load",
"dataset",
"use",
"boston",
"dataset"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/sklearn/regression/main.py#L33-L46 | [
"def",
"load_data",
"(",
")",
":",
"boston",
"=",
"load_boston",
"(",
")",
"X_train",
",",
"X_test",
",",
"y_train",
",",
"y_test",
"=",
"train_test_split",
"(",
"boston",
".",
"data",
",",
"boston",
".",
"target",
",",
"random_state",
"=",
"99",
",",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | get_model | Get model according to parameters | examples/trials/sklearn/regression/main.py | def get_model(PARAMS):
'''Get model according to parameters'''
model_dict = {
'LinearRegression': LinearRegression(),
'SVR': SVR(),
'KNeighborsRegressor': KNeighborsRegressor(),
'DecisionTreeRegressor': DecisionTreeRegressor()
}
if not model_dict.get(PARAMS['model_name'])... | def get_model(PARAMS):
'''Get model according to parameters'''
model_dict = {
'LinearRegression': LinearRegression(),
'SVR': SVR(),
'KNeighborsRegressor': KNeighborsRegressor(),
'DecisionTreeRegressor': DecisionTreeRegressor()
}
if not model_dict.get(PARAMS['model_name'])... | [
"Get",
"model",
"according",
"to",
"parameters"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/sklearn/regression/main.py#L55-L77 | [
"def",
"get_model",
"(",
"PARAMS",
")",
":",
"model_dict",
"=",
"{",
"'LinearRegression'",
":",
"LinearRegression",
"(",
")",
",",
"'SVR'",
":",
"SVR",
"(",
")",
",",
"'KNeighborsRegressor'",
":",
"KNeighborsRegressor",
"(",
")",
",",
"'DecisionTreeRegressor'",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | run | Train model and predict result | examples/trials/sklearn/regression/main.py | def run(X_train, X_test, y_train, y_test, PARAMS):
'''Train model and predict result'''
model.fit(X_train, y_train)
predict_y = model.predict(X_test)
score = r2_score(y_test, predict_y)
LOG.debug('r2 score: %s' % score)
nni.report_final_result(score) | def run(X_train, X_test, y_train, y_test, PARAMS):
'''Train model and predict result'''
model.fit(X_train, y_train)
predict_y = model.predict(X_test)
score = r2_score(y_test, predict_y)
LOG.debug('r2 score: %s' % score)
nni.report_final_result(score) | [
"Train",
"model",
"and",
"predict",
"result"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/examples/trials/sklearn/regression/main.py#L80-L86 | [
"def",
"run",
"(",
"X_train",
",",
"X_test",
",",
"y_train",
",",
"y_test",
",",
"PARAMS",
")",
":",
"model",
".",
"fit",
"(",
"X_train",
",",
"y_train",
")",
"predict_y",
"=",
"model",
".",
"predict",
"(",
"X_test",
")",
"score",
"=",
"r2_score",
"(... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | NetworkDescriptor.add_skip_connection | Add a skip-connection to the descriptor.
Args:
u: Number of convolutional layers before the starting point.
v: Number of convolutional layers before the ending point.
connection_type: Must be either CONCAT_CONNECT or ADD_CONNECT. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def add_skip_connection(self, u, v, connection_type):
""" Add a skip-connection to the descriptor.
Args:
u: Number of convolutional layers before the starting point.
v: Number of convolutional layers before the ending point.
connection_type: Must be either CONCAT_CONN... | def add_skip_connection(self, u, v, connection_type):
""" Add a skip-connection to the descriptor.
Args:
u: Number of convolutional layers before the starting point.
v: Number of convolutional layers before the ending point.
connection_type: Must be either CONCAT_CONN... | [
"Add",
"a",
"skip",
"-",
"connection",
"to",
"the",
"descriptor",
".",
"Args",
":",
"u",
":",
"Number",
"of",
"convolutional",
"layers",
"before",
"the",
"starting",
"point",
".",
"v",
":",
"Number",
"of",
"convolutional",
"layers",
"before",
"the",
"endin... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L75-L87 | [
"def",
"add_skip_connection",
"(",
"self",
",",
"u",
",",
"v",
",",
"connection_type",
")",
":",
"if",
"connection_type",
"not",
"in",
"[",
"self",
".",
"CONCAT_CONNECT",
",",
"self",
".",
"ADD_CONNECT",
"]",
":",
"raise",
"ValueError",
"(",
"\"connection_ty... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | NetworkDescriptor.to_json | NetworkDescriptor to json representation | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def to_json(self):
''' NetworkDescriptor to json representation
'''
skip_list = []
for u, v, connection_type in self.skip_connections:
skip_list.append({"from": u, "to": v, "type": connection_type})
return {"node_list": self.layers, "skip_list": skip_list} | def to_json(self):
''' NetworkDescriptor to json representation
'''
skip_list = []
for u, v, connection_type in self.skip_connections:
skip_list.append({"from": u, "to": v, "type": connection_type})
return {"node_list": self.layers, "skip_list": skip_list} | [
"NetworkDescriptor",
"to",
"json",
"representation"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L89-L96 | [
"def",
"to_json",
"(",
"self",
")",
":",
"skip_list",
"=",
"[",
"]",
"for",
"u",
",",
"v",
",",
"connection_type",
"in",
"self",
".",
"skip_connections",
":",
"skip_list",
".",
"append",
"(",
"{",
"\"from\"",
":",
"u",
",",
"\"to\"",
":",
"v",
",",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph.add_layer | Add a layer to the Graph.
Args:
layer: An instance of the subclasses of StubLayer in layers.py.
input_node_id: An integer. The ID of the input node of the layer.
Returns:
output_node_id: An integer. The ID of the output node of the layer. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def add_layer(self, layer, input_node_id):
"""Add a layer to the Graph.
Args:
layer: An instance of the subclasses of StubLayer in layers.py.
input_node_id: An integer. The ID of the input node of the layer.
Returns:
output_node_id: An integer. The ID of the o... | def add_layer(self, layer, input_node_id):
"""Add a layer to the Graph.
Args:
layer: An instance of the subclasses of StubLayer in layers.py.
input_node_id: An integer. The ID of the input node of the layer.
Returns:
output_node_id: An integer. The ID of the o... | [
"Add",
"a",
"layer",
"to",
"the",
"Graph",
".",
"Args",
":",
"layer",
":",
"An",
"instance",
"of",
"the",
"subclasses",
"of",
"StubLayer",
"in",
"layers",
".",
"py",
".",
"input_node_id",
":",
"An",
"integer",
".",
"The",
"ID",
"of",
"the",
"input",
... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L165-L185 | [
"def",
"add_layer",
"(",
"self",
",",
"layer",
",",
"input_node_id",
")",
":",
"if",
"isinstance",
"(",
"input_node_id",
",",
"Iterable",
")",
":",
"layer",
".",
"input",
"=",
"list",
"(",
"map",
"(",
"lambda",
"x",
":",
"self",
".",
"node_list",
"[",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph._add_node | Add a new node to node_list and give the node an ID.
Args:
node: An instance of Node.
Returns:
node_id: An integer. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def _add_node(self, node):
"""Add a new node to node_list and give the node an ID.
Args:
node: An instance of Node.
Returns:
node_id: An integer.
"""
node_id = len(self.node_list)
self.node_to_id[node] = node_id
self.node_list.append(node)
... | def _add_node(self, node):
"""Add a new node to node_list and give the node an ID.
Args:
node: An instance of Node.
Returns:
node_id: An integer.
"""
node_id = len(self.node_list)
self.node_to_id[node] = node_id
self.node_list.append(node)
... | [
"Add",
"a",
"new",
"node",
"to",
"node_list",
"and",
"give",
"the",
"node",
"an",
"ID",
".",
"Args",
":",
"node",
":",
"An",
"instance",
"of",
"Node",
".",
"Returns",
":",
"node_id",
":",
"An",
"integer",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L200-L212 | [
"def",
"_add_node",
"(",
"self",
",",
"node",
")",
":",
"node_id",
"=",
"len",
"(",
"self",
".",
"node_list",
")",
"self",
".",
"node_to_id",
"[",
"node",
"]",
"=",
"node_id",
"self",
".",
"node_list",
".",
"append",
"(",
"node",
")",
"self",
".",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph._add_edge | Add a new layer to the graph. The nodes should be created in advance. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def _add_edge(self, layer, input_id, output_id):
"""Add a new layer to the graph. The nodes should be created in advance."""
if layer in self.layer_to_id:
layer_id = self.layer_to_id[layer]
if input_id not in self.layer_id_to_input_node_ids[layer_id]:
self.layer_... | def _add_edge(self, layer, input_id, output_id):
"""Add a new layer to the graph. The nodes should be created in advance."""
if layer in self.layer_to_id:
layer_id = self.layer_to_id[layer]
if input_id not in self.layer_id_to_input_node_ids[layer_id]:
self.layer_... | [
"Add",
"a",
"new",
"layer",
"to",
"the",
"graph",
".",
"The",
"nodes",
"should",
"be",
"created",
"in",
"advance",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L214-L231 | [
"def",
"_add_edge",
"(",
"self",
",",
"layer",
",",
"input_id",
",",
"output_id",
")",
":",
"if",
"layer",
"in",
"self",
".",
"layer_to_id",
":",
"layer_id",
"=",
"self",
".",
"layer_to_id",
"[",
"layer",
"]",
"if",
"input_id",
"not",
"in",
"self",
"."... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph._redirect_edge | Redirect the layer to a new node.
Change the edge originally from `u_id` to `v_id` into an edge from `u_id` to `new_v_id`
while keeping all other property of the edge the same. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def _redirect_edge(self, u_id, v_id, new_v_id):
"""Redirect the layer to a new node.
Change the edge originally from `u_id` to `v_id` into an edge from `u_id` to `new_v_id`
while keeping all other property of the edge the same.
"""
layer_id = None
for index, edge_tuple in... | def _redirect_edge(self, u_id, v_id, new_v_id):
"""Redirect the layer to a new node.
Change the edge originally from `u_id` to `v_id` into an edge from `u_id` to `new_v_id`
while keeping all other property of the edge the same.
"""
layer_id = None
for index, edge_tuple in... | [
"Redirect",
"the",
"layer",
"to",
"a",
"new",
"node",
".",
"Change",
"the",
"edge",
"originally",
"from",
"u_id",
"to",
"v_id",
"into",
"an",
"edge",
"from",
"u_id",
"to",
"new_v_id",
"while",
"keeping",
"all",
"other",
"property",
"of",
"the",
"edge",
"... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L233-L255 | [
"def",
"_redirect_edge",
"(",
"self",
",",
"u_id",
",",
"v_id",
",",
"new_v_id",
")",
":",
"layer_id",
"=",
"None",
"for",
"index",
",",
"edge_tuple",
"in",
"enumerate",
"(",
"self",
".",
"adj_list",
"[",
"u_id",
"]",
")",
":",
"if",
"edge_tuple",
"[",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph._replace_layer | Replace the layer with a new layer. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def _replace_layer(self, layer_id, new_layer):
"""Replace the layer with a new layer."""
old_layer = self.layer_list[layer_id]
new_layer.input = old_layer.input
new_layer.output = old_layer.output
new_layer.output.shape = new_layer.output_shape
self.layer_list[layer_id] =... | def _replace_layer(self, layer_id, new_layer):
"""Replace the layer with a new layer."""
old_layer = self.layer_list[layer_id]
new_layer.input = old_layer.input
new_layer.output = old_layer.output
new_layer.output.shape = new_layer.output_shape
self.layer_list[layer_id] =... | [
"Replace",
"the",
"layer",
"with",
"a",
"new",
"layer",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L257-L265 | [
"def",
"_replace_layer",
"(",
"self",
",",
"layer_id",
",",
"new_layer",
")",
":",
"old_layer",
"=",
"self",
".",
"layer_list",
"[",
"layer_id",
"]",
"new_layer",
".",
"input",
"=",
"old_layer",
".",
"input",
"new_layer",
".",
"output",
"=",
"old_layer",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph.topological_order | Return the topological order of the node IDs from the input node to the output node. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def topological_order(self):
"""Return the topological order of the node IDs from the input node to the output node."""
q = Queue()
in_degree = {}
for i in range(self.n_nodes):
in_degree[i] = 0
for u in range(self.n_nodes):
for v, _ in self.adj_list[u]:
... | def topological_order(self):
"""Return the topological order of the node IDs from the input node to the output node."""
q = Queue()
in_degree = {}
for i in range(self.n_nodes):
in_degree[i] = 0
for u in range(self.n_nodes):
for v, _ in self.adj_list[u]:
... | [
"Return",
"the",
"topological",
"order",
"of",
"the",
"node",
"IDs",
"from",
"the",
"input",
"node",
"to",
"the",
"output",
"node",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L268-L289 | [
"def",
"topological_order",
"(",
"self",
")",
":",
"q",
"=",
"Queue",
"(",
")",
"in_degree",
"=",
"{",
"}",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"n_nodes",
")",
":",
"in_degree",
"[",
"i",
"]",
"=",
"0",
"for",
"u",
"in",
"range",
"(",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph._get_pooling_layers | Given two node IDs, return all the pooling layers between them. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def _get_pooling_layers(self, start_node_id, end_node_id):
"""Given two node IDs, return all the pooling layers between them."""
layer_list = []
node_list = [start_node_id]
assert self._depth_first_search(end_node_id, layer_list, node_list)
ret = []
for layer_id in layer_... | def _get_pooling_layers(self, start_node_id, end_node_id):
"""Given two node IDs, return all the pooling layers between them."""
layer_list = []
node_list = [start_node_id]
assert self._depth_first_search(end_node_id, layer_list, node_list)
ret = []
for layer_id in layer_... | [
"Given",
"two",
"node",
"IDs",
"return",
"all",
"the",
"pooling",
"layers",
"between",
"them",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L291-L303 | [
"def",
"_get_pooling_layers",
"(",
"self",
",",
"start_node_id",
",",
"end_node_id",
")",
":",
"layer_list",
"=",
"[",
"]",
"node_list",
"=",
"[",
"start_node_id",
"]",
"assert",
"self",
".",
"_depth_first_search",
"(",
"end_node_id",
",",
"layer_list",
",",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph._depth_first_search | Search for all the layers and nodes down the path.
A recursive function to search all the layers and nodes between the node in the node_list
and the node with target_id. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def _depth_first_search(self, target_id, layer_id_list, node_list):
"""Search for all the layers and nodes down the path.
A recursive function to search all the layers and nodes between the node in the node_list
and the node with target_id."""
assert len(node_list) <= self.n_nodes
... | def _depth_first_search(self, target_id, layer_id_list, node_list):
"""Search for all the layers and nodes down the path.
A recursive function to search all the layers and nodes between the node in the node_list
and the node with target_id."""
assert len(node_list) <= self.n_nodes
... | [
"Search",
"for",
"all",
"the",
"layers",
"and",
"nodes",
"down",
"the",
"path",
".",
"A",
"recursive",
"function",
"to",
"search",
"all",
"the",
"layers",
"and",
"nodes",
"between",
"the",
"node",
"in",
"the",
"node_list",
"and",
"the",
"node",
"with",
"... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L305-L322 | [
"def",
"_depth_first_search",
"(",
"self",
",",
"target_id",
",",
"layer_id_list",
",",
"node_list",
")",
":",
"assert",
"len",
"(",
"node_list",
")",
"<=",
"self",
".",
"n_nodes",
"u",
"=",
"node_list",
"[",
"-",
"1",
"]",
"if",
"u",
"==",
"target_id",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph._search | Search the graph for all the layers to be widened caused by an operation.
It is an recursive function with duplication check to avoid deadlock.
It searches from a starting node u until the corresponding layers has been widened.
Args:
u: The starting node ID.
start_dim: Th... | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def _search(self, u, start_dim, total_dim, n_add):
"""Search the graph for all the layers to be widened caused by an operation.
It is an recursive function with duplication check to avoid deadlock.
It searches from a starting node u until the corresponding layers has been widened.
Args:
... | def _search(self, u, start_dim, total_dim, n_add):
"""Search the graph for all the layers to be widened caused by an operation.
It is an recursive function with duplication check to avoid deadlock.
It searches from a starting node u until the corresponding layers has been widened.
Args:
... | [
"Search",
"the",
"graph",
"for",
"all",
"the",
"layers",
"to",
"be",
"widened",
"caused",
"by",
"an",
"operation",
".",
"It",
"is",
"an",
"recursive",
"function",
"with",
"duplication",
"check",
"to",
"avoid",
"deadlock",
".",
"It",
"searches",
"from",
"a"... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L324-L387 | [
"def",
"_search",
"(",
"self",
",",
"u",
",",
"start_dim",
",",
"total_dim",
",",
"n_add",
")",
":",
"if",
"(",
"u",
",",
"start_dim",
",",
"total_dim",
",",
"n_add",
")",
"in",
"self",
".",
"vis",
":",
"return",
"self",
".",
"vis",
"[",
"(",
"u"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph.to_deeper_model | Insert a relu-conv-bn block after the target block.
Args:
target_id: A convolutional layer ID. The new block should be inserted after the block.
new_layer: An instance of StubLayer subclasses. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def to_deeper_model(self, target_id, new_layer):
"""Insert a relu-conv-bn block after the target block.
Args:
target_id: A convolutional layer ID. The new block should be inserted after the block.
new_layer: An instance of StubLayer subclasses.
"""
self.operation_... | def to_deeper_model(self, target_id, new_layer):
"""Insert a relu-conv-bn block after the target block.
Args:
target_id: A convolutional layer ID. The new block should be inserted after the block.
new_layer: An instance of StubLayer subclasses.
"""
self.operation_... | [
"Insert",
"a",
"relu",
"-",
"conv",
"-",
"bn",
"block",
"after",
"the",
"target",
"block",
".",
"Args",
":",
"target_id",
":",
"A",
"convolutional",
"layer",
"ID",
".",
"The",
"new",
"block",
"should",
"be",
"inserted",
"after",
"the",
"block",
".",
"n... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L402-L419 | [
"def",
"to_deeper_model",
"(",
"self",
",",
"target_id",
",",
"new_layer",
")",
":",
"self",
".",
"operation_history",
".",
"append",
"(",
"(",
"\"to_deeper_model\"",
",",
"target_id",
",",
"new_layer",
")",
")",
"input_id",
"=",
"self",
".",
"layer_id_to_inpu... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph.to_wider_model | Widen the last dimension of the output of the pre_layer.
Args:
pre_layer_id: The ID of a convolutional layer or dense layer.
n_add: The number of dimensions to add. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def to_wider_model(self, pre_layer_id, n_add):
"""Widen the last dimension of the output of the pre_layer.
Args:
pre_layer_id: The ID of a convolutional layer or dense layer.
n_add: The number of dimensions to add.
"""
self.operation_history.append(("to_wider_mode... | def to_wider_model(self, pre_layer_id, n_add):
"""Widen the last dimension of the output of the pre_layer.
Args:
pre_layer_id: The ID of a convolutional layer or dense layer.
n_add: The number of dimensions to add.
"""
self.operation_history.append(("to_wider_mode... | [
"Widen",
"the",
"last",
"dimension",
"of",
"the",
"output",
"of",
"the",
"pre_layer",
".",
"Args",
":",
"pre_layer_id",
":",
"The",
"ID",
"of",
"a",
"convolutional",
"layer",
"or",
"dense",
"layer",
".",
"n_add",
":",
"The",
"number",
"of",
"dimensions",
... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L421-L436 | [
"def",
"to_wider_model",
"(",
"self",
",",
"pre_layer_id",
",",
"n_add",
")",
":",
"self",
".",
"operation_history",
".",
"append",
"(",
"(",
"\"to_wider_model\"",
",",
"pre_layer_id",
",",
"n_add",
")",
")",
"pre_layer",
"=",
"self",
".",
"layer_list",
"[",... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph._insert_new_layers | Insert the new_layers after the node with start_node_id. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def _insert_new_layers(self, new_layers, start_node_id, end_node_id):
"""Insert the new_layers after the node with start_node_id."""
new_node_id = self._add_node(deepcopy(self.node_list[end_node_id]))
temp_output_id = new_node_id
for layer in new_layers[:-1]:
temp_output_id =... | def _insert_new_layers(self, new_layers, start_node_id, end_node_id):
"""Insert the new_layers after the node with start_node_id."""
new_node_id = self._add_node(deepcopy(self.node_list[end_node_id]))
temp_output_id = new_node_id
for layer in new_layers[:-1]:
temp_output_id =... | [
"Insert",
"the",
"new_layers",
"after",
"the",
"node",
"with",
"start_node_id",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L438-L448 | [
"def",
"_insert_new_layers",
"(",
"self",
",",
"new_layers",
",",
"start_node_id",
",",
"end_node_id",
")",
":",
"new_node_id",
"=",
"self",
".",
"_add_node",
"(",
"deepcopy",
"(",
"self",
".",
"node_list",
"[",
"end_node_id",
"]",
")",
")",
"temp_output_id",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph.to_add_skip_model | Add a weighted add skip-connection from after start node to end node.
Args:
start_id: The convolutional layer ID, after which to start the skip-connection.
end_id: The convolutional layer ID, after which to end the skip-connection. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def to_add_skip_model(self, start_id, end_id):
"""Add a weighted add skip-connection from after start node to end node.
Args:
start_id: The convolutional layer ID, after which to start the skip-connection.
end_id: The convolutional layer ID, after which to end the skip-connection... | def to_add_skip_model(self, start_id, end_id):
"""Add a weighted add skip-connection from after start node to end node.
Args:
start_id: The convolutional layer ID, after which to start the skip-connection.
end_id: The convolutional layer ID, after which to end the skip-connection... | [
"Add",
"a",
"weighted",
"add",
"skip",
"-",
"connection",
"from",
"after",
"start",
"node",
"to",
"end",
"node",
".",
"Args",
":",
"start_id",
":",
"The",
"convolutional",
"layer",
"ID",
"after",
"which",
"to",
"start",
"the",
"skip",
"-",
"connection",
... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L467-L508 | [
"def",
"to_add_skip_model",
"(",
"self",
",",
"start_id",
",",
"end_id",
")",
":",
"self",
".",
"operation_history",
".",
"append",
"(",
"(",
"\"to_add_skip_model\"",
",",
"start_id",
",",
"end_id",
")",
")",
"filters_end",
"=",
"self",
".",
"layer_list",
"[... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph.to_concat_skip_model | Add a weighted add concatenate connection from after start node to end node.
Args:
start_id: The convolutional layer ID, after which to start the skip-connection.
end_id: The convolutional layer ID, after which to end the skip-connection. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def to_concat_skip_model(self, start_id, end_id):
"""Add a weighted add concatenate connection from after start node to end node.
Args:
start_id: The convolutional layer ID, after which to start the skip-connection.
end_id: The convolutional layer ID, after which to end the skip-... | def to_concat_skip_model(self, start_id, end_id):
"""Add a weighted add concatenate connection from after start node to end node.
Args:
start_id: The convolutional layer ID, after which to start the skip-connection.
end_id: The convolutional layer ID, after which to end the skip-... | [
"Add",
"a",
"weighted",
"add",
"concatenate",
"connection",
"from",
"after",
"start",
"node",
"to",
"end",
"node",
".",
"Args",
":",
"start_id",
":",
"The",
"convolutional",
"layer",
"ID",
"after",
"which",
"to",
"start",
"the",
"skip",
"-",
"connection",
... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L510-L563 | [
"def",
"to_concat_skip_model",
"(",
"self",
",",
"start_id",
",",
"end_id",
")",
":",
"self",
".",
"operation_history",
".",
"append",
"(",
"(",
"\"to_concat_skip_model\"",
",",
"start_id",
",",
"end_id",
")",
")",
"filters_end",
"=",
"self",
".",
"layer_list"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph.extract_descriptor | Extract the the description of the Graph as an instance of NetworkDescriptor. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def extract_descriptor(self):
"""Extract the the description of the Graph as an instance of NetworkDescriptor."""
main_chain = self.get_main_chain()
index_in_main_chain = {}
for index, u in enumerate(main_chain):
index_in_main_chain[u] = index
ret = NetworkDescriptor... | def extract_descriptor(self):
"""Extract the the description of the Graph as an instance of NetworkDescriptor."""
main_chain = self.get_main_chain()
index_in_main_chain = {}
for index, u in enumerate(main_chain):
index_in_main_chain[u] = index
ret = NetworkDescriptor... | [
"Extract",
"the",
"the",
"description",
"of",
"the",
"Graph",
"as",
"an",
"instance",
"of",
"NetworkDescriptor",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L580-L625 | [
"def",
"extract_descriptor",
"(",
"self",
")",
":",
"main_chain",
"=",
"self",
".",
"get_main_chain",
"(",
")",
"index_in_main_chain",
"=",
"{",
"}",
"for",
"index",
",",
"u",
"in",
"enumerate",
"(",
"main_chain",
")",
":",
"index_in_main_chain",
"[",
"u",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph.clear_weights | clear weights of the graph | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def clear_weights(self):
''' clear weights of the graph
'''
self.weighted = False
for layer in self.layer_list:
layer.weights = None | def clear_weights(self):
''' clear weights of the graph
'''
self.weighted = False
for layer in self.layer_list:
layer.weights = None | [
"clear",
"weights",
"of",
"the",
"graph"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L627-L632 | [
"def",
"clear_weights",
"(",
"self",
")",
":",
"self",
".",
"weighted",
"=",
"False",
"for",
"layer",
"in",
"self",
".",
"layer_list",
":",
"layer",
".",
"weights",
"=",
"None"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph.get_main_chain_layers | Return a list of layer IDs in the main chain. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def get_main_chain_layers(self):
"""Return a list of layer IDs in the main chain."""
main_chain = self.get_main_chain()
ret = []
for u in main_chain:
for v, layer_id in self.adj_list[u]:
if v in main_chain and u in main_chain:
ret.append(la... | def get_main_chain_layers(self):
"""Return a list of layer IDs in the main chain."""
main_chain = self.get_main_chain()
ret = []
for u in main_chain:
for v, layer_id in self.adj_list[u]:
if v in main_chain and u in main_chain:
ret.append(la... | [
"Return",
"a",
"list",
"of",
"layer",
"IDs",
"in",
"the",
"main",
"chain",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L680-L688 | [
"def",
"get_main_chain_layers",
"(",
"self",
")",
":",
"main_chain",
"=",
"self",
".",
"get_main_chain",
"(",
")",
"ret",
"=",
"[",
"]",
"for",
"u",
"in",
"main_chain",
":",
"for",
"v",
",",
"layer_id",
"in",
"self",
".",
"adj_list",
"[",
"u",
"]",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | Graph.get_main_chain | Returns the main chain node ID list. | src/sdk/pynni/nni/networkmorphism_tuner/graph.py | def get_main_chain(self):
"""Returns the main chain node ID list."""
pre_node = {}
distance = {}
for i in range(self.n_nodes):
distance[i] = 0
pre_node[i] = i
for i in range(self.n_nodes - 1):
for u in range(self.n_nodes):
for v... | def get_main_chain(self):
"""Returns the main chain node ID list."""
pre_node = {}
distance = {}
for i in range(self.n_nodes):
distance[i] = 0
pre_node[i] = i
for i in range(self.n_nodes - 1):
for u in range(self.n_nodes):
for v... | [
"Returns",
"the",
"main",
"chain",
"node",
"ID",
"list",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph.py#L723-L748 | [
"def",
"get_main_chain",
"(",
"self",
")",
":",
"pre_node",
"=",
"{",
"}",
"distance",
"=",
"{",
"}",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"n_nodes",
")",
":",
"distance",
"[",
"i",
"]",
"=",
"0",
"pre_node",
"[",
"i",
"]",
"=",
"i",
"f... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MsgDispatcherBase.run | Run the tuner.
This function will never return unless raise. | src/sdk/pynni/nni/msg_dispatcher_base.py | def run(self):
"""Run the tuner.
This function will never return unless raise.
"""
_logger.info('Start dispatcher')
if dispatcher_env_vars.NNI_MODE == 'resume':
self.load_checkpoint()
while True:
command, data = receive()
if data:
... | def run(self):
"""Run the tuner.
This function will never return unless raise.
"""
_logger.info('Start dispatcher')
if dispatcher_env_vars.NNI_MODE == 'resume':
self.load_checkpoint()
while True:
command, data = receive()
if data:
... | [
"Run",
"the",
"tuner",
".",
"This",
"function",
"will",
"never",
"return",
"unless",
"raise",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/msg_dispatcher_base.py#L57-L92 | [
"def",
"run",
"(",
"self",
")",
":",
"_logger",
".",
"info",
"(",
"'Start dispatcher'",
")",
"if",
"dispatcher_env_vars",
".",
"NNI_MODE",
"==",
"'resume'",
":",
"self",
".",
"load_checkpoint",
"(",
")",
"while",
"True",
":",
"command",
",",
"data",
"=",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MsgDispatcherBase.command_queue_worker | Process commands in command queues. | src/sdk/pynni/nni/msg_dispatcher_base.py | def command_queue_worker(self, command_queue):
"""Process commands in command queues.
"""
while True:
try:
# set timeout to ensure self.stopping is checked periodically
command, data = command_queue.get(timeout=3)
try:
... | def command_queue_worker(self, command_queue):
"""Process commands in command queues.
"""
while True:
try:
# set timeout to ensure self.stopping is checked periodically
command, data = command_queue.get(timeout=3)
try:
... | [
"Process",
"commands",
"in",
"command",
"queues",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/msg_dispatcher_base.py#L94-L110 | [
"def",
"command_queue_worker",
"(",
"self",
",",
"command_queue",
")",
":",
"while",
"True",
":",
"try",
":",
"# set timeout to ensure self.stopping is checked periodically",
"command",
",",
"data",
"=",
"command_queue",
".",
"get",
"(",
"timeout",
"=",
"3",
")",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MsgDispatcherBase.enqueue_command | Enqueue command into command queues | src/sdk/pynni/nni/msg_dispatcher_base.py | def enqueue_command(self, command, data):
"""Enqueue command into command queues
"""
if command == CommandType.TrialEnd or (command == CommandType.ReportMetricData and data['type'] == 'PERIODICAL'):
self.assessor_command_queue.put((command, data))
else:
self.defau... | def enqueue_command(self, command, data):
"""Enqueue command into command queues
"""
if command == CommandType.TrialEnd or (command == CommandType.ReportMetricData and data['type'] == 'PERIODICAL'):
self.assessor_command_queue.put((command, data))
else:
self.defau... | [
"Enqueue",
"command",
"into",
"command",
"queues"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/msg_dispatcher_base.py#L112-L126 | [
"def",
"enqueue_command",
"(",
"self",
",",
"command",
",",
"data",
")",
":",
"if",
"command",
"==",
"CommandType",
".",
"TrialEnd",
"or",
"(",
"command",
"==",
"CommandType",
".",
"ReportMetricData",
"and",
"data",
"[",
"'type'",
"]",
"==",
"'PERIODICAL'",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | MsgDispatcherBase.process_command_thread | Worker thread to process a command. | src/sdk/pynni/nni/msg_dispatcher_base.py | def process_command_thread(self, request):
"""Worker thread to process a command.
"""
command, data = request
if multi_thread_enabled():
try:
self.process_command(command, data)
except Exception as e:
_logger.exception(str(e))
... | def process_command_thread(self, request):
"""Worker thread to process a command.
"""
command, data = request
if multi_thread_enabled():
try:
self.process_command(command, data)
except Exception as e:
_logger.exception(str(e))
... | [
"Worker",
"thread",
"to",
"process",
"a",
"command",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/msg_dispatcher_base.py#L128-L139 | [
"def",
"process_command_thread",
"(",
"self",
",",
"request",
")",
":",
"command",
",",
"data",
"=",
"request",
"if",
"multi_thread_enabled",
"(",
")",
":",
"try",
":",
"self",
".",
"process_command",
"(",
"command",
",",
"data",
")",
"except",
"Exception",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | match_val_type | Update values in the array, to match their corresponding type | src/sdk/pynni/nni/metis_tuner/lib_data.py | def match_val_type(vals, vals_bounds, vals_types):
'''
Update values in the array, to match their corresponding type
'''
vals_new = []
for i, _ in enumerate(vals_types):
if vals_types[i] == "discrete_int":
# Find the closest integer in the array, vals_bounds
vals_new... | def match_val_type(vals, vals_bounds, vals_types):
'''
Update values in the array, to match their corresponding type
'''
vals_new = []
for i, _ in enumerate(vals_types):
if vals_types[i] == "discrete_int":
# Find the closest integer in the array, vals_bounds
vals_new... | [
"Update",
"values",
"in",
"the",
"array",
"to",
"match",
"their",
"corresponding",
"type"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/metis_tuner/lib_data.py#L25-L44 | [
"def",
"match_val_type",
"(",
"vals",
",",
"vals_bounds",
",",
"vals_types",
")",
":",
"vals_new",
"=",
"[",
"]",
"for",
"i",
",",
"_",
"in",
"enumerate",
"(",
"vals_types",
")",
":",
"if",
"vals_types",
"[",
"i",
"]",
"==",
"\"discrete_int\"",
":",
"#... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | rand | Random generate variable value within their bounds | src/sdk/pynni/nni/metis_tuner/lib_data.py | def rand(x_bounds, x_types):
'''
Random generate variable value within their bounds
'''
outputs = []
for i, _ in enumerate(x_bounds):
if x_types[i] == "discrete_int":
temp = x_bounds[i][random.randint(0, len(x_bounds[i]) - 1)]
outputs.append(temp)
elif x_type... | def rand(x_bounds, x_types):
'''
Random generate variable value within their bounds
'''
outputs = []
for i, _ in enumerate(x_bounds):
if x_types[i] == "discrete_int":
temp = x_bounds[i][random.randint(0, len(x_bounds[i]) - 1)]
outputs.append(temp)
elif x_type... | [
"Random",
"generate",
"variable",
"value",
"within",
"their",
"bounds"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/metis_tuner/lib_data.py#L47-L66 | [
"def",
"rand",
"(",
"x_bounds",
",",
"x_types",
")",
":",
"outputs",
"=",
"[",
"]",
"for",
"i",
",",
"_",
"in",
"enumerate",
"(",
"x_bounds",
")",
":",
"if",
"x_types",
"[",
"i",
"]",
"==",
"\"discrete_int\"",
":",
"temp",
"=",
"x_bounds",
"[",
"i"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | to_wider_graph | wider graph | src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py | def to_wider_graph(graph):
''' wider graph
'''
weighted_layer_ids = graph.wide_layer_ids()
weighted_layer_ids = list(
filter(lambda x: graph.layer_list[x].output.shape[-1], weighted_layer_ids)
)
wider_layers = sample(weighted_layer_ids, 1)
for layer_id in wider_layers:
layer... | def to_wider_graph(graph):
''' wider graph
'''
weighted_layer_ids = graph.wide_layer_ids()
weighted_layer_ids = list(
filter(lambda x: graph.layer_list[x].output.shape[-1], weighted_layer_ids)
)
wider_layers = sample(weighted_layer_ids, 1)
for layer_id in wider_layers:
layer... | [
"wider",
"graph"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py#L38-L55 | [
"def",
"to_wider_graph",
"(",
"graph",
")",
":",
"weighted_layer_ids",
"=",
"graph",
".",
"wide_layer_ids",
"(",
")",
"weighted_layer_ids",
"=",
"list",
"(",
"filter",
"(",
"lambda",
"x",
":",
"graph",
".",
"layer_list",
"[",
"x",
"]",
".",
"output",
".",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | to_skip_connection_graph | skip connection graph | src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py | def to_skip_connection_graph(graph):
''' skip connection graph
'''
# The last conv layer cannot be widen since wider operator cannot be done over the two sides of flatten.
weighted_layer_ids = graph.skip_connection_layer_ids()
valid_connection = []
for skip_type in sorted([NetworkDescriptor.ADD_... | def to_skip_connection_graph(graph):
''' skip connection graph
'''
# The last conv layer cannot be widen since wider operator cannot be done over the two sides of flatten.
weighted_layer_ids = graph.skip_connection_layer_ids()
valid_connection = []
for skip_type in sorted([NetworkDescriptor.ADD_... | [
"skip",
"connection",
"graph"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py#L58-L78 | [
"def",
"to_skip_connection_graph",
"(",
"graph",
")",
":",
"# The last conv layer cannot be widen since wider operator cannot be done over the two sides of flatten.",
"weighted_layer_ids",
"=",
"graph",
".",
"skip_connection_layer_ids",
"(",
")",
"valid_connection",
"=",
"[",
"]",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | create_new_layer | create new layer for the graph | src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py | def create_new_layer(layer, n_dim):
''' create new layer for the graph
'''
input_shape = layer.output.shape
dense_deeper_classes = [StubDense, get_dropout_class(n_dim), StubReLU]
conv_deeper_classes = [get_conv_class(n_dim), get_batch_norm_class(n_dim), StubReLU]
if is_layer(layer, "ReLU"):
... | def create_new_layer(layer, n_dim):
''' create new layer for the graph
'''
input_shape = layer.output.shape
dense_deeper_classes = [StubDense, get_dropout_class(n_dim), StubReLU]
conv_deeper_classes = [get_conv_class(n_dim), get_batch_norm_class(n_dim), StubReLU]
if is_layer(layer, "ReLU"):
... | [
"create",
"new",
"layer",
"for",
"the",
"graph"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py#L81-L124 | [
"def",
"create_new_layer",
"(",
"layer",
",",
"n_dim",
")",
":",
"input_shape",
"=",
"layer",
".",
"output",
".",
"shape",
"dense_deeper_classes",
"=",
"[",
"StubDense",
",",
"get_dropout_class",
"(",
"n_dim",
")",
",",
"StubReLU",
"]",
"conv_deeper_classes",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | to_deeper_graph | deeper graph | src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py | def to_deeper_graph(graph):
''' deeper graph
'''
weighted_layer_ids = graph.deep_layer_ids()
if len(weighted_layer_ids) >= Constant.MAX_LAYERS:
return None
deeper_layer_ids = sample(weighted_layer_ids, 1)
for layer_id in deeper_layer_ids:
layer = graph.layer_list[layer_id]
... | def to_deeper_graph(graph):
''' deeper graph
'''
weighted_layer_ids = graph.deep_layer_ids()
if len(weighted_layer_ids) >= Constant.MAX_LAYERS:
return None
deeper_layer_ids = sample(weighted_layer_ids, 1)
for layer_id in deeper_layer_ids:
layer = graph.layer_list[layer_id]
... | [
"deeper",
"graph"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py#L127-L141 | [
"def",
"to_deeper_graph",
"(",
"graph",
")",
":",
"weighted_layer_ids",
"=",
"graph",
".",
"deep_layer_ids",
"(",
")",
"if",
"len",
"(",
"weighted_layer_ids",
")",
">=",
"Constant",
".",
"MAX_LAYERS",
":",
"return",
"None",
"deeper_layer_ids",
"=",
"sample",
"... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | legal_graph | judge if a graph is legal or not. | src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py | def legal_graph(graph):
'''judge if a graph is legal or not.
'''
descriptor = graph.extract_descriptor()
skips = descriptor.skip_connections
if len(skips) != len(set(skips)):
return False
return True | def legal_graph(graph):
'''judge if a graph is legal or not.
'''
descriptor = graph.extract_descriptor()
skips = descriptor.skip_connections
if len(skips) != len(set(skips)):
return False
return True | [
"judge",
"if",
"a",
"graph",
"is",
"legal",
"or",
"not",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py#L144-L152 | [
"def",
"legal_graph",
"(",
"graph",
")",
":",
"descriptor",
"=",
"graph",
".",
"extract_descriptor",
"(",
")",
"skips",
"=",
"descriptor",
".",
"skip_connections",
"if",
"len",
"(",
"skips",
")",
"!=",
"len",
"(",
"set",
"(",
"skips",
")",
")",
":",
"r... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | transform | core transform function for graph. | src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py | def transform(graph):
'''core transform function for graph.
'''
graphs = []
for _ in range(Constant.N_NEIGHBOURS * 2):
random_num = randrange(3)
temp_graph = None
if random_num == 0:
temp_graph = to_deeper_graph(deepcopy(graph))
elif random_num == 1:
... | def transform(graph):
'''core transform function for graph.
'''
graphs = []
for _ in range(Constant.N_NEIGHBOURS * 2):
random_num = randrange(3)
temp_graph = None
if random_num == 0:
temp_graph = to_deeper_graph(deepcopy(graph))
elif random_num == 1:
... | [
"core",
"transform",
"function",
"for",
"graph",
"."
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/networkmorphism_tuner/graph_transformer.py#L155-L176 | [
"def",
"transform",
"(",
"graph",
")",
":",
"graphs",
"=",
"[",
"]",
"for",
"_",
"in",
"range",
"(",
"Constant",
".",
"N_NEIGHBOURS",
"*",
"2",
")",
":",
"random_num",
"=",
"randrange",
"(",
"3",
")",
"temp_graph",
"=",
"None",
"if",
"random_num",
"=... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | uniform | low: an float that represent an lower bound
high: an float that represent an upper bound
random_state: an object of numpy.random.RandomState | src/sdk/pynni/nni/parameter_expressions.py | def uniform(low, high, random_state):
'''
low: an float that represent an lower bound
high: an float that represent an upper bound
random_state: an object of numpy.random.RandomState
'''
assert high > low, 'Upper bound must be larger than lower bound'
return random_state.uniform(low, high) | def uniform(low, high, random_state):
'''
low: an float that represent an lower bound
high: an float that represent an upper bound
random_state: an object of numpy.random.RandomState
'''
assert high > low, 'Upper bound must be larger than lower bound'
return random_state.uniform(low, high) | [
"low",
":",
"an",
"float",
"that",
"represent",
"an",
"lower",
"bound",
"high",
":",
"an",
"float",
"that",
"represent",
"an",
"upper",
"bound",
"random_state",
":",
"an",
"object",
"of",
"numpy",
".",
"random",
".",
"RandomState"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/parameter_expressions.py#L43-L50 | [
"def",
"uniform",
"(",
"low",
",",
"high",
",",
"random_state",
")",
":",
"assert",
"high",
">",
"low",
",",
"'Upper bound must be larger than lower bound'",
"return",
"random_state",
".",
"uniform",
"(",
"low",
",",
"high",
")"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | quniform | low: an float that represent an lower bound
high: an float that represent an upper bound
q: sample step
random_state: an object of numpy.random.RandomState | src/sdk/pynni/nni/parameter_expressions.py | def quniform(low, high, q, random_state):
'''
low: an float that represent an lower bound
high: an float that represent an upper bound
q: sample step
random_state: an object of numpy.random.RandomState
'''
return np.round(uniform(low, high, random_state) / q) * q | def quniform(low, high, q, random_state):
'''
low: an float that represent an lower bound
high: an float that represent an upper bound
q: sample step
random_state: an object of numpy.random.RandomState
'''
return np.round(uniform(low, high, random_state) / q) * q | [
"low",
":",
"an",
"float",
"that",
"represent",
"an",
"lower",
"bound",
"high",
":",
"an",
"float",
"that",
"represent",
"an",
"upper",
"bound",
"q",
":",
"sample",
"step",
"random_state",
":",
"an",
"object",
"of",
"numpy",
".",
"random",
".",
"RandomSt... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/parameter_expressions.py#L53-L60 | [
"def",
"quniform",
"(",
"low",
",",
"high",
",",
"q",
",",
"random_state",
")",
":",
"return",
"np",
".",
"round",
"(",
"uniform",
"(",
"low",
",",
"high",
",",
"random_state",
")",
"/",
"q",
")",
"*",
"q"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | loguniform | low: an float that represent an lower bound
high: an float that represent an upper bound
random_state: an object of numpy.random.RandomState | src/sdk/pynni/nni/parameter_expressions.py | def loguniform(low, high, random_state):
'''
low: an float that represent an lower bound
high: an float that represent an upper bound
random_state: an object of numpy.random.RandomState
'''
assert low > 0, 'Lower bound must be positive'
return np.exp(uniform(np.log(low), np.log(high), random... | def loguniform(low, high, random_state):
'''
low: an float that represent an lower bound
high: an float that represent an upper bound
random_state: an object of numpy.random.RandomState
'''
assert low > 0, 'Lower bound must be positive'
return np.exp(uniform(np.log(low), np.log(high), random... | [
"low",
":",
"an",
"float",
"that",
"represent",
"an",
"lower",
"bound",
"high",
":",
"an",
"float",
"that",
"represent",
"an",
"upper",
"bound",
"random_state",
":",
"an",
"object",
"of",
"numpy",
".",
"random",
".",
"RandomState"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/parameter_expressions.py#L63-L70 | [
"def",
"loguniform",
"(",
"low",
",",
"high",
",",
"random_state",
")",
":",
"assert",
"low",
">",
"0",
",",
"'Lower bound must be positive'",
"return",
"np",
".",
"exp",
"(",
"uniform",
"(",
"np",
".",
"log",
"(",
"low",
")",
",",
"np",
".",
"log",
... | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | qloguniform | low: an float that represent an lower bound
high: an float that represent an upper bound
q: sample step
random_state: an object of numpy.random.RandomState | src/sdk/pynni/nni/parameter_expressions.py | def qloguniform(low, high, q, random_state):
'''
low: an float that represent an lower bound
high: an float that represent an upper bound
q: sample step
random_state: an object of numpy.random.RandomState
'''
return np.round(loguniform(low, high, random_state) / q) * q | def qloguniform(low, high, q, random_state):
'''
low: an float that represent an lower bound
high: an float that represent an upper bound
q: sample step
random_state: an object of numpy.random.RandomState
'''
return np.round(loguniform(low, high, random_state) / q) * q | [
"low",
":",
"an",
"float",
"that",
"represent",
"an",
"lower",
"bound",
"high",
":",
"an",
"float",
"that",
"represent",
"an",
"upper",
"bound",
"q",
":",
"sample",
"step",
"random_state",
":",
"an",
"object",
"of",
"numpy",
".",
"random",
".",
"RandomSt... | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/parameter_expressions.py#L73-L80 | [
"def",
"qloguniform",
"(",
"low",
",",
"high",
",",
"q",
",",
"random_state",
")",
":",
"return",
"np",
".",
"round",
"(",
"loguniform",
"(",
"low",
",",
"high",
",",
"random_state",
")",
"/",
"q",
")",
"*",
"q"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
train | qnormal | mu: float or array_like of floats
sigma: float or array_like of floats
q: sample step
random_state: an object of numpy.random.RandomState | src/sdk/pynni/nni/parameter_expressions.py | def qnormal(mu, sigma, q, random_state):
'''
mu: float or array_like of floats
sigma: float or array_like of floats
q: sample step
random_state: an object of numpy.random.RandomState
'''
return np.round(normal(mu, sigma, random_state) / q) * q | def qnormal(mu, sigma, q, random_state):
'''
mu: float or array_like of floats
sigma: float or array_like of floats
q: sample step
random_state: an object of numpy.random.RandomState
'''
return np.round(normal(mu, sigma, random_state) / q) * q | [
"mu",
":",
"float",
"or",
"array_like",
"of",
"floats",
"sigma",
":",
"float",
"or",
"array_like",
"of",
"floats",
"q",
":",
"sample",
"step",
"random_state",
":",
"an",
"object",
"of",
"numpy",
".",
"random",
".",
"RandomState"
] | Microsoft/nni | python | https://github.com/Microsoft/nni/blob/c7cc8db32da8d2ec77a382a55089f4e17247ce41/src/sdk/pynni/nni/parameter_expressions.py#L96-L103 | [
"def",
"qnormal",
"(",
"mu",
",",
"sigma",
",",
"q",
",",
"random_state",
")",
":",
"return",
"np",
".",
"round",
"(",
"normal",
"(",
"mu",
",",
"sigma",
",",
"random_state",
")",
"/",
"q",
")",
"*",
"q"
] | c7cc8db32da8d2ec77a382a55089f4e17247ce41 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.