-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample_optuna.yaml
63 lines (50 loc) · 2.21 KB
/
example_optuna.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# @package _global_
# example hyperparameter optimization of some experiment with Optuna:
# python train.py -m hparams_search=mnist_optuna experiment=example
defaults:
- override /hydra/sweeper: optuna
- override /model: arima
# choose metric which will be optimized by Optuna
# metrics have the naming pattern {data split}_{metric name} where metric name is the name of the function or class implementing the metric.
# make sure this is the correct name of some metric defined in:
# Torch models: model.loss_fn or model.torch_metrics
# Non-torch models: eval.kwargs.metric
optimized_metric: "val_mse"
# Sets callbacks to monitor same metric as hyperparameter optimization and same higher/lower is better.
callbacks:
early_stopping:
monitor: ${optimized_metric}
patience: 2
mode: ${eval:'"${hydra:sweeper.direction}"[:3]'}
model_checkpoint:
monitor: ${optimized_metric}
mode: ${eval:'"${hydra:sweeper.direction}"[:3]'}
# here we define Optuna hyperparameter search
# it optimizes for value returned from function with @hydra.main decorator
# docs: https://hydra.cc/docs/next/plugins/optuna_sweeper
hydra:
mode: "MULTIRUN" # set hydra to multirun by default if this config is attached
sweeper:
_target_: hydra_plugins.hydra_optuna_sweeper.optuna_sweeper.OptunaSweeper
# storage URL to persist optimization results
# for example, you can use SQLite if you set 'sqlite:///example.db'
storage: "sqlite:///${paths.log_dir}optuna/hyperopt.db"
# name of the study to persist optimization results
study_name: "arima_example"
# number of parallel workers
n_jobs: 5
# 'minimize' or 'maximize' the objective
direction: "minimize"
# total number of runs that will be executed
n_trials: 20
# choose Optuna hyperparameter sampler
# you can choose bayesian sampler (tpe), random search (without optimization), grid sampler, and others
# docs: https://optuna.readthedocs.io/en/stable/reference/samplers.html
sampler:
_target_: optuna.samplers.TPESampler
seed: 1234
n_startup_trials: 5 # number of random sampling runs before optimization starts
# define hyperparameter search space
params:
model.p: range(2, 12)
model.d: range(0, 1)