Skip to content

Direct Preference Optimization: Your Language Model is Secretly a Reward Model

Skip →DeepSeekMath / GRPO
main track #8corefundamentalpaperrubric 12/122023 · ~60 min

Rafael Rafailov, Archit Sharma, Eric Mitchell, …, Chelsea Finn

Status

TL;DR. RLHF maximises a learned reward minus a KL penalty to a reference policy. DPO notices that this objective has a closed-form optimum, so the reward can be rewritten in terms of the policy itself. Substituting that into the Bradley–Terry preference model gives one logistic loss on (chosen, rejected) pairs. DPO is offline preference optimisation without an online RL rollout loop or a separate reward model, derived from a KL-regularised RLHF objective. It is not “RL-free” in its objective, only in its training loop.

Why it matters now. DPO and its variants are widely used for preference tuning in open post-training recipes, because they need only a frozen reference model and a dataset of pairs. For IR this matters in two ways. You can align a reranker or RAG generator from judged pairs (human, UMBRELA-style, or an LLM judge) with a few lines of code. And the “implicit reward” view tells you that every DPO model is also a scorer. Its limits (off-policy data, unconstrained unseen responses, length effects) are exactly the ones you meet when judge labels drive training.

For prompts xx from a dataset and responses yy from the policy:

max⁡π  Ex Ey∼π(⋅∣x)[r(x,y)]  −  β DKL[π(⋅∣x) ∥ πref(⋅∣x)]\max_{\pi}\; \mathbb{E}_{x}\,\mathbb{E}_{y\sim\pi(\cdot\mid x)}\big[r(x,y)\big] \;-\; \beta\, \mathbb{D}_{\mathrm{KL}}\big[\pi(\cdot\mid x)\,\|\,\pi_{\mathrm{ref}}(\cdot\mid x)\big]

πref\pi_{\mathrm{ref}} is usually the SFT model and β\beta sets how far the policy may drift.

Step 1: write the KL as an expectation and flip the sign

Section titled “Step 1: write the KL as an expectation and flip the sign”

The KL is Ey∼π[log⁡π(y∣x)−log⁡πref(y∣x)]\mathbb{E}_{y\sim\pi}[\log \pi(y\mid x) - \log\pi_{\mathrm{ref}}(y\mid x)], so the objective is one expectation. Dividing by −β-\beta turns the max into a min:

min⁡π  Ex Ey∼π[log⁡π(y∣x)πref(y∣x)−1βr(x,y)]\min_{\pi}\; \mathbb{E}_{x}\,\mathbb{E}_{y\sim\pi}\Big[\log\frac{\pi(y\mid x)}{\pi_{\mathrm{ref}}(y\mid x)} - \frac{1}{\beta}r(x,y)\Big]

Define

Z(x)=∑yπref(y∣x)exp⁡ ⁣(1βr(x,y)),π∗(y∣x)=1Z(x) πref(y∣x)exp⁡ ⁣(1βr(x,y)).Z(x)=\sum_{y}\pi_{\mathrm{ref}}(y\mid x)\exp\!\Big(\tfrac{1}{\beta}r(x,y)\Big),\qquad \pi^{*}(y\mid x)=\frac{1}{Z(x)}\,\pi_{\mathrm{ref}}(y\mid x)\exp\!\Big(\tfrac{1}{\beta}r(x,y)\Big).

π∗\pi^{*} is a valid distribution, because Z(x)Z(x) normalises it. Now rewrite the bracket from Step 1:

log⁡ππref−rβ=log⁡ππrefexp⁡(r/β)=log⁡πZ(x) π∗=log⁡ππ∗−log⁡Z(x).\log\frac{\pi}{\pi_{\mathrm{ref}}}-\frac{r}{\beta} =\log\frac{\pi}{\pi_{\mathrm{ref}}\exp(r/\beta)} =\log\frac{\pi}{Z(x)\,\pi^{*}} =\log\frac{\pi}{\pi^{*}}-\log Z(x).

Step 3: recognise a KL divergence (Appendix A.1)

Section titled “Step 3: recognise a KL divergence (Appendix A.1)”

Taking the expectation over y∼πy\sim\pi:

min⁡π  Ex[DKL(π(⋅∣x) ∥ π∗(⋅∣x))−log⁡Z(x)]\min_{\pi}\;\mathbb{E}_{x}\Big[\mathbb{D}_{\mathrm{KL}}\big(\pi(\cdot\mid x)\,\|\,\pi^{*}(\cdot\mid x)\big)-\log Z(x)\Big]

Z(x)Z(x) does not depend on π\pi. A KL divergence is zero only when the two distributions are equal (Gibbs’ inequality), so the unique optimum is π=π∗\pi=\pi^{*} (paper Eq. 4). This is the classical result. On its own it is useless for training, because Z(x)Z(x) sums over every possible response.

Step 4: invert, so the reward is written with the policy (Eq. 5)

Section titled “Step 4: invert, so the reward is written with the policy (Eq. 5)”

Take logs of π∗\pi^{*} and solve for rr:

r(x,y)=βlog⁡π∗(y∣x)πref(y∣x)+βlog⁡Z(x).r(x,y)=\beta\log\frac{\pi^{*}(y\mid x)}{\pi_{\mathrm{ref}}(y\mid x)}+\beta\log Z(x).

Any reward corresponds to some optimal policy, and vice versa, up to the βlog⁡Z(x)\beta\log Z(x) term, which depends only on xx.

Step 5: plug into Bradley–Terry; Z cancels (Eq. 6)

Section titled “Step 5: plug into Bradley–Terry; Z cancels (Eq. 6)”

Bradley–Terry models a human preference between two responses to the same prompt as 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). Only a reward difference for one xx enters, so βlog⁡Z(x)\beta\log Z(x) subtracts away:

p∗(y1≻y2∣x)=σ(βlog⁡π∗(y1∣x)πref(y1∣x)−βlog⁡π∗(y2∣x)πref(y2∣x)).p^{*}(y_1\succ y_2\mid x)=\sigma\Big(\beta\log\frac{\pi^{*}(y_1\mid x)}{\pi_{\mathrm{ref}}(y_1\mid x)}-\beta\log\frac{\pi^{*}(y_2\mid x)}{\pi_{\mathrm{ref}}(y_2\mid x)}\Big).

Step 6: maximum likelihood over a parameterised policy (Eq. 7)

Section titled “Step 6: maximum likelihood over a parameterised policy (Eq. 7)”

Replace π∗\pi^{*} with πθ\pi_\theta and fit to the dataset D\mathcal{D} of (prompt, winner, loser) triples:

LDPO(πθ;πref)=−E(x,yw,yl)∼D[log⁡σ(βlog⁡πθ(yw∣x)πref(yw∣x)−βlog⁡πθ(yl∣x)πref(yl∣x))]\mathcal{L}_{\mathrm{DPO}}(\pi_\theta;\pi_{\mathrm{ref}})=-\mathbb{E}_{(x,y_w,y_l)\sim\mathcal{D}}\Big[\log\sigma\Big(\beta\log\frac{\pi_\theta(y_w\mid x)}{\pi_{\mathrm{ref}}(y_w\mid x)}-\beta\log\frac{\pi_\theta(y_l\mid x)}{\pi_{\mathrm{ref}}(y_l\mid x)}\Big)\Big]

This is the same logistic loss you would use to train a reward model, but the “reward model” is r^θ(x,y)=βlog⁡πθ(y∣x)πref(y∣x)\hat r_\theta(x,y)=\beta\log\frac{\pi_\theta(y\mid x)}{\pi_{\mathrm{ref}}(y\mid x)}, the implicit reward. Hence the title.

∇θLDPO=−β E[σ(r^θ(x,yl)−r^θ(x,yw))(∇θlog⁡πθ(yw∣x)−∇θlog⁡πθ(yl∣x))]\nabla_\theta\mathcal{L}_{\mathrm{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\mid x)-\nabla_\theta\log\pi_\theta(y_l\mid x)\big)\Big]

The direction raises the winner and lowers the loser. The weight σ(r^l−r^w)\sigma(\hat r_l-\hat r_w) is large when the implicit reward ranks the pair wrongly and fades once the pair is well separated. The paper reports that dropping this weight (plain unlikelihood) makes the model degenerate (Appendix Table 3).

Worked numbers (mine, not the paper’s). Take β=0.1\beta=0.1 and a pair with summed log-ratios +2+2 nats for ywy_w and −3-3 nats for yly_l. Then r^w=0.2\hat r_w=0.2, r^l=−0.3\hat r_l=-0.3, margin 0.50.5. Loss =−log⁡σ(0.5)≈0.474=-\log\sigma(0.5)\approx 0.474 and weight σ(−0.5)≈0.378\sigma(-0.5)\approx 0.378. At initialisation (πθ=πref\pi_\theta=\pi_{\mathrm{ref}}) the margin is 0, the loss is log⁡2≈0.693\log 2\approx 0.693 and the weight is 0.5. Note that πθ(y∣x)\pi_\theta(y\mid x) is a whole-sequence probability, a sum over tokens, so long responses can build large log-ratios quickly.

Classical RLHF pipeline versus DPO Top lane: classical RLHF takes preference pairs, fits a reward model with a Bradley-Terry loss, then runs an online loop that samples from the policy, scores samples with the reward model and penalises KL to the reference, producing the policy. Middle: the derivation that links them, the optimal policy equals the reference times exp of reward over beta divided by Z, so the reward equals beta log of the policy ratio plus beta log Z, and Z cancels in a pairwise comparison. Bottom lane: DPO takes the same preference pairs and trains the policy directly with one logistic loss on the difference of log-ratios against a frozen reference. Classical RLHF: two stages, online loop preference pairs (x, y_w, y_l) fit reward model r_φ (Bradley–Terry loss) sample y ~ π_θ, score with r_φ minus β·KL(π_θ ‖ π_ref) π_θ repeat: generate → score → update (PPO, critic) closed-form optimum: π* = π_ref · exp(r / β) / Z(x) ⇒ r = β·log(π* / π_ref) + β·log Z(x) Bradley–Terry uses r(x, y_w) − r(x, y_l) for the same x, so β·log Z(x) cancels DPO: one offline loss, no separate RM, no sampling loop same preference pairs loss = −log σ(β·LR(y_w) − β·LR(y_l)) LR(y) = log π_θ(y|x) − log π_ref(y|x); π_ref frozen π_θ In memory while training: RLHF with PPO holds policy, reference, RM and critic. DPO holds the policy and a frozen reference.
Original sketch. Top: classical RLHF fits a reward model, then runs an online RL loop that samples from the policy. Bottom: DPO uses the closed-form optimum to fold the reward into the policy, leaving one offline loss over preference pairs with a frozen reference.
  • Bradley–Terry (or Plackett–Luce, Appendix A.3) is the preference model. If preferences are deterministic in the data (one response always wins), the optimal margin is infinite, and the KL term no longer holds the policy back. This is IPO’s critique.
  • The optimum is about the population objective. With finite, offline pairs, responses that never appear in a comparison are not constrained by the loss.
  • The KL is implicit. DPO never measures KL on samples from πθ\pi_\theta. The constraint lives in the parameterisation and in β\beta.
  • Support. π∗\pi^{*} can only put mass where πref\pi_{\mathrm{ref}} does. The paper fine-tunes πref\pi_{\mathrm{ref}} on preferred completions (“Preferred-FT”) when no SFT model exists, to reduce the mismatch between the reference model and the data.
  • Reward vs KL frontier (§6.1, IMDb sentiment, GPT-2-large). Sweeping β\beta for DPO and the target KL for PPO (22 runs), DPO’s frontier is above PPO’s everywhere, including PPO given the ground-truth sentiment reward (Fig. 2, left).
  • TL;DR summarisation (§6.2). With GPT-4 as judge against reference summaries, DPO wins about 61% at temperature 0 vs about 57% for PPO at its best temperature, and DPO degrades less as temperature rises (Fig. 2, right). The authors note they did not meaningfully tune β\beta.
  • Anthropic HH single-turn dialogue (Pythia-2.8B). DPO is the only computationally efficient method that improves on the dataset’s preferred completions, and is similar to or better than Best-of-128 sampling (Fig. 3). The authors could not get a public PPO setup to beat the base model here, so Best-of-128 stands in as a rough proxy for PPO.
  • Distribution shift (Table 1). Policies trained on Reddit TL;DR, evaluated on CNN/DailyMail news: DPO win rates of 0.36 and 0.31 vs PPO’s 0.26 and 0.23 at temperatures 0 and 0.25.
  • Is GPT-4 a fair judge? (§6.4, Table 2). In a human study, GPT-4 agrees with humans about as often as humans agree with each other. However, the simple prompt made GPT-4 prefer longer, more repetitive summaries than humans did, so the authors added a “concise” prompt. This is a length bias in the judge, which is worth remembering for any IR evaluation that uses LLM judges.
  • Authors’ list (§7). Out-of-distribution generalisation compared with an explicit reward model, how reward overoptimisation shows up in DPO, scaling beyond the 6B models tested, and sensitivity of GPT-4 win rates to the judging prompt.
  • Overoptimisation does happen. Later work shows DPO, IPO and SLiC follow the same hump-shaped gold-reward curve as RLHF as KL grows (DAA overoptimization).
  • Deterministic or sparse preferences. Because the target margin is unbounded, DPO can drive a never-winning response’s probability towards zero regardless of β\beta (IPO).
  • Length and judge biases pass straight into the implicit reward (length correlations).
  • Offline data goes stale as the policy moves. Online and iterative variants re-sample and re-label, which brings back part of the RL loop (async RLHF).

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    Starting only from the objective max over π of E[r(x,y)] − β·KL(π ‖ π_ref), derive the optimal policy, invert it to express r in terms of that policy, and show why the intractable partition function Z(x) does not appear in the final DPO loss. Name the one modelling assumption about human preferences that the last step needs.

    What a strong answer covers
    • Write the KL as an expectation and divide by −β: the problem becomes min over π of E_y∼π[log(π/π_ref) − r/β].
    • Define Z(x) = Σ_y π_ref(y|x)·exp(r(x,y)/β) and π* = π_ref·exp(r/β)/Z. The bracket equals log(π/π*) − log Z, so the objective is KL(π ‖ π*) − log Z(x).
    • Z does not depend on π and KL ≥ 0 with equality only at π = π* (Gibbs), so π* is the unique optimum.
    • Taking logs: r(x,y) = β·log(π*(y|x)/π_ref(y|x)) + β·log Z(x).
    • Under Bradley–Terry, P(y_w ≻ y_l | x) = σ(r(x,y_w) − r(x,y_l)). Both responses share the same x, so the β·log Z(x) terms subtract away; maximum likelihood over π_θ then gives the DPO loss.
  2. Derive / compute

    Take β = 0.1. For one pair, the summed log-ratios are log π_θ(y_w)/π_ref(y_w) = +2 and log π_θ(y_l)/π_ref(y_l) = −3 nats. Compute the DPO loss and the scalar weight in front of the gradient. Then compute both at initialisation (π_θ = π_ref), and for a pair where the two log-ratios are swapped. What does the trend tell you about which pairs DPO learns from?

    What a strong answer covers
    • Implicit rewards r̂ = β·log-ratio: r̂_w = 0.2, r̂_l = −0.3, margin 0.5. Loss = −log σ(0.5) = −log 0.622 ≈ 0.474. Weight σ(r̂_l − r̂_w) = σ(−0.5) ≈ 0.378.
    • At initialisation the margin is 0: loss = log 2 ≈ 0.693, weight 0.5.
    • Swapped log-ratios give margin −0.5: loss = −log σ(−0.5) ≈ 0.974, weight σ(0.5) ≈ 0.622.
    • The weight is large when the implicit reward model ranks the pair wrongly and decays towards 0 as the margin grows, so well-separated pairs stop contributing.
    • Because the log-ratios are summed over tokens, long responses can produce large margins quickly. This is one reason SimPO later normalises by length.
  3. Mechanism

    The DPO gradient raises log π_θ(y_w) and lowers log π_θ(y_l), but scaled by σ(r̂_l − r̂_w). Explain what the paper says happens if you drop this weight and run plain unlikelihood training, and why the weight acts as a guard against degeneration.

    What a strong answer covers
    • Without the weight every pair pushes with the same force for ever, even when the policy already prefers y_w by a wide margin.
    • Lowering log π(y_l) without limit is easy for a language model: it can move mass to strange text. The paper reports that the naive unweighted version degenerates (Appendix Table 3).
    • With the weight, a pair stops contributing once the implicit reward margin is large, so the policy stays near π_ref where it has not been told otherwise.
    • β sets the scale: the weight depends on β times the log-ratio gap, so larger β means each nat of drift counts more and the weight saturates sooner.
  4. Critique

    A colleague says "DPO is just supervised learning, so it has nothing to do with RL or KL control." Give a precise rebuttal, then give the strongest version of their point: what part of the RLHF objective does DPO not enforce on its own outputs, and what experiment would expose it?

    What a strong answer covers
    • Rebuttal: DPO is derived from the same KL-regularised reward-maximisation objective as RLHF, and under Bradley–Terry with full coverage its optimum is the same policy.
    • What it drops is the online loop. It never samples from π_θ during training, never scores those samples, and never measures KL on them. The KL is implicit in the parameterisation.
    • With finite offline data, responses that never appear in a pair are unconstrained. Their implicit reward can move freely, which is how DPO can overoptimise.
    • Experiment: train DPO with several β values, then measure true KL to π_ref on fresh samples and a held-out gold reward or human score against that KL. Compare with PPO and with online or iterative DPO.
  5. What if…

    On IMDb sentiment the paper sweeps β for DPO and the target KL for PPO, then plots reward against KL to the reference policy. Why is this frontier the right comparison instead of final reward alone? What does "DPO dominates even PPO with the ground-truth reward" show, and what does it not show?

    What a strong answer covers
    • Each method trades reward for drift. A method can always buy more reward by moving further from π_ref, so you have to compare at matched KL.
    • DPO's points lie above PPO's at every KL, including PPO that is given the true sentiment classifier as reward. So the gap is in optimisation, not in reward-model error.
    • It does not show that DPO wins on open-ended tasks with learned rewards and noisy labels, at larger scale, or out of distribution. The authors list these as open questions.
    • The setting is small (GPT-2-large) with a clean, cheap ground-truth reward, which is rarely available in practice.
  6. Design

    You have 50k (query, passage-grounded answer A, answer B) pairs labelled by an LLM judge for a RAG answer generator, all sampled from last year's model. Argue whether to use DPO directly, PPO with a reward model trained on the same pairs, or iterative DPO with fresh samples, and say what you would monitor during training.

    What a strong answer covers
    • DPO is cheapest: two models in memory (policy and frozen reference), no sampling during training, and stable optimisation.
    • The pairs are off-policy (old model) and judge-labelled. DPO cannot see its own new failure modes, while an RM plus online RL, or iterative DPO with new samples labelled by the judge, can.
    • Judge biases such as length or verbosity become implicit-reward biases. Track response length, citation precision and grounding, not only judge win-rate.
    • Monitor: implicit reward margins and accuracy on held-out pairs, log-probabilities of chosen and rejected answers, KL to the reference on fresh samples, and a small human or gold-label check.

Done with this page?

Status