Unit 5 of 11 · about 4 hours · measure

Reference KL, entropy and collapse diagnostics, and actor, reference, reward and verifier roles

Reward can rise while exploration disappears or the policy drifts toward a verifier shortcut. Role identities and independent diagnostics make those explanations testable.

You'll be able to

  • Separate current actor, rollout policy, frozen reference, reward model, verifier and critic responsibilities.
  • Measure reference KL, token entropy, answer diversity and zero-signal groups without treating any one trace as a diagnosis.
  • Check sampled KL estimates against an exact categorical oracle.

Covers

Reference KL, entropy, exploration and collapse diagnosticsActor, reference, reward model, verifier and value-model roles
1

Read

In this order, only the parts listed

0 of 3 done

  1. RLHF Book Chapters 6 and 15: roles and regularizationRLHF Book - Policy Gradients, Reasoning and Rejection Sampling

    Chapter 15, KL Divergence in RL Optimization through Implementation Example; Chapter 6, The Role of Reinforcement Learning in RLHF

    Stop before Other Tools to Control Optimization. In the Implementation Example, F.kl_div receives log targets without log_target=True; do not copy that call. Use the exact oracle below instead.

  2. Build a Reasoning Model: entropy diagnosticsBuild a Reasoning Model (From Scratch), Chapters 4 to 7

    Chapter 7, Section 7.3.2, Entropy tracking, printed pp. 236 to 240

    Use the calculation, not the illustrative entropy bands as universal collapse thresholds. Entropy depends on vocabulary, prefixes and sampling policy.

  3. TRL 1.15.0: reference loading and KL estimatorTRL GRPO Trainer

    Reference-model initialization at self.beta == 0.0; loss computation of per_token_kl and use_bias_correction_kl

2

Focus on

  • The actor learns; the rollout snapshot generated the data; the reference defines drift. A learned reward model and a rule-based verifier are alternative feedback sources, not interchangeable evidence of correctness. A critic predicts future return.
  • The Math Foundations unit on entropy and KL divergence supplies the definitions. State the direction as . Token means and sequence sums have different length weighting.
  • For current-policy samples with common support, let . Both and have the KL expectation. The latter is nonnegative per sample in exact arithmetic; an old-policy sample average is not automatically that expectation.
  • Keep fixed diagnostic prefixes as well as rollout averages. Read entropy beside duplicate answers, length, invalid outputs, advantage spread and held-out correctness. A zero-variance reward group is not proof of entropy collapse.
Common mistakes · 3
  • Using the reference in the PPO ratio denominator. Old-policy drift and reference drift are different quantities.
  • Calling estimator-value agreement a proof of gradient agreement. Differentiating a fixed-old-sample KL surrogate requires its own check; TRL's ratio correction changes the gradient even at a ratio value of 1.
  • Reading low KL as guaranteed safety or generalization. It only measures the declared distributions on the declared support and prefixes.
3

Try it yourself

Closed-book, before checking anything

On CPU with PyTorch 2.14.1, let policy = torch.tensor([0.6, 0.4], dtype=torch.float64) and reference = torch.tensor([0.5, 0.5], dtype=torch.float64). Compute exact policy-to-reference KL, the policy-weighted log ratio and the policy-weighted k3 expression. All give approximately 0.02013551 nats. Policy entropy is approximately 0.67301167 nats. Cross-check with torch.nn.functional.kl_div(reference.log(), policy.log(), reduction="sum", log_target=True) within 1e-12 absolute tolerance.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Can a sampled log-ratio KL estimate be negative?Answer

    Yes. Individual log ratios and finite-sample means can be negative even though the population KL is nonnegative.

  2. 2.Does setting TRL's KL coefficient to zero mean no reference needs recording?Answer

    The trainer need not load a reference for optimization, but the study still records the starting reference identity and can score it separately for diagnostics.

  3. 3.All rewards are equal but completions differ. What has disappeared?Answer

    The centered outcome signal, not necessarily exploration. A separate KL or entropy term may still produce gradients.

You're done when

Your categorical oracle agrees across all three KL calculations, and your study dashboard distinguishes reference drift, old-policy drift and loss of outcome signal.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 17 more in the section
  • RLHF Book - Policy Gradients, Reasoning and Rejection SamplingNathan Lambert · required

    Read Chapter 6 (policy gradients: REINFORCE, RLOO, PPO, GRPO and loss aggregation), Chapter 7 (reasoning), Chapter 9 (rejection sampling), Chapter 12 (distillation) and Chapter 15 (regularization). Do the Suggested Experiments in Chapters 6 and 9. Derive only the estimator used in your experiment, then use Chapters 14 and 15 to design the reward-hacking tests.

  • Build a Reasoning Model (From Scratch), Chapters 4 to 7Sebastian Raschka / Manning · support

    Use Chapter 4 (temperature, top-p and self-consistency, pp. 94-135), Chapter 6 (GRPO on Qwen3-0.6B, pp. 179-224) and Chapter 7 (clipping, KL and metrics, pp. 225-266). Listing 6.13 is the unclipped policy gradient; clipping and KL arrive in Sections 7.4 and 7.5. Its advantage uses torch.std, which is the unbiased estimator.

  • TRL GRPO TrainerHugging Face · reference

    Read after your scratch loss passes. In TRL 1.15.0 the defaults are loss_type="dapo" (token mean), beta=0.0 (no reference model loaded) and scale_rewards="group"; set loss_type="grpo" and beta above zero to approach the DeepSeekMath objective, and state the choice beside any comparison.

Also in this section