Direct Preference Optimization (DPO)

Volume III, Chapter 13 — Part I. Deriving DPO from the RLHF objective: Bradley-Terry preferences, closed-form optimal policy, implicit reward modeling, and the DPO loss without reinforcement learning.

Advanced

Table of Contents

  1. Learning Objectives
  2. Prerequisites
  3. Notation
  4. Core Intuition
  5. Preference Data and Bradley-Terry Model
  6. The RLHF Objective
  7. Closed-Form Optimal Policy
  8. Deriving the DPO Loss
  9. Implicit Reward Model
  10. DPO vs. RLHF Pipeline
  11. Worked Examples
  12. Connection to the Broader Curriculum
  13. Common Pitfalls and Misconceptions
  14. Research Perspective
  15. Summary of Takeaways
  16. Exercises

Learning Objectives

After reading this chapter, you should be able to:

  1. State the Bradley-Terry preference model P(ywylx)P(y_w \succ y_l \mid x).
  2. Write the RLHF objective with KL penalty to reference policy πref\pi_{\text{ref}}.
  3. Derive the closed-form optimal policy π\pi^* in terms of reward rr.
  4. Eliminate the reward model to obtain the DPO loss directly on policy log-probabilities.
  5. Explain why DPO avoids reinforcement learning (PPO) during alignment.

Prerequisites


Notation

  • xx — Prompt
  • yw,yly_w, y_l — Preferred (winner) and dispreferred (loser) completions
  • πθ,πref\pi_\theta, \pi_{\mathrm{ref}} — Trainable and frozen reference policies
  • r(x,y)r(x, y) — Latent reward function
  • β\beta — KL penalty coefficient
  • σ()\sigma(\cdot) — Logistic sigmoid

Core Intuition

Alignment adjusts a pretrained LLM to produce helpful, harmless outputs. RLHF (Reinforcement Learning from Human Feedback) trains a reward model on human preferences, then optimizes the policy with PPO — unstable and complex.

DPO (Rafailov et al., 2023) shows the optimal RLHF policy has a closed form in terms of the reward. Substituting back into the preference model eliminates the reward entirely — alignment becomes supervised learning on preference pairs with a simple classification loss.

Series context. Volume III, Chapter 13 (Alignment).

Direct Preference Optimization

Preferred: "Helpful answer"Rejected: "Wrong answer"r̂ = β·log(π/π_ref) = 0.080 · L = 0.654
β
0.10
Explore: DPO reparameterizes the RLHF reward into a classification loss over preference pairs. Higher β sharpens the preference signal; no separate reward model needed.

Preference Data and Bradley-Terry Model

Definition 1 (Preference Dataset). Triples (x,yw,yl)(x, y_w, y_l) where ywy_w is preferred (winner) over yly_l (loser) for prompt xx.

Definition 2 (Bradley-Terry Model).

P(ywylx)=σ(r(x,yw)r(x,yl))=exp(r(x,yw))exp(r(x,yw))+exp(r(x,yl)),(1)P(y_w \succ y_l \mid x) = \sigma(r(x, y_w) - r(x, y_l)) = \frac{\exp(r(x, y_w))}{\exp(r(x, y_w)) + \exp(r(x, y_l))}, \tag{1}

where r(x,y)r(x, y) is a latent reward function and σ\sigma is the logistic sigmoid from Logistic Regression.


The RLHF Objective

Definition 3 (KL-Constrained RLHF).

maxπθExD,yπθ(x)[r(x,y)]βDKL(πθ(x)πref(x)),(2)\max_{\pi_\theta} \mathbb{E}_{x \sim \mathcal{D}, y \sim \pi_\theta(\cdot|x)}[r(x, y)] - \beta D_{\text{KL}}(\pi_\theta(\cdot|x) \| \pi_{\text{ref}}(\cdot|x)), \tag{2}

where πref\pi_{\text{ref}} is the frozen pretrained policy and β>0\beta > 0 controls deviation from reference.


Closed-Form Optimal Policy

Theorem 1 (Optimal Policy). The unique maximizer of (2) is:

π(yx)=1Z(x)πref(yx)exp(1βr(x,y)),(3)\pi^*(y|x) = \frac{1}{Z(x)} \pi_{\text{ref}}(y|x) \exp\left(\frac{1}{\beta} r(x, y)\right), \tag{3}

where Z(x)=yπref(yx)exp(r(x,y)/β)Z(x) = \sum_y \pi_{\text{ref}}(y|x) \exp(r(x,y)/\beta) is the partition function.

Proof. Lagrange multipliers on probability simplex; Gibbs distribution form. \blacksquare

Corollary 1 (Reward Recovery).

r(x,y)=βlogπ(yx)πref(yx)+βlogZ(x).(4)r(x, y) = \beta \log \frac{\pi^*(y|x)}{\pi_{\text{ref}}(y|x)} + \beta \log Z(x). \tag{4}

Deriving the DPO Loss

Substitute (4) into Bradley-Terry (1). The partition function Z(x)Z(x) cancels:

Theorem 2 (DPO Loss).

LDPO=E(x,yw,yl)[logσ(βlogπθ(ywx)πref(ywx)βlogπθ(ylx)πref(ylx))].(5)\mathcal{L}_{\text{DPO}} = -\mathbb{E}_{(x, y_w, y_l)}\left[\log \sigma\left(\beta \log \frac{\pi_\theta(y_w|x)}{\pi_{\text{ref}}(y_w|x)} - \beta \log \frac{\pi_\theta(y_l|x)}{\pi_{\text{ref}}(y_l|x)}\right)\right]. \tag{5}

Proof. From (1):

P(ywyl)=σ(r(x,yw)r(x,yl))=σ(βlogπθ(ywx)πref(ywx)βlogπθ(ylx)πref(ylx)),(6)P(y_w \succ y_l) = \sigma(r(x,y_w) - r(x,y_l)) = \sigma\left(\beta \log \frac{\pi_\theta(y_w|x)}{\pi_{\text{ref}}(y_w|x)} - \beta \log \frac{\pi_\theta(y_l|x)}{\pi_{\text{ref}}(y_l|x)}\right), \tag{6}

using (4) and cancellation of logZ(x)\log Z(x). Maximum likelihood on preferences gives (5). \blacksquare

Important equation. DPO optimizes policy πθ\pi_\theta directly — no explicit reward model, no PPO.


Implicit Reward Model

Definition 4 (Implicit Reward).

r^(x,y)=βlogπθ(yx)πref(yx).(7)\hat{r}(x, y) = \beta \log \frac{\pi_\theta(y|x)}{\pi_{\text{ref}}(y|x)}. \tag{7}

DPO implicitly defines a reward through the policy ratio to reference.


DPO vs. RLHF Pipeline

  • 1 — SFT on demonstrations — SFT (same)
  • 2 — Train reward model — —
  • 3 — PPO on reward — DPO loss (5)
  • Stability — PPO hyperparameters — Standard SGD
  • Compute — 3 models — 2 models (πθ\pi_\theta, frozen πref\pi_{\text{ref}})

Worked Examples

Example 1: Preference Probability

If πθ(ywx)/πref(ywx)=2\pi_\theta(y_w|x)/\pi_{\text{ref}}(y_w|x) = 2 and ratio for yly_l is 1, DPO logit =βlog2= \beta \log 2. For β=0.1\beta = 0.1, preference probability 0.52\approx 0.52.

Example 2: Identical to Reference

If πθ=πref\pi_\theta = \pi_{\text{ref}}, DPO logit =0= 0 — 50% preference probability (uninformative).


Connection to the Broader Curriculum


Common Pitfalls and Misconceptions

Pitfall 1: DPO still requires good SFT initialization.

Pitfall 2: β\beta too small → ignore preferences; too large → collapse to reference.

Pitfall 3: Length bias in preferences affects DPO.

Pitfall 4: DPO assumes Bradley-Terry transitivity.


Research Perspective

DPO (Rafailov et al., 2023). Extensions: IPO, KTO, ORPO, SimPO. Active: online DPO, multi-objective alignment.


Summary of Takeaways

  • Bradley-Terryσ(rwrl)\sigma(r_w - r_l)
  • Optimal policyππrefexp(r/β)\pi^* \propto \pi_{\text{ref}} \exp(r/\beta)
  • DPO loss — (5)
  • Implicit rewardβlog(πθ/πref)\beta \log(\pi_\theta / \pi_{\text{ref}})

Next: LoRA


Exercises

Exercise 1. Derive (3) from (2).

Exercise 2. Prove Z(x)Z(x) cancels in (6).

Exercise 3. Derive gradient of (5) w.r.t. θ\theta.

Exercise 4. Effect of β0\beta \to 0 and β\beta \to \infty.

Exercise 5. Connect Bradley-Terry to Logistic Regression.

Exercise 6. Why store πref\pi_{\text{ref}} separately?

Exercise 7. DPO with LoRA on both policies?

Exercise 8. Limitations of preference transitivity.