NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Inference-Aware Fine-Tuning for Best-of-N Sampling in Large Language Models

Yinlam Chow, Guy Tennenholtz, Izzeddin Gur, Vincent Zhuang, Bo Dai, Aviral Kumar, Rishabh Agarwal, Sridhar Thiagarajan, Craig Boutilier, Aleksandra Faust

TL;DR

Most Large Language Models (LLMs) are trained to produce a single best response. However, at inference time, we often use "Best-of-N" (BoN) sampling to generate multiple attempts and pick the best one. This paper introduces a new fine-tuning paradigm that makes the model "aware" of this BoN strategy during training. By optimizing for the entire set of generated candidates rather than just one, the model achieves significant performance gains in reasoning and coding tasks.

The Problem: A Mismatch in Training and Inference

In the current LLM landscape, scaling "inference-time compute" is a major frontier. Strategies like Best-of-N (BoN)—where a model generates $N$ different answers and a separate "verifier" selects the best one—have become standard practice for boosting performance on complex reasoning tasks.

However, there is a fundamental mismatch in how these models are built. We typically train models using standard Supervised Fine-Tuning (SFT) or Reinforcement Learning (RL) to maximize the likelihood of a single "correct" answer. Yet, we use them at test time to generate a diverse set of answers. The authors argue that this decoupling is sub-optimal. If a model knows it has 32 chances to solve a math problem, it should arguably spend some of those attempts exploring diverse strategies rather than repeatedly guessing its single "most likely" (and potentially wrong) answer.

Methods: Inference-Aware Fine-Tuning

To bridge this gap, the authors propose Inference-Aware Fine-Tuning, a method specifically tailored for the BoN strategy.

The Inference-Aware Fine-Tuning architecture illustrating the Best-of-N training loop.

The core technical challenge here is that the "argmax" operator used in BoN (selecting the single best response from a set) is non-differentiable. This makes it impossible to use standard gradient-based optimization directly. To bypass this hurdle, the authors employ several clever techniques:

  • Variational Approximation: They use a variational form to approximate the BoN distribution, turning the objective into a manageable loss function. This results in a "BoN-SFT" objective that balances standard likelihood with an "inference-awareness" term based on the expected win-rate of a response.
  • BoN-RL: They extend this concept to Reinforcement Learning, creating a policy gradient estimator that optimizes the environment reward of the best sample in a batch, rather than the average sample.
  • Binary Reward Optimization (BoN-RLB): For domains like math and code where rewards are strictly binary (pass/fail), they derive a closed-form solution. This method asymmetrically weights training examples, prioritizing learning from "scarce successes" on difficult problems. Essentially, it tells the model: "When a problem is hard, your successful outliers are more important than your average failures."

Key Insights and Ideas

The $T$ and $N$ Co-scaling Law

The paper identifies a crucial relationship between sampling temperature ($T$) and the number of samples ($N$). "Easier" problems benefit from low temperatures (exploitation), while "harder" problems require higher temperatures to encourage exploration, paired with a larger $N$ to find the "needle in the haystack" correct answer.

Performance scaling showing BoN Accuracy and Pass@N Accuracy across different sample sizes (N) and temperatures.

Implicit Meta-Strategy

Perhaps the most fascinating finding is that BoN-aware models implicitly learn to interleave high-quality "safe" responses with more diverse, "risky" responses. This mimics the exploration-exploitation tradeoff seen in traditional RL, but it occurs entirely at the level of a single inference batch.

Robustness to Verifier Error

By training with the inference strategy in mind, the models become more robust to "Type II" errors—situations where a verifier might mistakenly pick a high-confidence but incorrect response.

Datasets and Key Results

The researchers evaluated their methods using Gemma 2B and 9B models across several rigorous benchmarks, including Hendrycks MATH, Functional MATH, MathOdyssey, HumanEval, and MBPP. They used a separate Gemma model trained on Gemini 1.5 Flash outputs to act as the verifier.

The BoN-aware approach consistently outperformed standard SFT and RL baselines:

  • MATH Benchmark: Gemma 2B’s performance at Bo32 (Best of 32) jumped from 26.8% to 30.8%.
  • Pass@N Accuracy: On the MATH dataset, the pass@32 rate improved from 60.0% to 67.0%.
  • Coding: On HumanEval, the pass@16 rate increased from 61.6% to 67.1%.
  • Generalization: The improvements held steady even on held-out benchmarks like Functional MATH and MathOdyssey, proving the model wasn't just over-fitting to a specific dataset's quirks but was actually learning a better reasoning strategy.

Limitations and Future Work

While powerful, the authors note a few hurdles:

  • Computational Cost: Training is more expensive because the model must generate $N$ samples for each gradient update during the fine-tuning process.
  • Verifier Dependency: The system's success still relies heavily on the quality of the verifier. If the verifier is significantly flawed, the "inference-aware" training might align the model with those flaws.
  • Scaling to Complex Search: This paper focused on the relatively simple BoN strategy. The authors suggest that future work should extend this "inference-aware" paradigm to more complex search algorithms like Monte Carlo Tree Search (MCTS) or multi-turn "critique-and-revise" loops.

Summary updated

BibTeX
@inproceedings{chow2025inference,
  author = {Yinlam Chow and Guy Tennenholtz and Izzeddin Gur and Vincent Zhuang and Bo Dai and Aviral Kumar and Rishabh Agarwal and Sridhar Thiagarajan and Craig Boutilier and Aleksandra Faust},
  title = {{Inference-Aware Fine-Tuning for Best-of-N Sampling in Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=77gQUdQhE7},
}
Figure