Recent breakthroughs in Large Language Models (LLMs) have shown that "thinking longer"—using more compute at inference time through sampling and searching—can dramatically boost performance. However, most models are still trained using standard Supervised Fine-Tuning (SFT) or Reinforcement Learning (RL) that completely ignores how the model will be used at test time.
In this paper, researchers from Google DeepMind and Google Research introduce Inference-Aware Fine-Tuning, a paradigm that directly optimizes the model for its specific inference-time strategy. By focusing on the popular Best-of-N (BoN) sampling method, they show that models can learn to be better "team players" with their verifiers, leading to significant gains in reasoning and coding.
TL;DR
This paper proposes the first fine-tuning methods (both SFT and RL) that directly optimize for Best-of-N inference. By making the training "aware" of the sampling strategy, the authors improve Gemma 2B's math performance (Bo32) from 26.8% to 30.8% and coding (pass@16) from 61.6% to 67.1%.
What Problem Does This Paper Address?
Standard fine-tuning is "inference-agnostic." We typically train a model to maximize the likelihood of a single correct answer. But in practice, we often use Best-of-N (BoN): we sample $N$ different responses from the model and use a "verifier" (a reward model or a rule-based checker) to pick the best one.
There is a fundamental mismatch here. If a model knows it has 32 attempts to solve a hard math problem, it shouldn't just give its 32 most likely (and potentially very similar) guesses. It should explore diverse strategies. Standard training doesn't encourage this diversity, often leading to "mode collapse" where the model generates many variations of the same wrong idea.
The technical challenge is that the "Best-of-N" selection process involves an argmax operator (picking the best), which is non-differentiable and thus "breaks" standard gradient-based training.
Methods
The authors overcome the non-differentiability of BoN by using a variational approximation. They treat the BoN process as a new kind of policy ($\pi_{bon}$) and derive gradients for it.
They introduce several "BoN-aware" algorithms:
- BoN-SFT: An imitation learning approach that maximizes the likelihood of expert data while regularizing the model to improve its "win-rate" against its own base policy.
- BoN-RL: A reinforcement learning framework where the model optimizes the final reward of the selected best response, rather than the average reward of all samples.
- BoN-RLB: A specialized, highly efficient version for binary rewards (common in math and code) that uses a closed-form solution to weight training examples.
The general workflow for BoN-Aware RL is illustrated below, showing how the model ($\pi$) generates candidates that are ranked by a verifier ($r$) before the final selected answer ($y$) receives an environment reward ($R$) to update the model.
Datasets
The researchers evaluated their methods on two primary domains:
- Mathematics: Trained and evaluated on the Hendrycks MATH benchmark. To test generalization, they used two held-out benchmarks: Functional MATH and MathOdyssey.
- Coding: Trained on MBPP and evaluated on HumanEval.
- Models: They used Gemma 2B and Gemma 9B as base models.
Key Insights and Ideas
- Implicit Exploration-Exploitation: BoN-aware models implicitly learn a "meta-strategy." They learn to interleave high-probability "safe" responses with more diverse, exploratory responses. This ensures that at least one of the $N$ samples is likely to be correct.
- Co-scaling of $N$ and $T$: The authors found a clear relationship between the number of samples ($N$) and the sampling temperature ($T$). "Easier" problems benefit from low $N$ and $T$ (exploitation), while "harder" problems require higher $N$ and $T$ (exploration).
- Verifier Robustness: By including the verifier in the training loop, the model becomes more resilient to verifier errors. It learns to generate answers that are not just "correct" but are also easily recognizable as correct by the specific verifier being used.
Key Results
The BoN-aware methods consistently outperformed standard SFT and RL baselines across all metrics:
- MATH Benchmark (Gemma 2B):
- Bo32 Accuracy: Increased from 26.8% to 30.8%.
- pass@32: Increased from 60.0% to 67.0%.
- HumanEval (Gemma 2B):
- pass@16: Increased from 61.6% to 67.1%.
- Generalization: The performance gains held steady even when evaluating on different temperatures than those used in training and on completely held-out datasets like MathOdyssey.
The table below summarizes the different methods developed and their specific properties, such as whether they require offline data or have a closed-form solution.
Limitations and Future Work
- Training Cost: Generating $N$ samples for every training step is computationally expensive. While the authors suggest "BoN Distillation" as a potential fix, scaling this to very large $N$ remains a challenge.
- Verifier Dependency: The model's performance is somewhat "locked" to the verifier used during training. If the test-time verifier is significantly different, the gains might diminish.
- Beyond BoN: This work focuses on Best-of-N, but the authors note that the "inference-aware" paradigm could be extended to more complex strategies like Monte Carlo Tree Search (MCTS) or multi-turn self-correction loops.
Summary updated