Unit 4 of 10 · about 5 hours · implement, measure

Reward-model training contracts and reward shift across policies and lengths

A correct loss can still train a scorer of padding, length or generator style. The research question is whether its rankings and probabilities survive a change in the responses being scored.

You'll be able to

  • Train a bounded scalar reward head with a prompt-grouped split and an explicit padding/truncation contract.
  • Assess held-out ranking and pairwise probability calibration separately across generator and length slices.
  • Distinguish preference labels from outcome labels and diagnose a reward shortcut under distribution shift.

Covers

Preference and outcome reward-model training contractsReward-model shift across policies, prompts and response lengths
1

Read

In this order, only the parts listed

0 of 3 done

  1. The RLHF Book: Chapter 5, Reward ModelingRLHF Book - Reward Models, Direct Alignment and Preferences

    The Default Reward Model Architecture; Implementation Example; Outcome Reward Models; Suggested Experiments, item 1, Train a Bradley-Terry reward model

    Use the preference experiment. Read outcome modeling to specify its label and pooling contract, not to add a process-reward implementation. The example's last-token index assumes right padding; do not copy it for left-padded inputs.

  2. Reward-model training and evaluation implementationRLHF Book Code - Reward Models and Direct Alignment

    build_preference_dataset, collate_fn, PreferenceRewardModel.get_reward, evaluate_preference_rm and the accumulation loop in train_preference_rm

    Inspect rather than run the default full-backbone configuration. The final partial accumulation window uses a fixed divisor and is under-weighted; use accumulation 1 or correct the window weighting.

  3. Length shifts in reward learningA Long Way to Go: Investigating Length Correlations in RLHF (Singhal et al., 2023)

    arXiv:2310.03716v2, Sections 3.1 and 4.2: length-stratified analysis and interventions on reward modeling

2

Focus on

  • Reuse the audited preference records, but split by prompt/conversation and near-duplicate group before expansion. Reserve distinct training, calibration and final evaluation prompts; freeze their manifests.
  • Use the last real token's hidden state under a declared EOS and padding convention. Count empty, invalid and token-identical truncated pairs instead of silently losing them.
  • Report pairwise accuracy, margins, probability NLL and Brier score. Fit any temperature only on calibration prompts and freeze it before final scoring. Report source/generator and response-length slices with counts.
  • A preference reward predicts relative choice under a rubric. An outcome head predicts a specified correctness label with its own token or sequence supervision; swapping these targets changes the meaning of calibration.
Common mistakes · 3
  • Using the last array position when it is padding, or using the count of real tokens as an index under left padding. Test both layouts or reject the unsupported one explicitly.
  • Reading the companion evaluator as a calibration audit. It reports pair-averaged loss, strict accuracy, mean rewards and mean margin; you must add calibration and shift slices.
  • Centering scores on each new policy's outputs. This changes the measurement scale and can conceal shift. Freeze calibration statistics and report raw scores too.
3

Try it yourself

Closed-book, before checking anything

Closed-book, reconstruct the path from two tokenized responses through their last real hidden states, one scalar head and stable pairwise loss. Add padding without changing the real tokens and require scores to agree within a declared dtype tolerance. Then repeat held-out scoring on a different generator or length slice without refitting either the reward head or its calibrator; record whether errors track correctness, length or style rather than assuming transfer.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Can ranking accuracy stay unchanged while probability NLL worsens?Answer

    Yes. Enlarging correctly ordered but overconfident margins leaves order unchanged while increasing the cost of misranked or noisy comparisons. Evaluate probabilities, not only signs.

  2. 2.A frozen backbone fits the training pairs. What has not been established?Answer

    Held-out calibration, ranking under another policy, and behavior improvement after policy optimization. A reward-head fit alone establishes none of these.

  3. 3.Why use a separate calibration split?Answer

    Temperature or other calibration fitting is model selection. Using final evaluation labels for it leaks evaluation information into the scoring pipeline.

5

Practice

  • RLHF Book Chapter 5 Suggested Experiments: Train a Bradley-Terry reward model

    Suggested Experiments, item 1; adapt the linked preference reward-model implementation

    Freeze the backbone and train only the head on at most 1,000 audited training pairs with context at most 256 and batch 1. Use your immutable small-decoder SFT checkpoint from the Adaptation and Distillation section, or its smaller CPU version, rather than the default model. Pin PyTorch 2.14.1 and, if using the companion loader, Transformers 5.19.0 and datasets 5.1.0. Keep separate calibration and held-out prompts; compare at least two fixed training seeds and save all attempts. The mini-project retains the shift, calibration and shortcut evidence.

You're done when

Your head passes padding and identical-pair tests, and its frozen held-out report separates ranking, calibration and generator/length shift with counts and raw records, including a negative or inconclusive slice.

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.

  • A Long Way to Go: Investigating Length Correlations in RLHF (Singhal et al., 2023)UT Austin · required

    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.

  • RLHF Book Code - Reward Models and Direct AlignmentNathan Lambert · support

    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.

Also in this section