Where GRPO comes from
GRPO was introduced in 2024 in the DeepSeekMath paper as a leaner version of PPO (Proximal Policy Optimization, 2017), the algorithm behind most earlier RL fine-tuning of language models, including the RLHF used for InstructGPT. It became widely known when DeepSeek-R1 used it at scale, and it is now the default RL method in open-source trainers such as Hugging Face TRL and in most RFT services.
The value model is usually about as large as the model being trained, and is trained alongside it.
No value model to train or hold in memory. The price is generating N answers per prompt instead of one.
PPO needs a baseline to turn raw scores into advantages, and it learns one: a value model (the “critic”) that predicts, token by token, the score the answer is heading for. The DeepSeekMath authors point out that this value model is typically about as large as the model being trained, a heavy memory and compute burden, and that predicting a value at every token is hard when the reward only arrives at the end. GRPO removes it. It samples a group of answers to each prompt and uses the group's own average score as the baseline.
The algorithm
- Sample prompts. Take a batch of prompts from your data.
- Generate a group. For each prompt, the current model writes N answers, sampling with randomness so they differ. Groups of 4–16 are common; DeepSeekMath used 64.
- Score. The grader gives every answer a reward, here 0–1.
- Normalise within the group. Each answer's advantage is its score minus the group mean, divided by the group's standard deviation. Every token of the answer gets that same advantage.
- Update with a clipped objective. Make positive-advantage answers more likely and negative ones less likely, but never by more than a set ratio in one step (see below).
- Optionally, penalise drift. Subtract β × the KL divergence from a frozen copy of the starting model.
advantage_i = (score_i − mean(group)) / std(group)
answer 1 2 3 4
score 0.8 0.3 0.6 0.3
− mean +0.3 −0.2 +0.1 −0.2 mean = 0.5
÷ std +1.41 −0.94 +0.47 −0.94 std ≈ 0.21- The grader scores four answers to one prompt: 0.8, 0.3, 0.6 and 0.3.
- Group mean = (0.8 + 0.3 + 0.6 + 0.3) ÷ 4 = 0.5. Differences from the mean: +0.3, −0.2, +0.1, −0.2.
- Spread (standard deviation of the four) = √((0.09 + 0.04 + 0.01 + 0.04) ÷ 4) = √0.045 ≈ 0.21.
- Advantages = differences ÷ 0.21 ≈ +1.41, −0.94, +0.47, −0.94. Answer 1 is pushed up most, answer 3 a little; answers 2 and 4 are pushed down equally.
- Some libraries divide by n − 1 when computing the spread (≈ 0.24 here, giving +1.22, −0.82, +0.41, −0.82). The signs and the ranking, which are what steer the model, are the same.
- Group A scores 0, 0, 0, 0: every answer failed. Mean 0, spread 0, so every advantage is 0 and this prompt contributes nothing. (Implementations add a tiny constant to the spread so nothing divides by zero.)
- Group B scores 0.61, 0.60, 0.60, 0.59: practically identical. But the spread is tiny (≈ 0.007), so the advantages come out as +1.41, 0, 0, −1.41, as large as in a group with real differences.
- Dividing by the spread gives low-spread prompts outsized weight and lets grader noise become a full-strength signal. It is one reason the Dr. GRPO variant drops the division, and why a grader with coarse, consistent scores beats one with precise-looking noise.
The clipped objective, in plain words
Once the advantages are known, the model is updated, often for a few mini-batches on the same answers. Each time, the trainer compares how likely the current model finds an answer with how likely the model that wrote it found it. That ratio is 1.0 when the step starts. PPO's idea, which GRPO keeps, is to stop giving credit once the ratio has moved far enough: with the usual ε = 0.2, an above-average answer earns nothing more for becoming over 1.2× as likely, and a below-average one nothing more for dropping below 0.8×.
The result is a trust region: each step can only move the model a limited distance from the model that generated the data, which keeps one lucky or unlucky batch from causing a lurch. TRL logs how often the limit bites under clip_ratio; values that stay high mean updates keep hitting the edge, often a sign the learning rate is too large.
ratio r = P_new(answer) / P_old(answer) # 1.0 when the step starts
objective min( r × A , clip(r, 1 − ε, 1 + ε) × A ) − β × KL(new ‖ reference)
A = the answer's advantage
ε = 0.2 (how far one step may move an answer's probability)
β = 0 … 0.04 (pull back toward the starting model; 0 = none)The KL penalty
The original GRPO adds one more term: β times the KL divergence between the model being trained and a frozen copy of where it started, the reference. KL divergence measures how different two probability distributions are; here it grows as the model's word choices drift from the reference's. With β above 0, drifting costs reward, so the model improves at the task while staying close to its original language and style. DeepSeekMath used β = 0.04 and added the penalty directly to the loss rather than subtracting it from the reward.
Later work found the penalty often unnecessary on tasks with checkable answers, and TRL now defaults to β = 0, which also saves memory because no reference copy has to be loaded. A penalty is still worth having when a judge model is the grader and answers start to degrade (odd phrasing, broken formatting, a switch of language): drift a judge may not punish. RFT settings explains how to set it.
Known quirks
- Length bias. In the original formula each answer's loss is averaged over its own length, so a long wrong answer is penalised less per token than a short wrong one. The Dr. GRPO paper showed this inflates response length, especially for incorrect answers. TRL's default loss type,
dapo, averages over all tokens in the batch instead. - Zero-signal groups. Easy prompts (all answers right) and hopeless ones (all wrong) produce no update. TRL logs their share as
frac_reward_zero_std; the DAPO recipe filters such groups out and samples more. - Generation dominates the cost. Writing N answers token by token takes most of each step's time, which makes the group size and the answer length the main levers on speed and price.
Common mistakes
- Reading a single score in isolation. In GRPO an answer's score only matters relative to the other answers to the same prompt.
- Using groups of two to save time. With two answers, any difference at all, even grader noise, becomes a full +1 / −1 signal.
- Feeding prompts that are far too easy or far too hard. Both give identical scores within a group and no signal.
- Assuming the KL penalty is on. In many current libraries the default is β = 0.
- Trusting a precise-looking grader. Small, noisy score differences are scaled up to full-size advantages.
References and further reading
External sources open in a new tab.
- 01DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language ModelsShao et al., 2024 · arXiv · arxiv.orgIntroduces GRPO; its RL step lifted GSM8K from 82.9% to 88.2% and MATH from 46.8% to 51.7%.
- 02Proximal Policy Optimization AlgorithmsSchulman et al., 2017 · arXiv · arxiv.orgThe clipped objective and trust-region idea GRPO inherits.
- 03Understanding R1-Zero-Like Training: A Critical PerspectiveLiu et al., 2025 · arXiv · arxiv.orgFinds GRPO's length bias and proposes Dr. GRPO, an unbiased variant.
- 04DAPO: An Open-Source LLM Reinforcement Learning System at ScaleYu et al., 2025 · arXiv · arxiv.orgPractical fixes to GRPO: token-level loss, asymmetric clipping, filtering zero-signal groups.
- 05GRPO TrainerHugging Face TRL docs · huggingface.coLoss variants, defaults and the metrics a GRPO run logs.