Unit 2 of 11 · about 4 hours · derive

Implicit rewards from policy ratios and the DPO derivation

The partition function is intractable, but comparisons at the same prompt remove it. Knowing exactly why it cancels prevents using the derivation for mismatched prompts or treating finite-data fitting as an optimality guarantee.

You'll be able to

  • Derive DPO by substituting policy-ratio rewards into a Bradley-Terry likelihood.
  • State the reward-identifiability, preference-model and coverage assumptions behind the substitution.

Covers

Implicit reward reparameterization from policy ratiosBradley-Terry substitution and DPO derivation
1

Read

In this order, only the parts listed

0 of 3 done

  1. The RLHF Book: Bradley-Terry substitutionRLHF Book - Direct Alignment

    Chapter 8, DPO Derivation: Deriving DPO Objectives for BT Models (page read 2026-10-14)

    Stop before Deriving the BT DPO Gradient.

  2. DPO: reparameterization and reward equivalenceDirect Preference Optimization

    arXiv:2305.18290v3, Section 4 equations 5 to 7, Section 5.1 Definition 1 and Lemmas 1 to 2, Appendix A.2

  3. Stanford CS224R Lecture 09: DPO in four stepsStanford CS224R 2026 - LLM Preference Optimization

    PDF pages 43 to 45 (printed slide numbers 74 to 76): Can we simplify RLHF?, the closed-form optimum rearranged into a reward, and the Bradley-Terry loss on reward differences where the partition term cancels

    The slides write the reference as . Use them to check your derivation, not as a substitute for the paper's assumptions.

2

Focus on

  • Inversion gives . Keep the additive term until taking a same-prompt reward difference.
  • Bradley-Terry uses . Substitute first, then take the dataset mean negative log likelihood.
  • The implicit log-ratio reward is one representative of a prompt-dependent reward equivalence class. Fitting it needs preference coverage and a suitable policy family; the algebra alone supplies neither.
Common mistakes · 3
  • Dropping the partition term while claiming an absolute reward identity. It cancels in comparisons, not in the original reward equality.
  • Comparing completions from different prompts. Their partition constants need not agree.
  • Equating a finite empirical loss minimum with recovery of human preferences on unseen completions. The derivation is not a coverage or generalization theorem.
3

Try it yourself

Closed-book, before checking anything

Derive the likelihood and DPO loss without notes. Reuse the previous unit's two-completion setup: reference , optimum , . The two log-ratio rewards differ by , so Bradley-Terry predicts preference probability . Add 7 to both original rewards and show that the normalized optimal policy and preference probability are unchanged, although the partition function changes.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Which reward transformations preserve the Bradley-Terry probabilities?Answer

    Adding any function of the prompt to every completion reward. Multiplying rewards by a non-unit scale generally changes preference probabilities.

  2. 2.Does the DPO derivation require training a separate reward network?Answer

    No. It parameterizes the preference likelihood using policy-to-reference log ratios. The policy thereby supplies an implicit reward.

  3. 3.Why is same-prompt cancellation insufficient to justify arbitrary preference labels?Answer

    Cancellation is algebraic. The likelihood still assumes Bradley-Terry-style reward differences; contradictory, cyclic or population-mixed preferences may not admit that model.

You're done when

You reconstruct the loss from the regularized objective, recover the three-quarter preference probability, and explain both the cancellation and its assumptions.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 7 more in the section
  • RLHF Book - Direct AlignmentNathan Lambert · primary

    Study Chapter 8 (DPO, its derivation, numerical concerns and online versus offline data) and the code/direct_alignment package at natolambert/rlhf-book at commit 1042143 (DPO, IPO, KTO and APO are validated there; its SimPO and ORPO runs are marked noisy). Re-derive DPO from the KL-regularized objective, implement sequence log-ratio losses from blank tensors and test chosen-rejected swaps, prompt masking, reference drift and length normalization.

  • Direct Preference OptimizationRafailov et al. · required

    Read the complete derivation, objective and experiments. State the preference-model and reference assumptions, then compare a scratch DPO update with SFT and rejection-style baselines on a held-out slice.

  • Stanford CS224R 2026 - LLM Preference OptimizationStanford University · required

    Study Lecture 09 (RL for LLMs: preference optimization, slides/09_cs224r_rlhf_2026.pdf) and Section 1.3.2 (IPO) of the default project guidelines. Implement independently, preserve the reference policy and follow course material restrictions.

Also in this section

  • A General Theoretical Paradigm to Understand Learning from Human PreferencesGheshlaghi Azar et al. · required

    Study the preference-model misspecification argument and IPO objective. Use one synthetic preference problem to compare DPO and IPO behavior as noise, margin and data reuse change.

  • KTO: Model Alignment as Prospect Theoretic OptimizationEthayarajh et al. (ICML 2024) · support

    Read the unpaired-feedback setting and the KTO loss with its reference point. State what data KTO needs that DPO does not, and test its loss on fixed log probabilities.

  • SimPO: Simple Preference Optimization with a Reference-Free RewardMeng, Xia and Chen (NeurIPS 2024) · support

    Read the length-normalized, reference-free reward and the target margin. Use it as the no-reference baseline and compare its length behavior with summed-log-probability DPO.

  • TRL DPO TrainerHugging Face · support

    After the scratch loss passes, inspect the DPOTrainer data contract and options for TRL 1.15.0. Differential-test one tiny batch against the local objective and record library version, loss type, , padding, truncation and reference behavior.

  • TensorTonic - DPO and Preference ProblemsTensorTonic · support

    Solve Implement the DPO Loss (cs336-l15-direct-preference-optimization-loss), Canonicalize Pairwise Preference Data (cs336-l15-canonical-preference-pairs) and Score a KL-Regularized Policy Batch (cs336-l15-kl-regularized-policy-objective), free problems in the Language Modeling from Scratch plan, as closed-book checks after your own loss passes.

  • Hands-on Modern RL - Chapter 14 DPOWalking Labs · support

    Use the DPO derivation page and the hands-on page for a bounded DPO experiment and metrics. Its displayed loss is the per-pair summand (average it over the dataset), and its implicit reward is exact only at the KL-regularized optimum; its training logs are illustrative. Replace any opaque trainer-only step with a checked local loss and retain a or length regime where quality worsens. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its code/chapterNN folders do not follow the site chapter numbers.

  • LLM Post-Training Laboratory - Direct Preference ObjectiveRoadmap-Final · required

    Complete the DPO-style objective with exact sequence log probabilities, frozen reference identity, fixed loss and gradient tests, common raw evaluation records, support analysis and reward, length, style and judge-hacking probes.