PFNs4BO: In-Context Learning for Bayesian Optimization

Samuel Müller, Matthias Feurer, Noah Hollmann, Frank Hutter

Introduction

Bayesian Optimization (BO) is widely considered the gold standard for "black-box" optimization tasks, such as tuning the hyperparameters of complex machine learning models where every evaluation is computationally expensive. To function effectively, BO relies on a surrogate model—traditionally a Gaussian Process (GP)—to predict the outcomes of unvisited points based on previous observations.

However, traditional GPs suffer from several significant pain points:

  1. Rigidity: They assume data follows specific mathematical distributions that may not accurately reflect real-world landscapes.
  2. Scaling: Their computational cost grows cubically ($O(N^3)$) with the number of observations, severely limiting their use in data-rich scenarios.
  3. Inflexibility: It is notoriously difficult to integrate expert knowledge (e.g., a practitioner's hunch that the optimal learning rate lies in a specific range) or to handle "spurious" dimensions that do not meaningfully affect the outcome.

To address these limitations, researchers introduce PFNs4BO, a novel approach that replaces traditional GP surrogates with Prior-data Fitted Networks (PFNs). By training Transformers offline to mimic complex priors, PFNs4BO creates a surrogate model that is exceptionally fast, highly flexible, and capable of handling non-standard distributions that typically stymie traditional methods.

Methodology: Prior-data Fitted Networks

Instead of fitting a model to data during the optimization process, a PFN is a Transformer trained offline to perform Bayesian inference.

The PFN Workflow

  • Prior-Fitting (Offline): Researchers select a "prior" distribution, such as a GP or a Bayesian Neural Network. They sample millions of synthetic datasets from this prior and train a Transformer to predict the next point in a sequence. This process leverages in-context learning, conceptually similar to how Large Language Models learn to predict the next word in a sentence.
  • Inference (Online): During the actual optimization task, the trained PFN takes the observed data as a sequence and outputs a probability distribution for any new point in a single, highly efficient forward pass.

Novel Extensions

The flexibility of PFNs allows for several powerful extensions to standard BO:

  • HEBO+ Prior: A specialized prior that incorporates "input warping" to handle non-linear scales. Crucially, it includes a 30% probability that any given dimension is "spurious" (useless), effectively teaching the model to ignore noise and resist the curse of dimensionality.
  • User Priors: A mechanism designed to feed the PFN "hints" about where the optimum might lie. This allows the model to shift its focus based on human expertise without requiring complex space-warping techniques.
  • Non-Myopic BO: The PFN is trained to approximate the Knowledge Gradient, an advanced acquisition function that looks ahead to future steps. This is typically too computationally expensive for standard GPs but becomes feasible with a PFN's single forward pass.

Experimental Setup

The authors evaluated PFNs4BO across a comprehensive suite of tasks:

  • Synthetic GP Samples: Used to verify that the PFN can perfectly mimic the exact mathematical posterior of a standard GP.
  • HPO-B: A discrete benchmark focused on tree-based models like XGBoost and SVMs.
  • Bayesmark: A continuous hyperparameter optimization benchmark utilizing scikit-learn methods.
  • PD1: A highly challenging benchmark for tuning large-scale neural networks, including ResNets and Transformers.

Key Insights and Results

Prior-Fitting as "Algorithm Development"

The authors demonstrate that training a PFN is a one-time investment. Once trained on a broad, robust prior like HEBO+, the exact same model can be deployed across a vast array of different optimization tasks without any further training or fine-tuning.

State-of-the-Art Performance and Speed

On the HPO-B benchmark, the PFN utilizing the HEBO+ prior outperformed all baselines, including the original HEBO (a previous winner of a major NeurIPS competition). Furthermore, because the PFN performs inference in a single forward pass, it operates an order of magnitude faster than GPs, which require expensive hyperparameter tuning at every optimization step. In synthetic tests, PFNs trained on 20 million samples almost perfectly matched the exact mathematical posterior of a Gaussian Process.

The Power of Ignoring and Expert Integration

By explicitly including "spurious dimensions" in the training prior, the PFN learns to be robust against the "curse of dimensionality." Traditional GPs often get lost when too many irrelevant hyperparameters are tuned, but the PFN successfully isolates the signal from the noise. Additionally, on the PD1 benchmark, adding a simple, non-specific "user prior" (hinting at the general area of the optimum) significantly accelerated the optimization process, proving the viability of direct expert integration.

Limitations and Future Directions

Despite these strong results, the authors note several current limitations:

  • The "Out-of-Prior" Trap: PFNs perform poorly if the real-world data is extremely unlikely under the training prior. For instance, if the prior assumes a "smooth" function but the real landscape is highly "jagged," the PFN will struggle to adapt.
  • Data Limits: Currently, PFNs are most effective for datasets up to approximately 1,000 points. Beyond this threshold, the Transformer's context window and attention mechanism become computational bottlenecks.
  • Joint Sampling: Unlike GPs, PFNs cannot easily draw "joint samples" from multiple points simultaneously. This restricts their compatibility with certain advanced acquisition functions, such as "Noisy Expected Improvement."

Future work will likely focus on developing even more elaborate priors—such as those capable of handling categorical variables or non-stationary functions—and scaling the architecture to efficiently process thousands of observations.

Summary updated

BibTeX
@inproceedings{muller2023pfns,
  author = {Samuel Müller and Matthias Feurer and Noah Hollmann and Frank Hutter},
  title = {{PFNs4BO: In-Context Learning for Bayesian Optimization}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=1DP5fR3iTr},
}
Figure