Monitor Optuna hyperparameter optimization in Neptune

Optuna Neptune integration

Prerequisites

Integration with Optuna framework is introduced as a part of logging module so just need to have neptune-client and neptune-contrib installed.

pip install neptune-client neptune-contrib['monitoring']

Initialize Neptune and create an experiment

import neptune
neptune.init('jakub-czakon/blog-hpo')
neptune.create_experiment(name='optuna sweep')

Create NeptuneMonitor callback

Pass the experiment object as first argument.

Note

To be able to log information after the .fit() method finishes remember to pass close_after_train=False

import neptunecontrib.monitoring.optuna as opt_utils
neptune_monitor = opt_utils.NeptuneMonitor()

Pass neptune_monitor to study.optimize

It will monitor the metrics and parameters checked at each run.

study = optuna.create_study(direction='maximize')
study.optimize(objective, n_trials=100, callbacks=[monitor])

Log all results

It will log the following things to Neptune: * best score * best parameters * plot_convergence figure * plot_evaluations figure * plot_objective figure

opt_utils.log_study(study)

Monitor your Optuna training in Neptune

Now you can watch your Optuna hyperparameter optimization in Neptune!

Check out this example experiment.

Optuna monitoring in Neptune