# Optuna: A Next-generation Hyperparameter Optimization Framework

Optuna lets the objective function define its own search space during each run

Takuya Akiba, Shotaro Sano, Toshihiko Yanase, Takeru Ohta, Masanori Koyama · arXiv · 2019-7-25

- **Problem** Most hyperparameter frameworks require the full parameter space to be written down before search starts. That breaks down for studies covering many model types with conditional parameters.
- **Method** Optuna is a define-by-run framework where the objective builds its search space as it runs. Instead of a fixed space, each suggest call draws values from the history of earlier trials.
- **Results** Optuna with pruning explored 1278.6 trials per study on average, compared to 35.8 trials without pruning.

## Why declared search spaces get stuck

Hyperparameter tuning is costly, and frameworks such as Hyperopt, Spearmint, SMAC, Autotune and Vizier were built to make it cheaper. Most of them ask the user to write the whole parameter space down before the search starts. That works for one fixed model, but it breaks down when a study covers many model types, each with its own parameters and conditional choices.

When the space is described poorly, even a strong sampling algorithm can't deliver much.

A second weakness is pruning, which means stopping trials early when their intermediate values look unpromising. Many frameworks lack an efficient pruning strategy, even though both the search strategy and the performance estimation strategy matter under limited resources. So the authors set three design criteria: define-by-run construction, efficient sampling and pruning, and an architecture that is easy to set up and scales.

## Building the search space at run time

The core move is to let the objective function declare its own search space as it runs. Optuna calls one evaluation of the objective a trial and the whole optimization a study. Inside the objective, each call to a suggest method draws a value for the current trial from the history of earlier trials. The objective receives a trial object instead of fixed hyperparameter values.

In the MNIST example, an integer n\_layers is drawn between 1 and 4 first. A plain Python loop then draws one unit count, between 1 and 128, for each layer. Because the loop runs n\_layers times, the number of hyperparameters depends on what was sampled, and ordinary Python loops and conditionals are enough to express it.

Hyperopt can express the same model, but the nested choices must be written out as a full parameter list before exploration begins. The authors describe that Hyperopt version as considerably longer and harder to read, and they note that it isn't obvious it matches the Optuna code. Hyperopt belongs to the define-and-run style, where the search space is declared first and explored afterwards.

Because each part of the objective is built by its own method, parts of the search can be swapped in and out independently. For example, Figure 4 draws the layer structure in create\_model and the learning rate and weight decay in create\_optimizer, and the two methods don't depend on each other. To deploy a chosen configuration, a FixedTrial object suggests only the stored values, so the same objective runs without the sampler.

## Sampling in a space that changes during the run

Samplers fall into two types: relational sampling, which uses correlations among parameters, and independent sampling, which draws each parameter alone. Independent sampling is not automatically weak, since TPE performs well without modeling correlations. Optuna supports both, including TPE for independent sampling and CMA-ES for relational sampling.

Relational sampling is harder in a define-by-run setting, because the program doesn't reveal the relations from the start. So Optuna first samples independently, then infers which parameters are concurrent from the trial results. Once the relations are inferred, it can hand the space to a user-selected relational sampler such as CMA-ES or GP-BO.

The inference needs some independent trials first, and the paper doesn't say how many are required.

Users can also replace the built-in procedure with their own sampling code.

## How pruning stops trials early

A trial calls report with an intermediate value at each step, and should\_prune then decides whether the trial stops. The pruner works from the history of values reported by other trials at that step. Optuna's pruner is a variant of Asynchronous Successive Halving, or ASHA.

Successive Halving promotes the best trials through rungs and discards the rest, and ASHA lets each worker make that decision without waiting for the others. Because no worker waits, parallel workers can keep processing trials without delay.

The rung of a trial is the number of times it has survived pruning, computed from its step, a minimum resource r, a reduction factor eta and a minimum early-stopping rate s. The rung is computed as \\\[ rung \\leftarrow \\max(0, \\log\_\\eta(\\lfloor step/r \\rfloor) - s) \\\] A trial stays in the race only if its provisional value is in the top group of size about the number of trials divided by eta, and the best single trial is kept when that group is empty.

The implementation doesn't allow repechage, so a stopped trial can't come back, which avoids storing large numbers of checkpoints.

## Storage and distributed workers

All trial objects read and write a shared storage, so each worker sees the progress of the study. If no storage is specified, Optuna uses an in-memory store, which suits a single notebook session. For distributed runs, the user points the study at a relational database, and SQLite also works.

Running the same script several times with one study identifier and one storage URL is enough to add workers. Results can also be exported to pandas for analysis, and a web dashboard shows the study in real time. Because the storage is pluggable, the same objective moves from a notebook to a container setup such as Kubernetes without code changes.

## Sampler comparison on black-box tests

The authors ran 56 black-box test cases and repeated each study 30 times per algorithm. They compared TPE+CMA-ES against random search, Hyperopt, SMAC3 and GPyOpt, using the best-attained objective value within 80 trials. TPE+CMA-ES used TPE for the first 40 steps and CMA-ES afterwards, and a paired Mann-Whitney U test with alpha of 0.0005 judged each comparison.

TPE+CMA-ES was statistically worse than random search in 1 of 56 cases, than Hyperopt in 1 of 56, and than SMAC3 in 3 of 56. GPyOpt was better than TPE+CMA-ES in 34 of 56 cases, so on final value alone the mix didn't win on this suite.

Per trial, TPE+CMA-ES took about an order of magnitude less time than GPyOpt, and GPyOpt needed about twenty times longer to finish one study. The authors therefore call the mix a cost-effective choice, and they suggest a Gaussian process method if evaluation time is the bottleneck.

## Pruning on simplified AlexNet for SVHN

The test tuned a simplified AlexNet with 8 hyperparameters on the SVHN dataset. Each study ran for 4 hours on one NVIDIA Tesla P100 card and was repeated 40 times.

With pruning, TPE explored 1278.6 trials per study on average, of which 1271.5 were pruned, compared to 35.8 trials without pruning. Random search with pruning explored 1119.3 trials, with 1111.3 pruned, compared to 36.0 without pruning.

So pruning, rather than the sampler, is what changes the trial count within the time limit. The average test error curves show faster progress with pruning for both TPE and random search. ASHA pruning also reached lower average test errors than Median pruning, the method featured in Vizier. The authors conclude that a good sampler alone isn't enough, because the cost of each trial is the bottleneck.

## Scaling TPE with more workers

The authors ran TPE with 1, 2, 4 and 8 workers on the same setup as the pruning experiment. The convergence speed rose as the number of workers grew.

TPE is sequential by design, so more workers don't obviously help, and the authors therefore plotted score against the number of trials. Score per trial barely changed with the number of workers, so the authors read the gain as scaling with the number of trials, and so with workers. The same pattern held when pruning was used.

## Applications beyond benchmarks

Optuna has been in production use at Preferred Networks for more than a year. Optuna was a key part of the Faster-RCNN models, PFDet, that placed 2nd in the Open Images Object Detection Track 2018.

The default setting took 372 seconds for the store, search and delete operations, and the best Optuna setting took 30 seconds. Within the same 4 hours, the pruned search explored 937 parameter sets, compared to 39 without pruning. With the time-out disabled, the unpruned search explored only 2 trials.

For FFmpeg encoding, Optuna searched for the parameter set that minimized reconstruction error on Big Buck Bunny. Its best result was on par with the second-best preset supplied by the developers.

## Limits of the evidence

Pruning and worker scaling were measured only on simplified AlexNet for SVHN, on one P100 card. Scaling was tested only at 1, 2, 4 and 8 workers.

The sampler comparison covers one collection of 56 test cases with 80 trials per study. The RocksDB gain was measured under one time-out setting and one file workload.

The number of independent trials needed before relational sampling can start is not quantified. The authors plan an interface for deploying external optimization software, but they haven't built it yet.

## Paper info

- **Authors**: Takuya Akiba, Shotaro Sano, Toshihiko Yanase, Takeru Ohta, Masanori Koyama
- **Venue**: arXiv · Preprint
- **First published**: 2019-7-25
- **Added**: 2026-11-12
- **Updated**: 2019-7-25
- **Version**: v1
- **arXiv**: 1907.10902
- **Category**: cs.LG · stat.ML
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1907.10902v1) · [PDF ↗](https://arxiv.org/pdf/1907.10902v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Takuya Akiba, Shotaro Sano, Toshihiko Yanase, Takeru Ohta, Masanori Koyama (2019). Optuna: A Next-generation Hyperparameter Optimization Framework. arXiv:1907.10902v1. https://arxiv.org/abs/1907.10902v1

**BibTeX**

```
@misc{akiba2019optuna,
  title = {{Optuna: A Next-generation Hyperparameter Optimization Framework}},
  author = {Takuya Akiba and Shotaro Sano and Toshihiko Yanase and Takeru Ohta and Masanori Koyama},
  year = {2019},
  eprint = {1907.10902},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1907.10902v1}
}
```

## Other paper commentary

- [On the Convergence of FedAvg on Non-IID Data](https://refivu.com/en/papers/be876672-3359-432a-aef6-283efba8fc24-on-the-convergence-of-fedavg-on-non-iid.md)
- [On Large-Batch Training for Deep Learning: Generalization Gap and Sharp Minima](https://refivu.com/en/papers/9954c18e-def9-48fe-bfea-2f52f4ed7acb-on-large-batch-training-for-deep-learning-generalization.md)
- [On the Convergence of Adam and Beyond](https://refivu.com/en/papers/0071643a-b21a-4f45-ab31-5fa27e061226-on-the-convergence-of-adam-and-beyond.md)
- [On Hyperparameter Optimization of Machine Learning Algorithms: Theory and Practice](https://refivu.com/en/papers/e35d8e99-a32c-4e33-acef-50ee792021f2-on-hyperparameter-optimization-of-machine-learning.md)
- [Understanding deep learning requires rethinking generalization](https://refivu.com/en/papers/cb138997-32a3-4005-82f2-6597e2492ff8-understanding-deep-learning-requires-rethinking.md)
- [Federated Optimization in Heterogeneous Networks](https://refivu.com/en/papers/2cd45774-4d0c-4ae9-9650-6a1593f93832-federated-optimization-in-heterogeneous-networks.md)
- [Image Super-Resolution via Iterative Refinement](https://refivu.com/en/papers/3eef3bfb-00fb-4f8e-9c82-8b12a576f54c-image-super-resolution-via-iterative-refinement.md)
- [Latent Dirichlet Allocation (LDA) and Topic modeling: models, applications, a survey](https://refivu.com/en/papers/7c7dce20-b29a-401e-a22b-b97cd29a6ba4-latent-dirichlet-allocation-lda-and-topic-modeling-models.md)
- [A Time Series is Worth 64 Words: Long-term Forecasting with Transformers](https://refivu.com/en/papers/15822929-13f1-40c7-8503-ce263dcf1639-a-time-series-is-worth-64-words-long.md)
- [Pruning Convolutional Neural Networks for Resource Efficient Inference](https://refivu.com/en/papers/f9a56d26-44b5-4ea9-af4f-8f00b03fe628-pruning-convolutional-neural-networks-for-resource-efficient.md)
- [Free-Form Image Inpainting with Gated Convolution](https://refivu.com/en/papers/c438682f-8d73-4981-a1ac-035e6f376b93-free-form-image-inpainting-with-gated-convolution.md)
- [Person Transfer GAN to Bridge Domain Gap for Person Re-Identification](https://refivu.com/en/papers/68ab1f6a-e5fc-4ab0-aa97-7c531e651f1d-person-transfer-gan-to-bridge-domain-gap-for.md)

## Terms in this paper

- [AlexNet](https://refivu.com/en/terms/e5142ede4de4-alexnet)
- [SVHN](https://refivu.com/en/terms/c24d35c2e4d0-svhn)
- [Pruning](https://refivu.com/en/terms/143c3e7dde1f-pruning)
- [Hyperband](https://refivu.com/en/terms/b6051a2ca1d0-hyperband)
- [SMAC](https://refivu.com/en/terms/96cbe183f791-smac)
- [CMA-ES](https://refivu.com/en/terms/4165774f7c53-cma-es)
- [Hyperopt](https://refivu.com/en/terms/84f64f90d674-hyperopt)
- [TPE](https://refivu.com/en/terms/eba97fb80f4c-tpe)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/e942093c-e24f-4376-bcfb-cbd377aca1d1-optuna-a-next-generation-hyperparameter-optimization)
