← Back to writing

Direct preference optimization: what the paper actually says

Reading Rafailov et al. (Stanford, NeurIPS 2023) after a 3-hour PPO run crashed with reward hacking at KL=0.05 and learned nothing at KL=0.5.

We were fine-tuning a model to be more helpful and less prone to confident nonsense. The standard path: collect pairwise preferences, train a reward model, run PPO. The PPO loop crashed at hour three. KL penalty too low — the policy found a reward-hacking mode where padding tokens after the period got high scores from the reward model because they looked like confident endings. Crank the KL penalty and the model learned nothing — it diverged from the reference so little that it was essentially still the SFT model. Meanwhile the reward model was giving 9.2/10 to responses that were fluent but factually wrong.

Someone on the team sent the DPO paper. We read it over the weekend and ran our first DPO experiment by Monday morning. The PPO infrastructure sat unused.

"Direct Preference Optimization: Your Language Model is Secretly a Reward Model" — Rafailov, Sharma, Mitchell, Manning, Ermon, Finn. Stanford University. NeurIPS 2023.

The problem RLHF is actually solving

Standard instruction tuning (SFT) is a maximum likelihood problem: given a prompt, maximize the log-probability of a target response. This works, but it forces you to specify exactly what you want for every prompt. Human preferences are easier to express comparatively — "this response is better than that one" — and sometimes you can't produce a high-quality target response yourself, only judge between candidates.

RLHF addresses this by separating the feedback signal from the training signal. The three-stage pipeline:

  1. Collect human preferences: for each prompt x, show annotators two responses y_w (winner) and y_l (loser), record which is preferred.
  2. Train a reward model r(x, y) using a Bradley-Terry pairwise model — the reward model learns to assign higher scores to preferred responses.
  3. Fine-tune the LLM using RL (typically PPO) to maximize expected reward while staying close to a reference policy (usually the SFT model) via a KL penalty.

The KL-constrained objective:

max_π  E[r(x,y)] - β * KL[π || π_ref]

β controls the tradeoff between reward maximization and staying close to the reference. This pipeline works — InstructGPT used it, and so did every major aligned model for years. But it has compounding operational complexity:

  • Three separate training phases with separate hyperparameter budgets
  • PPO is notoriously sensitive and can destabilize on large models
  • The reward model must be served at full inference scale during RL training
  • Reward hacking is a real problem: the RL policy finds ways to maximize the proxy reward that diverge from actual human intent
  • Monitoring requires tracking reward scores, KL divergence, policy entropy, and value function convergence simultaneously — and they interact

The DPO paper's contribution is showing that this entire apparatus has an exact mathematical shortcut.

The key insight: the optimal policy has a closed form

The DPO paper starts from the observation that the KL-constrained RLHF objective has an analytical solution. You don't need RL to find it — the optimal policy can be written in closed form.

The solution to the constrained optimization problem:

π*(y|x) = (1/Z(x)) * π_ref(y|x) * exp(r(x,y)/β)

where Z(x) is the partition function that normalizes this to a valid probability distribution:

Z(x) = Σ_y π_ref(y|x) * exp(r(x,y)/β)

Z(x) is intractable — you can't compute it by summing over all possible completions. The usual move is to treat this as an actor-critic problem and use RL to approximately optimize. DPO makes a different move: rearrange to express the reward as a function of the optimal policy.

From the equation above:

r(x,y) = β * log(π*(y|x) / π_ref(y|x)) + β * log Z(x)

Now substitute this into the Bradley-Terry preference model. Under Bradley-Terry, the probability that y_w is preferred over y_l is:

p(y_w > y_l | x) = σ(r(x, y_w) - r(x, y_l))

When you compute the reward difference, the β * log Z(x) terms cancel — they're identical for both responses because Z depends only on the prompt. What remains:

p(y_w > y_l | x) = σ(β * log(π*(y_w|x)/π_ref(y_w|x)) - β * log(π*(y_l|x)/π_ref(y_l|x)))

The partition function is gone. The preference probability depends only on log-probability ratios between the optimal policy and the reference — quantities you can compute. Replace π* with your parameterized policy π_θ and maximize likelihood of observed preferences. The DPO loss:

L_DPO = -E[(x,y_w,y_l)] [log σ(β * (log π_θ(y_w|x)/π_ref(y_w|x) - log π_θ(y_l|x)/π_ref(y_l|x)))]

That's the complete training objective. No reward model. No RL. One loss function over preference triples (x, y_w, y_l). Standard binary cross-entropy over your preference dataset.

The gradient of this loss increases the log-probability ratio of chosen responses and decreases the log-probability ratio of rejected responses — weighted by how confident the implicit reward model (the current policy itself) already is. High-confidence examples get smaller gradients. Uncertain examples get larger gradients. This is the right weighting behavior, and it falls out of the math rather than being designed in.

What the performance numbers actually say

The paper evaluates on three tasks: sentiment-controlled text generation, summarization (Reddit TL;DR), and single-turn dialogue (Anthropic HH). The core comparison is DPO versus PPO-based RLHF at matched compute budgets.

Results on GPT-J (6B) for TL;DR summarization: win rate versus human-written summaries is ~67% for DPO compared to ~65% for PPO-RLHF. On the HH dialogue benchmark, DPO at 6B outperforms best-of-128 sampling under a reward model — meaning DPO with one sample per request matches the quality of generating 128 responses and picking the highest-scored one. That's a striking result, though it's specific to this model size and benchmark.

The paper also plots win rate versus KL divergence from the reference policy. DPO reaches competitive win rates at lower KL — it extracts more preference signal per unit of distributional shift. The theoretical explanation: DPO is optimizing the exact RLHF objective, not approximating it with PPO. There's no optimization gap from the RL approximation.

These numbers don't directly translate to 70B models on production annotation schemes. But the directional result — DPO competitive with PPO at lower complexity — held up in subsequent work and in the deployment experience of teams that adopted it through 2023–2024.

Production tradeoffs no one mentions in the benchmark post

You need a stable SFT model as the reference, not the base model. DPO optimizes the ratio π_θ(y|x) / π_ref(y|x). If the reference model is far from your domain distribution — you're using a base model as reference but your preference data is about customer service conversations — the log-ratio gradients are noisy and training is slow. Standard practice: SFT on domain data first to produce the reference model, then DPO against that reference. The SFT step is not optional, and it's not just initialization; it's defining the comparison baseline that the entire DPO loss is computed against.

β has no obvious in-training tuning signal. The standard range in practice is β ∈ [0.05, 0.5]. Too low: policy diverges from the reference, hallucination rates increase, the model generates fluent but untethered outputs. Too high: the policy barely moves; you're paying training compute for negligible behavioral change. Unlike PPO — where you can watch reward scores, KL, and entropy as live training metrics — DPO doesn't surface these naturally. You have to add explicit monitoring for chosen-response log-prob, rejected-response log-prob, and the log-ratio gap separately. Without that instrumentation, β tuning is blind.

The implicit reward is usable but rarely used. The DPO-trained model has an implicit reward score: β * log(π_θ(y|x) / π_ref(y|x)). You can compute this at inference time to rank multiple candidates, implement best-of-N sampling, or do output reranking. Most production deployments don't use it — they treat the DPO model as a chat model and ignore the implicit scoring capability. This is leaving quality on the table. If your latency budget allows 4–8 samples per request, best-of-N with the implicit reward is a straightforward quality improvement that requires no additional infrastructure beyond the reference model you already have.

Preference data quality has nowhere to hide. In RLHF, the reward model is trained on the preference data and acts as a noise smoother — individual annotation errors average out across thousands of training examples. In DPO, each preference triple is a direct training signal. A pair where y_w is only marginally better than y_l, or where two annotators would disagree, generates contradictory gradient signals. Teams that deploy DPO with preference data built for reward model training — noisy, 60% inter-annotator agreement, many borderline cases — routinely see worse results than teams that invest in clean, high-contrast preference pairs with 85%+ agreement.

Memory budget for the reference model. DPO requires the reference model to be loaded during training for log-prob computation. In full fine-tuning of a 70B model, you're already using 140 GB+ in BF16 for the trainable policy. Loading a second frozen copy of the same model doubles that. In practice, most teams use LoRA-based DPO — freeze the base weights, apply DPO gradients to a low-rank adapter, keep the reference as the same base weights with no adapter. This works but means the reference can't be a separately fine-tuned SFT model; it's always the base model. The tradeoff is memory feasibility versus reference model quality.

Failure modes in practice

Chosen-response log-probability decreasing during training. This is the most alarming metric to watch and the most commonly misunderstood. The DPO loss optimizes the gap between chosen and rejected log-probability ratios — not the absolute log-probability of chosen responses. The gradient can decrease the log-prob of chosen responses if it decreases the log-prob of rejected responses even faster. The loss still goes down; the preferred responses become less likely. This was identified as a degenerate behavior in follow-up work (IPO, DPO-positive). Monitor log π_θ(y_w|x) as a standalone training metric. If it trends downward throughout training, β is too low or your preference data has inconsistencies.

Safety behavior erosion after DPO. SFT bakes in refusal behavior and safety-relevant response patterns. DPO fine-tunes on preference pairs that are typically focused on helpfulness, tone, or task quality — not safety scenarios. The DPO objective has no cross-entropy term on chosen responses, so behaviors not reinforced by the preference data drift. If your SFT model had safety fine-tuning and your DPO preference pairs don't include safety-relevant prompts, DPO can erode safety behaviors silently over training epochs. Always run safety evaluation suites after DPO, not just the preference task metrics.

Multi-objective preference conflicts. You have preference pairs for helpfulness and add pairs for factual accuracy. The model now receives contradictory signals on the same prompt class: sometimes the longer, more confident response wins (helpfulness pairs); sometimes the shorter, more hedged response wins (accuracy pairs). DPO has no mechanism to separate these objectives — it tries to satisfy all pairs jointly. Performance on both degrades. Multi-dimensional alignment requires either separate DPO runs on filtered subsets, careful data mixing ratios, or a reward model that explicitly represents multiple dimensions.

Iterative DPO reference drift. A natural iteration strategy: run DPO, generate new responses from the trained model, collect preferences on those responses, run another DPO round. By iteration three, the policy has drifted far enough from the original reference that the log-ratio is no longer a useful gradient signal — everything looks like a large deviation from the reference. Online DPO variants (using the current policy as the reference at each step) fix this but reintroduce some complexity. If you're doing iterative DPO, re-evaluate reference model validity before each round.

When not to use direct preference optimization

When you need a deployable scoring signal. If your inference pipeline uses Best-of-N reranking, or test-time compute scaling (generate many candidates, rank by reward, return the best), you need a reward model that can score individual responses efficiently. DPO's implicit reward requires computing log-probs from two models — policy and reference — per candidate. For N=16 candidates, that's 32 forward passes versus 16 for a dedicated reward model, and the reference model must stay loaded at inference time. A trained reward model is cleaner operationally for scoring use cases.

When your preference data is scalar or ordinal. DPO requires pairwise comparisons: response A is preferred over response B. If your annotations are scalar ratings (1–5) or rankings across more than two responses, you must convert to pairwise format, which loses signal. A 5/5 versus 4/5 pair is different information than 4/5 versus 2/5 — DPO treats both as equivalent preference pairs. KTO (Kahneman-Tversky Optimization) handles non-pairwise feedback more naturally and may be a better fit when your annotation scheme doesn't produce clean pairs.

When the task has verifiable outcomes. For tasks where you can verify correctness — code execution, math with known answers, structured output validated against a schema — RLHF with an online verifier is stronger than offline DPO. The verifier can generate signal on novel outputs not in your preference dataset. DPO is a purely offline algorithm; it can only optimize toward your existing preference distribution. This is the core reason frontier model training for coding and math tasks uses PPO or GRPO variants even after DPO became mainstream for chat alignment.

When your SFT model is already close to the target. DPO training is a full fine-tuning compute cost over multiple epochs of a preference dataset. If your SFT model captures 80%+ of the target behavior and your preference dataset is under 5K pairs, the marginal improvement from DPO may not justify the training run. Prompt engineering or few-shot examples in the system prompt iterate faster in this regime.

When inter-annotator agreement is below ~70%. If your annotators disagree on which response is preferred more than 30% of the time, the preference pairs are too noisy for DPO to extract clean gradient signal. The contrastive loss amplifies disagreement rather than averaging over it the way a reward model can. Either tighten the annotation task definition, use a reward model that can smooth over more annotations, or reconsider whether your preference task is well-specified.

What the paper actually gives you

DPO's formal contribution is a proof that RL is not a required component of RLHF. The KL-constrained reward maximization objective — the thing PPO approximates — has a closed-form optimal solution. That solution can be expressed as a function of log-probability ratios between the policy and a reference, and optimizing it directly is equivalent to binary cross-entropy over preference pairs. No reward model. No RL loop. No partition function.

The practical implication is that preference fine-tuning becomes a standard supervised learning problem — same training infrastructure, same debugging primitives, same scaling behavior you already understand from SFT. The barriers that made RLHF a specialized capability disappear.

Subsequent work extended the foundation: IPO adds regularization to prevent overconfidence on preference margins, KTO reformulates the loss in prospect-theoretic terms for non-pairwise feedback, online DPO variants close the gap for tasks requiring exploration. DPO is best understood as the paper that made preference optimization accessible, not the final word.

The 3-hour PPO crash from the opening — reward hacking at KL=0.05, no learning at KL=0.5 — doesn't happen with DPO. What you get instead is more tractable: tune β, watch chosen-response log-probs as a training metric, iterate on annotation quality. The failure modes are visible and debuggable. The PPO infrastructure is still running for tasks with verifiable rewards. DPO handles everything else, and it handles it with a single hyperparameter and a loss function you can read in one line.


Direct Preference Optimization: Your Language Model is Secretly a Reward Model — Rafailov, Sharma, Mitchell, Manning, Ermon, Finn. Stanford University. NeurIPS 2023. Training language models to follow instructions with human feedback (InstructGPT) — Ouyang, Wu, Jiang, et al. NeurIPS 2022. A General Theoretical Paradigm to Understand Learning from Human Feedback (IPO) — Azar, Rowland, Piot, et al. arXiv 2023.