Chapter 17 · Section 17.4 · 60 min

The DPO family

DPO was published in May 2023. Within a year there were dozens of variants, usually named with a letter or two in front of "PO", and a reader of the literature could be forgiven for thinking each one is a new idea. Most are not. Line them up and nearly every one changes one of four things about the DPO loss.

  1. The function of the margin. DPO applies the logistic loss −log⁡σ(⋅)-\log\sigma(\cdot) to βh\beta h. Others use a squared loss (IPO), a hinge (SLiC), or a smoothed logistic (conservative DPO). Tang et al. (2024) make this precise, writing a whole family as E[f(βh)]\mathbb{E}[f(\beta h)] for a convex ff.
  2. What goes inside the margin. The log-ratio to a reference (DPO), another function of that ratio that comes from a different divergence penalty (ff-DPO, §17.1), the average log-probability with no reference at all (SimPO), an odds ratio (ORPO), with or without a target margin or a length term.
  3. The shape of the data. Pairs (DPO), full rankings (Plackett-Luce, §17.2), or single responses labeled good or bad (KTO).
  4. Extra terms. Most often a supervised likelihood term on the chosen response (ORPO, DPO-Positive, Llama 3's recipe).

This section covers the variants an interviewer expects you to know, IPO, conservative DPO, KTO, ORPO, and SimPO, and for each one the problem it was invented to fix. Throughout, πθ\pi_\theta is the policy, πref\pi_{\text{ref}} the frozen reference, β>0\beta > 0 the regularization strength, (x,yw,yl)(x, y_w, y_l) a prompt with chosen and rejected responses, and

hθ=log⁡πθ(yw∣x)πref(yw∣x)−log⁡πθ(yl∣x)πref(yl∣x)h_\theta = \log\frac{\pi_\theta(y_w\mid x)}{\pi_{\text{ref}}(y_w\mid x)} - \log\frac{\pi_\theta(y_l\mid x)}{\pi_{\text{ref}}(y_l\mid x)}

the log-ratio difference of §17.2 in nats (not the head count hh of Chapter 4), so that DPO's loss is −log⁡σ(βhθ)-\log\sigma(\beta h_\theta).

Why DPO overfits deterministic preferences

Start with the problem that motivated one of the earliest and most influential variants. Take a prompt with two possible responses, a uniform reference, and a dataset in which y1y_1 is always preferred to y2y_2. Bradley-Terry can only explain a preference probability of 1 with an infinite reward gap, r(y1)−r(y2)→∞r(y_1) - r(y_2) \to \infty, and plugging an infinite gap into the closed form of §17.1 gives π⋆(y2)=0\pi^\star(y_2) = 0 whatever β\beta is. The same is visible directly in the DPO loss. −log⁡σ(βh)-\log\sigma(\beta h) is strictly decreasing in hh, so its only infimum is at h→∞h \to \infty, and gradient descent keeps pushing πθ(y2)\pi_\theta(y_2) toward zero forever, slowly, at the logarithmic rate we derived in §17.2. The regularization strength changes how fast it gets there, not where it ends up.

That might sound like an edge case. It is the normal case. Azar et al. (2023) point out that with only a few labels per pair, the empirical preference is easily 0 or 1 even when the true one is, say, 0.8. Real datasets are more extreme still, because each pair is usually labeled once, so its empirical preference is exactly 0 or 1. On real data, almost every preference DPO sees is deterministic, and the KL regularization that was supposed to keep the policy near the reference becomes weaker the more deterministic the preferences are. They also give a persuasive account of why RLHF with an explicit reward model suffers less from this. Reward models are trained with regularization and early stopping, so they underfit, and their finite rewards keep the PPO policy at a finite distance from the reference. DPO fits the reward implicitly and loses that accidental protection.

IPO, regressing to a target margin

Azar et al. generalize the RLHF objective to Ψ\PsiPO, which maximizes

Ex Ey∼π(⋅∣x), y′∼μ(⋅∣x)[Ψ(p⋆(y≻y′∣x))]−β DKL(π(⋅∣x) ∥ πref(⋅∣x)),\mathbb{E}_{x}\,\mathbb{E}_{y\sim\pi(\cdot\mid x),\, y'\sim\mu(\cdot\mid x)}\big[\Psi\big(p^\star(y\succ y'\mid x)\big)\big] - \beta\, D_{\mathrm{KL}}\big(\pi(\cdot\mid x)\,\Vert\,\pi_{\text{ref}}(\cdot\mid x)\big),

where μ\mu is the distribution the comparison responses come from and Ψ\Psi is a non-decreasing function of the preference probability. With Ψ(q)=log⁡q1−q\Psi(q) = \log\frac{q}{1-q} and Bradley-Terry preferences, Ψ(p⋆(y≻y′))=r(y)−r(y′)\Psi(p^\star(y\succ y')) = r(y) - r(y') and the objective is the usual RLHF one, which is what DPO optimizes. That Ψ\Psi is unbounded, and its blow-up at q=1q = 1 is the problem above. Identity preference optimization (IPO) takes the simplest bounded choice, Ψ(q)=q\Psi(q) = q, maximizing the probability of beating μ\mu directly. The closed form of §17.1 applies with the reward replaced by p⋆(y≻μ)=Ey′∼μ[p⋆(y≻y′)]p^\star(y\succ\mu) = \mathbb{E}_{y'\sim\mu}[p^\star(y\succ y')], a number between 0 and 1.

∂ From the IPO objective to its sampled loss

The target. The optimal policy is π⋆(y)∝πref(y)exp⁡(β−1p⋆(y≻μ))\pi^\star(y) \propto \pi_{\text{ref}}(y)\exp\big(\beta^{-1}p^\star(y\succ\mu)\big), so for any two responses the log-ratio difference of the optimum is

h⋆(y,y′)=log⁡π⋆(y)πref(y)−log⁡π⋆(y′)πref(y′)=β−1(p⋆(y≻μ)−p⋆(y′≻μ)),h^\star(y, y') = \log\frac{\pi^\star(y)}{\pi_{\text{ref}}(y)} - \log\frac{\pi^\star(y')}{\pi_{\text{ref}}(y')} = \beta^{-1}\big(p^\star(y\succ\mu) - p^\star(y'\succ\mu)\big),

because the normalizer cancels in the difference, exactly as in DPO.

A regression whose answer is the target. Write gπ(y)=log⁡π(y)πref(y)g_\pi(y) = \log\frac{\pi(y)}{\pi_{\text{ref}}(y)}, so hπ(y,y′)=gπ(y)−gπ(y′)h_\pi(y, y') = g_\pi(y) - g_\pi(y'). Draw y,y′y, y' independently from μ\mu and let I(y,y′)∈{0,1}I(y, y') \in \{0, 1\} be a sampled preference label, 1 if yy won, with E[I∣y,y′]=p⋆(y≻y′)\mathbb{E}[I\mid y, y'] = p^\star(y\succ y'). Consider minimizing E[(hπ(y,y′)−β−1I(y,y′))2]\mathbb{E}\big[(h_\pi(y,y') - \beta^{-1}I(y,y'))^2\big] over gg. For a squared loss, a noisy target can be replaced by its conditional expectation without changing the minimizer, so this is the same as fitting g(y)−g(y′)g(y) - g(y') to β−1p⋆(y≻y′)\beta^{-1}p^\star(y\succ y'). Fix one response aa in the support of μ\mu and differentiate Ey,y′∼μ[(g(y)−g(y′)−β−1p⋆(y≻y′))2]\mathbb{E}_{y, y'\sim\mu}\big[(g(y) - g(y') - \beta^{-1}p^\star(y\succ y'))^2\big] with respect to g(a)g(a). It appears in the terms with y=ay = a (probability μ(a)\mu(a), sign ++) and with y′=ay' = a (probability μ(a)\mu(a), sign −-), so the derivative is

2μ(a)(Ey′[g(a)−g(y′)−β−1p⋆(a≻y′)]−Ey[g(y)−g(a)−β−1p⋆(y≻a)]).2\mu(a)\Big(\mathbb{E}_{y'}\big[g(a) - g(y') - \beta^{-1}p^\star(a\succ y')\big] - \mathbb{E}_{y}\big[g(y) - g(a) - \beta^{-1}p^\star(y\succ a)\big]\Big).

Use p⋆(y≻a)=1−p⋆(a≻y)p^\star(y\succ a) = 1 - p^\star(a\succ y), so Ey[p⋆(y≻a)]=1−p⋆(a≻μ)\mathbb{E}_y[p^\star(y\succ a)] = 1 - p^\star(a\succ\mu), and write gˉ=Eμ[g]\bar g = \mathbb{E}_\mu[g]. The bracket becomes 2g(a)−2gˉ−2β−1p⋆(a≻μ)+β−12g(a) - 2\bar g - 2\beta^{-1}p^\star(a\succ\mu) + \beta^{-1}, and setting it to zero gives g(a)−gˉ=β−1(p⋆(a≻μ)−12)g(a) - \bar g = \beta^{-1}\big(p^\star(a\succ\mu) - \tfrac12\big). Subtracting this for two responses, the fitted differences are exactly h⋆h^\star. The regression recovers the IPO optimum on the support of μ\mu.

The sampled loss. A data pair (yw,yl)(y_w, y_l) is one draw of an unordered pair with its label, and by symmetry it contributes two terms, (y,y′,I)=(yw,yl,1)(y, y', I) = (y_w, y_l, 1) and (yl,yw,0)(y_l, y_w, 0). Using h(yl,yw)=−h(yw,yl)h(y_l, y_w) = -h(y_w, y_l) and writing h=h(yw,yl)h = h(y_w, y_l),

12[(h−β−1)2+h2]=h2−β−1h+12β−2=(h−12β)2+14β2.\tfrac12\Big[\big(h - \beta^{-1}\big)^2 + h^2\Big] = h^2 - \beta^{-1}h + \tfrac12\beta^{-2} = \Big(h - \frac{1}{2\beta}\Big)^2 + \frac{1}{4\beta^2} .

Dropping the constant gives the IPO loss.

The result is strikingly simple,

LIPO(θ)=E(x,yw,yl)∼D[(hθ−12β)2].\mathcal{L}_{\text{IPO}}(\theta) = \mathbb{E}_{(x,y_w,y_l)\sim\mathcal{D}}\Big[\Big(h_\theta - \frac{1}{2\beta}\Big)^2\Big].

In plain words, IPO regresses each pair's log-ratio difference onto a fixed target of 1/(2β)1/(2\beta) nats, instead of pushing it toward infinity. (Azar et al. call the regularization strength τ\tau. We keep β\beta for consistency, as TRL does.) Its gradient is 2(hθ−12β)(∇θlog⁡πθ(yw)−∇θlog⁡πθ(yl))2(h_\theta - \tfrac{1}{2\beta})(\nabla_\theta\log\pi_\theta(y_w) - \nabla_\theta\log\pi_\theta(y_l)), which changes sign once a pair overshoots its target. A pair that has been learned too well is pulled back. Nothing in DPO does that.

Two details matter when you implement it. First, β\beta does not multiply hh inside the loss. It only sets the target, so β=0.1\beta = 0.1 means a target of 5 nats and β=0.01\beta = 0.01 a target of 50. Second, with hh computed from summed log-probabilities, a fixed target in nats means very different things for 20-token and 2,000-token responses. TRL's implementation divides each sequence's log-ratio by its number of tokens before forming hh, and a comment in its source says the IPO authors confirmed that the paper's results correspond to this normalized form, although the paper itself does not discuss it.

The cell runs the two-response example. With a uniform reference and tabular logits, hh is the difference of the two logits and π(y1)=σ(h)\pi(y_1) = \sigma(h). Azar et al. derive the IPO optimum in closed form for this case. p⋆(y1≻μ)=12⋅1+12⋅12=34p^\star(y_1\succ\mu) = \tfrac12\cdot1 + \tfrac12\cdot\tfrac12 = \tfrac34 and p⋆(y2≻μ)=14p^\star(y_2\succ\mu) = \tfrac14, so π⋆(y1)=σ(12β)\pi^\star(y_1) = \sigma(\tfrac{1}{2\beta}).

Python · cell 1

DPO drives π(y1)\pi(y_1) to essentially 1 for every β\beta, and its margin is still growing when we stop. IPO converges to h=1/(2β)h = 1/(2\beta), giving π(y1)=0.993\pi(y_1) = 0.993 at β=0.1\beta = 0.1 but only 0.622 at β=1\beta = 1. Now β\beta controls the destination, which is what a regularization strength is supposed to do.

Interview

The IPO loss

Implement ipo_loss(pc, pr, rc, rr, beta, lengths_c=None, lengths_r=None), the mean over a batch of (h−12β)2(h - \frac{1}{2\beta})^2. The first four arguments are sequence log-probabilities of shape (B,) (policy chosen, policy rejected, reference chosen, reference rejected). If the optional lengths_c and lengths_r are given, divide each sequence's log-ratio (policy minus reference) by its length before forming hh, as TRL does. Return a float.

Hidden tests, hints, and AI help, from $1.99 a month.

Noisy labels, conservative DPO and robust DPO

Human labels disagree with each other often. In the DPO paper's own human study on summarization, two humans judging the same comparison agreed only 65% of the time in one condition (87% in another). If a fraction ε\varepsilon of the labels in a dataset are flipped, DPO's loss treats every one of them as certain, and because its gradient weight σ(−βh)\sigma(-\beta h) is largest on pairs the model ranks the "wrong" way, a flipped label that the model correctly disbelieves keeps receiving the strongest push.

Mitchell (2023) proposed the obvious fix, in a two-page note. Replace the hard target "ywy_w wins with probability 1" with a soft target 1−ε1 - \varepsilon. The binary cross-entropy against that target is

LcDPO=−(1−ε)log⁡σ(βhθ)−εlog⁡σ(−βhθ),\mathcal{L}_{\text{cDPO}} = -(1-\varepsilon)\log\sigma(\beta h_\theta) - \varepsilon\log\sigma(-\beta h_\theta),

which is exactly label smoothing (§0.5) applied to the DPO classifier. Mitchell calls it conservative DPO (cDPO). Its derivative with respect to hh is β(σ(βh)−(1−ε))\beta\big(\sigma(\beta h) - (1 - \varepsilon)\big), which is zero when the model's implied preference probability equals the target,

σ(βh⋆)=1−ε⟹h⋆=1βlog⁡1−εε.\sigma(\beta h^\star) = 1 - \varepsilon \quad\Longrightarrow\quad h^\star = \frac{1}{\beta}\log\frac{1-\varepsilon}{\varepsilon}.

In plain words, cDPO stops pushing once the implicit reward model is 1−ε1-\varepsilon confident, and pushes back beyond that. With β=0.1\beta = 0.1 and ε=0.1\varepsilon = 0.1 the target is 10log⁡9=22.010\log 9 = 22.0 nats, and with ε=0.2\varepsilon = 0.2 it is 13.9. Like IPO it has a finite optimum. The two differ in what they fix. IPO targets a fixed log-ratio gap, while cDPO targets a fixed confidence. Mitchell's summary puts it well. cDPO trains until the implicit model assigns the desired probability to the observed preferences, and IPO trains until it reaches a desired reward gap. Older TRL versions implemented cDPO as the default sigmoid loss with label_smoothing set to ε\varepsilon. Recent versions keep label_smoothing only for the robust loss below and for EXO, so check which one your version computes.

Notice what cDPO does not change. On a pair the model ranks the wrong way by a wide margin, its push is β(1−ε)\beta(1-\varepsilon), barely less than DPO's β\beta, so a flipped label that the model correctly disbelieves still gets nearly the full force. Christiano et al.'s floor model of §16.3 is a different fix for the same worry. It mixes the Bradley-Terry probability with a coin flip, p=(1−2ε) σ(βh)+εp = (1 - 2\varepsilon)\,\sigma(\beta h) + \varepsilon, so the loss on a badly misranked pair is capped at −log⁡ε-\log\varepsilon and its gradient vanishes there. cDPO bounds overconfidence on the right side of the margin, and the floor model ignores hopeless pairs on the wrong side.

There is a third philosophy for the same problem. If labels are flipped with a known probability ε\varepsilon, one can build an unbiased estimate of the clean loss from the noisy one. Chowdhury, Kini, and Natarajan (2024) do this in robust DPO (rDPO),

LrDPO=(1−ε) ℓ(h)−ε ℓ(−h)1−2ε,ℓ(h)=−log⁡σ(βh).\mathcal{L}_{\text{rDPO}} = \frac{(1-\varepsilon)\,\ell(h) - \varepsilon\,\ell(-h)}{1 - 2\varepsilon}, \qquad \ell(h) = -\log\sigma(\beta h).

Its expectation over the label noise is the clean DPO loss, so it corrects the bias that noise introduces, but it inherits DPO's unbounded optimum (as h→∞h\to\infty the per-pair loss goes to −∞-\infty). cDPO instead accepts a biased objective in exchange for a bounded one. TRL calls rDPO loss_type="robust", with label_smoothing as ε\varepsilon.

Interview

Conservative DPO and its target margin

Implement cdpo_loss(pc, pr, rc, rr, beta, eps) returning the mean conservative DPO loss over a batch, and cdpo_target(beta, eps) returning the log-ratio difference h⋆h^\star at which the per-pair gradient vanishes. Both must be numerically stable, the loss for ∣βh∣|\beta h| in the thousands. With eps=0 the loss must equal the DPO loss.

Hidden tests, hints, and AI help, from $1.99 a month.

KTO, learning from thumbs up and thumbs down

Much of the feedback a deployed model collects is not a pair. A user clicks thumbs up or thumbs down on one response. A safety reviewer marks a single output as unacceptable. A grader says pass or fail. DPO cannot use this data directly, and the reason is precisely the cancellation it is built on. The partition function Z(x)Z(x) cancels only when two responses to the same prompt are compared. A single response's log-ratio log⁡πθ(y∣x)πref(y∣x)\log\frac{\pi_\theta(y\mid x)}{\pi_{\text{ref}}(y\mid x)} is its reward minus βlog⁡Z(x)\beta\log Z(x), an unknown per-prompt offset, so "this response is good" does not tell the loss which way to move it without some baseline.

Ethayarajh, Xu, Muennighoff, Jurafsky, and Kiela (2024) supply the baseline from an unexpected place, prospect theory, the model of human decisions under risk of Kahneman and Tversky. Its central observation is that people judge an outcome relative to a reference point, not in absolute terms, and that losses loom larger than gains. Tversky and Kahneman (1992) fit a value function

v(z)={(z−z0)αz≥z0−λ (z0−z)αz<z0v(z) = \begin{cases} (z - z_0)^{\alpha} & z \ge z_0 \\ -\lambda\,(z_0 - z)^{\alpha} & z < z_0 \end{cases}

with median parameters α=0.88\alpha = 0.88 (diminishing sensitivity) and λ=2.25\lambda = 2.25 (a loss hurts about twice as much as an equal gain). The KTO authors argue that DPO and PPO's clipped objective already behave like value functions of this kind, call losses of this type human-aware losses (HALOs), and design one for unpaired data.

Kahneman-Tversky optimization (KTO) works with the log-ratio gθ(x,y)=log⁡πθ(y∣x)πref(y∣x)g_\theta(x,y) = \log\frac{\pi_\theta(y\mid x)}{\pi_{\text{ref}}(y\mid x)} (the paper calls it rθr_\theta, and note there is no β\beta inside it) and a reference point equal to the policy's current KL from the reference,

z0=DKL(πθ(y′∣x) ∥ πref(y′∣x)),z_0 = D_{\mathrm{KL}}\big(\pi_\theta(y'\mid x)\,\Vert\,\pi_{\text{ref}}(y'\mid x)\big),

the average log-ratio over the policy's own outputs (the expectation is over y′∼πθ(⋅∣x)y' \sim \pi_\theta(\cdot\mid x)). The value of an example is a sigmoid of how far its log-ratio sits above or below that reference point,

v(x,y)={λD σ(β (gθ(x,y)−z0))y desirableλU σ(β (z0−gθ(x,y)))y undesirableLKTO=E(x,y)∼D[λy−v(x,y)],v(x, y) = \begin{cases}\lambda_D\,\sigma\big(\beta\,(g_\theta(x,y) - z_0)\big) & y \text{ desirable}\\ \lambda_U\,\sigma\big(\beta\,(z_0 - g_\theta(x,y))\big) & y\text{ undesirable}\end{cases} \qquad \mathcal{L}_{\text{KTO}} = \mathbb{E}_{(x,y)\sim\mathcal{D}}\big[\lambda_y - v(x, y)\big],

where λy\lambda_y is λD\lambda_D or λU\lambda_U for the example's class (subtracting it only makes the loss nonnegative). In plain words, push the log-ratio of good examples above the policy's average log-ratio and the log-ratio of bad examples below it, with a sigmoid that saturates in both directions.

The reference point is what makes unpaired learning work. Without it, the cheapest way to raise gθg_\theta on a good example is to raise the probability of everything the example has in common with other text, which also raises the KL. With z0z_0 subtracted, a blunt increase moves both terms and gains nothing. The model has to raise this example's probability more than it raises responses in general, so it must learn what makes the example desirable. In this sense z0z_0 plays the role that the rejected response plays in DPO, a baseline that cancels whatever is common.

Three practical details come straight from the paper.

  • Estimating z0z_0. Sampling from the policy at every step would be slow, so KTO estimates the reference point from the batch itself. It shifts the responses by one to form mismatched pairs (xi,yi+1)(x_i, y_{i+1}), averages their log-ratios, clamps at zero, and shares the result across the microbatch, z^0=max⁡(0,1m∑ilog⁡πθ(yi+1∣xi)πref(yi+1∣xi))\hat z_0 = \max\big(0, \frac1m\sum_i\log\frac{\pi_\theta(y_{i+1}\mid x_i)}{\pi_{\text{ref}}(y_{i+1}\mid x_i)}\big). No gradient flows through z^0\hat z_0. It exists only to set where the sigmoid saturates. Notice that this is a crude estimate, since the yi+1y_{i+1} are dataset responses rather than samples from πθ\pi_\theta. This needs a microbatch of at least two, and the authors recommend batch sizes between 8 and 128.
  • Hyperparameters. β=0.1\beta = 0.1 is the default. λD\lambda_D and λU\lambda_U (both 1 by default) rebalance classes, and the paper recommends choosing them so that λDnDλUnU\frac{\lambda_D n_D}{\lambda_U n_U} lies between 1 and 32\frac32, where nDn_D and nUn_U count desirable and undesirable examples (an earlier version of the paper, and TRL's documentation, give 43\frac43 as the upper end). With one desirable example per ten undesirable ones, that means λU=1\lambda_U = 1 and λD\lambda_D between 10 and 15. The paper finds KTO's best learning rate is usually 2 to 10 times DPO's, and recommends 5×10−65\times10^{-6} with AdamW as a default.
  • Results. Converting each preference pair into one desirable and one undesirable example, KTO matched or exceeded DPO at scales from 1B to 30B parameters in the paper's experiments, and matched DPO while discarding up to 90% of the desirable examples.

The gradient explains a qualitative difference from DPO. Differentiating λDσ(β(gθ−z0))\lambda_D\sigma(\beta(g_\theta - z_0)) gives a weight λDβ σ(⋅)(1−σ(⋅))\lambda_D\beta\,\sigma(\cdot)(1 - \sigma(\cdot)), a bell curve in gθg_\theta that peaks at the reference point and vanishes in both tails. KTO learns most from examples near the boundary and almost nothing from examples that are already far on the right side, or hopelessly far on the wrong side. The paper shows that this makes KTO implicitly ignore examples the model finds too hard, which it argues is often a blessing with noisy real-world feedback. DPO does the opposite, giving its largest weight to the pairs it ranks most wrongly.

Python · cell 2

At gθ=−30g_\theta = -30, an example the model is very sure is not good, KTO's weight has fallen to 0.0045, a sixth of its peak, while DPO's weight on an equally misranked pair is 0.095, close to its maximum of β=0.1\beta = 0.1.

Interview

The KTO loss with its reference point

Implement kto_loss(pol, ref, desirable, mm_pol, mm_ref, beta, lam_d=1.0, lam_u=1.0). pol and ref have shape (m,) and hold log⁡πθ(yi∣xi)\log\pi_\theta(y_i\mid x_i) and log⁡πref(yi∣xi)\log\pi_{\text{ref}}(y_i\mid x_i) for the microbatch's examples. desirable is a boolean array of shape (m,). mm_pol and mm_ref hold the same log-probabilities for the mismatched pairs (xi,yi+1)(x_i, y_{i+1}) used to estimate the reference point. Compute z^0=max⁡(0,mean(mm_pol−mm_ref))\hat z_0 = \max(0, \text{mean}(\texttt{mm\_pol} - \texttt{mm\_ref})) and return (loss, z0), where the loss is the mean over examples of λy−v(xi,yi)\lambda_y - v(x_i, y_i) as defined above. Both returned values are floats.

Hidden tests, hints, and AI help, from $1.99 a month.

ORPO, one stage and no reference

Every method so far needs a reference model and an SFT stage before it. Hong, Lee, and Thorne (2024) ask whether both can go. Their starting observation is about SFT itself. Fine-tuning OPT-350M on only the chosen responses of the Anthropic HH dataset raised the log-probabilities of the rejected responses along with the chosen ones, because the two share style and domain. SFT teaches "write like this" without "and not like that". Odds ratio preference optimization (ORPO) adds the "not like that" to the SFT loss, in a single stage.

ORPO works with the per-token geometric-mean probability of a response, Pθ(y∣x)=exp⁡(1∣y∣∑tlog⁡πθ(yt∣x,y<t))P_\theta(y\mid x) = \exp\big(\frac{1}{|y|}\sum_t\log\pi_\theta(y_t\mid x, y_{<t})\big), and its odds, odds⁡θ(y∣x)=Pθ(y∣x)1−Pθ(y∣x)\operatorname{odds}_\theta(y\mid x) = \frac{P_\theta(y\mid x)}{1 - P_\theta(y\mid x)}. The loss is the SFT negative log-likelihood of the chosen response plus a logistic loss on the log odds ratio,

LORPO=E[−1∣yw∣log⁡πθ(yw∣x)⏟LSFT  +  λ (−log⁡σ(log⁡odds⁡θ(yw∣x)odds⁡θ(yl∣x)))⏟LOR].\mathcal{L}_{\text{ORPO}} = \mathbb{E}\Big[\underbrace{-\tfrac{1}{|y_w|}\log\pi_\theta(y_w\mid x)}_{\mathcal{L}_{\text{SFT}}} \;+\; \lambda\,\underbrace{\Big(-\log\sigma\Big(\log\frac{\operatorname{odds}_\theta(y_w\mid x)}{\operatorname{odds}_\theta(y_l\mid x)}\Big)\Big)}_{\mathcal{L}_{\text{OR}}}\Big].

In plain words, imitate the chosen response, and at the same time make its odds of being generated higher than the rejected response's. The weight λ\lambda balances the two terms. The paper's main models use λ=0.1\lambda = 0.1 (Mistral-7B), 0.2 (Llama-2 7B), and 0.25 (Phi-2), and its ablation compares 0.1, 0.5, and 1.0. A worked example sets the scale. A chosen response with average token log-probability −0.5-0.5 has P=0.607P = 0.607 and odds 1.54. A rejected one at −2.0-2.0 has P=0.135P = 0.135 and odds 0.157. The log odds ratio is log⁡(1.54/0.157)=2.29\log(1.54/0.157) = 2.29, and LOR=−log⁡σ(2.29)=0.097\mathcal{L}_{\text{OR}} = -\log\sigma(2.29) = 0.097.

Why odds and not the probability ratio that DPO-style losses use? The authors argue that the probability ratio is too aggressive when preference learning is folded into SFT from the first step. Driving the log-sigmoid of a log probability ratio toward zero demands an extreme contrast, which over-suppresses the rejected tokens before the model has even adapted to the domain. The log odds ratio is distributed less sharply, so the same loss asks for a milder contrast, and their ablations favor it in this setting. The price of removing the reference is the anchor. Nothing in ORPO measures distance from a starting model, and only the SFT term keeps the policy on the data's distribution. Computing the log odds stably needs care, because 1−P1 - P underflows as P→1P \to 1. With a=1∣y∣log⁡πθ(y∣x)≤0a = \frac{1}{|y|}\log\pi_\theta(y\mid x) \le 0, use log⁡odds⁡=a−log⁡(−expm1⁡(a))\log\operatorname{odds} = a - \log(-\operatorname{expm1}(a)).

Core

The ORPO loss, computed stably

Implement orpo_loss(chosen_logps, chosen_len, rejected_logps, rejected_len, lam). The log-probability arrays have shape (B,) and hold summed response log-probabilities log⁡πθ(y∣x)\log\pi_\theta(y\mid x) (all strictly negative), and the lengths hold token counts. Return (total, sft, odds_ratio_term), three floats, the batch means of LSFT+λLOR\mathcal{L}_{\text{SFT}} + \lambda\mathcal{L}_{\text{OR}}, of LSFT\mathcal{L}_{\text{SFT}}, and of LOR\mathcal{L}_{\text{OR}}. It must be accurate when the average log-probability is as close to zero as −10−12-10^{-12} and as negative as −50-50.

Hidden tests, hints, and AI help, from $1.99 a month.

SimPO, a length-normalized margin with no reference

Meng, Xia, and Chen (2024) start from a mismatch. A model generates text by (approximately) maximizing likelihood, and when several candidates are compared, as in beam search or multiple-choice scoring, the usual criterion is the average log-probability per token (§6.6). DPO's implicit reward is something else, a summed log-ratio to a reference. The authors measured that after DPO training, on only about half of the training triples did the ranking by DPO's implicit reward agree with the ranking by average log-likelihood, so the criterion the model generates by barely agreed with the reward it was trained on. (Chen et al. (2024) report a related finding across many released preference-tuned models, whose ranking accuracy on common preference datasets is mostly below 60%.)

Simple preference optimization (SimPO) makes the reward the generation criterion itself, scaled, and adds a target margin γ\gamma to Bradley-Terry,

rSimPO(x,y)=β∣y∣log⁡πθ(y∣x),LSimPO=−E[log⁡σ(β∣yw∣log⁡πθ(yw∣x)−β∣yl∣log⁡πθ(yl∣x)−γ)].r_{\text{SimPO}}(x, y) = \frac{\beta}{|y|}\log\pi_\theta(y\mid x), \qquad \mathcal{L}_{\text{SimPO}} = -\mathbb{E}\Big[\log\sigma\Big(\frac{\beta}{|y_w|}\log\pi_\theta(y_w\mid x) - \frac{\beta}{|y_l|}\log\pi_\theta(y_l\mid x) - \gamma\Big)\Big].

In plain words, make the chosen response's average token log-probability exceed the rejected one's by more than γ/β\gamma/\beta, and stop caring much beyond that. Three design choices are packed into it.

  • Length normalization. A summed log-probability is lower for longer responses, so a summed reward forces the model to inflate the probability of long chosen responses unnaturally, and the authors found that removing the normalization made the model produce longer, lower-quality responses. Averaging removes the systematic effect of length.
  • No reference model. The reward needs only the policy, which saves the memory and compute of the reference, and removes the KL anchor along with it.
  • A target margin. The term γ\gamma shifts the sigmoid so that a pair contributes a substantial gradient until its reward gap exceeds γ\gamma. Pairs that are "barely right" keep being pushed.

The paper's guidance is β\beta between 2.0 and 2.5 and γ\gamma between 0.5 and 1.5 (both on the scale of averaged log-probabilities, hence much larger β\beta than DPO's), and it stresses that careful tuning mattered for every method it compared. In its experiments SimPO beat DPO by up to 6.4 points of length-controlled win rate on AlpacaEval 2 and up to 7.5 points on Arena-Hard, and its strongest model, Gemma-2-9B-it trained with SimPO, reached a 72.4% length-controlled win rate on AlpacaEval 2 and 59.1% on Arena-Hard.

Two close relatives are worth knowing. Length-normalized DPO, used by Tülu 3, keeps the reference but averages its log-ratios, β∣yw∣log⁡πθ(yw∣x)πref(yw∣x)−β∣yl∣log⁡πθ(yl∣x)πref(yl∣x)\frac{\beta}{|y_w|}\log\frac{\pi_\theta(y_w\mid x)}{\pi_{\text{ref}}(y_w\mid x)} - \frac{\beta}{|y_l|}\log\frac{\pi_\theta(y_l\mid x)}{\pi_{\text{ref}}(y_l\mid x)} inside the sigmoid, and in Tülu 3's own ablation it was the only variant (of DPO, SimPO, and length-normalized DPO) that beat their starting checkpoint overall, with β=5\beta = 5. Length-regularized DPO (R-DPO, Park et al. 2024) keeps sums but adds α(∣yw∣−∣yl∣)\alpha(|y_w| - |y_l|) inside the sigmoid, derived by putting a length penalty −α∣y∣-\alpha|y| in the reward, so a longer chosen response needs a smaller log-ratio gap to be explained. The disagreement between SimPO's and Tülu 3's results is itself instructive. Which variant wins depends on the model, the data, and how much each was tuned.

Python · cell 3

The rejected answer has a far higher summed log-probability only because it is a quarter of the length. Per token, the chosen answer is more likely, and SimPO's reward gap is 2.0×0.3=0.62.0 \times 0.3 = 0.6, still short of the target margin of 1.0, so the pair keeps pulling.

Interview

SimPO from token log-probabilities

Implement simpo_loss(token_logps_c, mask_c, token_logps_r, mask_r, beta, gamma). The token log-probability arrays have shape (B, T) and hold log⁡πθ(yt∣x,y<t)\log\pi_\theta(y_t\mid x, y_{<t}) at every position, and the masks of the same shape mark response tokens (other positions may hold anything, including large values). Return the mean SimPO loss over the batch as a float. It needs no reference model. It must be stable for large reward gaps.

Hidden tests, hints, and AI help, from $1.99 a month.

Keeping the chosen response likely

Section 17.3 showed the chosen response's log-probability falling during an ordinary DPO run. A family of fixes adds a term that resists it. DPO-Positive (DPOP, Pal et al. 2024) subtracts λmax⁡(0,log⁡πref(yw∣x)πθ(yw∣x))\lambda\max\big(0, \log\frac{\pi_{\text{ref}}(y_w\mid x)}{\pi_\theta(y_w\mid x)}\big) from hθh_\theta inside the sigmoid (so the sigmoid sees β\beta times the penalized margin), a penalty that switches on only when the chosen response has become less likely than under the reference. Simpler and more common is a plain negative log-likelihood term on the chosen response, added to the DPO loss with a small weight. Iterative reasoning preference optimization (Pang et al. 2024) found that term crucial for math reasoning, and Llama 3 uses it with weight 0.2. Exercise 17.3c implemented exactly this objective. Section 17.5 asks when the fall in chosen likelihood is harmless and when it is dangerous, which decides whether such a term is needed.

The family at a glance

The widget plots each loss as a function of a pair's log-ratio difference hh (or, for SimPO, the gap in average log-probability), together with its gradient. The shapes tell the story of the section. DPO's loss falls forever. IPO is a parabola with its bottom at 1/(2β)1/(2\beta). cDPO has a bottom at 1βlog⁡1−εε\frac1\beta\log\frac{1-\varepsilon}{\varepsilon} and rises beyond it. The hinge of SLiC (Zhao et al. 2023) is flat once the margin is met. SimPO is DPO's curve shifted right by its margin.

How do the DPO-family losses treat a pair as its margin grows?
The horizontal axis is a pair's log-ratio difference h in nats (for KTO, its log-ratio minus the reference point). Each curve is divided by its value at h = 0, so all start at 1 and the shapes can be compared.
Loading interactive figure…
methoddataneeds a referenceloss on the marginlength handlingfinite optimum per pairkey hyperparametersreach for it when
DPOpairsyeslogistic, −log⁡σ(βh)-\log\sigma(\beta h)none (sums)noβ≈0.1\beta\approx0.1the default, with good paired data
length-normalized DPOpairsyeslogistic on averaged log-ratiosaveragesnoβ≈5\beta\approx5length bias, as in Tülu 3
IPOpairsyessquared, (h−12β)2(h - \frac{1}{2\beta})^2often averagedyes, h=12βh = \frac1{2\beta}β\beta sets the targetnear-deterministic pairs, overfitting
cDPOpairsyessmoothed logisticnoneyes, h=1βlog⁡1−εεh = \frac1\beta\log\frac{1-\varepsilon}\varepsilonβ\beta, ε\varepsilonnoisy labels, a bounded objective
rDPOpairsyesdebiased logisticnonenoβ\beta, flip rate ε\varepsilonnoisy labels with a known flip rate
KTOsingle responses marked good or badyessigmoid around a KL reference pointnonesaturatesβ\beta, λD\lambda_D, λU\lambda_Uunpaired or imbalanced feedback
ORPOpairsnoSFT plus logistic on log odds ratioaveragesnoλ≈0.1\lambda\approx0.1 to 0.250.25one stage from a base model, no reference
SimPOpairsnologistic with margin γ\gamma on averaged log-probsaveragesnoβ≈2\beta\approx2 to 2.52.5, γ≈0.5\gamma\approx0.5 to 1.51.5memory limits, length bias
DPO plus NLL (RPO, Llama 3)pairsyesDPO plus α⋅\alpha\cdotNLL on chosennonenoα≈0.2\alpha\approx0.2chosen likelihood collapsing, reasoning tasks

How to choose, in practice? Start with DPO, or its length-normalized version if your data reward length, at the published defaults, and watch the metrics of §17.3. If the chosen log-probability collapses or generations degrade, add a small NLL term. If training accuracy races toward 100% and margins grow without bound, the pairs are being memorized, so try IPO or cDPO, or just fewer epochs. If your feedback is single thumbs-up or thumbs-down, or one class is rare, use KTO rather than inventing pairs. ORPO and SimPO save a reference model and, for ORPO, a whole SFT stage, at the cost of the KL anchor. Above all, hold your expectations loosely. Practitioners widely believe, and Ivison et al. (2024) found in a controlled study, that the quality of the preference data matters more than the choice of loss, and published comparisons of these variants frequently disagree once each method is tuned.

In PyTorch

All of these losses are a few lines on top of the same four (or two) vectors of log-probabilities. One function covers the paired ones, and autograd confirms the gradients we derived by hand, including the sign change of IPO and cDPO past their targets.

🔥 In PyTorchfor a machine with PyTorch

Below its target, each loss pushes the chosen log-probability up (negative gradient, so gradient descent increases it). Above the target, the sign flips and it pulls the pair back, the behavior that bounds these methods and that plain DPO lacks.

Read more

Watch next

🎬 Direct Preference Optimization (DPO) and Friends | Post-Training Course, Lecture 6 · Nathan Lambert · starts at 33:30A quick tour of the zoo of direct alignment algorithms, IPO, ORPO, SimPO, and others.
🎬 ORPO: Monolithic Preference Optimization without Reference Model (Paper Explained) · Yannic KilcherA critical paper reading of ORPO, including its odds-ratio loss and what the experiments do and do not show.