ResearchAgentsStory 1 of 5Sample

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.

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#

AspectPPO (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 trainingPolicy, reference, reward model, value modelPolicy, reference, reward function or model
Samples per promptOften oneA group of GG (DeepSeekMath used 64)
AdvantageGAE over the critic's per-token valuesGroup-normalised reward, shared by every token of the answer
KL to the reference modelUsually folded into the rewardAdded directly to the loss
Best fitDense or learned rewardsVerifiable 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#

Bar chart of top-1 accuracy on the MATH benchmark for open-source models, with DeepSeekMath 7B at the top
Figure 1 of DeepSeekMath: top-1 accuracy of open-source models on the competition-level MATH benchmark without external tools or voting. Source: Shao et al. (2024), arXiv 2402.03300, via the arXiv HTML (ar5iv) version.

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 qq. Sample a group of GG answers o1,…,oGo_1, \dots, o_G from the current (old) policy and score them to get rewards r=(r1,…,rG)\mathbf{r} = (r_1, \dots, r_G). The advantage of answer ii is its reward standardised within the group:

A^i=ri−mean⁡(r)std⁡(r)+ε\hat{A}_i = \frac{r_i - \operatorname{mean}(\mathbf{r})}{\operatorname{std}(\mathbf{r}) + \varepsilon}

With outcome supervision every token tt of answer ii shares that value: A^i,t=A^i\hat{A}_{i,t} = \hat{A}_i. Let the per-token probability ratio be

ρi,t(θ)=πθ(oi,t∣q,oi,<t)πθold(oi,t∣q,oi,<t)\rho_{i,t}(\theta) = \frac{\pi_\theta(o_{i,t} \mid q, o_{i,<t})}{\pi_{\theta_\text{old}}(o_{i,t} \mid q, o_{i,<t})}

The GRPO objective keeps PPO's clipped surrogate and adds a KL penalty towards a frozen reference model πref\pi_\text{ref}:

JGRPO(θ)=E[1G∑i=1G1∣oi∣∑t=1∣oi∣(min⁡(ρi,tA^i,t, clip⁡(ρi,t,1−ϵ,1+ϵ) A^i,t)−β DKL[πθ ∥ πref])]\mathcal{J}_\text{GRPO}(\theta) = \mathbb{E}\left[ \frac{1}{G} \sum_{i=1}^{G} \frac{1}{|o_i|} \sum_{t=1}^{|o_i|} \Big( \min\big(\rho_{i,t}\hat{A}_{i,t},\ \operatorname{clip}(\rho_{i,t}, 1-\epsilon, 1+\epsilon)\,\hat{A}_{i,t}\big) - \beta\, \mathbb{D}_\text{KL}\big[\pi_\theta \,\|\, \pi_\text{ref}\big] \Big) \right]

The KL term is estimated per token with an unbiased, always-positive estimator:

DKL[πθ ∥ πref]=πref(oi,t∣⋅)πθ(oi,t∣⋅)−log⁡πref(oi,t∣⋅)πθ(oi,t∣⋅)−1\mathbb{D}_\text{KL}\big[\pi_\theta \,\|\, \pi_\text{ref}\big] = \frac{\pi_\text{ref}(o_{i,t} \mid \cdot)}{\pi_\theta(o_{i,t} \mid \cdot)} - \log \frac{\pi_\text{ref}(o_{i,t} \mid \cdot)}{\pi_\theta(o_{i,t} \mid \cdot)} - 1

Here is the group-advantage step in PyTorch, for a batch of prompts with GG answers each:

python
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 1∣oi∣\frac{1}{|o_i|} 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_rewards setting 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 GG 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 GRPOTrainer now defaults to β=0\beta = 0, 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.

Try this weekend

Build it yourself

  1. Pick a 0.5B instruct model (e.g. Qwen/Qwen2.5-0.5B-Instruct) and the GSM8K training split.
  2. Write a reward function that extracts the final number from each completion and returns 1.0 if it matches the reference, else 0.0.
  3. Train with TRL's GRPOTrainer and loss_type="dr_grpo" for a few hundred steps on a free Colab or Kaggle GPU.
  4. Log the mean reward and mean completion length to Langfuse or Weights & Biases and watch how length changes.
  5. Compare accuracy on 200 held-out GSM8K questions before and after.

Sources

  1. DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models · arXiv (Shao et al.) · 5 Feb 2024
  2. DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning · arXiv (DeepSeek-AI) · 22 Jan 2025
  3. GRPO Trainer · Hugging Face TRL docs
  4. Understanding R1-Zero-Like Training: A Critical Perspective · arXiv (Liu et al.) · 26 Mar 2025