Unit 8 of 10 · about 4 hours · implement

Preference-data audits and objective sign, gradient and invariance tests

A healthy training curve cannot distinguish a correct objective from a consistently reversed label pipeline. Preflight tests must catch failures before the preference route spends its training budget.

You'll be able to

  • Build an audit ledger for provenance, duplicate groups, split leakage, raw votes and presentation/length slices.
  • Test objective signs, gradients, numerical stability and valid invariances against an independent oracle.
  • Inject reversed labels, reference mismatch and mask/normalization errors and retain a failing regression for each.

Covers

Provenance, duplicates, leakage, balance, agreement and slice auditPreference-loss numerical, sign, gradient and invariance tests
1

Read

In this order, only the parts listed

0 of 3 done

  1. CS336: pair inspection and the checked model-to-loss pathCS336 Assignment 5 Supplement - Preference Data and DPO

    Sections 6.2 and 6.3, Problems look_at_hh and dpo_loss; revisit the raw records and the public scalar test, not the full training run

  2. The RLHF Book: audit-sensitive collection and optimizationRLHF Book - Reward Models, Direct Alignment and Preferences

    Chapter 11, Collecting Preference Data, Multiturn Data and Bias: Things to Watch Out For in Data Collection; Chapter 8, Implementation Details and Suggested Experiments item 4, Change the data before changing the loss, at https://rlhfbook.com/c/08-direct-alignment.html

  3. TRL 1.15.0: logs and objective conventionsTRL DPO Trainer

    Computing the loss, Loss Types and Logged metrics; DPOConfig loss_type, label_smoothing and beta

    Use the default sigmoid branch as a differential reference, not the catalog as an assignment. Keep the explicit response-score oracle independent of trainer preprocessing.

2

Focus on

  • Audit both raw and model-visible data: prompt/candidate duplicates, source licenses and provenance, prompt-group leakage, label polarity, ties, annotator agreement, length/style balance, truncation and post-tokenization identical pairs. Save counts and reasons at every filter.
  • Compare scratch loss and policy-input gradients against analytic values before comparing to library code. Then check an actual batch with the frozen reference and the same IDs and completion masks.
  • Batch permutation and whole-batch duplication preserve a mean loss. Common chosen/rejected score offsets cancel within each model. These invariances do not justify changing one response, reference gap or length convention.
  • Seed corrupted copies, never overwrite the clean manifest: swapped labels, duplicate leakage, non-response mask bits, sum-to-mean replacement and stale reference scores. Require the intended check to fail and then pass after repair.
Common mistakes · 3
  • Calling label reversal an invariance of the loss. Swapping the two outcomes negates the logit; the loss generally changes. Batch permutation is an invariance, label polarity is not.
  • Requiring zero gradients for independent equal-valued chosen/rejected score tensors. Their partial derivatives are opposite and nonzero; cancellation occurs through the shared model graph for identical responses.
  • Claiming prompt decontamination from an exact-string check alone. State the normalization and duplicate-group rule, review matches and bound the claim; paraphrases may remain.
3

Try it yourself

Closed-book, before checking anything

Assemble a CPU preflight suite with PyTorch 2.14.1 and torch.float64 from the previous units' loss, derivative, mask and reference-mismatch oracles. On the fixed pair with scaled margin , swap chosen and rejected in both policy and reference scores. Verify within absolute tolerance , and verify that gradients now pressure the opposite response identity. Also test identical tokenized responses through the same deterministic scorer: loss is and the shared model-parameter gradient is zero. Preserve the failures from a single-sided swap and a stale cache as separate diagnoses.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Why can initial loss fail to expose reversed labels?Answer

    With matching policy and reference, both label orientations have zero adjusted margin and loss . Check the response-identity gradient and the raw label provenance, not only the loss.

  2. 2.Which gradient should whole-batch duplication preserve?Answer

    For the same deterministic model and a mean reduction, the aggregated model-parameter gradient. Independent per-copy input-score gradients can each be smaller because there are more averaged entries.

  3. 3.Can the public DPO test certify this entire preflight?Answer

    No. It checks one scalar fixture. Data lineage, leakage, response boundaries, gradients and reference-cache identity require independent tests.

You're done when

Your clean manifest passes preflight, every seeded defect fails a named independent check, and the retained report distinguishes data failure from loss or reference failure.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 17 more in the section
  • RLHF Book - Reward Models, Direct Alignment and PreferencesNathan Lambert · primary

    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.

  • CS336 Assignment 5 Supplement - Preference Data and DPOStanford University · required

    Do supplement Section 6: inspect the HH preference data (look_at_hh) and implement dpo_loss until 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.

  • TRL DPO TrainerHugging Face · support

    After the scratch loss passes, map dataset format, reference model, and loss variants into TRL 1.15.0: the default loss_type is ["sigmoid"] with beta=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.

Also in this section