TL;DR
Direct preference optimization (DPO) fine-tunes a language model on pairs of answers to the same prompt, one preferred by a person and one rejected. It needs no separate reward model and no reinforcement learning loop. The loss is a simple logistic classification loss that raises the model's probability of the preferred answer relative to the rejected one, measured against a frozen reference model so the model does not drift too far.
Where you'll see it: the preference-tuning stage that follows supervised fine-tuning in many open chat models, and in alignment pipelines where teams want RLHF-like behaviour without running a PPO loop.
Intuition
Learning from "this one is better"
Suppose you are teaching someone to write short summaries. Telling them a score for each summary is hard, because scores drift and mean different things from one day to the next. Showing them two summaries and saying "this one is better" is much easier, and people agree on those comparisons more reliably.
Classic RLHF uses such comparisons in two steps. First it trains a Reward Model to give each answer a score that predicts which answer people prefer. Then it runs reinforcement learning to make the language model produce answers that the reward model scores highly, while a penalty keeps the model close to where it started. That works, but it is fragile. It needs a second model, it needs sampling from the policy during training, and the reinforcement learning step is sensitive to its settings.
DPO asks a different question. If the reward model and the optimal policy are tied together by a fixed mathematical relation, then we can skip the reward model entirely and fit the language model directly to the comparisons. The language model itself plays the role of the reward model. Its own probabilities, measured against a reference model, become an implicit score.
flowchart LR P[Prompt x] --> W[Preferred answer y_w] P --> L[Rejected answer y_l] W --> R[Implicit reward: log ratio to reference] L --> R R --> Loss[Logistic loss on the difference] Loss --> U[Update the language model]
The data is fixed in advance. Each example is a prompt and two answers, and the training is ordinary gradient descent on a single loss.
The math
The preference model
Let be a prompt and two candidate answers. Assume there is a hidden reward function that measures how good an answer is, and that people choose between answers according to the Bradley-Terry model. This model says the probability that is preferred to is
Here turns a score into a positive number, and is the sigmoid function. The only thing that matters is the difference of the two scores. Writing for the preferred answer and for the rejected one, the probability of the observed label is .
Fitting a reward model means choosing a network to maximise this probability over a dataset of labelled pairs. That is the step DPO wants to skip.
The optimal policy under a KL constraint
RLHF maximises expected reward while penalising the KL divergence from a reference policy , usually the supervised fine-tuned model. For a reward and a strength the objective is
Here controls how far the policy may move from the reference: a large keeps it close, and a small lets it chase reward. Its optimum has a closed form,
where is a normalising constant that depends only on the prompt. The optimal policy reweights the reference by the exponentiated reward and renormalises.
Rearranging the reward
Take logarithms of the optimal policy and solve for the reward:
This is the key step. Any reward can be written as a scaled log ratio between a policy and the reference, plus a term that depends only on the prompt. Plug this into the Bradley-Terry model and the terms cancel, because they appear in both answers' scores and only the difference matters:
The preference probability is now written in terms of the optimal policy, not a reward model.
The DPO loss
Replace the unknown optimal policy with the model we are training, , and maximise the likelihood of the observed preferences. Minimising the negative log-likelihood over a dataset of triples gives
Define the implicit reward . The loss is then : a binary classification loss on the margin between the two implicit rewards. Each training step needs the log probabilities of both answers under the trained model and under the frozen reference. No sampling and no reward model are needed.
The gradient
Differentiating gives
Read it in two parts. The bracket raises the log probability of and lowers that of . The sigmoid factor scales each example by how wrong the implicit reward currently is: if the model already ranks the preferred answer well above the rejected one, the weight is near zero, and if it ranks them the wrong way round, the weight is near one. This weighting is what keeps training stable. The paper reports that a naive version without it can make the model degenerate.
Worked examples
Take . For one prompt, the trained model and the reference give these log ratios:
- Preferred answer: .
- Rejected answer: .
- Margin: .
- Loss: .
At initialisation the model equals the reference, so both log ratios are zero, the margin is zero, and the loss is . The loss has dropped from 0.693 to 0.621 because the model now gives the preferred answer a relatively higher probability. Interpretation: the loss is a measure of how well the implicit reward ranks the pair, and it falls as the margin grows.
The gradient weight for a pair is . Compare two pairs:
- Pair A is at initialisation, with margin 0. Its weight is .
- Pair B is already well ranked, with margin 3. Its weight is .
Pair A receives about ten times the weight of pair B. Interpretation: training effort goes to the comparisons the model still gets wrong, and examples it already ranks correctly contribute little. This is the built-in version of the importance weighting the paper found necessary.
Suppose a reward model, or the implicit reward of a trained model, gives answer a score of 2 and answer a score of 0.5. Under the Bradley-Terry model,
A score gap of 1.5 means the first answer is preferred about 82 percent of the time. Interpretation: the sigmoid turns a score difference into a probability, and the same function appears in the DPO loss, so the loss is simply the negative log of the probability that the model's implicit reward ranks the pair correctly.
Tradeoffs and failure modes
DPO is attractive because it is stable and cheap to run. It is a supervised-style loss over a fixed dataset, so it avoids the sampling and tuning burden of PPO-based RLHF, and it is easy to implement with the same training code used for fine-tuning. Its costs come from the same choices.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Preference data was collected from an older model | The pairs no longer reflect what the current policy would write, so the model learns from answers it rarely produces | Collect fresh pairs from the current policy (on-policy data), or use an online method |
| Large or small without tuning | Small lets the model drift far from the reference and degrade fluency; large barely changes it | Sweep and watch the KL and held-out win rates |
| The model is pushed hard on the same pairs | Probabilities of both answers can fall together, and outputs can become strange | Early stopping, a stronger KL term, or mixing in supervised data |
| You need a reusable score for ranking or filtering | DPO gives no separate reward model to query | Keep a Reward Model alongside the policy |
| The task has verifiable answers, such as code tests | Preference pairs are a weak signal when correctness can be checked directly | Reinforcement learning with the verifier as the reward |
| Memory is tight | Both the trained model and the frozen reference must be in memory during training | Share weights with the reference via parameter-efficient tuning, or precompute reference log probabilities |
The main conceptual risk is that DPO does not look at the reward directly. Its optimum is the same as RLHF's only under the assumptions of the Bradley-Terry model and an exact fit, and real preference data is noisy and not always transitive. Work that followed DPO has studied how these differences show up in practice, and it is still an active area.
History
Bradley and Terry proposed their pairwise comparison model in 1952 to rank items from paired contests. Its use for human preferences in machine learning grew through the 2010s. Christiano and colleagues showed in 2017 that a reward model fitted to human comparisons could train reinforcement learning agents on tasks that were hard to specify by hand. Stiennon and colleagues applied the same recipe to summarisation in 2020, and Ouyang and colleagues used it for instruction following in 2022. That line of work established RLHF as the standard way to align language models, and it also made clear how complicated the pipeline had become.
Rafailov and colleagues introduced DPO in a 2023 preprint, and it was later published at NeurIPS in 2023. Their main contribution was the rearrangement above, which shows that the reward model can be eliminated without changing the optimum under the stated assumptions. The method spread quickly because it replaced a multi-stage pipeline with one training loop and matched or exceeded PPO on the paper's summarisation task (about 61 percent win rate against reference summaries versus about 57 percent for PPO at its best temperature, judged by GPT-4) and did as well as or better than its other baselines on single-turn dialogue.
Check yourself
QuestionRecall: what does the DPO loss compare, and what plays the role of the reward model?Show answer
The loss compares the log probability ratios, against a frozen reference model, of the preferred and rejected answers to the same prompt. The trained model's own scaled log ratio, , acts as the implicit reward, so no separate reward model is trained.
QuestionComputation: take . A pair has log ratio for the preferred answer and for the rejected one. What is the margin, and what is the loss to three decimal places?Show answer
The margin is . The loss is .
QuestionWhy? Why does DPO weight each pair by rather than treating all pairs equally?Show answer
The weight is large when the implicit reward ranks the pair wrongly or only weakly, and small when it already ranks the pair correctly with a wide margin. Pairs the model already gets right therefore stop dominating the update, and effort goes to the comparisons still being learned. The paper reports that dropping this weighting can make the model degenerate.
QuestionApplied: a team has 50,000 preference pairs collected from a model that was retired last month. They plan to run DPO on their new model. What is the main concern, and what would you change?Show answer
The pairs were written by a different policy, so they may not cover the answers the new model produces, and the training signal may not match the model's own behaviour. A reasonable step is to sample fresh completions from the current model, collect new preferences on a subset, and then train with DPO on the mixed data, while tuning and checking held-out win rates against the reference model.
Sources
- Rafailov et al., Direct Preference Optimization: Your Language Model is Secretly a Reward Model, 2023.
- Christiano et al., Deep Reinforcement Learning from Human Preferences, 2017.
- Ouyang et al., Training Language Models to Follow Instructions with Human Feedback, 2022.