tabpfn-extensions Bayesian optimization example into a step-by-step notebook. We optimize the 2D Michalewicz benchmark and compare TabPFN-driven search against two baselines under the same evaluation budget: BoTorch’s Gaussian process with LogEI, the standard choice for this kind of problem, and random search. Along the way we show how propose_next_point() uses the predictive distribution from TabPFN to compute Expected Improvement (EI).
A single run tells you very little — the starting design alone can decide the outcome. So we repeat the whole experiment 5 times with different initial designs and report the mean with a min–max band.
This is a toy example. Michalewicz-2 is a cheap synthetic function in two dimensions, and 5 repeats of 50 evaluations is a small budget. The notebook shows how to put TabPFN into a Bayesian optimization loop; it is not a benchmark, and it is not representative of many real-world or higher-dimensional BO problems. Which method wins depends on the function and its dimension: in our larger benchmark the GP was ahead early on smoother problems such as Hartmann-6.
Relevant resources:
tabpfn-extensionsrepository- Bayesian optimization example script in
tabpfn-extensions PFNs4BOpaper / reference implementation- TabPFN repo
Setup
Install the full TabPFN package plus the Bayesian optimization extras fromtabpfn-extensions.
This example uses the local PyTorch-backed TabPFN implementation, because the acquisition function reads TabPFN’s predicted distribution directly. With tabpfn>=9.0.0 the default model is TabPFN 3.5. The extras pull in BoTorch, which provides the GP baseline and the benchmark function.
The Optimization Problem
Michalewicz-2 is a two-dimensional benchmark with steep, narrow valleys separated by flat plateaus on[0, π]^2. After negation its optimum is 1.8013 at about (2.20, 1.57). The plateaus carry almost no signal, so a stationary GP kernel has little to go on early, and random search rarely lands in the right valley.
The TabPFN surrogate predicts a full bar distribution over the objective value. propose_next_point() computes Expected Improvement exactly on that distribution — no Gaussian assumption — for a large batch of random candidates, then refines the most promising ones by sampling around them with a shrinking Gaussian. That optimizer is gradient-free, so it needs nothing special from the regressor.
Two details worth calling out:
negate=Trueturns the minimization benchmark into a maximization problem, which is what EI expects;optimal_valuefollows the sign.- The optimizer searches the unit cube
[0, 1]^2, but Michalewicz lives on[0, π]^2, so every candidate is mapped onto the problem’s own bounds before evaluation.
Build the TabPFN Surrogate
An ordinaryTabPFNRegressor is all it takes.
Nothing in the loop needs gradients with respect to the inputs, so we use the plain regressor with its full ensemble of 8 estimators. Those are the settings we validated on the continuous BoTorch benchmark suite (eight synthetic functions, 32 seeds, 250 evaluations each): an 8-estimator TabPFN with exact EI and this sampled optimizer had the best mean rank against BoTorch’s GP with EI and LogEI at 250 evaluations, while the GP led on the smooth single-basin functions (Branin, Hartmann-3, Rosenbrock-like valleys) early on. Michalewicz is one of the multimodal functions where TabPFN was clearly ahead, by about 7× in mean regret at 50 evaluations, so it is where the difference shows within a notebook-sized budget.
Each repeat gets its own surrogate, seeded with that repeat’s index, so the runs are independent. Keep TabPFN on cpu or cuda; Apple’s mps backend is an order of magnitude slower here.
Run Bayesian Optimization
Seed with a Sobol design, then let each method propose the next evaluation point. Each TabPFN iteration fits the surrogate on all observed evaluations so far, scores 2048 random candidates with Expected Improvement in one forward pass, and refines the top 16 by sampling around them for three rounds before returning the next point to evaluate. The GP baseline is BoTorch’sSingleTaskGP with LogEI, maximized with optimize_acqf, in the configuration of Ament et al. (NeurIPS 2023).
We run that loop N_SEEDS = 5 times. Within a repeat, all three methods start from the same N_INIT scrambled-Sobol evaluations, so the curves can only diverge once the acquisition strategy takes over. A Sobol sequence is a quasi-random design that covers the search space more evenly than uniform random points; scrambling randomizes it, so each repeat gets a different but still well-spread start. TabPFN takes nearly all of the runtime: one repeat of its loop takes about 9 minutes on 2 laptop CPU threads and about a minute on an L4 GPU, while the GP needs a few seconds. In a real campaign each evaluation of the objective usually costs far more than either.
Compare the Three Methods
Same objective, same budget, same starting points — only the choice of the next point differs. We report the gap to the optimum (optimum - best so far, the simple regret) on a log axis rather than the raw objective. Lower is better.
Where Each Method Searched
The same landscape, with every point each method evaluated in one repeat. We pick the repeat with TabPFN’s median final gap, so the picture is typical rather than its best case. Grey crosses are the shared Sobol start; colored dots are the 40 points each method chose, darker for later ones.
Takeaways
tabpfn-extensionsprovides the Bayesian optimization loop primitive,propose_next_point(), and it works with a plainTabPFNRegressor: exact EI on TabPFN’s predicted distribution, maximized by a gradient-free sampled optimizer.- On Michalewicz-2 with 50 evaluations, TabPFN-EI ends with a mean gap of 0.0010 (median 0.0002), against 0.22 for GP-LogEI and 0.70 for random search. TabPFN is ahead of the GP on four of the five repeats; on the fifth the GP gets closer (0.0003 against 0.004). Over 32 repeats the picture holds: TabPFN-EI gets within 1e-3 of the optimum on 20 of 32, GP-LogEI on 6, and the GP stays stuck above 0.1 on 12.
- The picture is function-dependent. In our larger benchmark the GP is ahead early on smooth single-basin functions such as Branin and Hartmann-3 and wins on final precision there; TabPFN leads on multimodal functions like this one and Ackley, and overall from about 100 evaluations on, once its context has grown. Use more evaluations and more repeats for a clean comparison on your own problem.
- For more background, start with the upstream example and the
tabpfn-extensionsrepo.