Unit 6 of 11 · about 5 hours · implement

Immutable rollout metadata, policy freshness, lag and off-policy importance weights

A loss can pass its arithmetic tests while training on the wrong distribution. The research artifact must preserve which policy actually produced each action, including failed and filtered work.

You'll be able to

  • Collect immutable language rollouts bound to prompt, sampler, policy, reference, verifier and RNG identities.
  • Implement a bounded rollout-update-evaluation cycle and detect overwritten old log probabilities.
  • Derive trajectory importance weights and explain what token clipping cannot correct.

Covers

Immutable prompt, policy, reference, reward, RNG and trajectory metadataOn-policy sampling, asynchronous policy lag and stale rolloutsOff-policy importance weighting, clipping and support mismatch
1

Read

In this order, only the parts listed

0 of 3 done

  1. CS336 Spring 2026 Assignment 5: live step and stale dataCS336 Assignment 5 - Alignment and Reasoning RL

    Section 4.2.4, grpo_train_step_standard_on_policy; Sections 6.1 and 6.2.1, importance reweighting and token-level surrogates

    Do not run the two-GPU vLLM recipe. Use the small synchronous substitute described below; read asynchronous execution as a source of lag, not infrastructure to build.

  2. RLHF Book code: rollout ownershipRLHF Book Code - Policy Gradients and Rejection Sampling

    RolloutEngine._generate_experience: generation configuration, action mask, rewards, log_probs_old, log_probs_ref and Experience construction

    Trace the data flow only. Add immutable version and outcome records yourself; the example's tensor buffer is not a complete experiment manifest.

  3. LLM Post-Training Laboratory: identity contractLLM Post-Training Laboratory - RL and Reasoning

    Architecture constraints; Milestone C; Milestone D stale-log-probability, ratio-direction and policy-lag injections

2

Focus on

  • Bind token IDs, prompt split and template, policy and reference hashes, verifier version, sampling settings, RNG state, action masks, raw reward components and stopping reasons. Stored old scores must survive later parameter changes unchanged.
  • Start the live study on your existing roughly 10M-parameter decoder and short string-reversal task, on CPU or your GPU. Use PyTorch 2.14.1, a character tokenizer, a small SFT initialization, groups of 4, at most 8 generated tokens and an initial 10-update budget. Keep the model config and starting checkpoint hash.
  • Choose the assignment's one-update on-policy variant explicitly: inclusive group mean, sample standard deviation plus 1e-6, response-mean loss, no KL optimization term. Keep a frozen reference for diagnostics. Use temperature 1 without probability truncation, disable dropout, and regenerate after each update.
  • Collect, verify, update and externally evaluate fresh held-out outputs. Count prompts, attempts, generated and training tokens, verifier calls and failures separately. Later minibatches become stale after an optimizer step; asynchronous version lag is another mismatch.
Common mistakes · 3
  • Recording raw-model scores after sampling through temperature or truncation. The actual behavior distribution includes those transformations; removed support cannot be restored by importance weights.
  • Calling a token ratio exact trajectory correction. It leaves old prefix visitation in place; the full trajectory weight is a product of token ratios.
  • Overwriting sampler scores with learner scores from a newer checkpoint. If scoring backends differ, retain both sets at the same old checkpoint under separate names.
3

Try it yourself

Closed-book, before checking anything

Enumerate a two-token binary completion with independent tokens: behavior probabilities [0.5, 0.5], current probabilities [0.75, 0.25] at both positions. For sequences '00', '01', '10', '11', trajectory weights are [2.25, 0.75, 0.75, 0.25]. Weighting the behavior probabilities by these recovers the current joint distribution. Implement this oracle, then inject an old-score overwrite into a collected batch and require the identity check to fail before an update.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Do importance weights recover actions given zero behavior probability?Answer

    No. Exact correction requires behavior support wherever the target distribution contributes.

  2. 2.Why are first-update ratios near 1 rather than necessarily bit-identical to 1?Answer

    Matching weights and distributions imply equality mathematically, but different kernels, precision or dropout can change computed scores. Test under a declared tolerance and fixed scoring mode.

  3. 3.Does clipping a huge importance weight preserve unbiasedness?Answer

    Generally no. It trades bias for reduced influence of extreme weights, and does not repair missing support or wrong metadata.

5

Practice

  • CS336 Assignment 5: grpo_train_step_standard_on_policy

    test_grpo_train_step_standard_on_policy: loss and updated-parameter snapshot with two accumulation microbatches and a final cleared-gradient assertion

    Use the public fixture on CPU and keep solutions private. It tests a supplied-response update, not on-policy collection or generalization. The mini-project supplies the actual small rollout-update-evaluation cycle and immutable manifest.

You're done when

The train-step snapshot passes, the old-score overwrite is rejected, and one bounded live run records fresh rollouts, updates, reference diagnostics and independent held-out evaluation without losing failed attempts.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 17 more in the section
  • CS336 Assignment 5 - Alignment and Reasoning RLStanford University · primary

    Do Sections 3 to 5: prompting and grading baselines, baseline_calcs, then the Section 4.2 functions (tokenization, response log probabilities, rollout rewards, group-normalized rewards, loss aggregation, the on-policy GRPO step) until the GRPO and metrics tests pass on CPU. The handout runs OLMo-2 1B with a two-GPU vLLM loop; run a small GRPO on a model and task that fit your GPU instead, with one normalization ablation and one preserved failure.

  • RLHF Book Code - Policy Gradients and Rejection SamplingNathan Lambert · support

    Run policy_gradients/train.py with the REINFORCE, RLOO or GRPO config and the rejection-sampling selection controls (top_per_prompt against random_per_prompt). Defaults use Qwen3-1.7B and a 7B scorer, so shrink the model, rollouts and tokens to fit your GPU. Sweep one variable and keep an unstable or hacked run.

  • LLM Post-Training Laboratory - RL and ReasoningRoadmap-Final · support

    Use the rollout, objective, policy-version, reward-hacking and compute-normalized evaluation requirements as the persistent artifact for this and later stages.

Also in this section