In-Context Batch Black-box Optimization via Flow Matching

Quoc-Anh Hoang Nguyen, Xinyu Zhang, Daolang Huang, Julien Martinelli, Samuel Kaski

TL;DR

Researchers have introduced Flow Matching for Thompson-Sampling Refinement (FMTR), a new "in-context" optimizer that generates high-quality batches for black-box optimization without needing to refit models at test time. By combining the diversity of Thompson Sampling with horizon-aware refinement, FMTR achieves state-of-the-art optimization performance while being orders of magnitude faster than traditional Bayesian Optimization methods.

What Problem Does This Paper Address?

Many scientific breakthroughs—from designing new enzymes to optimizing aircraft wings—rely on "black-box" optimization. These are problems where we don't know the underlying math of the system; we can only probe it by running expensive, time-consuming experiments.

To speed things up, we often evaluate candidates in batches (parallel experiments). However, constructing a good batch is a balancing act: you want to explore new areas of the search space while also exploiting known high-value regions, all while ensuring the points in your batch aren't redundant.

Traditional Bayesian Optimization (BO) handles this by fitting a surrogate model (like a Gaussian Process) and optimizing an "acquisition function." As the batch size ($q$) and the number of dimensions ($d$) grow, this becomes a nightmare of computational complexity. Furthermore, refitting these models every single round is slow. The authors aim to bridge this gap by creating a model that learns how to optimize offline, so it can generate batches instantly online.

Methods

The core of the paper is FMTR, an amortized approach that treats batch selection as a generative modeling task.

  1. In-Context Learning: Unlike standard BO, FMTR is a pretrained transformer. At test time, its parameters are fixed. It takes the history of previous observations as "context" and immediately outputs a proposal distribution for the next batch.
  2. Flow Matching (FM): The authors use Flow Matching—a generative technique related to diffusion models—to learn a continuous distribution over the search space. To generate a batch, you simply sample noise and "flow" it into promising query locations.
  3. Horizon-Aware Refinement: This is the "secret sauce." During pretraining, the model is taught to target a distribution based on Thompson Sampling (TS). These TS points are then refined using Langevin dynamics toward high-value regions. Crucially, this refinement is "horizon-aware":
  4. Early rounds: The model is encouraged to be more diverse (exploration).
  5. Late rounds: The model clusters points more tightly around predicted peaks (exploitation).
  6. Closed-Loop Pretraining: To ensure the model remains robust during a multi-round optimization, the authors used a technique called Dataset Aggregation (DAgger), training the model on the very trajectories it generates.
Overview of FMTR and its positioning relative to related methods.

Datasets

The model was evaluated on two main fronts:

  • Synthetic Benchmarks: Standard mathematical test functions including Ackley, Rosenbrock, Levy, Rastrigin, Dixon-Price, and Styblinski-Tang, with dimensions ranging from $d=2$ to $d=15$.
  • Real-World Benchmarks: Four data-derived tasks:
  • Oil-well depth (4D): Identifying wells with the greatest drilled depth.
  • XGBoost HPO (6D): Hyperparameter optimization for machine learning models.
  • Asteroid diameter (12D): Finding large asteroids based on numerical descriptors.
  • Air quality (14D): Identifying conditions associated with high $PM_{2.5}$ concentrations.

Key Insights and Ideas

  • Amortization Wins: By moving the heavy computational lifting (surrogate fitting and acquisition optimization) to an offline pretraining phase, the model can select batches in seconds that would take other methods minutes or hours.
  • The Power of Refinement: The authors found that simply amortizing Thompson Sampling wasn't enough. The "Langevin refinement" and "distributional tilt" (weighting targets by their objective value) were critical for outperforming standard BO baselines.
  • Variable Batch Sizes: Because FMTR learns a continuous proposal distribution, it can generate batches of any size $q$ simply by drawing more samples from the flow, making it highly flexible for different laboratory setups.

Key Results

FMTR consistently outperformed or matched state-of-the-art batch BO methods across various dimensions and functions.

  • Optimization Performance: In synthetic tests (Figure 2/6), FMTR achieved the best average rank, showing a particularly strong advantage as the batch size increased.
  • Computational Speedup: The runtime results are striking. For a 15-dimensional problem with a batch size of 64, FMTR took roughly 2.8 seconds for the entire optimization. In contrast, BEEBO (a joint-batch BO method) took over 789 seconds, and even the popular TuRBO took 10 seconds.
  • Real-World Robustness: Despite being trained only on synthetic data, FMTR remained highly competitive on real-world datasets, often reaching the best values in fewer rounds than baselines.
Figure 2: Experiments on synthetic functions. Log simple regret over 15 runs, shown as mean with 95% CI. The last column reports the average rank across dimensions for each function.

Limitations and Future Work

  • Within-Batch Redundancy: Currently, FMTR samples batch members independently from the learned proposal. While it performs well, it doesn't explicitly model the "diversity" between points in the same batch. The authors suggest that "joint proposals" could be a future improvement.
  • Prior Sensitivity: Like all in-context methods, FMTR's performance depends on the quality of the synthetic tasks it was trained on. If a real-world task looks nothing like the training data, performance might dip.
  • Dimensionality: The current study scales up to $D=15$. Extending this to much higher-dimensional spaces or discrete domains (like DNA sequences) remains an open challenge.

Summary updated

BibTeX
@misc{nguyen2026context,
  author = {Quoc-Anh Hoang Nguyen and Xinyu Zhang and Daolang Huang and Julien Martinelli and Samuel Kaski},
  title = {{In-Context Batch Black-box Optimization via Flow Matching}},
  year = {2026},
  eprint = {2610.20138},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2610.20138},
}
Figure