- Key idea
- Exponential tilting, the Boltzmann distribution, the closed-form RLHF optimum, RL as Bayesian inference, and best-of-n
- Real world
- In a gas, molecules occupy high-energy states less often, in proportion to exp(−energy / temperature). Turn the temperature down and they crowd into the lowest-energy states; turn it up and they spread out.
- In an LLM
- The best policy for "maximise reward, but stay close to the reference model" has a formula: take the reference model's probability of each answer and multiply by exp(reward / β). Low β: chase reward. High β: stay put. DPO, best-of-n and RL-as-inference all start from this formula.
Tilting a distribution
Take a distribution and a score . The tilted distribution multiplies each probability by , then renormalises:
- High-scoring outcomes gain probability, low-scoring ones lose it.
- controls how hard. As , nothing changes. As , all the probability goes to the highest score.
- Outcomes with stay at zero. Tilting can only reweight what already does.
, the partition function, is just the normaliser, but it's usually impossible to compute for text, because it's a sum over every possible answer. Much of the cleverness in this area is avoiding it.
Physics calls this the Boltzmann distribution: a state with energy is occupied with probability proportional to . It's the softmax with negative energy as the score, and temperature playing the role of . That's where the word "temperature" in sampling comes from.
The reference model writes a vague answer 35% of the time and the best answer 3% of the time, with rewards 0.1 and 1.0. With , the vague answer is multiplied by and the best by . After renormalising, the best answer goes from 3% to about 31%, and the vague one falls to about 4%.
The RLHF optimum
RLHF maximises reward minus a KL penalty to the reference model:
The exact answer is the tilted reference: . Nothing else achieves a higher value of that objective. Three consequences:
- RL fine-tuning is sharpening the reference model towards high reward. It can't create answers the reference gives zero probability (Does RL teach new skills?).
- DPO rearranges the formula to express the reward through the policy, . In a comparison of two answers to the same prompt, cancels, and the reward model disappears (DPO).
- RL as Bayesian inference: read as a prior and as a likelihood of "this answer is good". Then is the posterior. The KL penalty isn't an ad hoc regulariser; it's what makes the result a proper posterior instead of a collapse onto one answer.
Best-of-n
The simplest way to tilt at inference time: sample answers, score them, and keep the best. The result is a new distribution over answers, which you can compare to the tilted one. Two facts:
- Its KL from the reference is at most , small for practical : best-of-16 is under 2 nats.
- On a reward-versus-KL plot, best-of-n lands very close to the tilted optimum, which is why it's a strong baseline that RLHF methods have to beat.
Try it
Interview 5 candidates and hire the best. You haven't changed who applies; you've reshaped the distribution of who gets hired towards the top of the applicant pool. Interview 50 and you'd get even better hires, but each extra interview buys less.
Gao et al. (2022) measured progress against KL from the reference. With a learned reward model, true quality first rises, then falls as KL grows, for both best-of-n and RL. The proxy reward keeps rising. KL is the natural x-axis because it's the budget in the tilting objective, and it's how far you've moved from the distribution the reward model was trained on.
Where this shows up
- The KL-regularised objective and its optimum: KL and reward hacking.
- DPO and variants derive their losses from : DPO.
- Best-of-n as a baseline and as training data: distillation.
- Power distributions are tilting by the model's own log-probability: MCMC.
Deriving the optimum
with . The KL is minimised, at zero, by . The maximum value is .
DPO from the optimum
Solving for and plugging into the Bradley–Terry model, cancels between the chosen answer and the rejected answer :
RL as Bayesian inference
Korbak et al. write the target as a posterior with a binary "optimality" variable whose likelihood is :
KL-regularised RL is then variational inference: minimising , a reverse KL, which explains its mode-seeking behaviour.
Best-of-n
If rewards are distinct and is the reference's CDF of reward, the best of samples has . Beirami et al. show
with equality for continuous rewards. The widget computes the exact discrete version.
Papers
- RL with KL penalties is better viewed as Bayesian inference (Korbak et al., 2022)
- Direct Preference Optimization (Rafailov et al., 2023)
- Theoretical guarantees on the best-of-n alignment policy (Beirami et al., 2024)
- BoNBoN Alignment for Large Language Models and the Sweetness of Best-of-n Sampling (Gui et al., 2024): best-of-n is nearly optimal on the reward–KL frontier, and how to train towards it
- Scaling Laws for Reward Model Overoptimization (Gao et al., 2022)