Unit 5 of 12 · about 5 hours · derive, implement

Grouped sampling, group-relative advantages, GRPO and degenerate groups

GRPO replaces a fitted critic with comparisons between sibling completions. Its useful signal depends on reward differences within a prompt, not just on average success.

You'll be able to

  • Derive outcome-supervised group advantages and identify their differences from RLOO.
  • Implement a critic-free clipped loss that handles mixed and all-equal reward groups.

Covers

Grouped sampling and group-relative advantagesGRPO objective and critic-free trade-offsAll-equal, all-correct and all-wrong group behavior
1

Read

In this order, only the parts listed

0 of 2 done

  1. RLHF Book: GRPORLHF Book - Policy Gradients and Regularization

    Chapter 6, Group Relative Policy Optimization (GRPO), equations 33 to 38 (page read 2026-10-14)

  2. DeepSeekMath: original outcome-supervised GRPODeepSeekMath - GRPO

    arXiv:2402.03300v3, Sections 4.1.1 and 4.1.2, equations 3 and 4, Figure 4 and the unnumbered outcome-advantage formula

    Stop before process supervision in Section 4.1.3. Keep the original token ratios and per-response means separate from later trainer defaults.

2

Focus on

  • For outcome rewards, broadcast to completion tokens. Specify population or sample standard deviation, a positive stabilizer and a minimum group size.
  • Group centering, standard-deviation scaling, ratio clipping, KL placement and aggregation are separate choices. The algorithm name alone does not specify your loss.
  • All-equal rewards give zero outcome advantages with a finite denominator. All-correct and all-wrong binary groups share that property, but require different data decisions. An explicit KL term can still supply gradients.
  • The original method removes the critic and GAE. It does not remove sibling generation, verification or the need to test loss gradients.
Common mistakes · 3
  • Treating normalized inclusive centering as the unbiased RLOO estimator. The random denominator adds another dependence on the sampled group.
  • Adding a stabilizer after division. It cannot repair a zero denominator or an already undefined singleton sample standard deviation.
  • Calling all-correct groups proof of generalization. The held-out prompt distribution may still fail.
3

Try it yourself

Closed-book, before checking anything

On CPU, normalize rewards [1., 1., 0., 0.] with population standard deviation and stabilizer 1e-4. Obtain advantages approximately [0.99980004, 0.99980004, -0.99980004, -0.99980004]. Repeat with sample standard deviation and the same 1e-4 stabilizer: magnitudes become approximately 0.86587543. All-zero and all-one groups must give finite zero advantages. Reject a singleton before computing a sample standard deviation.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Does zero mean advantage imply zero policy gradient?Answer

    No. Different completions have different score vectors. Their weighted gradients need not cancel.

  2. 2.Does an all-wrong binary group identify the least wrong completion?Answer

    No. Equal verifier rewards give no relative outcome information. Use a specified richer reward or change sampling, not an invented ranking.

  3. 3.Why do NumPy and PyTorch ports sometimes disagree?Answer

    Their default standard-deviation corrections differ. Specify the convention and stabilizer in both implementations.

5

Practice

  • Normalize GRPO Group Advantages

    Language Modeling from Scratch plan, Normalize GRPO Group Advantages: statement, function signature and public examples

    The problem uses population standard deviation. The section mini-project also tests sample-standard-deviation parity and degenerate groups.

You're done when

Your mixed and all-equal groups match the specified convention, and you can list every choice needed to turn those advantages into a loss.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 11 more in the section
  • RLHF Book - Policy Gradients and RegularizationNathan Lambert · primary

    Study Chapter 6 completely (REINFORCE, RLOO, PPO, GRPO, GSPO, CISPO, loss aggregation, asynchronous systems, truncated importance sampling) and Chapter 15 on KL and regularization. Implement REINFORCE, PPO-style, RLOO and GRPO fixed-rollout losses from the chapter equations, then verify masks, ratios, group baselines and one-gradient-step simplifications.

  • DeepSeekMath - GRPODeepSeek AI · required

    Study the GRPO method and group-relative advantage construction, not the unrelated pretraining details. Implement all-equal and mixed-reward group tests and separate algorithmic changes from additional sampling.

Also in this section

  • RLHF Book Course - Lectures 3 and 4Nathan Lambert · required

    Use Lecture 3 (RL motivation and math, Chapter 6 part 1) and Lecture 4 (RL implementation and practice, Chapter 6 part 2: loss aggregation, asynchronous training). Reproduce the loss on a tiny frozen rollout before using any trainer library.

  • Back to Basics: REINFORCE Style Optimization for Learning from Human FeedbackAhmadian et al. · required

    Study the RLOO estimator, baseline construction and system simplifications. Compare RLOO with a value-baseline or grouped estimator under matched completions and reward calls.

  • Berkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - LLM RL Lecture and Homework 4UC Berkeley · required

    Slides are public at https://rail.eecs.berkeley.edu/deeprlcourse/static/slides/lec-N.pdf; current videos are not, and the public Fall 2023 playlist numbers lectures differently. Study Lecture 14 (LLM RL) and the Homework 4 handout: log probabilities, minibatching, advantage normalization, GR-REINFORCE and GRPO on a format task and a math task, plus a GRPO hyperparameter study. It is configured for H100 GPUs on Modal (about 8 GPU hours), so port the code paths to a tiny model on your GPU or run them on pre-generated rollouts.

  • DAPO: An Open-Source LLM Reinforcement Learning System at ScaleYu et al. (2025) · support

    Read Sections 2 and 3: decoupled clipping bounds, dynamic sampling that drops all-equal groups, the token-level loss and overlong reward shaping, and the removal of the KL term. Compare its token-level aggregation with GRPO's per-sequence mean on a fixed group.

  • Understanding R1-Zero-Like Training: A Critical Perspective (Dr. GRPO)Liu et al. (COLM 2025) · support

    Read Section 3: the response-length bias of per-sequence normalization and the question-difficulty bias of dividing by the group standard deviation. DAPO keeps the standard deviation that Dr. GRPO removes, so treat the choice as open and test both on a fixed group.

  • Build a Reasoning Model (From Scratch) - Chapters 6 and 7Sebastian Raschka (Manning) · support

    Use Chapter 6 (rollouts, rewards, group advantages, sequence log probabilities and the GRPO loss on Qwen3 0.6B) and Chapter 7 (metrics, clipped ratios, the KL term and a format reward) as the smallest runnable GRPO loop. Listing 6.13 is the unclipped loss; the clipped and KL versions come in Chapter 7. Its advantages use the unbiased torch.std.

  • TRL GRPO TrainerHugging Face · support

    After scratch estimator tests pass, inspect the GRPOTrainer for TRL 1.15.0: its reward-function, generation, loss and logging contracts. Its defaults changed across releases (loss_type="dapo" and beta=0.0 in 1.15.0), so differential-test one batch and record every default you rely on.

  • TensorTonic - GRPO ProblemsTensorTonic · support

    Solve Normalize GRPO Group Advantages (cs336-l16-grpo-group-advantages), Compute a Clipped GRPO Surrogate (cs336-l16-clipped-grpo-surrogate) and Compare Sequence and Token Length Normalization (cs336-l16-grpo-length-normalization-audit), free problems in the Language Modeling from Scratch plan, as closed-book checks after your own estimator passes.

  • Hands-on Modern RL - Chapter 15 GRPO and RLVRWalking Labs · support

    Use the GRPO practice and mechanism page and the RLVR page: its group-normalization demo and rule-based reward script run on CPU in seconds. Its TRL examples pin TRL 0.24, whose defaults differ from current releases. Run only a small verifier task and preserve zero-variance, length-hacking and invalid-output cases. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its code/chapterNN folders do not follow the site chapter numbers.

  • RLHF Book Code - Policy GradientsNathan Lambert · support

    Use the code/policy_gradients package at natolambert/rlhf-book at commit 1042143 as a differential reference after the hand implementation passes (loss.py holds the masked means, the GRPO and PPO losses and the , , KL estimators). Trace every tensor to prompt, completion and policy version and extend the tests with stale-log-prob and mask defects.

  • LLM Post-Training Laboratory - Online RLRoadmap-Final · required

    Complete one PPO-style, RLOO or verifiable group-relative update with immutable rollouts, fixed tests, bounded queues, SFT and direct-preference controls, reward-hacking probes and all failed or filtered samples retained.