Chapter 7 · DPO and Preference Optimization¶
7.1 How is DPO derived? ★★★¶
One-sentence answer
DPO starts from the KL-regularized RLHF objective: because this objective has a closed-form optimum, the reward can be expressed in reverse through "the log-probability ratio between the optimal policy and the reference model"; substituting this into the Bradley–Terry model makes the intractable partition function cancel exactly, leaving a classification loss that involves only the policy and the reference model and can be fit by maximum likelihood directly on preference pairs, with neither a reward model nor RL.
I will answer by following the four steps of the derivation. The starting point is the RLHF objective (see Chapter 6):
Here \(x\) is a prompt from the prompt set \(\mathcal{D}\), \(y\) is a response, \(r(x,y)\) is the reward, \(\pi\) is the policy being optimized, \(\pi_{\text{ref}}\) is the reference model (usually the SFT model), and \(\beta\) is the KL coefficient.
(1) The closed-form optimum: the optimal policy of the KL-regularized objective can be written down directly.
The objective is independent for each prompt. After folding the reward into the KL (the line-by-line derivation is in "Going deeper"), maximizing the objective is equivalent to minimizing the KL divergence from the current policy to the following distribution:
Since the KL divergence is non-negative and equals zero if and only if the two distributions are identical, the optimal policy is \(\pi^*\). Its meaning is that the reference model is reweighted by \(\exp(r/\beta)\): high-reward responses are amplified and low-reward responses are suppressed. \(Z(x)\) is the partition function, and it depends only on the prompt; but it requires a sum over all possible responses and cannot be computed, which is exactly why RLHF can only approximate \(\pi^*\) with RL.
(2) Inverting for the reward: reverse this relation and express the reward through the policy.
Taking the log of both sides of the definition of \(\pi^*\), rearranging and multiplying by \(\beta\) gives:
This means that any reward can be expressed through the log-probability ratio between its optimal policy and the reference model, plus a term that depends only on the prompt. In other words, the reward does not need its own network; it is already "hidden" in the optimal policy's log-probability ratio against the reference model.
(3) Substituting into the Bradley–Terry model: the partition function cancels.
The only place the preference data actually needs the reward is the Bradley–Terry model, and BT looks only at the difference between the rewards of two responses to the same prompt. \(y_w\) (chosen) and \(y_l\) (rejected) answer the same \(x\), so the \(\beta\log Z(x)\) terms on both sides are identical and cancel exactly when subtracted:
Here \(\sigma\) is the sigmoid function. This is the reward's "shift invariance" at work: the term we cannot compute is exactly the part BT does not care about. As a result, the probability of a human preference can be expressed using only the policy and the reference model.
(4) Maximum likelihood: fitting the preferences with a parameterized policy gives the DPO loss.
Replace \(\pi^*\) with the policy to be trained, \(\pi_\theta\) with parameters \(\theta\), and perform maximum likelihood on the preference dataset \(\mathcal{D}\), just as when training a reward model:
It has exactly the same form as the reward model loss \(-\log\sigma(r_\phi(x,y_w)-r_\phi(x,y_l))\), except that \(r_\phi\) is replaced by the implicit reward \(\hat{r}_\theta(x,y)=\beta\log\frac{\pi_\theta(y\mid x)}{\pi_{\text{ref}}(y\mid x)}\). Therefore, training DPO is essentially training a reward model; once this implicit reward fits the preferences well, the correspondence between reward and optimal policy from (1) means that \(\pi_\theta\) is automatically the optimal policy for that reward, and no RL is needed.
In summary: the core of DPO is to use the closed-form solution of the KL-regularized objective to merge "learning a reward + running RL" into a single classification loss that trains the policy directly; the partition function cancels because BT depends only on reward differences within the same prompt. This is also what the paper's subtitle, "Your Language Model is Secretly a Reward Model", means (Rafailov et al. 2023).
Going deeper: the line-by-line derivation of the closed-form optimum, the generality of the parameterization, and implementation
(1) The line-by-line derivation of the closed-form optimum: fold the reward into the log, then complete a valid distribution.
Fix a prompt \(x\):
The derivation first writes the KL as an expectation and then divides by \(-\beta\), turning maximization into minimization. The key step is to write \(\frac{1}{\beta}r\) as \(\log\exp(\frac{1}{\beta}r)\) and fold it into the denominator inside the log, so the denominator becomes \(\pi_{\text{ref}}\exp(r/\beta)\); but this does not sum to 1 and is not a valid probability distribution, so we divide it by \(Z(x)\) in the denominator and subtract \(\log Z(x)\) outside to keep the equation true. In the last line, \(\log Z(x)\) does not depend on \(\pi\), and the KL divergence reaches its minimum of 0 at \(\pi=\pi^*\), so the optimum is \(\pi^*\).
(2) The two limits of \(\beta\).
As \(\beta\to 0\), \(\pi^*\) concentrates all probability on the highest-reward response (among those to which the reference model gives nonzero probability), and the reference model's relative preferences no longer matter; as \(\beta\to\infty\), \(\exp(r/\beta)\to 1\) and \(\pi^*\) falls back to \(\pi_{\text{ref}}\).
(3) This parameterization loses no generality.
The paper proves that under the BT model (and the more general Plackett–Luce model), two rewards that differ by a prompt-only function \(f(x)\) belong to the same equivalence class and induce the same preference distribution and the same optimal policy; and every equivalence class contains exactly one reward that can be written in the form \(\beta\log\frac{\pi(y\mid x)}{\pi_{\text{ref}}(y\mid x)}\). Therefore, restricting the reward to this form does not exclude any reward that preference data can distinguish.
(4) Implementation: each pair needs only four log-probabilities.
\(\log\pi(y\mid x)=\sum_t\log\pi(y_t\mid x,y_{<t})\) is obtained with one teacher-forced forward pass, just as in SFT, summing only over the response tokens. Each pair needs the log-probabilities of \(y_w\) and \(y_l\) under \(\pi_\theta\) and under \(\pi_{\text{ref}}\); the reference model is frozen, so its two values can be computed once before training. No sampling from the model is needed during training.
(5) What is removed in going from RLHF to DPO.
| Aspect | PPO-RLHF | DPO |
|---|---|---|
| Reward model | Must be trained separately | Not needed; implicit in the log-probability ratio |
| Value model | Needed | Not needed |
| Sampling during training | Needed | Not needed |
| Models in memory | 4 | The policy, plus the reference model (whose log-probabilities can be precomputed) |
Follow-up questions
Follow-up 1: Why does the partition function \(Z(x)\) cancel?
Because the Bradley–Terry model depends only on the difference between the rewards of two responses to the same prompt, while \(\beta\log Z(x)\) depends only on the prompt. \(y_w\) and \(y_l\) share the same \(x\), so the \(\beta\log Z(x)\) terms on both sides are identical and cancel when subtracted. If the preferences compared responses to different prompts, this step would fail.
Follow-up 2: If the optimum has a closed form, why does RLHF still need RL?
Because \(Z(x)\) in the closed-form solution requires a sum over all possible responses and cannot be computed, so even with the reward known, one cannot obtain \(\pi^*\) directly or sample from it. Responses are variable-length token sequences whose number grows exponentially with length. RLHF can only approximate \(\pi^*\) with RL; DPO's cleverness lies in bypassing \(Z(x)\), not in computing it.
Follow-up 3: Is DPO reinforcement learning?
In terms of the optimization procedure, it is a supervised classification loss, with no sampling and no online interaction with a reward signal; in terms of the objective, it optimizes the same KL-regularized reward maximization as RLHF. A more precise statement is therefore that DPO is a way of solving the RLHF objective without RL, and that the equivalence between the two relies on idealized conditions (see 7.6).
Follow-up 4: Can DPO handle a ranking of several responses to one prompt?
Yes. Generalizing the Bradley–Terry model to the Plackett–Luce model, the implicit reward can be substituted in the same way and the partition function cancels likewise; the paper gives this generalization. In practice, the more common approach is to split the ranking into several preference pairs.
Common mistakes
- Do not say DPO has no KL constraint: The KL constraint is embodied implicitly in the loss through the reference model and \(\beta\); it is simply no longer computed explicitly (and it acts only at the data points; see 7.2).
- Do not say \(Z(x)\) cancels because it is a global constant: It depends on the prompt; it is merely identical for the two responses to the same prompt.
- Do not include the prompt tokens when computing \(\log\pi(y\mid x)\): Sum only over the response tokens.
- Do not say DPO does not train a reward model: It trains exactly a reward model whose parameterization is "the policy's log-probability ratio against the reference model".
7.2 What is the intuition behind the DPO gradient, and what roles do β and the reference model play? ★★¶
One-sentence answer
The DPO gradient raises the log-probability of the chosen response and lowers that of the rejected one, weighted by how wrongly the implicit reward ranks the pair, so it automatically concentrates its effort on pairs not yet learned. \(\beta\) controls how far the policy can move from the reference model; the reference model is the implicit KL anchor, but this constraint takes effect only on responses that appear in the data.
I will address three aspects: the form and intuition of the gradient, the role of \(\beta\), and the role of the reference model.
(1) The gradient splits into a "direction" and a "weight".
Writing the implicit reward as \(\hat{r}_\theta(x,y)=\beta\log\frac{\pi_\theta(y\mid x)}{\pi_{\text{ref}}(y\mid x)}\), the gradient of the DPO loss is:
- Direction: the two terms in the parentheses raise the log-probability of the chosen response and lower that of the rejected one, which can be viewed as "SFT on \(y_w\)" plus "reverse SFT on \(y_l\)".
- Weight: \(\sigma(\hat{r}_\theta(x,y_l)-\hat{r}_\theta(x,y_w))\) measures how wrongly the implicit reward ranks the pair. When the pair is ranked wrongly, the weight is near 1 and the update is large; when it is already ranked correctly by a wide margin, the weight is near 0 and there is essentially no update. The paper stresses that this weight is crucial: without it, directly maximizing \(\log\pi(y_w)-\log\pi(y_l)\) would keep pushing the rejected probability down without limit and eventually cause the language model to degenerate.
Notably, only the difference between the two appears in the gradient: the loss only requires the chosen response to be better relative to the rejected one, not that the chosen response's own probability go up, which sets the stage for likelihood displacement (see 7.3).
(2) \(\beta\) controls how far the policy moves from the reference model.
\(\beta\) comes from the KL coefficient in the original objective. In the loss, the input to the sigmoid is \(\beta\) times "the difference between the two log-probability ratios". The larger \(\beta\), the smaller the change in log-probability ratios needed to saturate the sigmoid, so the weight quickly falls to near 0 and the policy stops close to the reference model, as if the KL constraint were strong; the smaller \(\beta\), the more the log-probability ratios must change to reduce the loss, so the policy moves farther from the reference model and learns the preferences more strongly, but it also becomes more prone to overfitting the preference data and damaging its original abilities.
(3) The reference model is the implicit KL anchor, but it acts only at the data points.
The implicit reward measures "how much the policy has raised this response's probability relative to the reference model", so every change in the policy is measured against the reference model; without it, nothing would tie the policy to its starting point. Note, however, that the optimum in the derivation holds over all possible responses, whereas the DPO loss only touches the \(y_w\) and \(y_l\) in the dataset. For responses outside the data, whether the policy moves probability toward or away from them is invisible to the loss and therefore cannot be penalized. PPO is different: it samples from the policy itself, so wherever the policy puts probability, the KL penalty applies there. This difference is the root of many of DPO's failure modes.
In summary: the DPO gradient is "raise the chosen, lower the rejected", weighted by how wrongly the pair is ranked; \(\beta\) sets the strength of the constraint and the reference model sets its baseline, but the constraint covers only responses that appear in the data.
Going deeper: deriving the gradient, hyperparameters and training monitoring
(1) Deriving the gradient: the chain rule, with no gradient from the reference model.
Let \(u=\hat{r}_\theta(x,y_w)-\hat{r}_\theta(x,y_l)\); the loss is \(-\log\sigma(u)\). Since \(\frac{d}{du}\log\sigma(u)=1-\sigma(u)=\sigma(-u)\),
and \(\nabla_\theta u=\beta\big(\nabla_\theta\log\pi_\theta(y_w\mid x)-\nabla_\theta\log\pi_\theta(y_l\mid x)\big)\), because \(\pi_{\text{ref}}\) is a constant. Multiplying the two gives the gradient above.
(2) Common values of \(\beta\).
The original DPO paper uses \(\beta=0.1\) by default and \(\beta=0.5\) for summarization (Rafailov et al. 2023); Llama 3 also uses \(\beta=0.1\), with a learning rate of \(10^{-5}\) (Dubey et al. 2024).
(3) Metrics to monitor during training.
| Metric | Meaning |
|---|---|
| Implicit reward accuracy | Fraction of samples with \(\hat{r}_\theta(x,y_w)>\hat{r}_\theta(x,y_l)\) |
| Reward margin | Mean of \(\hat{r}_\theta(x,y_w)-\hat{r}_\theta(x,y_l)\) |
| Log-probabilities of chosen and rejected separately | Detects likelihood displacement |
| Response length and downstream evaluations | Detects length exploitation and damage to other abilities |
A common observation is that the margin keeps rising while the log-probabilities of both the chosen and the rejected responses fall, which is exactly the problem discussed in 7.3.
Follow-up questions
Follow-up 1: Why is SFT usually done before DPO?
Because the DPO derivation implicitly assumes that the responses in the preference data come from \(\pi_{\text{ref}}\). In practice, preference data often comes from other models (UltraFeedback's responses, for example, come from many different models), and these responses may have very low probability under \(\pi_{\text{ref}}\), making the log-probability ratios numerically unstable. The paper therefore recommends that if the data was not generated by the reference model, one first performs SFT on the chosen responses so that the reference model is as close as possible to the data distribution, and then runs DPO with this SFT model as both the starting point and the reference model.
Follow-up 2: How does DPO's KL constraint differ from PPO's?
PPO's KL is computed on the policy's own samples and covers everywhere the policy actually puts probability; DPO's KL constraint acts only implicitly, through the responses in the data. Therefore DPO cannot prevent the policy from shifting probability onto responses outside the data, whereas PPO can.
Follow-up 3: Why is DPO's cost said to be close to SFT's?
Because the reference model is frozen and its log-probabilities on the data can be precomputed, so training memory essentially holds only the one policy being trained. Each pair needs just two forward and backward passes on the policy (one each for the chosen and the rejected response), far lighter than PPO's four models and online sampling.
Common mistakes
- Do not say the DPO gradient always raises the chosen response's probability: It only guarantees that the implicit reward gap between the chosen and the rejected response widens; the chosen response's own probability may fall.
- Do not get the direction of \(\beta\) backwards: The larger \(\beta\), the stronger the constraint and the closer the policy stays to the reference model.
- Do not say the reference model can be swapped freely: The implicit reward is measured against the reference model, so changing the reference model changes the objective; the worse the reference model matches the data distribution, the less stable training becomes.
7.3 What are the failure modes of DPO? ★★¶
One-sentence answer
There are three main ones: likelihood displacement, where the probabilities of the chosen and rejected responses fall together and the removed probability may flow to bad responses outside the data; distribution shift from off-policy data, where DPO can neither see nor control the probability the policy places outside the data; and length exploitation, where the model widens the implicit reward gap by getting longer.
I will address three aspects, one for each of these failure modes.
(1) Likelihood displacement: the margin widens, yet the chosen response's probability falls too.
DPO training commonly shows a counterintuitive phenomenon: the loss falls steadily and the margin rises steadily, yet the log-probability of the chosen response also falls, only more slowly than that of the rejected response. The reason is that the chosen and rejected responses are often very similar: they answer the same question, share many tokens and have close internal representations; because parameters are shared, pushing down the probability of \(y_l\) also pushes down that of \(y_w\). And since the DPO gradient only constrains the difference between the two, the loss decreases as long as the rejected response falls faster than the chosen one, and nothing protects the chosen response itself. The removed probability flows to responses outside the data, which may be good or very bad. Razin et al. (2024) found that in a safety training setup, training Llama-3-8B-Instruct to prefer refusing harmful requests actually lowered its refusal rate on SORRY-Bench from 74.4% to 33.4%, as probability mass shifted to semantically opposite, harmful responses.
(2) Off-policy data causes distribution shift: DPO cannot control responses outside the data.
The DPO derivation rests on two implicit assumptions: the responses in the preference data come from \(\pi_{\text{ref}}\), and the data covers the response space sufficiently. In reality, usually neither holds. Since DPO never samples from the policy, it can neither see nor penalize the probability the policy places outside the data. Xu et al. (2024) showed theoretically and empirically that among the policies minimizing the DPO loss, some put a lot of probability on responses that never appear in the dataset, and DPO can converge to such a solution; PPO, by contrast, trains on its own samples, and its reward model can score new responses, so it can constrain the policy. Moreover, if \(y_w\) has extremely low probability under \(\pi_{\text{ref}}\), the log-probability ratio swings widely with small changes, making the implicit reward unstable; and as the policy improves, fixed preference pairs gradually become stale and can even backfire.
(3) Length exploitation: responses get longer and longer with training.
This phenomenon has two causes. On the one hand, there is data bias: both people and LLM judges tend to prefer longer, more detailed responses, so in preference data the chosen response is often longer than the rejected one, and DPO easily learns the shortcut "longer is better". On the other hand, there is the mechanism itself: \(\log\pi(y\mid x)\) is the sum of all tokens' log-probabilities, so the implicit reward is likewise a sum of per-token log-probability ratios, and the longer the response, the easier it is to accumulate a larger reward gap. Park et al. (2024) studied this phenomenon systematically and found that DPO clearly exploits response length. As a consequence, win rates on evaluations with a length preference (such as AlpacaEval, which uses an LLM judge) are inflated: it looks like progress, but the model has merely become wordier.
In summary: the three failure modes share a common root: DPO applies only a relative constraint, and only on the few responses in a fixed dataset, so it neither protects the chosen response's absolute probability nor controls the distribution outside the data.
Going deeper: mitigations for each failure mode
(1) A summary of mitigations.
| Failure mode | Mitigations |
|---|---|
| Likelihood displacement | Add an NLL (SFT) loss on the chosen response (e.g. Iterative RPO, Pang et al. 2024; Llama 3 uses a coefficient of 0.2); DPOP (Pal et al. 2024), which adds a penalty when the chosen response's log-probability ratio falls below the reference model's; filter out pairs whose representations are too similar using the CHES score (Razin et al. 2024); use on-policy data |
| Off-policy distribution shift | First do SFT on the chosen responses so the reference model is close to the data; use on-policy or iterative preference data; mix on-policy and off-policy data |
| Length exploitation | R-DPO (Park et al. 2024), which adds a regularizer on the length difference to the loss; length normalization (SimPO, Tülu 3's length-normalized DPO); build length-balanced preference data; control for length in evaluation (e.g. length-controlled AlpacaEval, Dubois et al. 2024) |
(2) The CHES score: finding the samples most likely to cause displacement.
Razin et al. (2024) proposed the CHES (centered hidden embedding similarity) score, which measures how similar a pair of responses is in the model's hidden representations. It identifies the samples that contribute most to displacement; in the refusal experiment above, filtering out high-CHES samples was more effective than adding an SFT term to the DPO loss. The authors of DPOP also showed theoretically that when the two responses have a small edit distance (e.g. math solutions differing by one step), standard DPO easily lowers the chosen response's probability.
(3) Llama 3's engineering lesson: mask the shared formatting tokens.
Formatting tokens that appear in both the chosen and the rejected response (such as header markers and termination tokens) create conflicting objectives, since the model must raise and lower the probability of the same tokens at once, leading to anomalies such as tail repetition or abruptly generating termination tokens. Llama 3 therefore masked these tokens out of the DPO loss and added an NLL term with coefficient 0.2 on the chosen responses (Dubey et al. 2024).
Follow-up questions
Follow-up 1: Is likelihood displacement always harmful?
Not necessarily; its severity depends on the task. In open-ended dialogue, probability shifting to other similar good responses is mostly harmless; but in tasks such as math and code where "there is one correct answer", or in safety-related settings, probability may flow to wrong or harmful responses, and then it is harmful.
Follow-up 2: Why does a well-tuned PPO often outperform DPO?
Because PPO trains on its own samples and can see and correct its own mistakes, and its reward model can generalize to score new responses and unlabeled prompts. Together these constrain the policy's behavior outside the data. Experiments by Xu et al. (2024) showed that well-tuned PPO beat DPO on both dialogue and code generation (CodeContests).
Follow-up 3: How can you tell whether DPO is exploiting length?
Compare the average response length before and after training, and check whether the gains persist on length-controlled evaluations. If the raw win rate rises sharply while the length-controlled win rate barely improves, the progress came mainly from getting longer.
Common mistakes
- Do not assume a rising margin means the chosen response's probability is rising: The margin reflects only the difference between the two; the log-probabilities of the chosen and rejected responses must be monitored separately.
- Do not say DPO is immune to distribution shift because it does not sample: It is precisely because it does not sample that it cannot constrain the policy's behavior outside the data.
- Do not judge DPO only on evaluations with a length preference: Length-controlled results should be reported as well.
7.4 What do IPO, KTO, SimPO and ORPO each improve? ★¶
One-sentence answer
Each patches one problem of DPO: IPO uses a squared loss that regresses to a finite margin, preventing overfitting under deterministic preferences; KTO needs only binary "good or bad" labels on single responses rather than paired data; SimPO uses the length-normalized average log-likelihood as the reward and drops the reference model; ORPO merges SFT and preference optimization into a single stage and likewise needs no reference model.
I will address two aspects: which problem each of the four methods targets, and which improvements have held up in practice.
(1) The four methods target four problems of DPO.
- IPO (Azar et al. 2023) targets overfitting: each pair in preference data is usually labeled only once, so the empirical preference probability is 1. Fitting a preference of probability 1 under the BT model requires the reward gap to go to infinity, i.e. pushing the rejected response's probability relative to the reference model toward 0, and this holds no matter what \(\beta\) is, so the KL constraint becomes toothless. IPO replaces the logistic loss with a squared loss that regresses the difference in log-probability ratios onto a finite target, so that overshooting the target is pulled back.
- KTO (Ethayarajh et al. 2024) targets the data format: paired preference data is expensive to collect, whereas products more commonly collect thumbs-up or thumbs-down on single responses. Inspired by prospect theory, KTO requires the implicit reward of a desirable response to exceed a reference point and that of an undesirable response to fall below it; the reference point is an estimate of the current policy's KL from the reference model and acts as a baseline.
- SimPO (Meng et al. 2024) targets length bias and the mismatch between training and generation: a high DPO implicit reward does not mean the response has high likelihood under the policy, whereas at generation time the model tends to output responses it considers high-likelihood. SimPO uses the policy's own average log-likelihood directly as the reward, which also performs length normalization, and adds a target margin; a side benefit is that no reference model is needed.
- ORPO (Hong et al. 2024) targets a lengthy pipeline: when SFT is done on the chosen responses, the probabilities of stylistically similar rejected responses get raised too. ORPO adds a contrastive term based on the odds ratio to the SFT loss, learning format and preference in one step, with neither a separate SFT stage nor a reference model.
(2) In practice the most robust improvement is length normalization, while the benefit of dropping the reference model varies with the setup.
Each of these variants reported gains over DPO in its own paper, but conclusions differ across setups. For example, Tülu 3 compared DPO, SimPO and length-normalized DPO in its ablations and found that only length-normalized DPO (keeping the reference model and just normalizing by length) beat the SFT baseline overall, so it adopted that (Lambert et al. 2024). Without a reference model, nothing ties the policy to its starting point, so training is more sensitive to hyperparameters such as the learning rate. KTO's main value, meanwhile, is that it can directly use unpaired feedback such as thumbs-up and thumbs-down.
In summary: the key to answering this kind of question is to state clearly which problem of DPO each variant patches, rather than listing formulas.
Going deeper: the loss functions of the four methods
(1) IPO: regress to a finite target margin.
\(h_\theta\) is the difference between the two log-probability ratios; \(\tau\) is a regularization coefficient that plays a role similar to \(\beta\): the larger \(\tau\), the smaller the target margin \(1/(2\tau)\) and the closer the policy stays to the reference model.
(2) KTO: a saturating value function relative to a reference point.
\(r_\theta\) is the same implicit reward as in DPO (without \(\beta\)); \(z_0\) is the reference point, the KL between the current policy and the reference model, where \(y'\) denotes any response the policy might generate; \(\mathcal{Y}_D\) and \(\mathcal{Y}_U\) are the sets of desirable and undesirable responses; \(\lambda_D\) and \(\lambda_U\) are the weights of the two kinds of samples, and \(\lambda_y\) denotes the weight for the sample's own class. In practice \(z_0\) is estimated by pairing each prompt with another sample's response within the microbatch, computing the average log-probability ratio over these mismatched pairs, and clipping it at 0; no gradient is backpropagated through it, and it only determines where the loss saturates. The paper recommends keeping \(\lambda_D n_D/(\lambda_U n_U)\) between 1 and 1.5 (\(n_D\) and \(n_U\) are the counts of the two kinds of samples). The point of \(z_0\) is this: if the model merely raised the probability of all responses indiscriminately (e.g. by drifting toward some overall style), the KL would grow and \(z_0\) would rise with it, so \(r_\theta-z_0\) would not increase; to reduce the loss, the model must raise desirable responses and lower undesirable ones in a targeted way.
(3) SimPO: length-normalized average log-likelihood plus a target margin.
\(|y|\) is the number of tokens in the response, \(\beta\) is a scaling coefficient, and \(\gamma\) is the target margin, similar to the margin in an SVM. The paper reported that SimPO beats DPO by up to 6.4 points on AlpacaEval 2 and up to 7.5 points on Arena-Hard (Meng et al. 2024).
(4) ORPO: SFT loss plus an odds-ratio penalty.
\(\mathcal{L}_{\text{SFT}}(y_w)\) is the negative log-likelihood on the chosen response; \(\text{odds}_\theta(y\mid x)\) is the ratio of "the probability of generating \(y\)" to "the probability of not generating \(y\)", where \(P_\theta(y\mid x)\) is the length-normalized average per-token likelihood; \(\lambda\) is the weight of the contrastive term.
(5) An overview.
| Method | Data needed | Reference model | Key change | Problem patched |
|---|---|---|---|---|
| DPO | Paired preferences | Needed | Implicit reward in the BT loss | Baseline: no reward model, no RL |
| IPO | Paired preferences | Needed | Squared loss regressing to a finite margin | Overfitting under deterministic preferences |
| KTO | Unpaired good / bad labels | Needed | Prospect-theory value function with the KL as reference point | No pairs needed; handles class imbalance |
| SimPO | Paired preferences | Not needed | Length-normalized average log-likelihood reward plus a target margin | Length bias, training–generation mismatch, memory |
| ORPO | Paired preferences | Not needed | SFT loss plus an odds-ratio penalty, in one stage | Separate SFT stage and reference model |
Follow-up questions
Follow-up 1: Why does DPO overfit when preferences are "deterministic"?
Because fitting a preference of probability 1 under the BT model requires the reward gap to go to infinity. In terms of the implicit reward, this requires \(\pi_\theta(y_l\mid x)/\pi_{\text{ref}}(y_l\mid x)\to 0\), which is independent of \(\beta\), so the KL constraint that \(\beta\) represents stops working. In practice this shows up as the rejected probability being pushed down relentlessly and the policy drifting ever farther from the reference model. IPO avoids this with a finite target margin; early stopping and label smoothing (e.g. cDPO) can have a similar effect.
Follow-up 2: What are the risks of SimPO dropping the reference model?
Nothing ties the policy to its starting point. The policy is more sensitive to hyperparameters such as the learning rate and more likely to drift and damage other abilities, and \(\beta\) and \(\gamma\) also need careful tuning. A safer reading, therefore, is that length normalization is the most robust improvement in SimPO, while the benefit of dropping the reference model depends on the setup.
Follow-up 3: When would you use KTO?
When you have only good-or-bad labels on single responses and no paired comparisons, or when the two kinds of samples are severely imbalanced. Examples include thumbs-up and thumbs-down in a product, or whether generated code was accepted. The KTO paper reported that it matches or exceeds preference-based methods at scales from 1B to 30B (Ethayarajh et al. 2024).
Common mistakes
- Do not say these variants are uniformly better than DPO: Their advantages depend on the setup, and independent comparisons reach inconsistent conclusions.
- Do not say KTO needs no reference model: Both KTO's implicit reward and its reference point depend on the reference model; the methods that need no reference model are SimPO and ORPO.
- Do not equate IPO's \(\tau\) with DPO's \(\beta\): Both control regularization strength, but IPO's \(\tau\) sets a finite target margin, whereas DPO's \(\beta\) cannot stop the margin from growing without bound under deterministic preferences.
7.5 How do online and offline DPO differ, and what is iterative DPO? ★★¶
One-sentence answer
Offline DPO trains on a preference dataset collected in advance that does not change during training; this data often comes from other models and is off-policy relative to the current policy. Online DPO keeps sampling responses from the current policy, scores them with a reward model, an LLM judge or a verifier, and builds preference pairs, so the data is always on-policy. Iterative DPO is a compromise that refreshes the data in rounds: each round resamples and relabels with the latest model and then runs another round of DPO.
I will address three aspects: the limitations of offline DPO, the procedure of online and iterative DPO, and why it works and what it costs.
(1) Offline DPO is simple, but its data is off-policy and gradually goes stale.
Standard DPO is offline: the preference dataset is collected in advance and does not change during training. UltraFeedback, for example, has several models generate responses and GPT-4 score and rank them. This approach is simple, cheap and reproducible, but its costs are clear: the responses in the data may be very different from what the policy itself would generate, so the policy learns "how to rank other models' responses" rather than "how to improve its own"; the policy never sees its own mistakes and so never gets feedback on them; and once the policy improves, the chosen responses in the data may already be worse than the policy's own, so pushing them up further does harm.
(2) Online and iterative DPO share the same loop and differ in how often the data is refreshed.
The loop is: for each prompt, sample several responses from the current policy; score them with a reward model, an LLM judge, a programmatic verifier or humans; take the highest-scoring response as chosen and the lowest as rejected to build preference pairs; run a DPO update on this new data; and repeat.
- Fully online: resample and relabel every batch. For example, OAIF (Guo et al. 2024) has an LLM annotator label pairs sampled from the current policy at every step, and it clearly beats offline DPO.
- Iterative: refresh the data in rounds. For example, Llama 3 repeated "SFT, rejection sampling, DPO" for six rounds, with each round's DPO mainly using the latest preference data collected with the best models from the previous round, in order to keep the training data close to the distribution of the policy being optimized (Dubey et al. 2024).
(3) On-policy data works because the gradient lands exactly on the mistakes the policy actually makes; the price is that the reward signal and the sampling cost return.
Because the preference pairs come from the policy's own distribution, DPO's constraint falls where the policy actually places probability, so "the KL constraint acts only at the data points" from 7.2 is no longer a big problem, and likelihood displacement and distribution shift are eased as well. However, online training needs a source of reward signal, so the risk of reward hacking returns (see Chapter 6); sampling during training brings back the generation cost too. Still, it needs no critic and none of PPO's complex optimization, so its complexity sits between offline DPO and PPO, which makes it a common compromise.
In summary: the essence of online and iterative DPO is switching DPO's training data from "other models' responses" to "the policy's own responses", obtaining most of the benefit of on-policy data at relatively low complexity.
Going deeper: empirical evidence and implementation choices
(1) Several works support the value of on-policy data.
| Work | Finding |
|---|---|
| OAIF (Guo et al. 2024) | Labeling the current policy's samples with an LLM at every step clearly beats offline DPO |
| Tajwar et al. (2024) | Both on-policy sampling and the "negative gradient that pushes the rejected down" matter, especially when good responses lie in regions of low probability under the reference model |
| Tülu 3 (Lambert et al. 2024) | Adding on-policy data to the preference data yields better downstream DPO results than fully off-policy data |
| Llama 3 (Dubey et al. 2024) | Six iterative rounds, each recollecting preference data with the best models from the previous round |
(2) A few implementation choices.
Preference pairs are usually the highest- and lowest-scoring responses, though several pairs can also be drawn from the same group of responses. The reference model can be updated each round to the previous round's model or kept as the SFT model throughout: the former lets the policy move farther round by round, while the latter constrains it more strongly. The choice of scorer determines the risk of reward hacking, and tasks whose answers can be verified automatically should prefer a programmatic verifier. (For Self-Rewarding, where the model acts as its own judge for iterative self-improvement, see the Self-Improving & RSI direction.)
Follow-up questions
Follow-up 1: What differences remain between online DPO and PPO?
There are three main differences.
- How the reward is used: online DPO uses the reward only to rank responses and pick the chosen and rejected ones, discarding the actual values; PPO uses the values directly to compute advantages, making fuller use of the information.
- Credit assignment: DPO's loss is a contrast at the level of whole responses, with no critic judging each token's contribution; PPO assigns an advantage to every token through the value model and GAE.
- How updates are made: PPO limits each step's policy change through clipping, whereas DPO's constraint comes from \(\beta\) and the reference model; iterative DPO refreshes the data in rounds, so the same data is used for more steps and is less "fresh" than PPO's.
Follow-up 2: How are preference pairs built in iterative DPO?
The common approach is rejection sampling: sample several responses per prompt, score them, and take the highest-scoring as chosen and the lowest-scoring as rejected. This makes the gap between the two clear enough for the label to be reliable, and both come from the current policy, so the data is on-policy. One should avoid pairs whose two responses are nearly identical, since these easily worsen likelihood displacement.
Follow-up 3: Why is iterative DPO described as a compromise between DPO and PPO?
It keeps DPO's simple loss and stability while gaining PPO's on-policy data. It needs no critic and no sampling at every step, so its engineering complexity is far lower than PPO's; but compared with offline DPO it needs a scorer and periodic generation, so both the cost and the risk of reward hacking increase.
Common mistakes
- Do not say online DPO needs no reward signal: Building preference pairs requires a source of scores, which may be a reward model, an LLM judge, a verifier or humans.
- Do not conflate "online" with "iterative": The former refreshes data every batch; the latter refreshes it in rounds.
- Do not say on-policy data automatically eliminates reward hacking: It eases distribution shift; as long as a learned scorer is used, the risk of hacking remains.
7.6 How do you choose between DPO and PPO? ★★¶
One-sentence answer
In theory both optimize the same KL-regularized objective; in practice, PPO can explore on its own samples and use unlabeled prompts, so when well tuned it is usually slightly better, while DPO is simple, stable and costs about as much as SFT. Choose DPO when resources are limited and the goal is aligning conversational style and safety (ideally with on-policy data); choose PPO or another online RL method when there is a reliable reward signal, exploration is needed, or the highest quality is the goal.
I will address four aspects: how the two relate in theory, why they differ in practice, what the empirical evidence says, and how to choose.
(1) In theory, the two optimize the same objective.
Both DPO and PPO-based RLHF optimize KL-constrained reward maximization under the BT preference model. In the ideal case of infinite data covering every possible response and optimization to the global optimum, both reach the same policy. In practice, however, these ideal conditions do not hold, so the two perform differently.
(2) The practical differences come from four sources.
- Data source: PPO trains on samples it generates itself, and its reward model can score any new response, so it can also use large numbers of unlabeled prompts; DPO can use only labeled preference pairs, and its coverage is the data itself.
- Exploration: PPO can see and correct its own mistakes and may discover better responses that are not in the data; DPO can only learn a ranking among responses already in the data.
- Failure modes: PPO's main risk is exploiting the reward model; DPO's risks are the policy drifting outside the data, likelihood displacement, length exploitation and overfitting.
- Cost and stability: DPO costs about as much as SFT and has essentially one key hyperparameter, \(\beta\); PPO maintains four models, samples inside the training loop, and has many coupled hyperparameters.
(3) Empirically, a well-tuned PPO comes out slightly ahead, but industrial choices also weigh cost and depend on whether the task has a verifiable reward.
Xu et al. (2024) found that carefully tuned PPO beat DPO on both dialogue and code generation; Ivison et al. (2024) disentangled the factors in a unified setup and found PPO better than DPO, but only modestly, with the quality of the preference data actually being the most important factor. On the other hand, Llama 3 tried on-policy algorithms such as PPO but found that for large-scale models DPO needed less compute and performed better (Dubey et al. 2024); Tülu 3 likewise chose length-normalized DPO for its simplicity and efficiency, followed by an RLVR step (Lambert et al. 2024). In the era of reasoning models, online RL (the GRPO family) has become mainstream for tasks with verifiable rewards such as math and code, because online exploration is irreplaceable there (see Chapter 8).
(4) The choice depends on resources, data, the reward signal and the type of task.
- Choose DPO: when compute and engineering resources are limited; when you have good preference data, ideally on-policy; when the goal is aligning conversational preferences such as style, format and safety; when you need fast iteration and stable training; or as a step before RL.
- Choose PPO or another online RL method: when there is a reliable reward signal (a strong reward model or verifiable rules); when you want to go beyond the quality of the existing data and need exploration; when the task involves reasoning or multi-step decisions; and when you want the highest quality and can invest in the infrastructure.
- Middle ground: iterative or online DPO, which obtains most of the benefit of on-policy data at far lower complexity than PPO (see 7.5).
In summary: choosing between DPO and PPO is essentially a trade-off between "simple, stable and cheap" and "online exploration with a higher ceiling", and the quality of the preference data often matters more than the choice of algorithm.
Comparing the two methods:
| Aspect | PPO-RLHF | DPO |
|---|---|---|
| Reward | Explicit reward model, trained first | Implicit, in the policy's log-probability ratio |
| Training data | Online: fresh samples from the current policy | Offline: fixed preference pairs (can be made iterative) |
| Unlabeled prompts | Usable | Not usable |
| Models in memory | 4 (policy, value, reward, reference) | 2 (policy, reference); the reference model's log-probabilities can be precomputed |
| Sampling during training | Yes; generation is the main cost | No |
| Stability and tuning | Many coupled hyperparameters; fragile | Supervised-style loss; stable; mainly tune \(\beta\) |
| Exploration | Yes; learns from its own mistakes | No; limited to responses in the data |
| Main failure modes | Exploiting the reward model | Drifting off the data distribution, likelihood displacement, length exploitation, overfitting |
| Typical use | RLHF for frontier models; online RL with a strong reward model or a verifier | Open models; dialogue, style and safety alignment; limited budgets |
Going deeper: key empirical results
| Work | Setup | Conclusion |
|---|---|---|
| Xu et al. (2024) | Dialogue and code generation (CodeContests) | Well-tuned PPO beat DPO in all settings; theoretically, DPO can converge to solutions that put probability on responses outside the data |
| Ivison et al. (2024) | Disentangling data, algorithm, reward model and prompts in a unified setup | PPO beat DPO by up to 2.5% in math and 1.2% in general domains; in decreasing order of impact: preference data quality, algorithm, reward model quality, additional unlabeled prompts |
| Llama 3 (Dubey et al. 2024) | Preference alignment of large-scale models | DPO needed less compute and performed better, especially on instruction-following benchmarks such as IFEval |
| Tülu 3 (Lambert et al. 2024) | Controlled comparison | PPO's average score was comparable to DPO's (slightly lower), but its runtime was about 28 hours on two nodes versus about 4 hours on a single node for DPO |
Follow-up questions
Follow-up 1: If DPO and RLHF optimize the same objective, why do they perform differently?
Because the equivalence relies on idealized conditions: data covering all responses and optimization to the global optimum. In practice data is limited and often off-policy; DPO can constrain only the responses that appear in the data, whereas PPO trains on its own samples and gains extra supervision from the reward model's generalization. As a result, the two converge to different policies under finite data.
Follow-up 2: Why can PPO use unlabeled prompts while DPO cannot?
Because in PPO the policy generates the responses and the reward model scores them, so the prompts need no labels at all; DPO's loss, by contrast, requires paired chosen and rejected responses. To let DPO use unlabeled prompts, one must first sample from the policy and then build preference pairs with a scorer, which turns it into online or iterative DPO.
Follow-up 3: Why did Llama 3 use DPO, while reasoning models mostly use online RL?
Because the tasks differ in nature. Llama 3's preference alignment mainly targeted dialogue quality, instruction following and safety, with abundant human preference data, and DPO achieved better results at lower cost; reasoning tasks, by contrast, aim to go beyond the existing data and discover better solution processes through exploration, and they have automatically verifiable rewards, which is where online RL's advantages are most pronounced.
Common mistakes
- Do not say DPO optimizes a different objective from RLHF: The objectives are the same; the differences come from the data and the optimization process.
- Do not say DPO is always worse than PPO: PPO's advantage depends on careful tuning and a reliable reward; when resources are limited or tuning is insufficient, DPO is often comparable or better.
- Do not answer only from the algorithm's perspective: Empirically, the quality of the preference data affects results more than the choice of algorithm.