Preference Modeling and Direct Optimization
Preference optimization can improve its own reward while degrading real behavior. This stage derives the data and objective path, then tests it against length, style, evaluator and distribution shortcuts.
Section 7 of 11 · 10 units · about 45 hours
By the end you can Gradient-check the chosen preference objective, audit its data and policy versions, then show that its improvement over SFT survives external evaluation and controls for response length, style, judge bias, and reference mismatch.
Units
- Policy-dependent preference data and pairwise, listwise and tie labels4h
- Annotator agreement and noise, and position, length and style bias4h
- The Bradley-Terry likelihood and reward identifiability4h
- Reward-model training contracts and reward shift across policies and lengths5h
- Reward overoptimization and the KL-regularized objective with a reference policy4h
- The DPO derivation, \(\beta\), margins and gradient pressure5h
- Response-only log probabilities, masks and reference-checkpoint identity5h
- Preference-data audits and objective sign, gradient and invariance tests4h
- External evaluation and the versioned sampling, labeling and optimization loop6h
- IPO, SimPO and ORPO, and constitution-conditioned AI feedback4h
Build it
Mini project · about 16 to 20 hours
Audited preferences with independent behavior and rollback evidence
Extend lmlab in pref/ with audited comparison data, a bounded reward head and a checked DPO path from the existing SFT checkpoint. Test whether preference optimization changes the study's behavior rather than merely its proxy, length or judge score, using your machine and no paid judge.
- 1Version preference records in
pref/with generator identities, source-group splits, raw votes, ties and adjudication. Pass TensorTonic canonical-pair cases; retain blinded order/identity/length/style audits and trace a principle-conditioned label's exact principle and judge identity, distinguishing comparison provenance from critique/revision data. - 2Implement Bradley-Terry likelihood and certify the KL-regularized optimum against independent algebra and TensorTonic policy-objective cases. Before training, retain repeated-vote calibration, offset/scale and separated-vote regressions; test reward-head pooling against last-real-token fixtures, padding changes, identical pairs and partial accumulation windows.
- 3Derive DPO and implement shifted response-only scoring with explicit EOS, padding, empty and truncation rules. Match analytic loss and gradients, TensorTonic DPO cases, pinned RLHF Book scoring/loss code and CS336's tiny-model DPO test; preserve token evidence and reference-identity rejection tests.
- 4Gate training on parameter/FLOP counts and versioned audits: annotator-noise copies, swapped labels, duplicate leakage, mask shifts, wrong normalization and reference mismatch must fail named independent checks. Retain before-and-after regressions; optionally specify an alternative objective contract without requiring another training sweep.
- 5Train or reuse the section's bounded frozen-backbone reward head across seeds. Freeze calibration on separate prompts, then check held-out ranking and probability calibration under generator and length shifts against trusted labels; retain raw scores, shortcut probes, counts and negative or inconclusive evidence.
- 6Compare untouched SFT, chosen-only SFT and DPO with a versioned training-label-noise intervention at matched training and inference budgets across seeds. Use the frozen
eval/suite and untouched held-out labels; retain independent capability, safety, calibration and diversity outcomes beside margins, proxy rewards and policy drift. - 7Reproduce the selected comparison from clean state and rebuild
reports/from rawregistry/records. Check length/style and judge controls against blinded review; retain paired uncertainty, all candidate-generation, labeling, reference-scoring and failed-run costs, proxy-versus-behavior discrepancies, reduced-scale limits and an owned release or rollback decision.
What you hand in
- Versioned
pref/data and label audit, scalar reward head, DPO scorer and objective preflight regressions. - Immutable SFT, reference and preference checkpoints with raw votes, generations, calibration, shift, noise and budget records in
registry/. - Clean reproduction and independent behavior report with length/style/judge controls, negative evidence and rollback ownership.
How to check it
- Self-grade with the rubric below
- TensorTonic: Canonicalize Pairwise Preference Data
Pass public ranking cases; add tie, duplicate, grouping and label-provenance checks.
- TensorTonic: Score a KL-Regularized Policy Batch
Pass masked-score cases; independently certify the normalized optimum and state its support assumptions.
- TensorTonic: Implement the DPO Loss
Pass public loss cases; add analytic gradients, extreme logits and response-identity swap tests.
- RLHF Book response scoring and DPOLoss at pinned commit
Differential-test frozen-batch scores, loss and gradients with the same completion masks and summed-score convention.
- CS336 Assignment 5 supplement: tiny-model DPO test
Keep course solutions private; the scalar test supplements rather than replaces your mask, gradient and reference regressions.
How it's graded
Label and reward integrity
Pass: Raw votes, adjudication, presentation audits and principle provenance survive conversion; independent likelihood and pooling oracles pass, and held-out calibration and shift reports retain untouched labels and shortcut evidence.
Great: Offset, scale and separation tests distinguish identification failures from probability errors; disagreements remain traceable to source, rubric, annotator and generator without being erased by adjudication.
Objective preflight correctness
Pass: Analytic and pinned-reference loss/gradient tests validate shifted response scoring and DPO; each planted label, leakage, mask, normalization and reference defect fails a named check before training.
Great: Equal-valued independent score inputs are distinguished from identical responses sharing model parameters, and gradient checks expose defects hidden by initial scalar loss equality.
Independent behavior decision
Pass: Matched multi-seed controls, noise intervention, length/style/judge checks and untouched capability/safety evaluation support a bounded verdict; clean reproduction rebuilds paired outcomes, costs, failed attempts and rollback evidence.
Great: The report separates proxy fit from behavior, discloses residual budget mismatches and tests the strongest alternative explanation without requiring DPO to win.
Resources
- RLHF Book - Reward Models, Direct Alignment and PreferencesNathan Lambert
Read Chapter 5 (reward models), Chapter 8 (direct alignment), Chapters 10 and 11 (preferences and preference data) and Chapters 14 and 15 (over-optimization and regularization) at
rlhfbook.com/c/NN-slug.html. Only Chapters 5 and 8 have Suggested Experiments; do those. Trace preference data through reward modeling or DPO and list each distribution and evaluator assumption before training. - Direct Preference OptimizationStanford University
Read Section 4 and Appendix A: derive the objective from the KL-constrained reward formulation, implement it from policy and reference log probabilities summed over response tokens, and gradient-check , sign, masking and identical-pair cases. TRL's
sigmoid_normvariant normalizes by length, which the paper does not. - Training Language Models to Follow Instructions with Human Feedback (Ouyang et al., 2022)OpenAI
Read Sections 1 to 3: demonstrations, comparisons, the reward model and PPO with a pretraining mix, then the human-preference results. The 1.3B-beats-175B headline is a preference win rate, not capability.
- Scaling Laws for Reward Model Overoptimization (Gao et al., 2022)OpenAI
Read Sections 2 to 4: a gold reward model stands in for humans, and gold score against optimization pressure takes different forms for best-of-n and RL. The lesson is the shape, not a universal KL threshold.
- A Long Way to Go: Investigating Length Correlations in RLHF (Singhal et al., 2023)UT Austin
Read Sections 2 to 5: reward correlates with length, PPO lengthens outputs, and a length-only reward reproduces much of the gain. Report length beside every preference result.
- CS336 Assignment 5 Supplement - Preference Data and DPOStanford University
Do supplement Section 6: inspect the HH preference data (
look_at_hh) and implementdpo_lossuntil its test passes. Run a bounded DPO comparison only after the baseline and evaluator are frozen, with a small open model in place of the Llama 3.1 8B B200 run. - Disentangling Length from Quality in Direct Preference Optimization (Park et al., 2024)Stanford University
Read Sections 2 and 3: add a length penalty to the reward and derive length-regularized DPO, then check its length-controlled results in Section 4.
- A General Theoretical Paradigm to Understand Learning from Human Preferences (Azar et al., 2023)Google DeepMind
Read Sections 3 to 5: why DPO can overfit deterministic preferences and how IPO's squared loss avoids it. Its tau is DPO's beta under another name.
- SimPO: Simple Preference Optimization with a Reference-Free Reward (Meng et al., 2024)Princeton University
Read Section 2 (length-normalized average log probability as the reward plus a target margin, with no reference model) and Sections 4.2 and 4.3 (the length-normalization and margin ablations). Without the reference there is no KL anchor, so watch for drift.
- ORPO: Monolithic Preference Optimization without Reference Model (Hong et al., 2024)KAIST AI
Read Sections 3 and 4: an odds-ratio penalty added to the SFT loss in one stage. Merging the stages makes an SFT-versus-preference ablation harder, so evaluate them apart.
- KTO: Model Alignment as Prospect Theoretic Optimization (Ethayarajh et al., 2024)Stanford and Contextual AI
Read Section 3.2 (human-aware losses) and Section 4 (a loss for unpaired desirable and undesirable examples with a reference point). Unpaired data still needs label-noise and reference-drift checks.
- RewardBench: Evaluating Reward Models for Language Modeling (Lambert et al., 2024)Allen Institute for AI
Read Section 4 (the chat, chat-hard, safety and reasoning splits, detailed in Appendix F), Section 5 and Appendix H.2 (length bias). Pin the benchmark version; reward accuracy is not policy quality.
- RLAIF vs. RLHF: Scaling Reinforcement Learning from Human Feedback with AI Feedback (Lee et al., 2023)Google Research
Read Sections 2 to 5: AI-labeled versus human-labeled preferences on summarization and dialogue, and direct RLAIF without a distilled reward model. The parity holds for their tasks and labelers.
- Tulu 3, Section 5 (Preference Finetuning)Allen Institute for AI
Read Sections 5.2 to 5.4: building on-policy preference data, the data ablations and the DPO recipe. Use the ablations as the model for your own one-variable comparison.
- RLHF Book Code - Reward Models and Direct AlignmentNathan Lambert
Run the preference reward model with a frozen backbone (only the head trains) and the DPO, IPO and length-normalized DPO configs with smaller models and contexts than the defaults. The final partial accumulation window is under-weighted, so fix or avoid it. Explain margins, accuracy and rewards rather than raw loss.
- TensorTonic - Preference Optimization SetTensorTonic
Solve Canonicalize Pairwise Preference Data (
cs336-l15-canonical-preference-pairs), Score a KL-Regularized Policy Batch (cs336-l15-kl-regularized-policy-objective) and Implement the DPO Loss (cs336-l15-direct-preference-optimization-loss). The DPO problem takes sequence log probabilities, so add your own swapped-label, duplicate, length and reference-mismatch cases. Public test cases check the listed edge cases, not gradients or the hidden grader, so keep your own tests beside each solution. - TRL DPO TrainerHugging Face
After the scratch loss passes, map dataset format, reference model, and loss variants into TRL 1.15.0: the default
loss_typeis["sigmoid"]withbeta=0.1, log probabilities are summed over the completion, and the trainer refuses a policy that is the same object as the reference. Confirm the library loss matches your scratch objective on one frozen batch. - Constitutional AI: Harmlessness from AI FeedbackAnthropic
arXiv:2212.08073v1, Sections 3.1 and 4.1 and Appendix C.2: distinguish critique/revision data from constitution-conditioned comparison labels and trace the principle into label provenance. Read and audit the examples; no large-model RL reproduction is required.
- Modern LLM Notebook - RLHF AlignmentWalking Labs
Use
notebooks-en/part2-training/19-rlhf-alignment.ipynbas a compact end-to-end orientation. Do not substitute its overview for the RLHF Book derivations or the CS336 objective tests. - Build a Large Language Model (From Scratch) - DPO Bonus NotebookSebastian Raschka
Use
ch07/04_preference-tuning-with-dpo/only as a gentle starter before the DPO paper and CS336 tests.