This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update readme in ga_squad * update readme * fix typo * Update README.md * Update README.md * Update README.md * update readme * update * fix path * update reference * fix bug in config file * update nni_arch_overview.png * update * update * update * add metis tuner code * 1. fix bug about import 2.update other sdk file * add auto-gbdt-example and remove unused code * add metis_tuner into README * update the README * update README | remove unused variable * fix typo * add sklearn into requirments * Update src/sdk/pynni/nni/metis_tuner/metis_tuner.py add default value in __init__ Co-Authored-By: xuehui1991 <[email protected]> * Update docs/HowToChooseTuner.md Co-Authored-By: xuehui1991 <[email protected]> * Update docs/HowToChooseTuner.md Co-Authored-By: xuehui1991 <[email protected]> * fix typo | add more comments
- Loading branch information
1 parent
573f23c
commit 816dd60
Showing
21 changed files
with
1,377 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
authorName: default | ||
experimentName: example_auto-gbdt-metis | ||
trialConcurrency: 1 | ||
maxExecDuration: 10h | ||
maxTrialNum: 10 | ||
#choice: local, remote, pai | ||
trainingServicePlatform: local | ||
searchSpacePath: search_space_metis.json | ||
#choice: true, false | ||
useAnnotation: false | ||
tuner: | ||
#choice: TPE, Random, Anneal, Evolution, BatchTuner | ||
#SMAC (SMAC should be installed through nnictl) | ||
builtinTunerName: MetisTuner | ||
classArgs: | ||
#choice: maximize, minimize | ||
optimize_mode: minimize | ||
trial: | ||
command: python3 main.py | ||
codeDir: . | ||
gpuNum: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pip install lightgbm | ||
lightgbm | ||
pandas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"num_leaves":{"_type":"choice","_value":[31, 28, 24, 20]}, | ||
"learning_rate":{"_type":"choice","_value":[0.01, 0.05, 0.1, 0.2]}, | ||
"bagging_freq":{"_type":"choice","_value":[1, 2, 4, 8, 10]} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/sdk/pynni/nni/metis_tuner/Regression_GMM/CreateModel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright (c) Microsoft Corporation | ||
# All rights reserved. | ||
# | ||
# MIT License | ||
# | ||
# Permission is hereby granted, free of charge, | ||
# to any person obtaining a copy of this software and associated | ||
# documentation files (the "Software"), to deal in the Software without restriction, | ||
# including without limitation the rights to use, copy, modify, merge, publish, | ||
# distribute, sublicense, and/or sell copies of the Software, and | ||
# to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
import os | ||
import sys | ||
from operator import itemgetter | ||
|
||
import sklearn.mixture as mm | ||
|
||
sys.path.insert(1, os.path.join(sys.path[0], '..')) | ||
|
||
|
||
def create_model(samples_x, samples_y_aggregation, percentage_goodbatch=0.34): | ||
''' | ||
Create the Gaussian Mixture Model | ||
''' | ||
samples = [samples_x[i] + [samples_y_aggregation[i]] for i in range(0, len(samples_x))] | ||
|
||
# Sorts so that we can get the top samples | ||
samples = sorted(samples, key=itemgetter(-1)) | ||
samples_goodbatch_size = int(len(samples) * percentage_goodbatch) | ||
samples_goodbatch = samples[0:samples_goodbatch_size] | ||
samples_badbatch = samples[samples_goodbatch_size:] | ||
|
||
samples_x_goodbatch = [sample_goodbatch[0:-1] for sample_goodbatch in samples_goodbatch] | ||
#samples_y_goodbatch = [sample_goodbatch[-1] for sample_goodbatch in samples_goodbatch] | ||
samples_x_badbatch = [sample_badbatch[0:-1] for sample_badbatch in samples_badbatch] | ||
|
||
# === Trains GMM clustering models === # | ||
#sys.stderr.write("[%s] Train GMM's GMM model\n" % (os.path.basename(__file__))) | ||
bgmm_goodbatch = mm.BayesianGaussianMixture(n_components=max(1, samples_goodbatch_size - 1)) | ||
bad_n_components = max(1, len(samples_x) - samples_goodbatch_size - 1) | ||
bgmm_badbatch = mm.BayesianGaussianMixture(n_components=bad_n_components) | ||
bgmm_goodbatch.fit(samples_x_goodbatch) | ||
bgmm_badbatch.fit(samples_x_badbatch) | ||
|
||
model = {} | ||
model['clusteringmodel_good'] = bgmm_goodbatch | ||
model['clusteringmodel_bad'] = bgmm_badbatch | ||
return model | ||
|
104 changes: 104 additions & 0 deletions
104
src/sdk/pynni/nni/metis_tuner/Regression_GMM/Selection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Copyright (c) Microsoft Corporation | ||
# All rights reserved. | ||
# | ||
# MIT License | ||
# | ||
# Permission is hereby granted, free of charge, | ||
# to any person obtaining a copy of this software and associated | ||
# documentation files (the "Software"), to deal in the Software without restriction, | ||
# including without limitation the rights to use, copy, modify, merge, publish, | ||
# distribute, sublicense, and/or sell copies of the Software, and | ||
# to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
import os | ||
import random | ||
import sys | ||
|
||
import nni.metis_tuner.lib_acquisition_function as lib_acquisition_function | ||
import nni.metis_tuner.lib_constraint_summation as lib_constraint_summation | ||
import nni.metis_tuner.lib_data as lib_data | ||
|
||
sys.path.insert(1, os.path.join(sys.path[0], '..')) | ||
|
||
|
||
CONSTRAINT_LOWERBOUND = None | ||
CONSTRAINT_UPPERBOUND = None | ||
CONSTRAINT_PARAMS_IDX = [] | ||
|
||
|
||
def _ratio_scores(parameters_value, clusteringmodel_gmm_good, clusteringmodel_gmm_bad): | ||
''' | ||
The ratio is smaller the better | ||
''' | ||
ratio = clusteringmodel_gmm_good.score([parameters_value]) / clusteringmodel_gmm_bad.score([parameters_value]) | ||
sigma = 0 | ||
return ratio, sigma | ||
|
||
def selection_r(x_bounds, | ||
x_types, | ||
clusteringmodel_gmm_good, | ||
clusteringmodel_gmm_bad, | ||
num_starting_points=100, | ||
minimize_constraints_fun=None): | ||
''' | ||
Call selection | ||
''' | ||
minimize_starting_points = [lib_data.rand(x_bounds, x_types)\ | ||
for i in range(0, num_starting_points)] | ||
outputs = selection(x_bounds, x_types, | ||
clusteringmodel_gmm_good, | ||
clusteringmodel_gmm_bad, | ||
minimize_starting_points, | ||
minimize_constraints_fun) | ||
return outputs | ||
|
||
def selection(x_bounds, | ||
x_types, | ||
clusteringmodel_gmm_good, | ||
clusteringmodel_gmm_bad, | ||
minimize_starting_points, | ||
minimize_constraints_fun=None): | ||
''' | ||
Select the lowest mu value | ||
''' | ||
results = lib_acquisition_function.next_hyperparameter_lowest_mu(\ | ||
_ratio_scores, [clusteringmodel_gmm_good, clusteringmodel_gmm_bad],\ | ||
x_bounds, x_types, minimize_starting_points, \ | ||
minimize_constraints_fun=minimize_constraints_fun) | ||
|
||
return results | ||
|
||
def _rand_with_constraints(x_bounds, x_types): | ||
''' | ||
Random generate the variable with constraints | ||
''' | ||
outputs = None | ||
x_bounds_withconstraints = [x_bounds[i] for i in CONSTRAINT_PARAMS_IDX] | ||
x_types_withconstraints = [x_types[i] for i in CONSTRAINT_PARAMS_IDX] | ||
x_val_withconstraints = lib_constraint_summation.rand(x_bounds_withconstraints, | ||
x_types_withconstraints, | ||
CONSTRAINT_LOWERBOUND, | ||
CONSTRAINT_UPPERBOUND) | ||
if x_val_withconstraints is not None: | ||
outputs = [None] * len(x_bounds) | ||
for i, _ in enumerate(CONSTRAINT_PARAMS_IDX): | ||
outputs[CONSTRAINT_PARAMS_IDX[i]] = x_val_withconstraints[i] | ||
for i, _ in enumerate(outputs): | ||
if outputs[i] is None: | ||
outputs[i] = random.randint(x_bounds[i][0], x_bounds[i][1]) | ||
return outputs | ||
|
||
def _minimize_constraints_fun_summation(x): | ||
''' | ||
Minimize constraints fun summation | ||
''' | ||
summation = sum([x[i] for i in CONSTRAINT_PARAMS_IDX]) | ||
return CONSTRAINT_UPPERBOUND >= summation >= CONSTRAINT_LOWERBOUND |
Empty file.
52 changes: 52 additions & 0 deletions
52
src/sdk/pynni/nni/metis_tuner/Regression_GP/CreateModel.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Copyright (c) Microsoft Corporation | ||
# All rights reserved. | ||
# | ||
# MIT License | ||
# | ||
# Permission is hereby granted, free of charge, | ||
# to any person obtaining a copy of this software and associated | ||
# documentation files (the "Software"), to deal in the Software without restriction, | ||
# including without limitation the rights to use, copy, modify, merge, publish, | ||
# distribute, sublicense, and/or sell copies of the Software, and | ||
# to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | ||
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
import os | ||
import sys | ||
import numpy | ||
|
||
import sklearn.gaussian_process as gp | ||
|
||
sys.path.insert(1, os.path.join(sys.path[0], '..')) | ||
|
||
|
||
def create_model(samples_x, samples_y_aggregation, | ||
n_restarts_optimizer=250, is_white_kernel=False): | ||
''' | ||
Trains GP regression model | ||
''' | ||
kernel = gp.kernels.ConstantKernel(constant_value=1, | ||
constant_value_bounds=(1e-12, 1e12)) * \ | ||
gp.kernels.Matern(nu=1.5) | ||
if is_white_kernel is True: | ||
kernel += gp.kernels.WhiteKernel(noise_level=1, noise_level_bounds=(1e-12, 1e12)) | ||
regressor = gp.GaussianProcessRegressor(kernel=kernel, | ||
n_restarts_optimizer=n_restarts_optimizer, | ||
normalize_y=True, | ||
alpha=0) | ||
regressor.fit(numpy.array(samples_x), numpy.array(samples_y_aggregation)) | ||
|
||
model = {} | ||
model['model'] = regressor | ||
model['kernel_prior'] = str(kernel) | ||
model['kernel_posterior'] = str(regressor.kernel_) | ||
model['model_loglikelihood'] = regressor.log_marginal_likelihood(regressor.kernel_.theta) | ||
|
||
return model |
Oops, something went wrong.