GRPO and Verifiable Rewards
GRPO drops PPO's value model and uses a group of answers as its baseline. The advantage, the clipped update and the KL term behind DeepSeek-R1.
Jump to a section
A critic the size of the policy
PPO estimates each action's advantage with a learned value model, and for a language model that value model is typically another network about the size of the policy. The DeepSeekMath paper names that memory and compute burden as its reason for Group Relative Policy Optimization (GRPO): drop the value model, and estimate the baseline from several samples for the same prompt.
The trade worked. GRPO took DeepSeekMath 7B to 51.7% on the competition-level MATH benchmark without tools or voting. DeepSeek-R1-Zero then applied it directly to a base model, with no supervised reasoning data, and its pass@1 on AIME 2024 rose from 15.6% to 71.0% over training.
Both runs paired GRPO with rewards from a program rather than a learned preference model: check the final answer, or run the tests. That combination is usually called reinforcement learning with verifiable rewards (RLVR). GRPO is the optimizer and the verifier is the reward, and either can be swapped without the other.
The group is the baseline
Ask the policy the same question six times. Three answers pass the verifier and three fail, so the rewards are . A reward of 1 is only informative relative to what the policy usually gets on this prompt, and the group supplies that reference: its mean is 0.5.
For prompt , sample outputs from the current policy and score them. With one outcome reward per response, every token in output shares the advantage
In the example the standard deviation is 0.5, so each passing answer gets and each failing one . Responses above the group mean become more likely; those below become less likely.
With 0/1 rewards the advantages have a closed form. If a fraction of the group passes, a passing response gets and a failing one . When one answer in six passes, it gets and each failure : a rare success is pushed hard. When all six pass, or all six fail, every reward equals the mean and every advantage is zero.
Rewards become advantages within one group
Edit the six rewards. Responses above the group mean gain probability; those below lose it. Set every reward equal and the update disappears.
The visual loads as you reach this section.
The objective, term by term
With the per-token ratio against the policy that generated the samples, GRPO maximizes
The clipped term is PPO's. It removes the incentive to move a token's ratio outside in the direction its advantage favors. If the policy takes a single update per batch of samples, as DeepSeekMath did, the ratio is exactly 1 at that update and the clip never binds. It matters when the same samples are reused for several updates.
The KL term is where GRPO departs from many PPO setups for language models. Instead of folding a KL penalty into the reward, DeepSeekMath adds it to the loss and estimates it per token with
which is never negative, because for every . DeepSeekMath sampled 64 outputs per question and set .
Which prompts teach anything
A group only produces a gradient when its rewards disagree. If the policy solves a prompt with probability , the chance that all samples get the same 0/1 reward is .
At and that is 43%: almost half the rollouts spent on an easy prompt teach nothing. At it falls below 1%. Doubling the group to 16 cuts the easy-prompt waste to 19%, at twice the sampling cost. Prompts the policy always solves, or never solves, are wasted compute for GRPO, which is why training sets for it are filtered by difficulty for the current policy.
1from statistics import fmean, pstdev
2
3
4def group_advantages(rewards, eps=1e-6):
5 mean, std = fmean(rewards), pstdev(rewards)
6 return [(r - mean) / (std + eps) for r in rewards]
7
8
9def p_no_signal(p, group_size):
10 # chance that every 0/1 reward in the group is identical
11 return p**group_size + (1 - p) ** group_size
12
13
14assert all(abs(abs(a) - 1) < 1e-5 for a in group_advantages([1, 0, 1, 0, 0, 1]))
15rare = group_advantages([1, 0, 0, 0, 0, 0])
16assert abs(rare[0] - 5**0.5) < 1e-4 and abs(rare[1] + 5**-0.5) < 1e-4
17assert group_advantages([1] * 6) == [0.0] * 6 # all pass: no signal
18assert round(p_no_signal(0.9, 8), 2) == 0.43
19assert round(p_no_signal(0.9, 16), 2) == 0.19
20assert p_no_signal(0.5, 8) < 0.01In code
Group-relative advantages and the clipped token-level loss in PyTorch. Shapes: logp_new, logp_old, logp_ref and mask are [G, T]; rewards is [G].
1import torch
2
3def grpo_loss(logp_new, logp_old, logp_ref, rewards, mask, eps=0.2, beta=0.04):
4 std = rewards.std(unbiased=False)
5 adv = (rewards - rewards.mean()) / (std + 1e-6) # [G]; zeros if all rewards equal
6 ratio = torch.exp(logp_new - logp_old) # [G, T]
7 surrogate = torch.minimum(ratio * adv[:, None],
8 ratio.clamp(1 - eps, 1 + eps) * adv[:, None])
9 log_r = logp_ref - logp_new
10 kl = torch.exp(log_r) - log_r - 1 # per-token, >= 0
11 per_token = surrogate - beta * kl
12 per_seq = (per_token * mask).sum(1) / mask.sum(1).clamp(min=1)
13 return -per_seq.mean() # minimize the negative
14
15G, T = 6, 5
16logp = torch.randn(G, T)
17loss = grpo_loss(logp, logp.detach(), logp.detach(),
18 rewards=torch.tensor([1., 0., 1., 0., 0., 1.]),
19 mask=torch.ones(G, T))In a real loop, logp_old comes from the policy that generated the samples, logp_ref from a frozen reference model, and gradients flow only through logp_new.
Where it goes wrong
The verifier has holes. GRPO optimizes whatever the reward measures. A lenient answer parser, a format reward that pays for tags around empty reasoning, or unit tests that miss edge cases can all be satisfied without solving the task, and the policy will find them.
Length grows for the wrong reason. Dividing each response's loss by spreads a negative advantage over more tokens when the response is longer, so a long wrong answer is penalized less per token than a short one. Liu et al. (Dr. GRPO) identify this as a bias that inflates length, especially in incorrect responses, and argue that dividing by the reward standard deviation over-weights prompts whose groups nearly all agree. Treat both normalizations as design choices to test.
Exploration collapses. Rising reward with collapsing entropy can mean the policy has stopped trying alternatives, and future groups will disagree less often. Rising response length is not evidence of better reasoning by itself.
The data stops matching the policy. As the policy improves, prompts it once found hard become easy and their groups stop producing signal. Track the fraction of groups with zero advantage alongside reward, length and entropy; when it climbs, the prompt set needs refreshing.
Sources and further reading
- Shao et al., DeepSeekMath: introduces GRPO, its group baseline, and the KL estimator.
- DeepSeek-AI, DeepSeek-R1: GRPO with rule-based accuracy and format rewards at scale.
- Lambert et al., Tülu 3: names and evaluates reinforcement learning with verifiable rewards.
- Liu et al., Understanding R1-Zero-Like Training: analyses length and standard-deviation normalization in GRPO (Dr. GRPO).