ENGINEERING GUIDE 6 MIN READ

Build and diagnose an RLHF training pipeline

Trace every artifact from demonstrations to an evaluated policy.

Explore the mechanism /05 stages

Follow the training signal.

Choose a stage to see what goes in, what comes out, and which part of the system actually changes.

0102030405

All stages are shown below. Enable JavaScript to explore one stage at a time.

01

Demonstrations

Write the behavior before fitting it.

Input
Prompts, evidence and a review rubric.
Output
Reviewed example answers with data provenance.
What changes
The training data changes; model weights do not.

A demonstration shows one acceptable response. Preserve uncertainty and missing-evidence cases instead of teaching confident guessing.

02

SFT

Teach the model to imitate the examples.

Input
A base policy and the reviewed demonstration set.
Output
A supervised policy, plus a frozen reference copy.
What changes
Policy weights change through supervised likelihood training.

SFT supplies the starting behavior. It does not yet learn which of two plausible answers a reviewer prefers.

03

Comparisons / reward

Learn a score from relative judgments.

Input
Alternative answers to the same prompt, with preference labels.
Output
A reward model that scores prompt–answer pairs.
What changes
Reward-model weights change. The policy waits.

Check held-out rankings and reward shortcuts. A higher scalar score predicts collected preferences; it does not certify factual truth.

04

Rollout / PPO

Generate fresh experience, then update.

Input
Current-policy rollouts, a frozen reward model and a frozen reference.
Output
An updated policy and value estimator.
What changes
Policy/value weights change; reference and reward stay frozen.

Keep behavior-policy log probabilities fixed while optimizing that rollout batch. PPO clips current-to-behavior ratios; the separate reference penalty discourages drift.

05

Evaluation

Select with evidence outside the reward.

Input
Candidate and baseline answers on held-out tasks.
Output
Separate usefulness, safety and over-refusal findings.
What changes
The release decision changes; evaluation is not a weight update.

A rising training reward can coexist with worse answers. Review independent outcomes and keep final assessment separate from checkpoint selection.

A teaching map of classic RLHF, with data preparation and independent evaluation shown explicitly. InstructGPT paper ↗

IN THIS GUIDE
  • Separate the frozen reference from the rollout policy.
  • Follow reward, KL, advantages, and PPO updates.
  • Select a checkpoint using evidence outside the reward loop.

Establish the model and artifact handoffs

RLHF connects a starting policy, preference data, a reward model and policy optimization. Stiennon and colleagues study these components in summarization. Their task-specific recipe motivates a reproducible experiment; it is not a universal configuration.

Save the supervised policy checkpoint, tokenizer, conversation template and demonstration revision. Export a tiny reference batch containing token IDs, answer masks and expected output boundaries. Load that batch through the rollout and reward paths before training. Text that looks identical can tokenize differently when separators or special tokens change.

Define four roles: the trainable policy generates answers; the frozen reference anchors behavior; the frozen reward model scores completions; the trainable value model estimates returns. They may share initialization, but their parameter updates and saved versions must remain distinguishable.

Freeze the data split and reward interpretation

Use a family-level split for demonstrations, comparisons and evaluation. Keep all alternatives for one prompt together. Preserve label reasons and ties; decide their treatment before fitting. Reserve a development set for reward-model selection and a final policy test that neither selection process can inspect.

A usable comparison rubric might prefer the response that preserves release conditions and admits missing evidence, while separately flagging invented functionality. Test short accurate answers against verbose inventions. Export the scorer’s exact input serialization, truncation rule, scalar extraction point and score transformation. A new normalization changes the effective strength of every downstream penalty.

Run a frozen-scoring check twice on an inspected batch. Investigate different scores, incorrect answer boundaries or a score taken from padding before launching policy training. Save the held-out comparison report alongside the reward checkpoint. Pairwise accuracy alone cannot establish that the scorer remains reliable on outputs produced later by optimization.

Define reward and the reference penalty

For prompt x and response y, consider a sequence-level objective:

OBJECTIVE & NOTATIONJ(θ) = E[rφ(x,y)] − β E_x[KL(πθ(.|x) || πref(.|x))] y ~ πθ(.|x)

The reference stays frozen. For a rollout from behavior policy πold, one sampled penalty uses:

OBJECTIVE & NOTATIONk_t = log πold(y_t|s_t) − log πref(y_t|s_t) u_t = −β k_t u_last = u_last + rφ(x,y)

Here s_t is the prompt plus preceding response tokens. Huang and colleagues’ reproduction details reward and reference scoring, terminal handling and implementation choices. The displayed token rewards are fixed rollout data during that batch’s update. Their expected summed log ratio estimates sequence KL under the behavior policy; one sampled sum can be negative.

Decide whether reported KL is a token mean or sequence sum. Record reward scaling and β together. Compare neither values across incompatible reductions nor differently normalized scorers. The reference penalty controls departure from the reference; it does not certify correctness or permissions.

Compute advantages and the clipped update

Store behavior log probabilities and value estimates with every rollout. For a completed episode, use zero continuation value at termination. A token limit needs an explicit truncation policy; treating truncation as termination changes the target.

Generalized advantage estimation combines value residuals with a decay controlled by γ and λ:

OBJECTIVE & NOTATIONδ_t = u_t + γ V(s_next) − V(s_t) Â_t = Σ_l (γλ)^l δ_(t+l)

Apply episode boundaries and response masks to these sums. Save advantages before the update so policy changes do not silently change that batch’s target.

PPO’s clipped objective:

OBJECTIVE & NOTATIONL_clip(θ) = E[min(ρ_t Â_t, clip(ρ_t, 1−ε, 1+ε) Â_t)]

Compute ρ_t by exponentiating current minus saved behavior log probability. The reference model is absent from that ratio. For an illustrative positive advantage of 2, ratio 1.4 and ε=0.2, the terms are 2.8 and 2.4; the surrogate selects 2.4. This arithmetic explains one sample’s objective, not a guaranteed limit on parameter movement.

Maximize the policy surrogate, or minimize its negative, while fitting the value model to declared return targets. Refresh rollouts after the configured update cycle. The reproduction paper also shows why scoring and optimization details need inspection rather than blind adoption.

Instrument the loop and diagnose symptoms

Record generation, reward/reference scoring, value estimation and optimization costs separately. Log raw reward, penalized return, reference KL, update ratios, clipped fraction, value loss, response length and termination rate. State masks and reductions; changing length can change several metrics without improving quality.

SymptomInspect firstControlled check
Ratios differ from one before an updateSaved/current scoring conventionsReplay identical tokens without updates
High reward, poor answersScorer shortcutsBlind review matched outputs
Length hits the capTerminal and truncation handlingInspect boundary-token traces
KL spikesReward scale and update sizeCompare an earlier saved batch

These are hypotheses to test, not diagnoses supplied by a single metric. Alter one suspected cause and replay the relevant check.

Follow one fictional rollout through the system

Use the fictional release-note corpus from the alignment guide. Generate 32 training responses with a 96-token limit, temperature 1 and no probability filtering. These are teaching settings, not hardware or model recommendations. Save the exact generation distribution used to compute behavior probabilities.

Suppose one invented response receives reward 1.8 and a summed behavior/reference log ratio of 4.0. With illustrative β=0.05, its summed penalty is 0.2 and shaped return is 1.6. Inspect the token trace to confirm that the terminal reward is added once and padding contributes nothing. Compute its advantages, check the positive-advantage example above, and save the updated checkpoint.

Now imagine development review finds longer, confident answers asserting planned features as available, despite higher reward. Pause the run. Compare matched responses using the frozen scorer and inspect training labels. If the scorer prefers the invention, repair reward data and issue a new scorer revision; if rewards were attached to the wrong token, repair the implementation. Restart from the declared baseline instead of mixing incomparable scoring regimes.

Select a checkpoint using independent evidence

Choose candidates on development data using a written rule that first blocks critical failures, then compares quality and cost. Randomize response order, allow ties and retain adjudication reasons. Inspect unfamiliar prompt families, evidence gaps and legitimate requests that might be refused. Report sample counts and uncertainty.

After selection, evaluate once on the sealed assessment set with the same evidence and decoding settings as the baseline. The summarization study directly examines divergence between optimized reward and human judgments; a training-score maximum is insufficient. Preserve the selected checkpoint, rejected alternatives, evaluation outputs and full cost record. A failed final gate requires a new documented experiment and assessment plan, not repeated tuning against the same supposedly unseen test.

BEFORE YOU MOVE ON

Make the work reviewable.

  • Versioned SFT, reference, reward, and policy artifacts.
  • A rollout trace linking rewards, penalties, and updates.
  • A held-out comparison against the SFT baseline.

Sources & further reading

  1. Stiennon et al. — Learning to summarize from human feedback
  2. Huang et al. — The N+ Implementation Details of RLHF with PPO
  3. Schulman et al. — High-Dimensional Continuous Control Using Generalized Advantage Estimation
  4. Schulman et al. — Proximal Policy Optimization Algorithms