From Demonstrations to Preferences: SFT, DPO and PPO Compared
Machine LearningModel answerLast updated
Explain SFT's token-likelihood objective, DPO's pairwise log-ratio loss, and how PPO fits into KL-regularized post-training.
You are asked to walk through the main stages of post-training an autoregressive language model and to compare three approaches: supervised fine-tuning (SFT), Direct Preference Optimization (DPO), and PPO-style reinforcement learning with a reward derived from preferences.
Part 1 — SFT
Describe the SFT training objective and explain why a pipeline often still runs SFT before any preference-based stage. Cover how the loss is computed over tokens, which tokens are masked out, and what SFT does and does not teach the model.
Part 2 — DPO versus PPO
Describe what the standard DPO loss optimizes, given pairs of chosen and rejected responses and a frozen reference model. Then contrast the DPO training loop with a PPO loop that uses preference-derived rewards: where data comes from, what is sampled, what is estimated, and what is updated. Explain why SFT, DPO and PPO-style RL are often combined rather than treated as mutually exclusive replacements.
Part 3 — The KL claim
A colleague says: "DPO has no KL term, so it needs no KL regularization." Evaluate that statement carefully. Separate (a) the fact that the usual DPO loss contains no explicitly computed KL penalty from (b) the KL-regularized objective that DPO is derived from and its dependence on the reference policy. Also explain the role of DPO's temperature / regularization coefficient β.
Assumptions
Discuss the standard formulations; acknowledge that later variants may differ. Assume an autoregressive model, demonstration data for SFT, and paired response preferences for the preference stage. Do not assume one method is universally best.
Questions you may want to ask first
- What data is available: demonstrations, preference pairs, or an online reward signal?
- Is the focus on the training loss, the full data-collection pipeline, or final model quality?
- Are we allowed to sample new responses from the current policy during training?
Hints
Hint 1
SFT is plain next-token cross-entropy on demonstrations; write down what the target token is and which positions you zero out.
Hint 2
DPO never rolls out a policy to score samples: it turns the Bradley–Terry preference model into a closed-form loss on log-probability ratios between the policy and a frozen reference model.
Hint 3
The usual DPO loss hides its KL term inside the reference model — it is implicit in the log-ratio, not computed separately. β sets how strongly the policy is tied to the reference.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Part 1 — SFT
SFT is maximum likelihood on demonstrations. Given a prompt $x$ and a demonstrated response $y=(y_1,\dots,y_T)$, the model is trained to minimize
$$L_{\text{SFT}}(\theta) = -\sum_{t=1}^{T} \log \pi_\theta(y_t \mid x, y_{<t}).$$
In practice the prompt tokens are masked out of the loss: you set the label to an ignore index at prompt positions and keep only positions where the target is a response token. For multi-turn data, assistant turns are kept and user/system turns are masked. The reason is that you want to shape the model's own generations, not teach it to reproduce the prompt. A typical implementation shifts logits and labels by one, computes per-token cross-entropy with reduction='none', multiplies by a mask, then averages over the unmasked tokens. Padding is masked as well, and you normalize by the number of kept tokens (or do token-level averaging per sequence and then batch-average, which matters when response lengths vary).
What SFT teaches: the format, style, tool-call syntax, refusal behavior, and a reasonable mode of the demonstration distribution. What it does not teach: how to choose between two plausible answers. A demonstration says "this is one good response," not "this is better than that one." SFT also has no mechanism to penalize outputs that are plausible but bad; it never sees them. That is why a pipeline usually still runs SFT first — it puts the model in the right region of output space so that preference training starts from a policy that already produces reasonable candidates, and it defines the reference model that preference methods regularize toward.
Part 2 — DPO versus PPO
DPO. Data are triples $(x, y_w, y_l)$ — a prompt with a preferred and a dispreferred response. With a frozen reference model $\pi_{\text{ref}}$ (usually the SFT model) and coefficient $\beta$:
$$L_{\text{DPO}} = -\mathbb{E}\left[\log\sigma!\left(\beta\log\frac{\pi_\theta(y_w\mid x)}{\pi_{\text{ref}}(y_w\mid x)} - \beta\log\frac{\pi_\theta(y_l\mid x)}{\pi_{\text{ref}}(y_l\mid x)}\right)\right].$$
The inner quantity is the difference of sequence-level log-ratios; the loss pushes the margin up. Everything is computed with a forward pass and log-probability sums — no sampling, no reward model, no value function, no per-token credit assignment. It is an offline, supervised-style classification loss on pairs.
PPO. The pipeline is: (1) a reward model $r_\phi(x,y)$ is trained on the same preference pairs with a Bradley–Terry loss; (2) the policy samples responses to prompts; (3) the reward model scores the samples; (4) advantages are estimated (with a learned value function and GAE); (5) the policy is updated with a clipped surrogate objective, commonly with a KL penalty to the reference:
$$L_{\text{PPO}} = -\mathbb{E}\left[\min\left(\rho_t \hat A_t,\ \text{clip}(\rho_t, 1-\epsilon, 1+\epsilon)\hat A_t\right)\right] + \beta,\mathrm{KL}(\pi_\theta ,|, \pi_{\text{ref}}),$$
where $\rho_t$ is the importance ratio of new to old policy probabilities.
Practical differences: PPO is on-policy and needs a rollout engine, reward model inference, a value head, and careful tuning of clip range, batch size, learning rate and KL coefficient; it also allows exploration beyond the fixed dataset, which can help with reasoning-heavy tasks where the good behavior isn't in the pairs. DPO is much simpler and cheaper, is stable, and uses the data once — but it is offline, so it can only reweight behavior present in the pairs, and it can overfit to stylistic artifacts of the preference data. Combining them is normal: SFT to establish format and a reference, DPO for cheap preference alignment, PPO/RL when you have a verifiable or online reward and want to push beyond the data. They are not interchangeable; they consume different data and optimize different things.
Part 3 — The KL claim
The claim conflates two things. It is true that the standard DPO loss has no separately computed KL term added to the objective — there is no explicit + β·KL step, no reward model, and no per-token KL estimate during training. But it is false that DPO "has no KL regularization."
DPO is derived from the KL-regularized objective
$$\max_\pi\ \mathbb{E}{x,,y\sim\pi}\left[r(x,y)\right] - \beta,\mathrm{KL}!\left(\pi(\cdot\mid x),|,\pi{\text{ref}}(\cdot\mid x)\right),$$
whose optimum has a closed form $\pi^*(y\mid x) \propto \pi_{\text{ref}}(y\mid x)\exp(r(x,y)/\beta)$. Solving for the reward and substituting into the Bradley–Terry preference likelihood eliminates the reward model and yields the DPO loss above. The KL constraint is therefore baked in: it is what makes the optimal policy a reweighting of the reference model, and it is why the log-ratio $\log \pi_\theta/\pi_{\text{ref}}$ appears at all. $\pi_{\text{ref}}$ is not a cosmetic detail — it is the anchor. With $\pi_{\text{ref}}$ set to the SFT model, DPO implicitly penalizes drifting far from it in probability space.
The coefficient $\beta$ is exactly the KL strength. While in PPO a larger $\beta$ means a larger explicit penalty, in DPO the effect is inverted in appearance: $\beta$ scales the logit margin, so larger $\beta$ makes the loss more sensitive to small log-ratio differences and keeps the policy closer to the reference; smaller $\beta$ lets the policy move farther from $\pi_{\text{ref}}$. Practically this means $\beta$ controls how aggressively preferences are enforced versus how much likelihood mass on the reference behavior is preserved, and it interacts with the learning rate. Common pitfalls: forgetting that $\pi_{\text{ref}}$ must be frozen and identical to the starting checkpoint; computing log-probabilities with different tokenization or length normalization for chosen and rejected (sequence-sum vs. length-normalized changes the effective regularization); and assuming the derived objective guarantees bounded divergence — DPO regularizes in expectation on the data distribution, but nothing stops large drift off-distribution, which is why later variants add explicit constraints or online sampling.