Foundations to Frontier
Tests

DPO, IPO, KTO, ORPO

Direct preference optimisation (DPO) and its relatives skip the reward model and the RL loop. The KL-regularised RLHF optimum links reward and policy in closed form, r = β log(π/π_ref) + const, so preferences can train the policy directly with a simple classification loss on the log-ratio margin. IPO replaces the logistic loss with a squared loss towards a fixed margin, to resist overfitting. KTO needs only thumbs-up/thumbs-down labels. ORPO drops the reference model, adding an odds-ratio penalty to SFT. This page derives DPO, compares the losses and covers when offline methods suffice. In the exercises you implement the DPO and IPO losses and DPO's implicit reward. You then train all four, plus PPO through a reward model, on the same 225 noisy preference pairs. True reward rose from −0.05 to 1.09 with DPO, 1.04 with KTO and 1.03 with PPO. IPO reached 0.76 while staying much closer to the reference (KL 0.73 against 1.57), and ORPO, without a reference model, moved least (0.24).

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Learning from preferences without a judge

RLHF trains a judge (reward model) and then practises against it. DPO notices that the judge can be folded into the model itself: from pairs of answers where people preferred one, it directly raises the chosen answer’s probability and lowers the rejected one’s, relative to the original model. No judge, no practice loop, just a supervised-style training run. IPO, KTO and ORPO are variations on the same idea. The demo shows the preference probability that all of them assume.

Alignment lab
P(a preferred over b) = σ(1) = 0.731. Reward models are trained so that this probability matches human choices.
Why engineers care

Offline preference methods make alignment tuning feasible on modest hardware, so a team can adapt an open model to its own reviewers’ preferences without running a full RL pipeline.

📝 Quick check (Level 0)
0/3 answered
  1. 1. DPO needs a separate reward model?
  2. 2. DPO trains on…
  3. 3. KTO needs…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Implicit reward: from the RLHF optimum, r(x, y) = β log(π(y|x)/π_ref(y|x)) + β log Z(x). The partition function Z cancels in pairwise comparisons.
  • DPO: L = −log σ(β[(log π(yw) − log π_ref(yw)) − (log π(yl) − log π_ref(yl))]). At initialisation it is log 2. Its gradient weights each pair by how wrong the implicit reward ranks it.
  • IPO: L = (margin − 1/(2τ))². It pushes the margin to a fixed target instead of to infinity, so near-deterministic preferences do not drive the policy to extremes.
  • KTO: prospect-theory loss on unpaired examples: raise desirable responses above a reference point (the KL) and push undesirable ones below.
  • ORPO: no reference model: SFT loss on the chosen response plus a penalty on the log odds-ratio of chosen to rejected. One model in memory.
  • Models in memory: PPO four, DPO/IPO/KTO two, ORPO one.
📝 Quick check (Level 1)
0/3 answered
  1. 1. DPO loss at initialisation:
  2. 2. IPO pushes the margin towards…
  3. 3. ORPO needs a reference model?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Preference optimisation in code

Exercise 1.

  • Compute the DPO loss for a pair.
  • Compute the IPO loss and its target margin.
  • Compute DPO’s implicit reward β(log π − log π_ref).

Practice.

  • TRL has DPOTrainer (with loss_type sigmoid for DPO, ipo and others), KTOTrainer and ORPOTrainer.
  • Typical β is 0.1; learning rates are small (5e-7 to 5e-6) and one to three epochs suffice.
  • Preference data from on-policy samples (from the SFT model) works better than pairs from other models.
  • Watch for both chosen and rejected log-probabilities falling (likelihood displacement) and for growing response length.
from trl import DPOConfig, DPOTrainer
cfg = DPOConfig(beta=0.1, learning_rate=5e-7, num_train_epochs=1, loss_type="sigmoid")
trainer = DPOTrainer(model=policy, ref_model=ref, args=cfg, train_dataset=pairs,   # prompt / chosen / rejected
                     processing_class=tok)
trainer.train()
🐍 Exercise 1: DPO and IPO losses
Implement the DPO loss, the IPO loss and DPO's implicit reward.
📝 Quick check (Level 2)
0/3 answered
  1. 1. TRL trainer for DPO:
  2. 2. Typical DPO β:
  3. 3. A known DPO failure mode:

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Deriving DPO. The KL-regularised optimum π* ∝ π_ref exp(r/β) inverts to r = β log(π*/π_ref) + β log Z. Substituting into the Bradley–Terry likelihood P(yw ≻ yl) = σ(r(yw) − r(yl)) cancels Z. Maximising the likelihood of observed preferences over policies then gives the DPO loss: reward modelling and RL collapse into one supervised objective.

Why IPO. If a pair is always preferred in the data, the Bradley–Terry maximum likelihood wants an infinite reward gap, so DPO keeps increasing the margin and the policy drifts far from the reference however large β is. IPO’s squared loss towards 1/(2τ) is a direct regulariser on the margin.

Offline vs online. DPO learns only from fixed pairs. When those pairs come from the reference policy, it covers the same responses PPO would sample at first, and both perform similarly. When the policy moves to responses never seen in the data, online methods can query the reward model there; offline ones cannot, which is why iterative or online DPO variants exist.

📝 Quick check (Level 3)
0/3 answered
  1. 1. What cancels in the DPO derivation?
  2. 2. Why IPO?
  3. 3. An offline method's weakness:

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Can direct preference methods match PPO with a reward model, and how do they differ?

History.

  • R. Rafailov et al., “Direct preference optimization” (NeurIPS 2023).
  • M. Azar et al., “A general theoretical paradigm to understand learning from human preferences” (IPO, 2023).
  • K. Ethayarajh et al., “KTO” (2024).
  • J. Hong et al., “ORPO” (2024).

Exercise 2.

  • Setup: the simulated prompt–response problem of F7-2 (200 prompts, 8 responses with 16 features, hidden true reward, random reference policy). Preference data: 300 random prompts, two responses sampled from the reference and labelled by a noisy Bradley–Terry human using the true reward; ties dropped, leaving 225 pairs.
  • Methods: PPO against a reward model fitted to the same pairs (β = 0.1); DPO (β = 0.1); IPO (τ = 0.1); KTO (each winner desirable, each loser undesirable); ORPO (SFT on winners plus 0.2 × the odds-ratio loss). All train the same linear policy adjustment.
method true reward KL to reference (nats)
reference −0.046 0
PPO + reward model 1.027 1.419
DPO 1.088 1.567
IPO 0.762 0.727
KTO 1.036 1.316
ORPO 0.243 0.081
  • DPO matched PPO: with on-policy pairs and a simple policy class, the offline method reached the same true reward as the full RLHF pipeline, with two models instead of four. Seed 1 gave exactly the same (0.712 each).
  • KTO came close with weaker labels: splitting pairs into thumbs-up/down examples lost little here.
  • IPO stayed closer to the reference: about half the KL of DPO for about 70% of the gain; its bounded target is a stronger leash.
  • ORPO moved least: without a reference model it is mostly SFT on the chosen answers, which were sampled from the reference itself, so there is little to imitate. ORPO is meant to replace SFT on good demonstrations; on this data it is the weakest.
  • Seeds 1 and 2: same ordering of KL (DPO > PPO ≈ KTO > IPO > ORPO); DPO within 0.08 of PPO’s true reward.
🐍 Exercise 2 (research): can direct preference methods match PPO with a reward model, and how do they differ?
Train DPO, IPO, KTO, ORPO and PPO (through a reward model) on the same preference pairs; compare true reward and KL.

Preference optimisation in AI, robotics and aerospace

  • Open-model alignment: most open chat models (Zephyr, Tülu, Llama-based) use DPO or variants after SFT.
  • Robotics: preference-based policy learning from pairwise human comparisons of trajectories uses the same Bradley–Terry machinery.
  • Domain assistants: a team can collect pairs of expert-preferred answers and run DPO on one GPU.

References

  1. R. Rafailov, A. Sharma, E. Mitchell, S. Ermon, C. Manning and C. Finn (2023). “Direct preference optimization: your language model is secretly a reward model.” NeurIPS.
  2. M. G. Azar et al. (2024). “A general theoretical paradigm to understand learning from human preferences.” AISTATS.
  3. K. Ethayarajh, W. Xu, N. Muennighoff, D. Jurafsky and D. Kiela (2024). “KTO: model alignment as prospect theoretic optimization.” ICML.
  4. J. Hong, N. Lee and J. Thorne (2024). “ORPO: monolithic preference optimization without reference model.” EMNLP.