Abstract
Recent studies have indicated that effectively utilizing inference-time compute is crucial for attaining better performance from large language models (LLMs). In this work, we propose a novel inference-aware fine-tuning paradigm, in which the model is fine-tuned in a manner that directly optimizes the performance of the inference-time strategy. We study this paradigm using the simple yet effective Best-of-N (BoN) inference strategy, in which a verifier selects the best out of a set of LLM-generated responses. We devise the first imitation learning and reinforcement learning (RL) methods for BoN-aware fine-tuning, overcoming the challenging, non-differentiable argmax operator within BoN. We empirically demonstrate that our BoN-aware models implicitly learn a meta-strategy that interleaves best responses with more diverse responses that might be better suited to a test-time input -- a process reminiscent of the exploration-exploitation trade-off in RL. Our experiments demonstrate the effectiveness of BoN-aware fine-tuning in terms of improved performance and inference-time compute. In particular, we show that our methods improve the Bo32 performance of Gemma 2B on Hendrycks MATH from 26.8% to 30.8%, and pass@32 from 60.0% to 67.0%, as well as the pass@16 on HumanEval from 61.6% to 67.1%.
Introduction
Standard fine-tuning paradigms for Large Language Models (LLMs), such as Supervised Fine-Tuning (SFT) and Reinforcement Learning (RL), typically optimize for the likelihood of a single correct response. However, at inference time, performance is often boosted by using "inference-time compute" strategies like Best-of-N (BoN) sampling. In BoN, the model generates $N$ candidates, and a separate verifier selects the best one.
A significant gap exists between these training and inference phases. Standard training is "inference-agnostic," failing to account for the fact that a verifier will filter the results. This paper introduces inference-aware fine-tuning, which optimizes models specifically for multi-sample strategies. By making the model "aware" of the test-time selection process, it can learn to produce a more effective set of candidates rather than just variations of a single "best" guess.
Methods
The primary challenge in BoN-aware training is the non-differentiable argmax operator used by the verifier to select the best sample. To overcome this, the authors derive a variational formulation of the BoN strategy, treating it as an energy-based model. This allows for the development of several training objectives that directly incorporate the verifier's selection process into the optimization loop.
The proposed methods include:
- BoN-SFT: An imitation learning approach aligning the model's distribution with the BoN policy.
- BoN-RL: A reinforcement learning framework directly optimizing the reward of the selected sample.
- BoN-RLB: A specialized version for binary rewards (e.g., pass/fail in coding) that uses a closed-form solution to re-weight examples by difficulty.
Experimental Setup
The methods were evaluated using Gemma 2B and Gemma 9B as base models across several reasoning and coding benchmarks:
- Mathematical Reasoning: Hendrycks MATH (training/primary eval), Functional MATH, and MathOdyssey (generalization).
- Code Generation: MBPP (training) and HumanEval (evaluation).
Results and Discussion
Inference-aware fine-tuning consistently outperformed standard SFT and RL baselines across all tasks.
Performance Gains
On the MATH benchmark, BoN-aware RL improved Gemma 2B's Best-of-32 (Bo32) accuracy from 26.8% to 30.8%. The pass@32 metric saw a significant jump from 60.0% to 67.0%. Similar improvements were observed in coding, with HumanEval pass@16 increasing from 61.6% to 67.1%. These gains generalized well to held-out benchmarks like MathOdyssey.
Emergent Meta-Strategies
A key insight is that BoN-aware models implicitly learn an exploration-exploitation trade-off. Instead of just becoming "smarter" in a linear sense, they learn to interleave high-probability "safe" responses with diverse, exploratory ones. This diversity is crucial for difficult problems where the first-best guess might be wrong, but a more creative alternative might succeed.
Robustness and Scaling
The models also showed increased robustness to verifier errors. By including the verifier in the training loop, the policy learns to avoid generating "noisy" or hallucinated content that might trick the verifier into a false positive. Additionally, the researchers identified "co-scaling laws" between the number of samples ($N$) and sampling temperature ($T$), finding that harder problems require higher temperatures and more samples to find correct solutions.
Conclusion
Inference-aware fine-tuning represents a shift toward training models that are better suited for the complex ways they are deployed. While generating multiple samples during training increases computational overhead, the resulting performance gains and the emergence of sophisticated exploration strategies suggest this is a promising direction for future LLM development. Future work may extend this paradigm to multi-turn reasoning or search-based strategies like Monte Carlo Tree Search (MCTS).
Summary updated