GRPO

Sample several answers to the same question. Each answer's advantage is how it scored against the others.

Key idea
Group-relative advantage: the group is the baseline
Real world
Grading on a curve. A 70% is great if the class averaged 50% and poor if it averaged 90%. GRPO scores each answer against the other answers to the same question.
In an LLM
DeepSeek-R1-style reasoning training: 8 to 16 samples per maths prompt, reward = right answer plus right format, no critic network. TRL's GRPOTrainer.

Why a new algorithm

Policy gradient needs a baseline, and PPO gets it from a critic: a second network, roughly the size of the policy, trained alongside it. For a large language model that doubles the memory and adds a model that's hard to train well.

GRPO (Group Relative Policy Optimization, introduced with DeepSeekMath in 2024) drops the critic. The baseline comes from sampling several answers to the same prompt and comparing them.

One GRPO step

  1. Sample a group of G answers for one prompt.
  2. Score each one. Here: +1 for the right number, +0.2 for putting it in the answer tags.
  3. Normalise: advantage = (score − group mean) ÷ group standard deviation (a measure of how spread out the scores are).
  4. Update as in policy gradient, with PPO's clip and optionally the KL penalty.
example · a group of four

Prompt: "What is 17 × 6?". The model writes four answers:

AnswerCorrect?Tags?RewardAdvantage
<answer>102</answer>✓✓1.2+0.99
<answer>112</answer>✓0.2−0.81
"It's about 100"0−1.17
<answer>102</answer>✓✓1.2+0.99

Mean reward = 0.65, standard deviation ≈ 0.55. The correct answers are made more likely, the wrong ones less, and the answer that ignored the format is pushed down the most.

If all four had been correct, every reward would be 1.2, every advantage 0, and the prompt would teach nothing.

Try it

Prompt
Janet has 3 boxes of 12 eggs and uses 7. How many are left? Answer in <answer> tags.
group mean–
group std–
updates0
P(correct)40%
Sampling a group…
Policy: chance of each kind of completion
tags + rightr = 1.215.0%
right, no tagsr = 1.025.0%
tags + wrong (28)r = 0.220.0%
tags + wrong (8)r = 0.220.0%
ramblesr = 0.020.0%

Why it works

The group mean plays the role of the baseline from policy gradient. It is re-estimated for each prompt from samples you already paid for, so there is no critic to train. Dividing by the spread keeps the update size similar for easy and hard prompts, although that turned out to have side effects.

GRPO as first published has a few such quirks, and nearly every recipe since 2025 changes some of them. The next pages cover what verifiable rewards made possible and then the standard fixes.

going deeper

Advantage and loss

A^i=ri−mean⁡(r1..G)std⁡(r1..G)every token of answer i gets A^i\hat A_i = \frac{r_i - \operatorname{mean}(r_{1..G})}{\operatorname{std}(r_{1..G})} \qquad \text{every token of answer } i \text{ gets } \hat A_iL=−1G∑i1∣oi∣∑t[min⁡(ρi,tA^i, clip⁡(ρi,t,1−ϵ,1+ϵ) A^i)−β KLi,t]L = -\frac{1}{G} \sum_i \frac{1}{|o_i|} \sum_t \Big[\min\big(\rho_{i,t} \hat A_i,\ \operatorname{clip}(\rho_{i,t}, 1-\epsilon, 1+\epsilon)\, \hat A_i\big) - \beta\, \mathrm{KL}_{i,t}\Big]

The example uses the population standard deviation. Variants such as Dr. GRPO and DAPO change the length normalisation and drop the std division; see Fixing GRPO. TRL exposes these through loss_type and scale_rewards; check the docs for your version.

Paper

Related

  • rlvr - Let a program check the answer, run GRPO on hard maths and code, and models learn to think longer. This is the recipe behind DeepSeek-R1 and today's reasoning models.
  • grpo-fixes - Dr. GRPO, DAPO, GSPO, CISPO and friends. A handful of small changes to GRPO that nearly every recipe since 2025 uses.