AI State of the Art
SOTA/Alignement : instruction, RLHF, DPO et apprentissage par renforcement/27 min
Section 122

DPO in Practice: Data, Settings, Variants

Listen as a podcast →

The Flaw in Classic RLHF That DPO Fixes

In one sentence: RLHF with PPO needs a separately trained reward model and four models in memory; DPO gets alignment straight from preference pairs, with no explicit reward and no reinforcement learning.

A reminder of what classic RLHF costs, set out in full, with the memory count and the distinction between what learns and what stays frozen, in RLHF in practice:

  1. train a separate reward model on human preferences;
  2. keep four models in memory at once: the policy and the critic, which are trained, plus the reference model and the reward model, which are frozen;
  3. manage the instability of RL: reward hacking (the model finding how to maximize the score without answering better), divergences, sensitive settings.

DPO (Direct Preference Optimization) asks a simple question: what if you could get the same result directly from preferences?

Direct Preference Optimization: Your Language Model is Secretly a Reward Model
The Mathematical Idea Underneath

The paper's title says it: your language model is secretly a reward model. DPO shows there is an analytical correspondence (written out on paper, with no training involved) between the optimal policy and an implicit reward model. In other words, you don't need to build a reward model: it is already "hidden" in your model's probabilities, and DPO exploits it directly.

The DPO Formulation: From RL to Supervised

The classic RLHF objective seeks to maximize the reward while staying close to the reference model:

max⁡πE[reward(x,y)]−β×KL(π∥πref)\max_\pi \mathbb{E}[\text{reward}(x, y)] - \beta \times \text{KL}(\pi \| \pi_{\text{ref}})

The symbols: π\pi is the policy, i.e. the model, and πref\pi_{\text{ref}} its frozen starting copy; xx is the prompt and yy the response; E\mathbb{E} denotes an average; KL is short for Kullback-Leibler, after the two authors of the measure: the Kullback-Leibler divergence between two probability distributions is zero when they are identical and grows as they separate. In plain words: push the score up, but do not stray far from the starting model, and β\beta sets how tight that leash is.

DPO's trick: this optimization has an analytical solution. It can be rewritten as a simple supervised loss that directly compares preference pairs:

LDPO=−E[log⁡σ(β×(log⁡πθ(yw∣x)πref(yw∣x)−log⁡πθ(yl∣x)πref(yl∣x)))]\mathcal{L}_{\text{DPO}} = -\mathbb{E}\left[\log \sigma\left(\beta \times \left(\log \frac{\pi_\theta(y_w|x)}{\pi_{\text{ref}}(y_w|x)} - \log \frac{\pi_\theta(y_l|x)}{\pi_{\text{ref}}(y_l|x)}\right)\right)\right]

Where:

  • ywy_w = the preferred response (ww for winner);
  • yly_l = the rejected response (ll for loser);
  • xx = the prompt shared by both responses;
  • πθ\pi_\theta = the policy being trained, i.e. your model, whose learned parameters are collectively called θ\theta (theta);
  • πref\pi_{ref} = the reference model: the frozen copy of the starting SFT (Supervised Fine-Tuning) model;
  • β\beta (beta) = the setting that decides how far the model may stray from that reference;
  • σ\sigma (sigma) = the sigmoid function, the S-shaped curve that squashes any number into the range 0 to 1. It is what turns a preference gap into a probability;
  • log⁡\log = the logarithm, used here only to turn ratios of probabilities into differences you can work with.

In plain words: the loss is low when the model gives, relative to its reference, clearly more probability to the preferred answer than to the rejected one; it blows up when the reverse happens.

Intuitive Interpretation

DPO does two things simultaneously: it increases the probability of the preferred response and decreases that of the rejected response, all relative to the reference model. The reference term prevents the model from drifting too far from its initial behavior. No explicit reward model. No RL. Just a binary classification loss, with stable and well-defined gradients.

DPO training curve over 100 steps. The y axis is the implicit reward. The green curve, chosen response, starts at 0.06 and climbs to about 0.39 before flattening. The red curve, rejected response, starts at -0.01 and steadily falls to -0.15. The shaded blue area between them, labeled reward margin, keeps widening. Two annotations note that the rewards start close together and end clearly separated.
What a healthy DPO run looks like. The green curve (good answer) rises, the red one (bad answer) falls, and the blue area between them (the margin) widens. That is the paragraph above turned into curves. The plateau after step 60 is normal: the model has finished absorbing the preferences.Source : Marcel Brenndoerfer, DPO Implementation
Theoretical Equivalence with RLHF

Under certain assumptions (notably that preferences follow the Bradley-Terry statistical model, the one that infers a ranking from a series of head-to-head duels, which comes up again in RLHF in practice) DPO targets the same optimal solution as RLHF with PPO.

Be careful with the practical inference, though. DPO is unquestionably simpler and steadier to run, but whether it "does as well or better" depends on the dataset and the benchmark. Part of the recent literature concludes the opposite on some settings, arguing for online methods, hence the interest in online DPO, described in GRPO and oDPO. No general ranking is claimed here.

The Four Concrete Advantages

1. Trivial Implementation

It's a standard binary classification loss. No trajectory generation, no reward model to maintain, no PPO algorithm to debug. Anyone who knows how to train a classifier can do DPO.

2. Stable Training

No more RL instability: no reward hacking, no sudden divergences. It's a classic supervised optimization problem with well-behaved gradients. Which is not the same as trap-free: see below the curve where the good answer never goes up.

3. Less Memory

Two models in memory (the policy and its reference) instead of four for PPO. The saving is not exactly "half", and it is worth seeing why: a frozen model costs only its weights, whereas a trained model costs its weights plus its gradients plus its optimizer states. PPO trains two models (the policy and the critic), DPO trains one. What disappears is therefore the weights of the critic and of the reward model, and above all the critic's entire training apparatus.

4. PEFT Compatible

DPO works directly with parameter-efficient fine-tuning methods, PEFT: see LoRA, QLoRA and the PEFT comparison. Do the arithmetic on what that buys: a 7-billion-parameter model in 4-bit precision (0.5 byte per parameter) weighs 7×109×0.5=3.57 \times 10^9 \times 0.5 = 3.5 GB of weights, against 14 GB in BF16, where each parameter takes 2 bytes. That fits on a 24 GB consumer graphics card with room left for activations and the small trained adapter. This is what democratized alignment in the open-source community.

Implementation with TRL

Hugging Face's TRL library (Transformer Reinforcement Learning) makes DPO accessible in a few lines:

from trl import DPOTrainer, DPOConfig

config = DPOConfig(
    output_dir="./dpo_model",
    per_device_train_batch_size=4,
    gradient_accumulation_steps=4,
    learning_rate=5e-7,
    beta=0.1,
    num_train_epochs=1,
    bf16=True,
)

trainer = DPOTrainer(
    model=model,
    ref_model=ref_model,
    args=config,
    train_dataset=preference_dataset,
)
trainer.train()
DPO + LoRA: The Free Reference Model

LoRA does not train the model's weights: it leaves the original weights frozen and learns only a small adapter placed on top. That has an elegant consequence for DPO: switching the adapter off gives you exactly the starting model, so the reference model is the base model itself. No need to load a second copy of the weights, one frozen set plays both roles depending on whether the adapter is plugged in. What you save is therefore the reference model's full weights, the larger of the two costs. TRL handles the switching automatically.

Data Format: Maximum Simplicity

{
  "prompt": "How does photosynthesis work?",
  "chosen": "Photosynthesis is a biochemical process...",
  "rejected": "Plants eat sunlight..."
}

A prompt, two responses, and you indicate which one is better. That's it. The simplicity of the format has contributed to DPO's popularity.

Where Do Preference Data Come From?

  • Human annotations: the quality benchmark, and the most expensive one, you are paying a person to read two answers and decide, across hundreds of thousands of pairs. No per-pair price is quoted here: it varies far too much with the domain and the expertise demanded of the annotator.
  • A model as judge (LLM-as-a-judge): a large model compares and ranks the responses automatically. This has become the most common route; which judge you pick is a project parameter, not a constant.
  • UltraFeedback: per its dataset card, about 64,000 prompts with 4 responses each, i.e. 256,000 responses, scored by a large model.
  • Nectar: per its dataset card, 182,954 prompts with 7 ranked responses each.
  • Distilabel: a tool for producing synthetic preference data at scale.

Critical Hyperparameters

Beta (β\beta): The Cautious/Aggressive Slider

β\beta sets the length of the leash holding the model near its reference. The orders of magnitude below are common ecosystem practice, not demonstrated values:

  • β=0.1\beta = 0.1: the most widespread default, a compromise between alignment and preserving the starting model;
  • small β\beta (around 0.01 to 0.05): the model strays further from its reference, potentially stronger alignment, but a risk of degradation;
  • large β\beta (around 0.2 to 0.5): the model stays very close to its reference, cautious but safe alignment.
Two panels side by side. On the left, a bar chart of implicit rewards: the chosen response sits at +1.8 in green, the rejected one at -0.6 in red, and a purple double arrow measures the margin of 2.4 between them, with annotations reading goal push chosen up and goal push rejected down. On the right, a sigmoid curve mapping the margin on the x axis to the probability of preferring the chosen response on the y axis, with the formula accuracy equals sigmoid of beta times margin; a margin of 2.4 gives an accuracy of 0.77; left of zero the model prefers the rejected response.
What beta actually controls. The margin (left) is the reward gap between the good and the bad answer; beta is the factor that turns that gap into a preference probability (right). A larger beta makes the curve steeper: a smaller margin is already enough to count as convinced, so the model moves less. A smaller beta flattens the curve and lets the model drift further from its reference.Source : Chris von Csefalvay, The post-training instrument cluster

Learning Rate: Be Careful

The learning rate is the size of each correction applied to the weights. DPO is very sensitive to it. The values used in practice sit around 10−710^{-7} to a few 10−610^{-6}, markedly lower than for a standard SFT run. Start low and raise it cautiously: too high a rate makes the model diverge within a few hundred steps.

Number of Epochs: Less Is More

An epoch is one complete pass over the dataset. One is often enough. Beyond two or three, the model overfits the training preferences and generalizes worse: it learns to reproduce the pairs it has seen rather than to internalize the preference they illustrate.

Four panels tracking 900 training steps for four variants: DPO in blue, DPOP in orange, DPO plus NLL in green, BDPO in red. First panel, chosen log probability: the blue DPO curve stays flat around -500 and never rises, while the other variants climb. Second panel, rejected log probability: the blue curve collapses from -500 to -1100. Third panel, KL divergence from the reference model: the blue curve climbs from 200 to 380, higher than all the others. Fourth panel, NLL loss: the blue curve rises from 2.5 to 3.4.
The classic DPO failure mode, seen in curves. With plain DPO (blue), the probability of the good answer does not go up, it stalls or even drops, and only the bad answer collapses. The margin does widen, but from below: the model mostly learns to stop saying what it used to say. The last two panels show the consequence: the Kullback-Leibler divergence climbs, and so does the NLL loss, NLL for negative log-likelihood, i.e. a measure of how surprised the model is by its own text. A drifting model, in other words. Watch these four curves rather than the margin alone, and stop early.Source : Rethinking DPO paper (figure 4), via the bonin147 blog

This pattern is a training pathology in its own right, of a piece with those catalogued in What breaks when you run RL on an LLM.

The Quality of the Base SFT Is Critical

DPO is entirely dependent on the initial SFT model. A bad SFT model will produce a bad DPO model, period. DPO only reorients existing probabilities: it amplifies good responses and attenuates bad ones. If the model can't respond at all, DPO can't teach it. Invest in your SFT before moving to DPO, see Instruction tuning.

DPO Variants

Each one fixes a specific flaw in DPO; that is the thread to follow if you want to keep them apart.

IPO, Identity Preference Optimization

The flaw it targets: DPO assumes preferences follow the Bradley-Terry model, which fits noisy or contradictory annotations badly. IPO adds regularization that makes it more robust in that case.

A General Theoretical Paradigm to Understand Learning from Human Preferences (IPO)

KTO, Kahneman-Tversky Optimization

The flaw it targets: DPO requires comparative pairs, which are expensive to obtain. KTO makes do with binary good/bad labels on individual responses, far easier to collect, though each label carries less information than a comparison. The name refers to Kahneman and Tversky's work on how humans weigh gains against losses.

KTO: Model Alignment as Prospect Theoretic Optimization

ORPO, Odds Ratio Preference Optimization

The flaw it targets: the two-stage chain of SFT then alignment, and the reference model it requires. ORPO merges the two stages into a single training run and needs no separate reference model.

ORPO: Monolithic Preference Optimization without Reference Model

SimPO, Simple Preference Optimization

The flaw it targets: the reference model itself, which has to be kept in memory. SimPO replaces it with an implicit reward computed from the response's average log-probability per token, that is, normalized by its length, which incidentally stops long answers from being mechanically favoured.

SimPO: Simple Preference Optimization with a Reference-Free Reward

DPO or RLHF with PPO: What to Take Away

DPO's advantages are operational, and those are solid:

  • simpler to implement and to diagnose;
  • steadier to train, fewer sensitive settings;
  • less memory (one trained model instead of two);
  • compatible with PEFT methods (LoRA, QLoRA).

What is not claimed here is any figure on comparative quality: depending on the preference set, the starting model and the benchmark, online methods (RLHF with PPO, GRPO, online DPO) can take the lead back, precisely because they learn from the model's current mistakes. DPO + QLoRA remains the most accessible route to aligning a model on a modest budget; that is not the same statement as "the best alignment achievable".


In short: DPO is alignment without a reward model and without reinforcement learning. Simpler, steadier, lighter on memory. It is the open-source ecosystem's default choice for a first alignment pass.

Check your understanding0 / 4

1. What is DPO's central trick compared with classic RLHF?

2. During a DPO run, the margin between the chosen and rejected answers widens steadily. Why is that not sufficient proof that all is well?

3. A team applies DPO to a mediocre SFT model, hoping alignment will make up the difference. What does the page answer?

4. DPO keeps two models in memory instead of PPO's four. Why is the memory saving actually bigger than just half the weights?