GRPO, explained: reinforcement learning without a critic
Sample story. How DeepSeek trains reasoning models by grading each answer against its siblings instead of a learned value function.
TL;DR
- GRPO replaces PPO's learned critic with a group baseline: sample answers per prompt and use the group mean (and std) as the yardstick.
- It only needs a reward you can compute, such as a correct final answer or a passing test, which suits maths, code and other verifiable tasks.
- Known rough edges: per-answer length normalisation biases the model towards long wrong answers (fixed by Dr. GRPO), reward hacking, and the cost of sampling many answers.
Grading on a curve#
Imagine a teacher who has no answer key for how good an essay should be. Instead, she asks each student to write eight drafts of the same essay, reads them all, and marks each draft relative to the others: better than the class average gets a gold star, worse gets a note to try a different approach. Over time the student learns which habits produce above-average drafts.
That is the whole idea of GRPO (Group Relative Policy Optimization), introduced by DeepSeek in the DeepSeekMath paper. A language model answers the same question several times. A simple checker scores each answer (right or wrong, test passes or fails). Every answer is then judged against its own group, and the model is nudged towards the answers that beat the group.
The trick is what is missing. Classic RL for language models (PPO) trains a second network, the critic or value model, to predict how good an answer is likely to be. That critic is usually about as big as the model being trained, so it roughly doubles the memory bill. GRPO throws it away and uses the group itself as the yardstick.
This is a sample story written to exercise the site: the intuition section, a Mermaid diagram, the Overview / Full switch, a table, a hotlinked figure, KaTeX, a code block and a glossary.
One training step, end to end#
Each step samples a group of answers for every prompt in the batch, turns raw scores into advantages by comparing them with the group, and then makes a small, clipped update so the model does not lurch too far from where it started.
PPO vs GRPO, side by side#
| Aspect | PPO (as used in RLHF) | GRPO |
|---|---|---|
| Baseline for "was this good?" | A learned value model (critic) | Mean reward of the other answers to the same prompt |
| Extra networks during training | Policy, reference, reward model, value model | Policy, reference, reward function or model |
| Samples per prompt | Often one | A group of (DeepSeekMath used 64) |
| Advantage | GAE over the critic's per-token values | Group-normalised reward, shared by every token of the answer |
| KL to the reference model | Usually folded into the reward | Added directly to the loss |
| Best fit | Dense or learned rewards | Verifiable rewards: maths, code, format checks |
Two consequences follow. First, memory: dropping the value model frees roughly a model's worth of GPU memory, which is why the DeepSeekMath authors could afford large groups. Second, the advantage is the same for every token in an answer when the reward only arrives at the end (outcome supervision). GRPO also supports process supervision, where each reasoning step gets its own score, but the outcome-only version is what most people run.
DeepSeek later used GRPO at much larger scale. In the DeepSeek-R1 report, R1-Zero is trained with GRPO directly from a base model using only rule-based rewards (answer accuracy and output format), with no supervised fine-tuning first, and its AIME 2024 pass@1 rose from 15.6% to 71.0% over training.
The paper's own picture#

The headline result: with GRPO on top of math-specific pre-training, DeepSeekMath-RL 7B reached 51.7% on MATH without tools or majority voting.
The maths, one line at a time#
Start with a prompt . Sample a group of answers from the current (old) policy and score them to get rewards . The advantage of answer is its reward standardised within the group:
With outcome supervision every token of answer shares that value: . Let the per-token probability ratio be
The GRPO objective keeps PPO's clipped surrogate and adds a KL penalty towards a frozen reference model :
The KL term is estimated per token with an unbiased, always-positive estimator:
Here is the group-advantage step in PyTorch, for a batch of prompts with answers each:
import torch
def group_advantages(rewards: torch.Tensor, eps: float = 1e-6, scale: bool = True) -> torch.Tensor:
"""rewards: shape (num_prompts, G). Returns advantages of the same shape."""
mean = rewards.mean(dim=1, keepdim=True)
adv = rewards - mean
if scale: # Dr. GRPO sets scale=False to remove the difficulty bias
adv = adv / (rewards.std(dim=1, keepdim=True) + eps)
return adv
# 2 prompts, 4 answers each; reward 1.0 = correct final answer
r = torch.tensor([[1.0, 0.0, 0.0, 1.0],
[0.0, 0.0, 0.0, 1.0]])
print(group_advantages(r))
# The lone correct answer in the hard prompt gets a much larger advantage.
Notice the edge case: if every answer in a group gets the same reward, all advantages are zero and that prompt teaches nothing. Prompts that are always solved or never solved are wasted samples.
Where it bends#
- Length bias. The factor divides each answer's loss by its own length. A long wrong answer is penalised less per token than a short wrong one, so the model can learn to ramble when it is wrong. Liu et al. call this out in Understanding R1-Zero-Like Training and propose Dr. GRPO, which drops the per-answer length normalisation and the std division. TRL exposes this as
loss_type="dr_grpo". - Difficulty bias. Dividing by the group's standard deviation up-weights prompts where almost every answer is the same (very easy or very hard), which skews what the model optimises for. Dr. GRPO removes it; TRL's
scale_rewardssetting controls it. - Reward hacking. GRPO optimises exactly what the reward measures. A regex that checks the final number can be gamed by formatting tricks; a unit test can be gamed by special-casing inputs. Verifiable rewards are only as good as the verifier.
- Sampling cost. The critic is gone, but you now generate completions per prompt. Generation usually dominates wall-clock time, which is why serious setups pair GRPO with a fast inference engine such as vLLM.
- KL or no KL. DeepSeekMath used a KL penalty; TRL's
GRPOTrainernow defaults to , which switches the KL term off entirely. Which is right depends on how far you can afford to drift from the reference model.
You are reading the overview. Switch to “Full deep dive” in the top bar for the mechanics, maths and code.
Build it yourself
- Pick a 0.5B instruct model (e.g.
Qwen/Qwen2.5-0.5B-Instruct) and the GSM8K training split. - Write a reward function that extracts the final number from each completion and returns 1.0 if it matches the reference, else 0.0.
- Train with TRL's
GRPOTrainerandloss_type="dr_grpo"for a few hundred steps on a free Colab or Kaggle GPU. - Log the mean reward and mean completion length to Langfuse or Weights & Biases and watch how length changes.
- Compare accuracy on 200 held-out GSM8K questions before and after.
Why this matters to you
Your agent work at HivePro and Susanoo lives on tool-use and reasoning quality. GRPO is the cheapest credible way to RL-tune a small model on a verifiable task, such as a JanusGuard triage policy scored against labelled CIC-IDS2017 flows.
Sources
- DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models · arXiv (Shao et al.) · 5 Feb 2024
- DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning · arXiv (DeepSeek-AI) · 22 Jan 2025
- GRPO Trainer · Hugging Face TRL docs
- Understanding R1-Zero-Like Training: A Critical Perspective · arXiv (Liu et al.) · 26 Mar 2025