Suppose a model makes several attempts at a maths problem, and a checker can tell which answers are correct. Those attempts give you something to learn from, even if you have no separate model estimating how good each answer ought to be. GRPO compares each attempt with the others in its group to build that learning signal. It is the idea used in DeepSeekMath and DeepSeek-R1, and we can study it with much smaller examples.
Using the group as a baseline saves the cost of a critic sized to match a 7-billion-parameter policy. We build the update and test its learning signal on checkable answers. Arithmetic accuracy reaches 37% from random initialisation and 86% after a warm start, showing how the starting policy matters.
This post builds GRPO from scratch in Python, in three settings that all finish in CPU-seconds on a laptop. You will check the group-relative advantage against a closed-form answer on a bandit, race GRPO against PPO and REINFORCE on a maze, and then train a tiny model to do arithmetic using nothing but a right/wrong checker. By the end you will know exactly what GRPO removes, what it keeps, and the failure mode that decides whether it works at all.
Let's Build It
Open this in Google Colab and run it top to bottom.
Here is GRPO on a five-armed bandit. The left panel is the policy; the right panel is the group it drew on that step, coloured by whether each sample beat its siblings. Watch the group spread across all five actions, then collapse onto the best one.

The entire algorithm is the group_relative_advantage function. Everything else is a standard policy gradient.
import numpy as np
def group_relative_advantage(rewards, eps=1e-4):
"""GRPO in one line: standardise the rewards inside each group."""
mean = rewards.mean(axis=-1, keepdims=True)
std = rewards.std(axis=-1, keepdims=True)
return (rewards - mean) / (std + eps)
def softmax(z):
e = np.exp(z - z.max())
return e / e.sum()
rng = np.random.default_rng(5)
true_reward = np.array([0.31, 1.10, 0.42, 0.18, 0.72]) # unknown to the agent
logits, G, lr = np.zeros(5), 8, 1.6
for step in range(14):
probs = softmax(logits)
actions = rng.choice(5, size=G, p=probs) # one group of G samples
rewards = true_reward[actions] + rng.normal(0, 0.3, G)
advantage = group_relative_advantage(rewards.reshape(1, -1)).ravel()
grad = np.zeros(5) # score-function gradient
for a, adv in zip(actions, advantage):
onehot = np.zeros(5); onehot[a] = 1.0
grad += adv * (onehot - probs)
logits += lr * grad / G
print(np.round(softmax(logits), 3)) # [0.005 0.972 0.008 0.005 0.01 ]
No critic, no value network, no baseline to tune. After 14 updates the policy puts 97% of its mass on action 2, which is the best arm. The group is the baseline.
What Just Happened?
GRPO answers one question: how good was this answer? Every policy gradient method needs that number, because the update rule is "make good actions more likely, in proportion to how good they were". The disagreement between methods is entirely about how to compute it.
REINFORCE uses the raw return. If an episode scored 12, every action in it gets pushed up by 12. That works, but it is noisy: an action gets credit for reward it had nothing to do with, and a task where every return happens to be positive pushes every action up, including the bad ones.
PPO fixes this with a critic. The critic learns , the expected return from state , and the advantage becomes : how much better the episode went than the critic expected. Actions that beat expectations get pushed up, actions that fall short get pushed down, regardless of the absolute scale of the reward. The cost is a whole second network that has to be trained alongside the policy, and that can be wrong in ways that quietly corrupt the policy update.
GRPO gets the same "compared to what?" signal for free by changing what you sample. Instead of one answer per prompt, draw of them. Now you have a set of scores for the same question, and the mean of that set is an unbiased estimate of exactly what the critic was trying to predict.

The maths is three operations on the group's rewards:
Subtracting the mean is the baseline: it centres the scores so beating your siblings is positive and losing to them is negative. Dividing by the standard deviation is a normaliser: it puts every prompt's advantages on the same scale, so an easy question where all answers score around 0.9 and a hard one where they all score around 0.1 contribute gradients of comparable size.
That the group mean substitutes for a critic is a claim you can check. On a contextual bandit the true advantage is available in closed form, so we can compare GRPO's estimate against it directly. Averaging the measured advantage over 40,000 groups and plotting it against the analytic value gives a straight line.

Slope 1.04, = 0.999. Two details are worth naming. Because of that denominator the estimate recovers the true advantage divided by , the spread of rewards the policy sees, so GRPO learns the ranking inside a prompt and discards the absolute reward scale. It also carries a factor of , because sample sits inside the mean it is being compared against. With that shrinks the advantage by 12.5%, which the learning rate absorbs.
Going Deeper
The PPO inheritance
GRPO is not a new family of algorithm. Strip out the advantage calculation and what remains is PPO, unchanged. The full objective from the DeepSeekMath paper:
Reading it term by term:
- is the importance ratio, how much more likely the current policy is to emit this token than the policy that sampled it
- The and are PPO's clipped surrogate, which stops any single update moving the policy too far and is the reason you can safely take several gradient steps on one batch of samples
- penalises drift from a frozen reference policy, which in LLM post-training is the model before RL started
- has no subscript . Every token in a completion receives the same advantage, because the reward is awarded to the whole sequence
That last point is the structural consequence of dropping the critic. A critic gives you a per-timestep value estimate and therefore per-timestep credit assignment. GRPO gives you one number per completion, broadcast across every token in it. Some tokens in a correct answer were irrelevant and still get rewarded; the algorithm relies on averaging over many groups to sort that out.
The KL term uses an unbiased low-variance estimator rather than the naive difference of log-probabilities:
log_diff = ref_logp - logp
kl = torch.exp(log_diff) - log_diff - 1.0 # always positive, low variance
GRPO against PPO and REINFORCE
Talk is cheap, so here are all three on the same task: a 6x6 maze with 24 possible start cells, an average of 7.2 steps to the goal, a reward of +1 for reaching it and a cost of 0.02 a step. Each method gets the same budget, the same network shape, and three random seeds.

| Method | Final return | % of optimal | Parameters | Iterations to 90% |
|---|---|---|---|---|
| GRPO | 0.856 | 100% | 2,628 | 30 |
| PPO | 0.857 | 100% | 5,061 | 34 |
| REINFORCE | 0.839 | 98% | 2,628 | 149 |
Read this honestly: all three solve the maze. This is a small problem, and given enough iterations even plain REINFORCE gets there. The differences are in the two things that cost you at scale. GRPO reaches 90% of optimal in 30 iterations against PPO's 34, a tie within seed noise, while carrying 48% fewer parameters, because the 2,433-parameter critic is not there at all. Both are also roughly five times more sample-efficient than REINFORCE, which is the value of having any baseline whatsoever.
Scale that parameter column to a 7-billion-parameter policy and the critic you did not build is 7 billion parameters of optimiser state, gradients and activations you do not have to fit on the GPU.
The group size as the variance knob
The critic's real job was variance reduction, so if GRPO removes it, something has to take over. That something is . Measuring the variance of the gradient estimate at a fixed mid-training policy, across 200 replicates per group size:

The fitted log-log slope is -0.94, near the -1.0 of exact scaling, and the variance drops 23-fold from to . So the knob works, and it is a knob with an obvious price: means 64 generations per prompt. In LLM post-training, generation dominates the compute bill, which is why production recipes stop at a of 8 to 64.
This is the honest trade against PPO. PPO buys variance reduction with parameters and a second training problem. GRPO buys it with sampling. Which is cheaper depends on whether your bottleneck is memory or throughput.
The failure mode that decides everything
Now the part that matters more than any hyperparameter. Look again at the advantage formula and ask what happens when every sample in a group scores the same.
The numerator is zero, the denominator is zero, and without the you get a NaN that destroys the run. With it, the advantage is exactly zero. The does not rescue the group, it just converts a crash into silence: that group contributes nothing to the gradient.
With a binary verifiable reward this is not an edge case, it is the normal case. A group is wasted whenever all answers are wrong, and wasted again whenever all are right. Only mixed groups teach the model anything.
To see how much this bites, here is the same tiny model trained two ways on two-digit addition, where the reward is 1 for an exactly correct answer and 0 otherwise. One run starts from random initialisation. The other gets a short supervised warm start on 40 of the 100 sums first, then runs identical GRPO.

From random init the model has roughly a 1-in-100 chance of getting an answer right, so almost every group is unanimously wrong and almost every group is discarded. It crawls to 37% and is still crawling when the budget runs out. The warm-started run spends the same number of GRPO iterations and reaches 86%.
Both runs end with over 90% of their groups degenerate, and that is the reason the curves flatten. As a policy sharpens, it starts answering each prompt the same way every time, so its groups become unanimous and the learning signal dries up. GRPO's gradient comes entirely from disagreement within a group, which means the algorithm quietly starves itself as it succeeds.
This is why frontier recipes run RL after pretraining and usually after a supervised cold start, exactly as DeepSeek-R1 does. A policy that never succeeds has nothing to be relatively better than.
Learning from a checker with no labels
The payoff of the warm-start run is worth isolating, because it is the whole argument for reinforcement learning with verifiable rewards. Supervised fine-tuning saw labelled answers for 40 of the 100 sums. GRPO then trained on all 100, but it never saw a label: it only ever received a 1 or a 0 from a checker.

On the 60 sums that supervised training never touched, accuracy goes from 60% to 75%. The model was not told a single correct answer during the RL stage. It generated candidates, a verifier marked them, and the group-relative advantage turned those marks into a gradient. That is DeepSeek-R1's recipe in miniature, and it is why the method took hold for maths and code, where a checker is easy to write, rather than for open-ended writing, where it is not.
Poor fits for GRPO
- Dense per-step rewards. If your environment scores every timestep, a critic can exploit that structure for genuine per-step credit assignment. GRPO throws it away by design, giving every step in a trajectory the same scalar.
- Expensive generation. GRPO's cost is rollouts per prompt. If a single rollout is slow (a physics simulator, a real robot, a paid API call), paying for 8 to 64 of them per prompt is worse than training a critic once.
- Single-attempt settings. Without repeated samples from the same prompt you have no group, and so no baseline.
- Unreliable rewards. GRPO amplifies whatever your verifier measures. A checker with a loophole gets you a policy that exploits the loophole, which is the pathology covered in reward hacking.
Where This Comes From
Shao et al. introduced GRPO in "DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models" (2024, arXiv:2402.03300). Their target was concrete rather than theoretical: PPO's critic made RL on a 7B maths model too expensive, so they looked for an advantage estimate that did not need one.
Their framing of the change:
"GRPO foregoes the critic model, instead estimating the baseline from group scores, significantly reducing training resources."
Side by side, that sentence is the whole difference. PPO runs the policy once and asks a second network how good the result should have been; GRPO runs the policy times and lets the samples answer that question themselves.

The paper's formulation samples a group of outputs from the old policy for each question , then optimises the objective given in the Going Deeper section above. The intellectual lineage is direct: TRPO established the trust-region idea, PPO (Schulman et al., 2017, arXiv:1707.06347) turned it into a cheap clipped ratio, and GRPO keeps that clipped ratio while swapping the advantage estimator underneath it.
The idea of comparing samples against each other rather than against a learned value is older than GRPO, and the paper is explicit that the group-score baseline "aligns with the comparative nature of reward models", which are themselves trained on pairs of outputs for the same prompt.
DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning (DeepSeek-AI, 2025, arXiv:2501.12948) is where the method proved itself. R1-Zero applied GRPO to a base model with rule-based rewards for correctness and format, no supervised stage at all, and reasoning behaviour emerged from the RL alone. The released R1 then added a small supervised cold start before RL, for the reason the degenerate-group experiment above demonstrates in miniature: pure RL from a weak starting policy is slow and unstable, because most groups carry no signal.
Ahmadian et al.'s "Back to Basics: Revisiting REINFORCE-Style Optimization for Learning from Human Feedback" (2024, arXiv:2402.14740) is the useful sceptical counterpoint. They argue much of PPO's machinery is unnecessary in the RLHF setting and that simpler REINFORCE-style estimators with a good baseline are competitive. GRPO sits neatly inside that argument: it is closer to a well-baselined REINFORCE than to full PPO, and its success is evidence that the critic was the expensive part rather than the essential one.
Further reading
- The original paper: Shao et al. (2024), sections 4.1 and 4.1.2 for the objective and the comparison against PPO
- The scaled-up result: DeepSeek-AI (2025), section 2.2 for the R1-Zero reward design and the cold-start rationale
- The counterpoint: Ahmadian et al. (2024), for the case that simpler is enough
- Next algorithm to learn: On-policy distillation, which keeps the on-policy sampling loop but replaces the reward with a teacher's distribution
Interactive Tools
- Q-Learning Visualiser: Step through value updates on a grid to see the credit-assignment problem GRPO sidesteps with outcome rewards
- LLM Cost Calculator: Price up the generation budget a group size of 8 to 64 implies when the policy is a large language model
Related Posts
- REINFORCE from Scratch in Python: Policy Gradients: The baseline-free estimator GRPO improves on, and the variance problem it leaves behind
- Trust Region Methods: From REINFORCE to TRPO to PPO: Where the clipped surrogate objective GRPO inherits comes from
- A3C: Asynchronous Advantage Actor-Critic in PyTorch: The critic-based approach to variance reduction that GRPO replaces with sampling
- Reward Hacking in Reinforcement Learning: What happens when the verifier driving your group scores has a loophole
- On-Policy Distillation: When Self-Generated Data Wins: Another post-training method built on sampling from the policy you are training





