9.7 — Group Relative Policy Optimization (GRPO)
Goal: Derive GRPO as a simplification of PPO that removes the critic by computing advantages within a *group* of completions per prompt. Identify why this matters for LLM RL — no value head, half the memory, half the compute — and place GRPO as the algorithm behind DeepSeek-Math, DeepSeek-V2-Math, and DeepSeek-R1's reasoning training.
1. Why this session exists
PPO (9.6) is the workhorse of RLHF, but it carries machinery that LLM training stretches uncomfortably:
- A value-function critic — usually a second LLM-sized network (or an extra head on the policy) that estimates the expected reward of a prompt. Trained jointly with the policy via a value-loss term. In LLM RLHF, the critic doubles the memory and adds a non-trivial training cost.
- Generalised Advantage Estimation (GAE) — a weighted sum of temporal-difference errors used to compute the advantage . Sensible for multi-step control, but LLM trajectories are one shot (generate the whole response, get one reward at the end), so most of GAE's machinery is overkill.
Shao, Wang, Zhu, et al., 2024[2], DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models (arXiv:2402.03300) introduced Group Relative Policy Optimization (GRPO): drop the critic entirely; compute the advantage by sampling completions per prompt and normalising rewards within the group. Same clipped surrogate as PPO, no value head, half the memory.
GRPO is the algorithm behind DeepSeek-Math, DeepSeek-V2-Math, and DeepSeek-R1 (2025, arXiv:2501.12948) — the reasoning models that prompted the "o1-style" inference-time-scaling era. Beyond DeepSeek, GRPO has been adopted broadly for reasoning-RL since 2024: it's simpler, more memory-efficient, and (empirically) at least competitive with PPO at reasoning tasks.
This session: the GRPO advantage estimator, the loss function, the relationship to PPO, and the practical recipe.[1]
2. The group-relative advantage
Consider a prompt and the policy . PPO uses an advantage
where is the critic — a learned baseline. GRPO replaces with an empirical baseline computed from a group of completions.
2.1 The construction
For each prompt , sample completions from the current policy. Compute the rewards for each. The group mean and standard deviation are
Define the group-relative advantage for completion :
with a small to guard against zero variance.
That is the entire advantage estimator. No critic, no GAE, no temporal-difference machinery. Just "how much better than the rest of this group is this completion, in standard-deviation units?"
2.2 Why this works
The PPO-style critic is trying to estimate — the expected reward under the current policy. The group sample mean is an unbiased Monte Carlo estimate of the same quantity, computed from samples per prompt. So replaces the critic's role at no estimation-quality cost, given enough .
Subtracting centres the advantage; dividing by normalises it. After normalisation, is in standard-deviation units of the group's reward — comparable across prompts that have wildly different absolute reward magnitudes (e.g., easy vs hard math problems).
The normalisation is what distinguishes GRPO from earlier "REINFORCE with sample baseline" methods. It gives a scale-invariant gradient signal that doesn't blow up for high-variance prompts.
2.3 The reward is a scalar at the end of the sequence
For LLM RL, the reward is usually a single scalar per completion: either a verifier output (math problem solved correctly?), a code-execution outcome (tests pass?), or a reward-model score. There's no per-token reward; the policy gradient applies the same group-advantage at every token of completion :
Each token contributes the same to the gradient. (Variants attach token-level advantages from a process reward model — see 9.12.)
3. The GRPO loss
GRPO inherits PPO's clipped surrogate (9.6 §3) and adds the same KL penalty as RLHF (9.9). The per-token clipped objective:
with the importance ratio
Same shape as PPO, with three things changed:
- is the group-relative advantage, not the critic-based .
- The outer expectation includes the average over the group — — to combine the completions per prompt.
- No value-loss term for training a critic.
The KL term keeps the policy from drifting too far from a reference policy (typically the SFT model). Same as RLHF; we cover it properly in 9.9.
4. The compute and memory savings
The single biggest practical advantage of GRPO over PPO for LLMs.
4.1 Memory
PPO needs three models in memory:
- Policy — the LLM being trained.
- Value critic — usually an LLM-sized network (or an LLM with a value head).
- Reference policy — the SFT baseline, frozen, used for the KL term.
Plus, often, a fourth: the reward model. For PPO-RLHF you carry all four.
GRPO drops the critic. Three models become two (plus the reward model). For a 70B-parameter model in bf16 with Adam-state-included memory:
- PPO: GB (policy) + GB (critic) + GB (frozen ref) = GB.
- GRPO: GB (policy) + GB (frozen ref) = GB.
That's a ~ memory saving for the training stack alone. With reward-model included, the absolute saving is a smaller fraction but still substantial.
4.2 Compute
The critic's forward and backward passes during PPO are roughly the same cost as the policy's. So GRPO's per-step compute is roughly half of PPO's — at fixed number of samples and gradient steps.
GRPO does pay for sampling completions per prompt (PPO needs only one). But is typically small () and the sampling cost is forward-only (no backward), so this is a modest counter. Net: GRPO is meaningfully cheaper per outer training step.
4.3 Why the savings matter for reasoning RL
The reasoning-RL regime (training a model on math/code/reasoning tasks via RL) requires long completions — a chain of thought, often thousands of tokens. Sampling completions per prompt is already the inference budget of a single completion. Removing the critic's forward/backward at each step frees substantial compute and memory, which can be spent on more samples or larger models.
DeepSeek-R1's reasoning training reportedly uses GRPO with completions per prompt — feasible because the critic is gone.
5. The GRPO training loop
Pseudocode for one outer GRPO step on a batch of prompts:
For each prompt x in the batch:
Sample K completions {y_1, ..., y_K} ~ π_θ_old(·|x)
Compute rewards r_i = r(x, y_i) # reward model or verifier
Compute group statistics μ_G, σ_G
Compute per-completion advantages A_i = (r_i - μ_G) / (σ_G + ε)
# All N · K completions are now associated with an A value
# Optimise the clipped surrogate + KL for M inner steps:
For m = 1, ..., M:
For each (x, y_i, A_i):
Compute ρ_{i,t} = π_θ(y_{i,t}|x, y_{i,<t}) / π_θ_old(y_{i,t}|x, y_{i,<t})
Compute per-token clipped loss
Compute KL term against π_ref
Update θ by gradient descent
θ_old ← θ # snapshot for next outer iteration
The outer loop (– iterations) drives the policy through reasoning RL. The inner loop ( or so) reuses each batch of samples for multiple gradient steps, like PPO. Sampling is the bottleneck in wall-clock; compute-cheap inner steps are essentially free.
6. GRPO vs PPO: when to use which
A short comparison:
| | PPO | GRPO | |---|---|---| | Critic | yes (, learned) | no (group mean) | | Advantage | GAE on rewards | | | Memory | for policy+critic | for policy | | Compute per step | full forward+backward × 2 | full forward+backward × 1 | | Samples per prompt | 1 | – | | KL penalty | usually yes | usually yes | | Best for | dense per-token rewards | sparse end-of-sequence rewards |
Use PPO when: you have per-token rewards (e.g., a per-step process reward model from 9.12) — the critic and GAE machinery actually earn their keep.
Use GRPO when: you have a sparse end-of-sequence reward (verifier outcome, reward model score) — which is the typical RLHF and reasoning-RL setting. The simpler estimator suffices.
7. The DeepSeek-R1 story
DeepSeek-R1 (2025, arXiv:2501.12948) is the canonical demonstration of GRPO at frontier scale. Two relevant points:
7.1 RL on a pretrained base, no SFT
DeepSeek-R1-Zero takes the pretrained base model (no SFT, no human demonstrations) and applies GRPO directly with an automatic reward signal — "correct math answer?" verified by an external checker. The model learns reasoning from RL alone. This was the breakthrough finding: pure RL on a pretrained base, with a sparse correctness reward, produces chain-of-thought reasoning behaviour.
7.2 RL after SFT, the production version
DeepSeek-R1 (the full model) uses a two-stage recipe:
- SFT on curated reasoning data.
- GRPO with a mixture of verifier and reward-model signals.
Stage 2 is GRPO with completions per prompt, running for hundreds of thousands of steps. The resulting model matches OpenAI o1-preview on reasoning benchmarks (AIME, MATH, code).
The empirical lesson: GRPO is a viable alternative to PPO for frontier RLHF, especially when rewards are sparse and completions are long. PPO is not deprecated — most of OpenAI and Anthropic's RLHF infrastructure remains PPO-based — but GRPO is now a real choice.
8. What we keep going forward
Three things:
- GRPO's advantage is empirical, not learned. from a group of samples per prompt. No critic.
- GRPO is ~ cheaper than PPO at the cost of more samples per prompt. Best for sparse end-of-sequence rewards, which is most LLM RL.
- DeepSeek-R1 is the existence proof. Frontier reasoning models can be trained with GRPO.
Next session puts the pieces together: SFT → reward model → PPO (or GRPO) → KL-penalised policy. The full RLHF pipeline, end to end.
(a) Write down the GRPO advantage formula and identify each term's role. Compare with PPO's . Why does the group mean replace the critic without loss of unbiasedness?
(b) A GRPO setup uses completions per prompt with rewards . Compute , , and the advantage of the best and worst completions.
(c) GRPO is ~50% cheaper than PPO at the cost of more samples per prompt. State why this trade is favourable for long, reasoning-style completions (where each completion is thousands of tokens).
(d) DeepSeek-R1-Zero trains directly from a pretrained base with no SFT. Argue why this is feasible with GRPO + a verifier reward but would be expensive with PPO.
(e) Read Shao et al., 2024 §4. Identify the empirical comparison between GRPO and PPO on math reasoning. What is the magnitude of the GRPO improvement, and at what cost?
References
- [1]
DeepSeek-AI (2025). "DeepSeek-R1: Incentivizing reasoning capability in LLMs via reinforcement learning". arXiv:2501.12948 — R1 architecture inherits V3's MLA + MoE (referenced in 8.5; primary citation in Cap 9.7).
↩ - [2]
Shao, Z., Wang, P., Zhu, Q., et al. (2024). "DeepSeekMath: Pushing the limits of mathematical reasoning in open language models". arXiv:2402.03300 — Group Relative Policy Optimization (GRPO) (9.7).
↩