Unit 11 of 11 · about 3 hours · implement

Rejection fine-tuning, RLOO and neighboring estimators

Simple controls can explain a result attributed to a complex RL recipe. Baseline dependence and data reuse matter more than the estimator's name.

You'll be able to

  • Implement leave-one-out advantages and verify their relation to inclusive group centering.
  • Build a filtered-SFT control with explicit acceptance, retention and normalization rules.
  • Compare estimator assumptions without treating every newer named loss as a required experiment.

Covers

Rejection fine-tuning, RLOO and neighboring estimators
1

Read

In this order, only the parts listed

0 of 3 done

  1. CS336 Spring 2026 Assignment 5: rejection fine-tuningCS336 Assignment 5 - Alignment and Reasoning RL

    Section 5.2, Rejection fine tuning; Equations 34 to 36 and think_about_rft

    Stop before Section 5.3, MaxRL. Compare gradient estimators with detached samples; do not assume the inclusive group baseline has the same expectation as raw REINFORCE.

  2. RLHF Book code: leave-one-out implementationRLHF Book Code - Policy Gradients and Rejection Sampling

    compute_loo_advantages and compute_nonstandardized_advantages

    The first tensor axis is the rollout group. Add an explicit error for groups smaller than 2; the source formula alone does not guard that case.

  3. RLHF Book code: selection controlsRLHF Book Code - Policy Gradients and Rejection Sampling

    select_top_per_prompt, select_random_per_prompt and _chapter_worked_example

    Read the matched per-prompt selection controls. Top-ranked is not necessarily correct; add a strict correctness threshold for binary-reward RFT. Do not launch the default large reward model.

2

Focus on

  • For independent same-prompt samples, use . Detach rewards and baselines. The leave-one-out baseline is independent of the current sampled action conditional on the prompt; the inclusive mean is not.
  • With identical sequence-sum scores, fixed normalization and no extra scaling, inclusive group centering has expected gradient times raw REINFORCE. Leave-one-out removes that factor. Reward standardization, response-length weighting and clipping break this simple equivalence.
  • Fresh on-policy binary reward weighting with fixed normalization is a REINFORCE estimator. Repeated likelihood training on a fixed retained set is filtered SFT, not a fresh on-policy update. Normalizing by a random accepted count changes the estimator.
  • For the tiny reversal control, reuse a versioned starting-policy candidate pool, retain strict-correct outputs and fit with response-only cross-entropy. Record empty groups, retained counts, duplicates, training tokens and optimizer steps. Compare a matched-size random-per-prompt refit where data permit; disclose prompt or token imbalance.
Common mistakes · 3
  • Dividing by group standard deviation and still calling it the unscaled leave-one-out estimator. That changes prompt weighting.
  • Keeping one top-ranked output even when all candidates fail. That is ranking-based self-training, not correct-only RFT.
  • Calling accepted-data count the rollout budget. Rejected generations and scoring work still cost compute and can expose different task coverage.
3

Try it yourself

Closed-book, before checking anything

On CPU with PyTorch 2.14.1 and float64, rewards [0, 0, 3] have inclusive centered values [-1, -1, 2] and leave-one-out values [-1.5, -1.5, 3]. Verify the explicit other-sample means against the scaled centered formula, then test equal rewards and reject a singleton group. Enumerate two independent Bernoulli actions with success probability 0.5 and reward equal to the action: raw REINFORCE and leave-one-out have expected logit gradient 0.25, while inclusive centering gives 0.125, using the same group-mean reduction.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Why does leave-one-out need at least two samples?Answer

    There is no other-sample reward mean for a singleton group, and the formula divides by zero.

  2. 2.Can a correct-only refit improve when every collected output is wrong?Answer

    Not from that pool. It has no retained training examples. Preserve the empty-pool result rather than inventing successful data.

  3. 3.Does an action-independent baseline always reduce variance?Answer

    No. It preserves the expected score-function gradient under the stated assumptions, but its variance effect depends on the baseline and reward distribution.

5

Practice

  • CS336 Assignment 5: Think about RFT

    Section 5.2, think_about_rft, 2 points

    Write the comparison privately and check it with the two-action enumeration. This is a discussion exercise, not an autograded guarantee of unbiasedness. The mini-project supplies the small retained-data refit and matched evaluation.

You're done when

The leave-one-out fixtures and expected-gradient enumeration pass, and the filtered-SFT control retains its acceptance rule, data lineage and full cost ledger even if no outputs pass.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 18 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.

Also in this section