Bring Your Own Optimizer
At SigOpt, we have invested thousands of hours in developing a powerful optimization engine to efficiently conduct the hyperparameter search process. We understand, however, that some users prefer to bring their own strategies to the model development process — SigOpt fully supports this. In this page, and in the notebook linked below, we explain how you can use your own optimization tool and store the progress in SigOpt to inspect and visualize on our web dashboard.

Show me the code

View sample Bring Your Own Optimizer implementations in a notebook
See this notebook for a complete demonstration for Manual Search, Grid Search, Random Search, Optuna and Hyperopt. For more notebook instructions and tutorials, check out our GitHub notebook tutorials repo.
The content below on this page previews the visualizations generated by that notebook, as well as brief code snippets.

Goal: Visualize and store results from different optimization approaches

You will see how to track each iteration of multiple optimization loops - each using a different optimization approach - as a SigOpt run, and group all of the runs into a SigOpt project. You can then visualize the results of all the runs in the project together without writing any plotting code. Note that if you have custom plots in your code you can attach these to runs and store them on the SigOpt platform with any other metadata you decide is relevant to track as a run artifact - for more detail please see the runs API reference.

Logging run artifacts with SigOpt

In the notebook linked above you will find a class structured like the following pseudocode to instantiate data objects to manage training runs across optimization approaches. These training runs will be created during each iteration of the various optimization loops executed for each global optimization strategy we invoke. Please see here to learn more about experiment management in SigOpt:
1
class Run(object):
2
def __init__(self, run_type):
3
...
4
self.run_type = run_type
5
6
def execute(self, args):
7
with sigopt.create_run(name=self.run_type) as run:
8
# get data
9
...
10
# register hyperparameter values with sigopt
11
...
12
# log metadata about source of hyperparameter suggestion
13
...
14
# instantiate, train, and evaluate model
15
...
16
# log metric results to sigopt run
17
...
Copied!
Random search
Grid search
Hyperopt
Optuna
To create a customized random process for generating parameter configurations, SigOpt allows assigning user-generated values (randomly generated in this case) for each parameter. Using the API in this way allows you to run your random process for as many iterations as you wish during an Experiment, and then to continue the Experiment with other optimization approaches.
1
for _ in range(BUDGET):
2
args = dict()
3
args["parameter_0"] = numpy.random.randint(low=32, high=512)
4
args["parameter_1"] = "class-0" if numpy.random.random() >= 0.75 else "class-1"
5
random_run = Run(run_type="random search")
6
random_run.execute(args)
Copied!
Another common approach to optimizing hyperparameters is to specify a grid of values, evaluate the learning algorithm with those parameters, and then observe results across the grid you defined.
1
for p0 in p0_grid_values:
2
for p1 in p1_grid_values:
3
args = dict(p0=p0, p1=p1)
4
grid_run = Run(run_type="grid search")
5
grid_run.execute(args)
Copied!
Hyperopt was introduced by Bergstra et al. in 2013. Below you see how to use Hyperopt as an optimizer while leveraging the logging and visualization functionality of SigOpt.
1
def hyperopt_objective_function(args):
2
hyperopt_run = Run(run_type="hyperopt search")
3
metric_value = hyperopt_run.execute(args)
4
return metric_value
5
6
7
hyperopt_space = {...}
8
9
result = hyperopt.fmin(
10
fn=hyperopt_objective_function, space=hyperopt_space, algo=ALGORITHM, max_evals=BUDGET, show_progressbar=False
11
)
Copied!
Optuna was introduced in 2019 by Takuya et al. at Preferred Networks. Using a code like the one below you can use Optuna as an optimizer while leveraging the logging and visualization functionality of SigOpt.
1
def optuna_objective_function(trial):
2
args = dict(
3
hidden_layer_size=trial.suggest_int("hidden_layer_size", 32, 512, 1),
4
activation_function=trial.suggest_categorical("activation_function", ["tanh", "relu"]),
5
)
6
optuna_run = Run(number_of_epochs=NUMBER_OF_EPOCHS, run_type="optuna search")
7
metric_value = optuna_run.execute(args)
8
return metric_value
9
10
11
study = optuna.create_study(direction="maximize")
12
study.optimize(optuna_objective_function, n_trials=BUDGET, show_progress_bar=False)
Copied!