Sam Babichenko

Reading notes / Learning from human preferences

Direct preference optimization

Korbak et al., 2022; Rafailov et al., 2023; Azar et al., 2024

Context. RLHF fits a reward to human comparisons and runs PPO against it with a KL penalty to the supervised model, which means several large models in memory, sampling inside the training loop and a hard-to-train value function. Korbak et al. (2022), a short position paper with no experiments, show that the optimum of that objective is a fixed target, the base model tilted by er/βe^{r/\beta}. DPO (Rafailov et al., 2023) solves the tilt for the reward and fits the policy with a logistic loss on preference pairs, with no reward model and no RL. IPO (Azar et al., 2024) shows where that loss stops enforcing the KL penalty and fixes it with a squared loss on the same margin. A policy defines its own reward, r=βlog⁡(π/πref)r=\beta\log(\pi/\pi_{\rm ref}), up to a prompt-only term that cancels in a comparison. The penalty keeps the policy near the reference only if the tilting function is bounded, and the logit of a near-deterministic preference is unbounded.

Setting. Prompts xx, responses yy, a reference policy πref\pi_{\rm ref} (usually the SFT model, which is also the initialization), and comparisons (x,yw,yl)(x,y_w,y_l) with ywy_w preferred. Bradley-Terry models them with a latent reward, p∗(y1≻y2∣x)=σ(r∗(x,y1)−r∗(x,y2))p^*(y_1\succ y_2\mid x)=\sigma\big(r^*(x,y_1)-r^*(x,y_2)\big), and RLHF solves, for each prompt, max⁡π Ey∼π(⋅∣x) r(x,y)−β KL(π(⋅∣x) ∥ πref(⋅∣x)).\max_\pi\ \mathbb E_{y\sim\pi(\cdot|x)}\,r(x,y)-\beta\,\mathrm{KL}\big(\pi(\cdot|x)\,\|\,\pi_{\rm ref}(\cdot|x)\big). Write r^θ(x,y)=βlog⁡πθ(y∣x)πref(y∣x)\hat r_\theta(x,y)=\beta\log\frac{\pi_\theta(y|x)}{\pi_{\rm ref}(y|x)} for the reward a policy implicitly defines, and hπ(y,y′)=log⁡π(y) πref(y′)π(y′) πref(y)h_\pi(y,y')=\log\frac{\pi(y)\,\pi_{\rm ref}(y')}{\pi(y')\,\pi_{\rm ref}(y)} for the log-ratio margin, the quantity both DPO and IPO act on; r^θ(y)−r^θ(y′)=β hπθ(y,y′)\hat r_\theta(y)-\hat r_\theta(y')=\beta\,h_{\pi_\theta}(y,y').

Main results. (a) The optimum is a tilt (Korbak et al.): with π∗=πrefer/β/Z(x)\pi^*=\pi_{\rm ref}e^{r/\beta}/Z(x), every π\pi satisfies Eπr−β KL(π ∥ πref)=βlog⁡Z−β KL(π ∥ π∗),\mathbb E_\pi r-\beta\,\mathrm{KL}(\pi\,\|\,\pi_{\rm ref})=\beta\log Z-\beta\,\mathrm{KL}(\pi\,\|\,\pi^*), so π∗\pi^* is the unique maximizer. (b) DPO is the Bradley-Terry negative log-likelihood with r^θ\hat r_\theta as the reward, LDPO(θ)=−E(x,yw,yl)log⁡σ(r^θ(x,yw)−r^θ(x,yl)),\mathcal L_{\rm DPO}(\theta)=-\mathbb E_{(x,y_w,y_l)}\log\sigma\big(\hat r_\theta(x,y_w)-\hat r_\theta(x,y_l)\big), and Theorem 1 (with Proposition 1) says the restriction loses no generality: if πref>0\pi_{\rm ref}\gt0 and β>0\beta\gt0, each class of rewards that differ by a function of xx alone (same preferences, same optimal policy) contains exactly one reward of the form βlog⁡π/πref\beta\log\pi/\pi_{\rm ref}, namely r−βlog⁡Zr(x)r-\beta\log Z_r(x). (c) IPO maximizes the win rate against the pair-generating policy μ\mu under the same penalty, p∗(π≻μ)−τ KL(π∥πref)p^*(\pi\succ\mu)-\tau\,\mathrm{KL}(\pi\|\pi_{\rm ref}) (τ\tau has the role of β\beta); if Supp(μ)=Supp(πref)\mathrm{Supp}(\mu)=\mathrm{Supp}(\pi_{\rm ref}), its optimum is the unique local minimum of a squared loss whose sampled form is min⁡π E(yw,yl)∼D[(hπ(yw,yl)−12τ)2].\min_\pi\ \mathbb E_{(y_w,y_l)\sim\mathcal D}\Big[\Big(h_\pi(y_w,y_l)-\frac1{2\tau}\Big)^2\Big].

Step 1

The KL penalty turns reward maximization into fitting a fixed target. Without it, Eπr\mathbb E_\pi r is linear in π\pi, so its maximum over the simplex is a vertex, all mass on the best sequence; even a reward that ranks every sequence correctly asks for a model that emits one string. Folding the penalty into the reward, as PPO does per token, gives rθ′=r+β(log⁡πref−log⁡πθ)r'_\theta=r+\beta(\log\pi_{\rm ref}-\log\pi_\theta), a reward that moves with the policy and whose −βlog⁡πθ-\beta\log\pi_\theta part penalizes concentrating mass, so this is no longer reward maximization in the usual sense. Instead combine the two terms under one logarithm, −β Eπlog⁡[π/(πrefer/β)]-\beta\,\mathbb E_\pi\log[\pi/(\pi_{\rm ref}e^{r/\beta})], and insert ZZ: that is (a), the Gibbs variational principle, so the regularized problem is minimizing a reverse KL to a target that does not depend on π\pi. The target puts mass exactly where πref\pi_{\rm ref} does; it returns πref\pi_{\rm ref} as β→∞\beta\to\infty and concentrates on the best sequences in that support as β→0\beta\to0, so collapse is the β=0\beta=0 end of the same family.

Step 2

The tilt is a posterior, which splits alignment into choosing a target and approximating it. If r≤0r\le0 (shifting rr changes ZZ and not π∗\pi^*), introduce an event OO with p(O=1∣y)=er(y)p(O=1\mid y)=e^{r(y)} and absorb β\beta into rr; Bayes' rule gives p(y∣O=1)=π∗p(y\mid O=1)=\pi^* with Z=p(O=1)Z=p(O=1), and Jensen gives log⁡p(O=1) ≥ Eπθr−KL(πθ ∥ πref),\log p(O=1)\ \ge\ \mathbb E_{\pi_\theta}r-\mathrm{KL}(\pi_\theta\,\|\,\pi_{\rm ref}), with gap KL(πθ∥π∗)\mathrm{KL}(\pi_\theta\|\pi^*), so KL-regularized RL is variational inference with πθ\pi_\theta as the family and β\beta as the temperature of the tilt. The posterior is formal, since "this sample is optimal" is a modelling device. The split separates failure modes: a wrong target (the exponential tilt is one choice; a hard constraint gives πref\pi_{\rm ref} renormalized on the allowed set) is a modelling error, a poor fit is an inference error, and decoding-time methods are the sampling-based alternative to fine-tuning. Korbak et al. then argue, without a theorem, that the divergence is responsible for the success: RL without the KL term degenerates, while divergence minimization without an RL form (forward KL to the same target, or maximum likelihood) works.

Step 3

DPO solves the tilt for the reward, and the normalizer cancels in a comparison. Take logs of the closed form: r(x,y)=βlog⁡πr(y∣x)πref(y∣x)+βlog⁡Z(x).r(x,y)=\beta\log\frac{\pi_r(y|x)}{\pi_{\rm ref}(y|x)}+\beta\log Z(x). Z(x)Z(x) sums over all responses, which is why RLHF approximates πr\pi_r with PPO. But Bradley-Terry compares two responses to the same prompt, both carry the same βlog⁡Z(x)\beta\log Z(x), and it cancels, so the preference likelihood is a function of the policy; parametrize the policy in place of the reward and maximize it, and that is LDPO\mathcal L_{\rm DPO} (Plackett-Luce rankings cancel the same way). The fitted policy is KL-optimal for its implicit reward by construction, so reward fitting and policy optimization are one step, needing only log-probabilities of two responses under πθ\pi_\theta and the frozen πref\pi_{\rm ref}.

Step 4

Restricting to implicit rewards loses no generality. Classes are the right notion because both ends of the pipeline ignore prompt-only terms: a shift f(x)f(x) cancels in every Bradley-Terry or Plackett-Luce factor and in the tilt's normalizer. For existence, the projection r↦r−βlog⁡∑yπref(y∣x)er(x,y)/βr\mapsto r-\beta\log\sum_y\pi_{\rm ref}(y|x)e^{r(x,y)/\beta} stays in the class and, by Step 3, equals βlog⁡πr/πref\beta\log\pi_r/\pi_{\rm ref}. For uniqueness, if two implicit rewards differ by f(x)f(x), then π′=πef/β\pi'=\pi e^{f/\beta}, and summing over yy forces f=0f=0; positivity of πref\pi_{\rm ref} keeps every log ratio finite. So the implicit reward is an identifiability constraint, the representative whose partition function is 1 for every prompt. The same normalizer is the soft value of πref\pi_{\rm ref}; left in the reward, it is a prompt-dependent offset that inflates the variance of the policy gradient, which PPO's learned value function estimates as a baseline, and the implicit reward has it removed, so DPO needs none (the paper's argument, not a measurement).

Step 5

The gradient is a weighted likelihood-ratio update, and the weight prevents degeneration. ∇θLDPO=−β E[σ(r^θ(x,yl)−r^θ(x,yw))(∇θlog⁡πθ(yw∣x)−∇θlog⁡πθ(yl∣x))].\nabla_\theta\mathcal L_{\rm DPO}=-\beta\,\mathbb E\Big[\sigma\big(\hat r_\theta(x,y_l)-\hat r_\theta(x,y_w)\big)\big(\nabla_\theta\log\pi_\theta(y_w|x)-\nabla_\theta\log\pi_\theta(y_l|x)\big)\Big]. The update raises log⁡πθ(yw∣x)\log\pi_\theta(y_w|x) and lowers log⁡πθ(yl∣x)\log\pi_\theta(y_l|x), weighted by the probability the implicit reward model assigns to the wrong ordering, so pairs already ordered with a wide margin stop contributing. Drop the weight and the update is unlikelihood training, maximize log⁡π(yw∣x)−αlog⁡π(yl∣x)\log\pi(y_w|x)-\alpha\log\pi(y_l|x), which is unbounded because log⁡π(yl∣x)\log\pi(y_l|x) can be pushed to −∞-\infty; on summarization it produces strings like "when when when", the degeneration the weighting prevents.

Step 6

DPO optimizes the shared objective better than PPO and does at least as well on real tasks. On IMDb, with a sentiment classifier as the true reward, DPO's reward-KL frontier dominates PPO's, even PPO trained on the true reward. On Reddit TL;DR with a 6B model, GPT-4 prefers DPO's summaries to the reference about 61% of the time, against 57% for PPO at its best temperature, and DPO degrades less as temperature rises; on HH dialogue it roughly matches best-of-128. The caveats are mostly the paper's own: models up to 6B, β\beta barely tuned (0.1, and 0.5 for TL;DR), GPT-4 as the main judge, and PPO baselines whose quality depends on implementation.

Step 7

On near-deterministic preferences DPO's loss ignores β\beta. If p∗(y≻y′)=1p^*(y\succ y')=1, Bradley-Terry needs r(y)−r(y′)=+∞r(y)-r(y')=+\infty, and the tilt sets π∗(y′)=0\pi^*(y')=0 for every β\beta. The finite-sample version matters in practice: a pair seen once has empirical preference 1 even when p∗=0.8p^*=0.8. There the DPO loss of the margin is −log⁡σ(βh)-\log\sigma(\beta h), strictly decreasing with no finite minimizer, and β\beta only rescales hh, so the optimum is h=∞h=\infty and πθ(yl∣x)/πref(yl∣x)→0\pi_\theta(y_l|x)/\pi_{\rm ref}(y_l|x)\to0 whatever β\beta is. This is logistic regression on separable data (Soudry et al., 2018): the margin grows slowly without bound, and only early stopping limits it. The loss also sees the policy only through log-ratio differences on observed pairs, so the probability of responses outside the data is unconstrained. Neither gap is discussed in the DPO paper. Azar et al. argue, without testing it, that RLHF suffers less because its underfit reward model keeps rewards finite on {0,1} data.

Step 8

IPO bounds the tilt by using the win rate itself, and its optimum solves linear equations. Azar et al. write all three methods as one objective, ΨPO: maximize Ey∼π, y′∼μΨ(p∗(y≻y′))−τ KL(π∥πref)\mathbb E_{y\sim\pi,\,y'\sim\mu}\Psi\big(p^*(y\succ y')\big)-\tau\,\mathrm{KL}(\pi\|\pi_{\rm ref}) for a non-decreasing Ψ\Psi, with nothing tying p∗p^* to a reward. By the same Gibbs argument the optimum is πrefeg/τ\pi_{\rm ref}e^{g/\tau} normalized, with g(y)=Ey′∼μΨ(p∗(y≻y′))g(y)=\mathbb E_{y'\sim\mu}\Psi(p^*(y\succ y')), so log⁡(π∗/πref)\log(\pi^*/\pi_{\rm ref}) moves exactly as far as g/τg/\tau. With the logit, Ψ(σ(r(y)−r(y′)))=r(y)−r(y′)\Psi(\sigma(r(y)-r(y')))=r(y)-r(y') and gg is the RLHF reward up to a constant, which proves that RLHF and DPO are instances of ΨPO; the logit is unbounded, which is the problem of Step 7. With the identity, g(y)=p∗(y≻μ)∈[0,1]g(y)=p^*(y\succ\mu)\in[0,1], so log ratios span at most 1/τ1/\tau however deterministic the preferences are. Log ratios of the tilt remove the normalizer and leave equations linear in the logits s=log⁡πs=\log\pi, hπ∗(y,y′)=τ−1(p∗(y≻μ)−p∗(y′≻μ))for all y,y′,h_{\pi^*}(y,y')=\tau^{-1}\big(p^*(y\succ\mu)-p^*(y'\succ\mu)\big)\qquad\text{for all }y,y', and the IPO loss is their mean squared residual under μ⊗μ\mu\otimes\mu, so L≥0=L(π∗)L\ge0=L(\pi^*). In the logits it is a convex quadratic whose second-order part ∑μ(y)μ(y′)(s(y)−s(y′))2\sum\mu(y)\mu(y')(s(y)-s(y'))^2 vanishes only along the all-ones direction, which leaves the softmax unchanged, so the minimizer is unique as a policy and every local minimum is it. Without the support condition the quadratic does not see actions μ\mu never samples, and their mass is left free.

Step 9

The sampled loss is unbiased, and it regresses the margin to 1/(2τ)1/(2\tau). The Bernoulli label can replace the win-rate difference although the two targets differ pointwise, because the loss sees the target only through a cross term with the margin, and hπ(y,y′)=f(y)−f(y′)h_\pi(y,y')=f(y)-f(y') with f=log⁡(π/πref)f=\log(\pi/\pi_{\rm ref}), so that term needs only the label's one-sided means, E[I∣y]=p∗(y≻μ)\mathbb E[I\mid y]=p^*(y\succ\mu) and E[I∣y′]=1−p∗(y′≻μ)\mathbb E[I\mid y']=1-p^*(y'\succ\mu). On a dataset each comparison enters as (yw,yl,1)(y_w,y_l,1) and (yl,yw,0)(y_l,y_w,0), and with hh antisymmetric it contributes 12[(h−τ−1)2+h2]=(h−12τ)2+const.\tfrac12\big[(h-\tau^{-1})^2+h^2\big]=\big(h-\tfrac1{2\tau}\big)^2+\text{const}. DPO and IPO act on the same margin and differ only in the loss: the logistic loss always decreases as the margin grows, while the square has a finite target, and that target provides the regularization.

Step 10

In small bandits DPO goes greedy or drops actions for every τ\tau, while IPO stays a τ\tau-controlled tilt. With two actions, uniform πref=μ\pi_{\rm ref}=\mu and p∗(y1≻y2)=1p^*(y_1\succ y_2)=1, IPO gives π∗(y1)=σ(1/(2τ))\pi^*(y_1)=\sigma(1/(2\tau)) and DPO gives 1 for every τ\tau. With three actions and a total order seen once per pair, DPO converges to the top action for τ∈{0.1,0.5,1}\tau\in\{0.1,0.5,1\}, while IPO gives equal log gaps of 1/(3τ)1/(3\tau) (my computation), (0.45,0.32,0.23)(0.45,0.32,0.23) at τ=1\tau=1. The commoner failure in a large action space with little data is an action that never wins: when yay_a and yby_b each beat the other once and ycy_c loses once, DPO sends ycy_c to 0, and IPO leaves it 0.16 and 0.23 at τ=0.5\tau=0.5 and 1.

Consequences and limits. DPO turned preference fine-tuning into supervised learning on a fixed dataset. DPO, IPO and RLHF share one target, the tilt πrefeg/τ\pi_{\rm ref}e^{g/\tau}, and differ in the tilting function and in what stops the fit from running to the boundary: early stopping for DPO, an underfit reward model for RLHF, a finite target margin for IPO. A drawback of IPO is that its target is a win rate against the sampling policy μ\mu, so its optimum depends on how the pairs were generated, whereas under Bradley-Terry the logit turns μ\mu into a constant shift of gg; and its evidence comes only from toy bandits, with no language-model experiments. The tilt also says how reward errors enter (not discussed by Korbak et al.): with a learned r=rtrue+er=r_{\rm true}+e the target gains a factor ee/βe^{e/\beta}, so errors are amplified without bound as β\beta shrinks, one mechanism for the over-optimization Gao et al. measure.

Terms

π∗=πrefer/β/Z(x)\pi^*=\pi_{\rm ref}e^{r/\beta}/Z(x)
KL-regularized optimum, a tilt of the reference; Z(x)Z(x) sums over all responses
Eπr−β KL(π∥πref)=βlog⁡Z−β KL(π∥π∗)\mathbb E_\pi r-\beta\,\mathrm{KL}(\pi\|\pi_{\rm ref})=\beta\log Z-\beta\,\mathrm{KL}(\pi\|\pi^*)
Gibbs variational principle; the objective is affine in the reverse KL to a fixed target
Distribution collapse
Eπr\mathbb E_\pi r is linear in π\pi, so its maximizer is a point mass on the best sequence
Implicit reward r^θ\hat r_\theta
βlog⁡πθ(y∣x)/πref(y∣x)\beta\log\pi_\theta(y|x)/\pi_{\rm ref}(y|x), the reward for which πθ\pi_\theta is optimal
LDPO\mathcal L_{\rm DPO}
Bradley-Terry log loss with r^θ\hat r_\theta as reward; Z(x)Z(x) cancels in the difference
Gradient weight
β σ(r^θ(yl)−r^θ(yw))\beta\,\sigma(\hat r_\theta(y_l)-\hat r_\theta(y_w)): probability the implicit reward misorders the pair
Theorem 1
each class of rewards differing by a function of xx has exactly one of the form βlog⁡π/πref\beta\log\pi/\pi_{\rm ref}, namely r−βlog⁡Zr(x)r-\beta\log Z_r(x)
ΨPO
max⁡πE Ψ(p∗(y≻y′))−τ KL(π∥πref)\max_\pi\mathbb E\,\Psi(p^*(y\succ y'))-\tau\,\mathrm{KL}(\pi\|\pi_{\rm ref}); logit gives RLHF/DPO under Bradley-Terry, identity gives IPO
hπ(y,y′)h_\pi(y,y')
log-ratio margin log⁡π(y)πref(y′)π(y′)πref(y)\log\frac{\pi(y)\pi_{\rm ref}(y')}{\pi(y')\pi_{\rm ref}(y)}, the quantity DPO and IPO fit
IPO loss
(h−1/(2τ))2(h-1/(2\tau))^2 per comparison; a finite target margin, so log ratios span at most 1/τ1/\tau

Quiz

  1. Why does maximizing Eπθr\mathbb E_{\pi_\theta}r collapse the model even with perfect exploration and a reward that ranks every sequence correctly?
  2. Which sequences can the KL-regularized optimum π∗\pi^* put mass on, for any finite reward and any β>0\beta\gt0?
  3. Suppose the learned reward is r=rtrue+er=r_{\rm true}+e. What does the tilt formula say about small β\beta?
  4. What keeps the KL penalty effective in IPO even when preferences are deterministic?

Sources