Fine-Tuning & PEFT Series — Presentation 04

DPO and Its Cousins

DPO, IPO, KTO, ORPO, GRPO — what each fixes, when each wins, and a decision tree for choosing the right one for your use case.

DPO IPO KTO ORPO GRPO Implicit Reward Preference Optimisation DeepSeek-R1
SFT Model → Pref Pairs → DPO Loss → No RM Needed → No Rollouts → Aligned Policy
00

Topics We'll Cover

01

Why DPO — Skipping the Reward Model

PPO RLHF requires three training stages: SFT, reward model training, and RL fine-tuning. Each stage introduces a new failure mode. The reward model is the most fragile piece: it must generalise well beyond its training distribution, and even small calibration errors are amplified by the RL optimisation loop.

Rafailov et al. (2023) — Direct Preference Optimisation: Your Language Model Is Secretly a Reward Model — showed you can mathematically re-derive the optimal RLHF policy without ever training a separate reward model. The key insight is that under the Bradley-Terry preference model, the optimal policy implicitly encodes the reward function — and you can optimise directly for the optimal policy using a classification-like loss on the preference data.

PPO RLHF (three stages)

1. Train SFT model πSFT

2. Collect preference pairs (yw, yl)

3. Train reward model rφ

4. PPO: optimise πθ with rφ + KL(πθ || πSFT)

Four model copies in VRAM simultaneously

DPO (two stages)

1. Train SFT model πSFT

2. Collect preference pairs (yw, yl)

3. DPO: optimise πθ directly from pairs

 

Two model copies: πθ (training) + πref (frozen)

DPO quality vs PPO

On standard benchmarks (MT-Bench, AlpacaEval 2.0) DPO matches or slightly trails well-tuned PPO on single-turn instruction following. PPO retains an advantage on tasks requiring online exploration or non-differentiable rewards (code execution, math). For the vast majority of chat-style alignment work, DPO is the simpler and cheaper choice.

02

DPO Derivation — Implicit Reward, Reference Model

Starting from the RLHF objective — maximise expected reward minus KL divergence from the reference policy:

Objective: max E[r(x,y)] − β KL(π θ || π ref ) Step 1: The closed-form optimal policy is: π*(y|x) = (1/Z(x)) · π ref (y|x) · exp(r(x,y) / β) Step 2: Rearrange to express r(x,y) in terms of π* and π_ref: r(x,y) = β log(π*(y|x) / π ref (y|x)) + β log Z(x) Step 3: Substitute into Bradley-Terry; log Z(x) cancels in the preference difference → DPO loss depends only on log-ratios: no reward model, no partition function
The key cancellation

The normalisation constant Z(x) = ∑y πref(y|x) exp(r(x,y)/β) is intractable to compute — but when you subtract the implicit reward of the winner from the implicit reward of the loser (as the Bradley-Terry model does), Z(x) cancels exactly. This is why DPO works without ever computing or sampling from the partition function.

03

DPO Loss, Beta, Positive/Negative Pairs

The DPO training objective is a binary cross-entropy over the log-ratio of policy probabilities relative to the reference, applied to pairwise preference data:

L DPO = −log σ(β · [log(π θ (y w |x) / π ref (y w |x)] − [log(π θ (y l |x) / π ref )]) β controls how strongly the model diverges from π_ref: higher β = more conservative. Typical range: 0.01–0.5
TRL DPOTrainer — minimal setup
from trl import DPOTrainer, DPOConfig

training_args = DPOConfig(
    beta=0.1,
    loss_type="sigmoid",     # "sigmoid" (DPO), "ipo", "kto_pair", "robust"
    label_smoothing=0.0,    # >0 reduces overconfidence on easy pairs
    max_length=2048,
    max_prompt_length=512,
    per_device_train_batch_size=4,
    gradient_accumulation_steps=8,
    learning_rate=5e-7,     # DPO needs lower LR than SFT; 1e-6–5e-7
)

# dataset must have columns: "prompt", "chosen", "rejected"
trainer = DPOTrainer(
    model=model,
    ref_model=ref_model,    # or None to use the model's own frozen copy
    args=training_args,
    train_dataset=dataset,
)
Label smoothing and length normalisation

Set label_smoothing=0.1 to reduce overconfidence on clear-cut pairs. Enable length_normalization=True in DPOConfig (≥0.12) to normalise log-probabilities by sequence length — this prevents the loss from being dominated by long completions and is particularly important when your chosen/rejected pairs have very different lengths.

04

IPO — Fixing Preference Saturation

Azar et al. (2023) — A General Theoretical Paradigm to Understand Learning from Human Feedback — identified a subtle failure mode in DPO: the sigmoid in the DPO loss saturates when the margin between chosen and rejected log-probabilities becomes very large. Once the model is very confident in a preference direction, the gradient vanishes and learning stalls.

IPO (Identity Preference Optimisation) replaces the sigmoid with an identity link (squared loss), preventing saturation:

L IPO = (log(π θ (y w |x) / π ref (y w |x)) − log(π θ (y l |x) / π ref (y l |x)) − 1/(2β) ) ² Minimises squared deviation from a margin of 1/(2β); gradient never saturates regardless of how large the log-ratio grows
PropertyDPOIPO
Loss shapeLogistic (sigmoid)Squared (MSE-like)
Gradient at high marginVanishes (saturation)Never saturates
Hyperparameter sensitivityModerateMore sensitive to β
Use whenStandard preference pairs, moderate-difficulty casesLong training, hard/easy pair imbalance, Pareto-diverse preference data
TRL loss_type"sigmoid""ipo"
05

KTO — Kahneman-Tversky, No Pairs Needed

Ethayarajh et al. (2023) — KTO: Model Alignment as Prospect-Theoretic Optimisation — observed that pairwise preference data is expensive to collect. In practice, annotation platforms produce far more desirability labels ("this response is good/bad") than pairwise comparisons. KTO exploits this.

KTO models human utility using Kahneman-Tversky Prospect Theory: humans are loss-averse — they feel the pain of a bad output more than the pleasure of an equivalently good one. The loss function encodes this asymmetry:

KTO loss (conceptual) — no pairs needed
# For a desirable response y_w (label = 1):
# Maximise: v(r(x, y_w) - z_ref)   where v is the utility of gains
# For an undesirable response y_l (label = 0):
# Minimise: -v(z_ref - r(x, y_l))  where v is the utility of losses

# v is the value function (concave gains, convex losses):
# v(x) = log(1 + exp(x)) for gains
# v(x) = -lambda * log(1 + exp(-x)) for losses (lambda > 1 encodes loss aversion)

# z_ref = KL(pi_theta || pi_ref) acts as the reference baseline

KTO advantages

  • Works on unpaired good/bad labels — dataset is much cheaper to collect
  • Good/bad ratio doesn't need to be balanced; typically 1:1 to 3:1 good:bad works
  • Loss-aversion weight λ provides a principled knob for helpfulness vs safety balance
  • Often matches DPO quality when paired data is scarce

KTO disadvantages

  • Harder to tune: λ, β, and z_ref interaction is less intuitive than DPO's single β
  • With abundant paired data, DPO typically outperforms KTO
  • Less theoretical clarity on why the Kahneman-Tversky framing transfers to LLMs
  • TRL support added in 0.10; fewer community examples than DPO
06

ORPO — No Reference Model

Hong et al. (2024) — ORPO: Monolithic Preference Optimisation without Reference Model — eliminates the reference model entirely by incorporating the preference objective directly into the SFT loss. Instead of training SFT first then running DPO, ORPO does both in a single pass.

L ORPO = L SFT + λ · L OR L_SFT = standard NLL on chosen tokens (as in standard SFT) L_OR = −log σ (log(odds(y_w)) − log(odds(y_l))) — odds ratio avoids reference model Odds ratio = P(y|x) / (1 − P(y|x)) from the current policy — self-referential, no π_ref needed
PropertyDPOORPO
Stages2 (SFT then DPO)1 (combined)
Reference modelRequired (πSFT)Not needed
VRAM2 model copies1 model copy
Data formatPairs (chosen, rejected)Pairs (chosen, rejected)
Training from scratch?Requires SFT firstCan train from base model directly
Quality vs DPOSlight edge with pre-trained SFTCompetitive; best when compute budget for 2-stage is unavailable
When ORPO shines

ORPO is particularly attractive when you're starting from a base model (no instruction-tuned checkpoint available), when your GPU budget can't afford two 7B model copies, or when you want to compress the entire alignment pipeline into a single training run. The λ hyperparameter trades off SFT quality vs preference learning; start at 0.1 and tune.

07

GRPO — DeepSeek-R1's Group-Relative Variant

DeepSeek-AI (2025) — DeepSeek-R1: Incentivising Reasoning Capability in LLMs via Reinforcement Learning — introduced GRPO (Group Relative Policy Optimisation) as a simplified PPO variant that eliminates the separate value network (critic), replacing it with a group-level baseline.

How GRPO Differs from PPO

For each prompt x, generate G completions {y1, …, yG} using the current policy. Score all G with a reward function. The advantage of each completion is:

A i = (r i − mean(r)) / std(r) — over G completions for the same prompt No critic network needed: the group mean acts as the value baseline. G = 4–8 typical. Reward r_i from verifier (math/code) or RM.

GRPO eliminates

  • Separate value/critic network (saves ~50 % VRAM vs PPO)
  • Generalised Advantage Estimation (GAE) bookkeeping
  • Critic loss term in the objective

GRPO requires

  • G≥4 rollouts per prompt (increased generation cost)
  • A reliable per-completion reward signal (verifiable tasks work best)
  • Rule-based or verifier rewards; RM still optional but common
  • Format reward (DeepSeek-R1 used explicit <think> chain reward)
DeepSeek-R1 reward design

DeepSeek-R1 used two reward signals: accuracy reward (0 or 1 based on whether the final answer matched ground truth for math/code), and format reward (positive for correct use of <think>...</think> chain-of-thought markers, negative for empty or malformed thinking sections). No neural reward model was used — demonstrating that with a verifiable task, GRPO + rule-based rewards can achieve reasoning capability surpassing earlier RLHF-trained models.

08

Choosing — Decision Tree

The algorithm landscape can be confusing. This decision tree covers the majority of real-world use cases.

Do you have a verifiable reward signal? (math, code, formal verification)
↓
YES → GRPO (no critic, no RM needed) — or PPO if you want GAE stability
↓
Do you have pairwise preference data (chosen, rejected)?
↓
YES, and GPU budget allows 2 models → DPO (simplest, well-supported in TRL)
↓
YES, but only 1 GPU model copy budget → ORPO (no reference model)
↓
Do you only have good/bad labels (no pairs)?
↓
YES → KTO (no pairs needed, prospect-theoretic loss)
↓
Long training or hard/easy pair imbalance? → IPO over DPO (no saturation)
Practical starting point

For most teams with a standard instruction-following alignment task: start with DPO using TRL's DPOTrainer, β=0.1, 1–3 epochs, learning rate 5e-7. If you observe the model ignoring the preference signal (log-ratio near zero throughout training), switch to IPO. If you're compute-constrained or fine-tuning from a base model, try ORPO. Save GRPO for tasks where you have verifiable ground truth.

09

What to Take Away

Where to next

Deck 05 covers Constitutional AI and RLAIF — Anthropic's approach to replacing expensive human preference labels with an AI model following a written constitution of principles. This is the technique behind Claude's training and the Harmless/Helpful/Honest balance.