Paper 07~12 min readNeurIPS 2023worked math + runnable code
Paper Breakdown

Direct Preference
Optimization, explained.

Teaching a model to be helpful and harmless used to mean building a second AI to grade the first, then running finicky reinforcement learning to chase those grades — a Rube Goldberg machine that fell over constantly. This 2023 paper proved you can throw the whole contraption away and get there with one ordinary training loss.

Written breakdown
This one is a written deep-dive.
Paper, mechanism, worked math and a runnable version — all below ↓
01

The RLHF machine

The reason a raw language model becomes a helpful assistant is alignment — tuning it to prefer the responses humans actually like. The dominant recipe, RLHF (reinforcement learning from human feedback), does this in three stages: collect human preferences (this answer is better than that one), train a separate reward model to imitate those judgments, then use reinforcement learning (PPO) to push the model toward high-reward outputs.

It works — it's how ChatGPT was aligned — but that third stage is a beast. Reinforcement learning on a giant model is memory-hungry, hyperparameter-sensitive, prone to instability, and happy to "reward-hack" by finding cheap tricks that score high without being good.

02

The insight: your model is already the reward model

DPO's authors did the algebra everyone had skipped. They showed that the reward function RLHF works so hard to learn can be rewritten in terms of the model's own probabilities relative to a frozen reference copy. The policy and the reward aren't two separate things to train — they're two views of the same object.

The paper's memorable framing: your language model is secretly a reward model. If that's true, you never need to build the reward model or run RL against it. You can optimize the model directly.

03

One loss instead of three stages

DPO uses the exact same data as RLHF — pairs of a chosen (preferred) and a rejected response for each prompt — but trains with a single, supervised, classification-style loss: raise the model's probability of the chosen response and lower the rejected one, gently anchored to the reference model so it doesn't drift.

RLHF vs DPO
RLHF — 3 stages
1 · Collect preference pairs
2 · Train a reward model
3 · Optimize with PPO (RL)
DPO — 1 stage
1 · Collect preference pairs
2 · One direct loss on the model
— no reward model, no RL —

Same inputs, same goal, two stages deleted.

04

The loss, worked with real numbers

Here is the entire method as one line. For a prompt x with chosen response yw and rejected response yl:

Each bracketed term is a log-ratio: how much more (or less) the policy likes a response than the frozen reference does. The paper's key claim is that β times this log-ratio is the reward — the reward model RLHF trains separately already lives implicitly inside the policy. Concrete numbers, with β = 0.1:

QuantityChosen ywRejected yl
log πθ (policy)−10−9
log πref (reference)−12−7
Log-ratio (implicit reward ÷ β)+2 — policy likes it more than ref−2 — policy likes it less

Margin = 2 − (−2) = 4, so the loss is −log σ(0.1 × 4) = −log σ(0.4) = −log 0.5987 = 0.513. Three behaviors fall straight out of the formula:

SituationMarginLossGradient weight σ(−βΔ)
Model prefers the right answer (above)+40.5130.40 — keep nudging
Model has no preference yet0log 2 = 0.6930.50
Model prefers the wrong answer−40.9130.60 — pushed hardest

That last column is DPO's quiet elegance: the gradient on each pair is scaled by σ(−βΔ) — how wrong the model currently is about that pair. Examples it already ranks correctly fade; examples it ranks backwards shout. And β controls the anchor: small β lets the policy drift far from the reference, large β pins it close — the same KL-leash PPO enforces with machinery, achieved by one scalar.

05

Why it's stable

PPO is online reinforcement learning: it samples fresh outputs from the model, scores them, updates, and repeats — a feedback loop with many ways to wobble. DPO is offline and supervised: a fixed dataset of preference pairs, one loss, gradient descent. It trains as calmly and reproducibly as ordinary fine-tuning, on far less hardware.

Worth knowing

The practical unlock is accessibility: a team that could never stand up a stable PPO pipeline can run DPO with a standard training script, which is a big part of why open models aligned so quickly after 2023.

RUN IT YOURSELF

The DPO loss in 15 lines

The complete loss from the worked example, running in your browser through WebAssembly. Feed it the four log-probabilities and β; get the loss and the implicit rewards. Run it to reproduce the 0.513 from above, then flip the preference or shrink β and watch the gradient weight respond exactly as the table predicts.

CPython · WebAssembly
sigmoid(0) is 0.5 :: abs(sigmoid(0) - 0.5) < 1e-9 ;; the chosen response earns a higher implicit reward than the rejected :: dpo_loss(-10,-12,-9,-7,beta=0.1)['reward_chosen'] > dpo_loss(-10,-12,-9,-7,beta=0.1)['reward_rejected']">
06

The real results

Across sentiment control, summarization, and single-turn dialogue, DPO matched or beat PPO-based RLHF on how well outputs aligned with human preferences — while being dramatically simpler to implement and train, and far more stable.

Reward model?RL loop?Stability
RLHF (PPO)Yes — separate modelYes — online RLFragile
DPONoNoStable, supervised
07

Why it still matters

DPO became the default alignment method for a huge fraction of open models — its simplicity made preference tuning something any team could do. It also opened a whole family of direct-preference variants (IPO, KTO, ORPO and more), each tweaking the loss for different data or goals.

More deeply, it's a lesson in looking harder before reaching for heavy machinery: an entire reinforcement-learning stage turned out to be unnecessary once someone did the math. Sometimes the reward model you're training is already sitting inside the model you have.

07

Why it still matters

DPO — Direct Preference Optimization — made aligning a model to human preferences dramatically simpler. Classic RLHF is a two-stage pipeline: train a separate reward model on preference data, then use reinforcement learning (PPO) to optimize the policy against that reward — fiddly, unstable, and compute-heavy. DPO collapses both stages into a single supervised-style loss on the preference pairs directly, with no reward model and no RL loop.

The insight is mathematical: the optimal RLHF policy has a closed-form relationship to the reward, so you can rewrite the objective to optimize the policy directly from the "chosen vs rejected" pairs. The model learns to raise the likelihood of preferred responses and lower the likelihood of dispreferred ones, relative to a frozen reference model that keeps it from drifting too far.

The practical payoff is huge: DPO is far more stable to train, needs no reward-model infrastructure, and runs on ordinary supervised-training setups — which is why it and its variants became the default alignment method for most open-weight models. Where full RLHF was the province of large labs, DPO put preference-tuning within reach of anyone who can fine-tune a model.

It is not strictly better at everything — online RL methods can still edge it on some objectives, and DPO is sensitive to the quality and coverage of the preference data. But as the simple, stable, reproducible baseline that captures most of RLHF's benefit at a fraction of the complexity, DPO reset the field's default and spawned a family of successors (IPO, KTO, ORPO, and more).

Frequently asked

Quick answers

What is DPO?

A method that aligns a model to human preference pairs directly, with one classification-style loss — no separate reward model and no reinforcement learning.

How is it different from RLHF?

RLHF trains a reward model then optimizes with PPO (RL). DPO proves you can skip both and optimize the policy directly from the same preference data.

"Your LM is secretly a reward model"?

DPO shows the RLHF reward can be rewritten in terms of the model's own probabilities vs a reference — so policy and reward are the same object, and you can optimize directly.

Why is it more stable than PPO?

PPO is online RL with many fragile moving parts; DPO is a simple supervised loss over a fixed dataset, as stable as ordinary fine-tuning.

What data does DPO need?

Preference pairs — a chosen and a rejected response per prompt — the same data RLHF collects, with no reward labels beyond the comparison.

Direct Preference Optimization: Your Language Model is Secretly a Reward Model · Rafailov, Sharma, Mitchell, Ermon, Manning, Finn · NeurIPS 2023 · read the original paper on arXiv → · Vibe Engines · 2026
Finished this one? 0 / 111 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns