Towards Learning Universal Hyperparameter Optimizers with Transformers

Yutian Chen, Xingyou Song, Chansoo Lee, Zi Wang, Richard Zhang, David Dohan, Kazuya Kawakami, Greg Kochanski, Arnaud Doucet, Marc'Aurelio Ranzato, Sagi Perel, Nando de Freitas

Abstract

Hyperparameter optimization (HPO) is a critical component of the machine learning pipeline, yet traditional methods often treat each task in isolation or require rigid, shared search spaces. This paper introduces OptFormer, the first Transformer-based framework designed for universal HPO. By framing optimization as a sequence modeling task and training on a massive corpus of diverse optimization trajectories, OptFormer learns to both imitate existing algorithms and act as a highly accurate surrogate model. Experimental results demonstrate that OptFormer provides better-calibrated uncertainty estimates than Gaussian Processes and achieves state-of-the-art performance across multiple benchmarks.

1. Introduction

Hyperparameter optimization—the process of identifying the optimal configuration for a machine learning model—is traditionally approached as a "cold start" problem. Standard techniques like Bayesian Optimization (BO) using Gaussian Processes (GPs) are effective but often fail to leverage the vast amount of metadata and historical data available from previous experiments. Furthermore, existing meta-learning approaches for HPO typically require all tasks to share identical hyperparameters, limiting their utility in real-world scenarios where search spaces vary significantly.

OptFormer addresses these limitations by treating HPO as a text-based sequence modeling problem. By utilizing a Transformer architecture, the model can process arbitrary search spaces and learn universal patterns of objective function behavior from hundreds of thousands of prior studies.

2. Methodology

2.1 Serialization and Tokenization

The core of the OptFormer framework is a serialization scheme that converts an entire optimization study into a single string. This includes:

  • Metadata: The optimization goal, parameter names, types, and ranges.
  • Trial History: A sequence of parameter values and their corresponding metric results.

Numerical values are normalized and quantized into 1,000 discrete bins, allowing the Transformer to treat them as tokens within a unified vocabulary.

2.2 Architecture and Training

OptFormer utilizes a standard T5 (Transformer) encoder-decoder architecture. The encoder processes the study metadata, while the decoder is trained to predict the sequence of trials. The model is trained via joint learning on two distinct objectives:

  1. Policy Prediction: Imitating the behavior of the algorithms present in the training data (e.g., predicting the next set of hyperparameters to try).
  2. Function Prediction: Acting as a surrogate model to predict the resulting metric value for a given set of hyperparameters.

2.3 Inference and Acquisition

At test time, OptFormer can be used in two ways. It can generate suggestions directly by "prompting" it to imitate a specific prior policy (like Vizier's GP-UCB). Alternatively, it can function as a surrogate model, where its function predictions are used to rank candidate points via standard acquisition functions such as Expected Improvement (EI).

3. Data and Training

The model was trained on an unprecedented scale of optimization data, including:

  • RealWorldData: 750,000 internal studies from Google Vizier, spanning vision, NLP, and robotics.
  • HPO-B: A public benchmark with 1.9k tuning tasks.
  • BBOB (Black-Box Optimization Benchmark): Synthetic functions used to ensure diverse optimization trajectories.

In total, the authors generated 20 million studies using seven different HPO algorithms to teach the model a wide variety of optimization strategies.

4. Key Insights

4.1 Algorithm Prompting

By including the algorithm name in the metadata, OptFormer can be prompted to mimic specific optimizers. This allows a single model to represent the behaviors of seven distinct algorithms, from Random Search to Regularized Evolution.

4.2 Transformers vs. Gaussian Processes

While GPs are the standard for HPO, they suffer from cubic computational complexity relative to the number of trials. OptFormer’s complexity is linear (with proper caching). More importantly, OptFormer learns a data-driven prior that is significantly more complex and accurate than the standard kernels used in GPs.

4.3 Calibration and Uncertainty

A critical finding is that OptFormer provides superior uncertainty estimates. In HPO, accurate calibration is essential for balancing exploration and exploitation. OptFormer achieved an Expected Calibration Error (ECE) of approximately 1.11%, significantly lower than the 5.34% observed in standard GPs.

5. Results

OptFormer (EI) outperformed all baselines, including the highly tuned Google Vizier service, on both the HPO-B and RealWorldData benchmarks. On the RealWorldData test set, OptFormer achieved a log-predictive likelihood of 2.12, compared to 0.83 for a standard GP. The model also demonstrated strong generalization capabilities, matching or exceeding specialized optimizers on unseen tasks such as ResNet-50 tuning and neural architecture search (NASBench-201).

6. Limitations and Future Work

Despite its success, OptFormer has limitations. It currently does not support "conditional" hyperparameters or parallel trial suggestions (batching). Additionally, the model is restricted by the Transformer's maximum sequence length (1024 tokens), which limits the number of trials it can process simultaneously. Future work will focus on extending the framework to multi-objective optimization and increasing the sequence capacity.

7. Conclusion

OptFormer represents a significant step toward universal hyperparameter optimization. By leveraging the sequence modeling power of Transformers, it moves beyond the limitations of traditional Bayesian Optimization, offering a scalable, well-calibrated, and highly flexible approach to tuning machine learning models.

Summary updated

BibTeX
@inproceedings{chen2022towards,
  author = {Yutian Chen and Xingyou Song and Chansoo Lee and Zi Wang and Richard Zhang and David Dohan and Kazuya Kawakami and Greg Kochanski and Arnaud Doucet and Marc'Aurelio Ranzato and Sagi Perel and Nando de Freitas},
  title = {{Towards Learning Universal Hyperparameter Optimizers with Transformers}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=6AEbdOU-BA},
}
Figure