knowledge base · entry 16
Your language model is secretly a reward model
A read-through of Direct Preference Optimization: Your Language Model is Secretly a Reward Model. Entry 15 built a four-model pipeline to learn from human preferences. This paper does the algebra that makes half of it vanish — same objective, no reward model, no RL loop, one supervised loss. It is why a two-GPU team can now afford preference tuning.
every figure zooms — click it, scroll to magnify, drag to pan
part one
The idea, before any algebra
figure 1 · two routes to the same place
Delete the middleman
RLHF’s route to “prefer the better answer” is long: fit a reward model to human comparisons, then run PPO — with a value network and a frozen reference copy along for the ride — to chase that reward. Four models in memory, a sampling loop, and PPO’s famous instability. DPO’s observation: the destination of that whole journey can be written down directly as a loss on the preference pairs themselves.
click any figure to zoom · scroll to magnify · drag to pan
Nothing about the goal changes — it is the same KL-leashed reward maximization as entry 15. What changes is that the reward model and the RL loop turn out to be scaffolding you can fold into the loss and throw away.
part two · the trick
The algebra that deletes the pipeline
figure 2 · the change of variables
Solve for the policy, then read it backwards
The KL-constrained reward objective has a known closed-form optimum:
π*(y|x) ∝ πref(y|x)·exp(r(x,y)/β) — boost
the reference model’s probabilities wherever reward is high. DPO’s move is to
read that equation backwards: solve it for the reward, and every reward function
becomes expressible through the policy it would produce:
r(x,y) = β·log π(y|x)/πref(y|x) + β·log Z(x).
The awkward term is Z(x), a sum over every possible answer — uncomputable. And here is
the gift: human preferences under the Bradley–Terry model depend only on reward
differences, and in a difference, Z(x) cancels.
That cancellation is the entire paper. Preferences compare two answers to the same prompt, so the one intractable object never needs to exist. What remains is written purely in probabilities the language model already computes.
figure 3 · the loss
One line, four probabilities
Substitute the reparameterized reward into the Bradley–Terry likelihood and out falls the DPO loss — a binary cross-entropy over preference pairs. For each triple (prompt, chosen answer yw, rejected answer yl), gather four numbers: the policy’s and the reference model’s log-probabilities of both answers. Push the chosen margin up, the rejected margin down, through a sigmoid, scaled by β.
Training is: freeze a copy of your SFT model as the reference, run both models over a batch of pairs, compute the loss, backpropagate. No sampling during training, no reward model, no value network — a preference stage that behaves like ordinary fine-tuning.
figure 4 · worked by hand
The loss on one toy pair
To feel the mechanics, run one pair through by hand with β = 0.5, in per-token-averaged log-probabilities. The model slightly prefers the rejected answer — so the implicit reward margin comes out negative, the sigmoid weight comes out large, and this pair teaches a strong lesson.
Run the same arithmetic on a pair the model already orders correctly and the weight shrinks toward zero — DPO spends its gradient where the model is wrong, which is precisely what keeps it from over-optimizing pairs it has already learned.
figure 5 · the gradient
A gradient that knows how wrong it is
Differentiate the loss and the structure is legible: increase the likelihood
of the chosen answer, decrease the rejected one — with the whole update scaled
by σ(r̂l − r̂w), the model’s
own estimate of how badly its implicit reward mis-orders the pair. Confidently-correct
pairs contribute almost nothing; confidently-wrong pairs dominate the batch.
part three · the evidence
Does the shortcut lose anything?
results · summarization
Matches PPO at its best — and doesn’t fall over
On Reddit TL;DR summarization, judged by GPT-4 against human-written references, DPO reaches about a 61% win rate at temperature 0 — above PPO’s 57% at its best temperature. The sharper finding is robustness: sweep the sampling temperature and PPO’s win rate collapses toward the base model’s, while DPO’s barely moves. On Anthropic helpful-harmless dialogue, DPO is the only computationally cheap method that improves on the dataset’s own preferred completions — roughly matching a 128-sample best-of-n that costs two orders of magnitude more compute at inference.
| method | machinery | TL;DR win rate | across temperatures |
|---|---|---|---|
| DPO | one loss, two model copies | ≈61% | stays flat |
| PPO (RLHF) | reward model + value net + sampling | ≈57% at its best | degrades sharply |
| best-of-128 | 128 samples + reward model, per query | competitive | — (unaffordable) |
| SFT only | imitation | well below | — |
part four · the descendants
The family it spawned
figure 7 · the DPO family
Pick by the data you can actually collect
DPO’s simplicity made it a foundation to iterate on, and the descendants are best told apart by one question: what feedback can you actually gather? Paired comparisons → DPO (or IPO if it overfits). Only independent thumbs-up/thumbs-down → KTO. Want to skip the separate SFT stage → ORPO. Memory too tight for a reference copy → SimPO. All of them are one-line trainer swaps in today’s tooling.
the finding that outranks the choice across this whole family, the quality of the preference pairs dominates the choice of loss. A better dataset beats a fancier objective almost every time — which is entry 14’s lesson, again, one stage later.
the math · in the paper's notation
The derivation, in three equations
The three lines the prose above walked around — the optimum, the loss, and the gradient, numbered as the paper numbers them. With these decoded, section 4 of the PDF reads in one pass.
the equations · worked
Solve, substitute, differentiate
eqs. (4)–(5) · the optimum, read backwards
πr(y|x) = 1Z(x) πref(y|x) · exp( r(x,y) / β )
⟹ r(x,y) = β·log πr(y|x)πref(y|x) + β·log Z(x)
read aloud: the best KL-leashed policy boosts the reference model wherever reward is high — so, backwards, any reward is β times the log of how much a policy boosts the reference, plus a term that depends only on the prompt. That prompt-only term Z(x) sums over every possible answer and cannot be computed — and in the next line it will never need to be.
- πrefthe frozen SFT model — InstructGPT's πSFT, renamed
- βthe same KL leash strength as in entry 15's equation (2)
- Z(x)the partition function: the normalizer over all answers to x — intractable, and about to cancel
eq. (7) · the DPO loss
ℒDPO = −E [ log σ( β·log πθ(yw|x)πref(yw|x) − β·log πθ(yl|x)πref(yl|x) ) ]
read aloud: substitute the backwards-read reward into the Bradley–Terry preference model, watch Z(x) cancel in the difference, and what remains is a binary cross-entropy on the margin between two log-ratios. Four log-probabilities per pair — policy and reference, chosen and rejected — and nothing else.
- ywthe chosen answer of the pair…
- yl…and the rejected one
- β·log π/πrefthe implicit reward r̂ — the language model scoring answers without a reward model existing
eq. (8) · the gradient — where the intuition lives
∇ℒ = −β·E [ σ( r̂l − r̂w ) · ( ∇log πθ(yw|x) − ∇log πθ(yl|x) ) ]
read aloud: raise the chosen answer's likelihood, lower the rejected one's — with the whole step scaled by how badly the implicit reward mis-orders the pair. The green factor is figure 5's "knows how wrong it is" weight: near 0 on pairs already ordered correctly, near 1 on confident mistakes.
- r̂w, r̂lthe implicit rewards of the chosen and rejected answers, from the card above
part five
What we take from it
applied · our reading
Preference tuning for teams without an RL bench
- Default to SFT → DPO. It is stable, cheap, debuggable with ordinary fine-tuning intuition, and it removes the classic excuse — “we don’t have RLHF infrastructure” — for shipping an unaligned domain model. Add complexity only when you can name the specific gain.
- Design the review queue to emit pairs. Every expert correction of a model draft is a (rejected, chosen) pair with the prompt attached. Log them from day one and the preference dataset builds itself as a by-product of normal review work — the richest cheap signal a domain team has.
- Mind what β is holding back. The reference model is the only thing standing between you and reward hacking without a reward model — DPO can still over-shoot on narrow data. Keep the KL anchor honest: reasonable β, fresh SFT reference, and an eval you did not train on (entry 15’s tax lesson applies unchanged).
Next in the arc: the other half of affordability. Preference tuning became one loss; entry 17 makes the hardware fit on one GPU.
source
Rafael Rafailov, Archit Sharma, Eric Mitchell, Stefano Ermon, Christopher D. Manning, Chelsea Finn. Direct Preference Optimization: Your Language Model is Secretly a Reward Model. arXiv:2305.18290. Figures on this page are our own; the derivation, win rates and robustness finding are the paper’s, the worked example uses toy numbers, and the family entries cite their respective papers (IPO, KTO, ORPO, SimPO).
← back to the knowledge base · ← entry 15 · InstructGPT · entry 17 · QLoRA →
attention.sh — a division of Jinacode Systems. Transformers,
fine-tuning, and sovereign LLMs.
we're hiring the curious — hello@attention.sh