Math Foundations — Lecture 10
Bradley–Terry preference model, RM loss, RLHF/PPO objective with KL penalty, clipped surrogate, DPO loss derivation.
Notation
Bradley–Terry preference model
Model the probability that \(y_w\) is preferred to \(y_l\) by a sigmoid of the reward gap:
Only score differences are identifiable: \(r' = r + c\) produces an identical likelihood, so the reward model is unique only up to an additive constant.
Reward model loss (negative log-likelihood)
Equivalent to logistic regression on the score gap with labels always "winner". Minimising this NLL fits \(r_\phi\) so that preferred completions score higher.
RLHF objective with KL anchor
After the reward model is trained, freeze \(r_\phi\) and optimise the policy:
The KL term is implemented in practice as a per-token penalty on the log-ratio \(\log\pi_\theta(y_t\mid x,y_{<t}) - \log\pi_{\text{SFT}}(y_t\mid x,y_{<t})\), folded into the per-step reward used by PPO.
Why the KL term?
- Reward hacking: with no anchor, \(\pi_\theta\) can drift into degenerate text that the imperfect \(r_\phi\) over-scores.
- Mode collapse: a pure reward-max objective concentrates probability on one or two completions; KL keeps the distribution spread.
- Fluency anchor: \(\pi_{\text{SFT}}\) already speaks like a normal LM; we only want a small corrective shift toward preferred behaviour.
The optimal solution to the KL-regularised reward objective is a tilted reference policy:
Reward acts as a log-density tilt of strength \(1/\beta\); large \(\beta\) → stay close to SFT, small \(\beta\) → chase reward.
PPO clipped surrogate objective
Define the importance ratio between the current policy and the policy used to collect rollouts:
Vanilla policy gradient maximises \(\mathbb{E}[\rho_t \hat A_t]\) but can blow up if \(\rho_t\) drifts far from 1. PPO clips:
With \(\epsilon\) typically 0.1–0.2. The \(\min\) picks the more conservative of the two terms, so once the ratio leaves \([1-\epsilon, 1+\epsilon]\) in the helpful direction, the gradient is clipped — limiting any single update step. This is what makes PPO "proximal".
Direct Preference Optimisation (DPO)
Start from the closed-form optimum of the KL-regularised reward objective:
Invert to express the implicit reward in terms of the policy:
Plug into the Bradley–Terry likelihood. The intractable \(Z(x)\) cancels because it appears for both \(y_w\) and \(y_l\) at the same prompt, leaving the DPO loss:
Train \(\pi_\theta\) directly on preference pairs — no reward model, no PPO sampling loop. Two model passes per pair: score \(y_w\) and \(y_l\) under both \(\pi_\theta\) and \(\pi_{\text{SFT}}\).
RLHF (PPO) vs DPO at a glance
Both share the Bradley–Terry preference model and a KL-style anchor to \(\pi_{\text{SFT}}\) controlled by \(\beta\). Both inherit the limitations and biases of the preference data, and Lee et al. (2024) show that DPO de-toxification can be brittle — internal toxic feature vectors persist even when outputs no longer expose them.