Search

Search papers and lessons

Group Relative Policy Optimization (GRPO)

Level 4 · 15 min read

GRPO trains a language model with reinforcement learning by sampling a group of answers per question and scoring each answer against the group average, which removes the need for a separate value model.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Reinforcement learning
  • Linear algebra
  • Discrete math
  • Information theory
  • Sign in to see your progress

TL;DR

Group Relative Policy Optimization (GRPO) fine-tunes a language model with reinforcement learning. For each question it samples a group of answers, scores each one with a reward, and uses the group's own average as the baseline. An answer is reinforced if it beat the group and discouraged if it did not. This drops the value model that PPO needs, which is usually a second network as large as the policy.

Where you'll see it: training the reasoning behaviour of open math and code models, where answers can be checked automatically and a critic network would double the memory bill.

Intuition

Grade on a curve

Imagine a class sitting an exam, where you can only say whether each answer was good or bad, not how good. A common way to grade on a curve is to compare each student to the class average. Someone above average gets credit, someone below gets a mark against them, and the absolute score does not matter so much as the ranking inside the group.

GRPO does exactly that for a language model. Pick one question, let the current model write GG answers to it, score every answer, and compare each score to the mean of its own group. The reward model or checker does not need to be calibrated across questions. It only needs to rank answers that answer the same question.

Why not a critic

Policy gradient methods need a baseline to reduce variance. The baseline is an estimate of how well the model usually does from a given state, and Actor-Critic Methods methods learn it with a Value Function network. PPO does this, and for language models the critic is typically another model about the size of the policy. A critic also has to produce a value at every token, but the reward model usually scores only the finished answer, so the critic has very little signal to learn from at most positions.

GRPO replaces the learned baseline with a statistic of the group. The mean of several sampled rewards is a fair baseline for the question, and it costs nothing to train. The authors of DeepSeekMath describe it as obviating the value model and using the average reward of multiple sampled outputs as the baseline.

flowchart LR
    subgraph PPO
        P1[Sample one answer] --> P2[Reward model scores it]
        P2 --> P3[Value network estimates baseline]
        P3 --> P4[Advantage per token]
    end
    subgraph GRPO
        G1[Sample G answers] --> G2[Reward each answer]
        G2 --> G3[Subtract group mean, divide by group std]
        G3 --> G4[Advantage per answer, shared by its tokens]
    end

The math

Definition: Group relative advantage

For a question qq, sample GG answers o1,…,oGo_1, \dots, o_G from the old policy πθold\pi_{\theta_{old}} and give each a scalar reward rir_i. The group-relative advantage of answer ii is

A^i=ri−mean⁡(r1,…,rG)std⁡(r1,…,rG)\hat{A}_i = \frac{r_i - \operatorname{mean}(r_1, \dots, r_G)}{\operatorname{std}(r_1, \dots, r_G)}

Every token of answer oio_i receives this same advantage, A^i,t=A^i\hat{A}_{i,t} = \hat{A}_i, in the outcome-supervised setting.

Here mean⁡\operatorname{mean} and std⁡\operatorname{std} are taken over the group only. Dividing by the standard deviation puts advantages on a comparable scale across questions where the rewards spread differently.

The objective

GRPO maximises the following objective, which is PPO's clipped surrogate applied per answer and averaged over the group, with a KL penalty against a reference model:

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

Here ρi,t=πθ(oi,t∣q,oi,<t) / πθold(oi,t∣q,oi,<t)\rho_{i,t} = \pi_\theta(o_{i,t} \mid q, o_{i,\lt t}) \,/\, \pi_{\theta_{old}}(o_{i,t} \mid q, o_{i,\lt t}) is the probability ratio for token tt of answer ii, ε\varepsilon is the clipping range, and β\beta is the KL coefficient. The inner average over ∣oi∣|o_i| divides each answer's contribution by its length, so long answers do not dominate the update.

Three pieces are worth separating:

  1. The ratio ρi,t\rho_{i,t} is the importance weight that lets the update reuse samples from the old policy (see Importance Sampling). The clip stops any single token from moving the policy too far in one step, exactly as in PPO.
  2. The advantage A^i,t\hat{A}_{i,t} comes from the group, not from a critic.
  3. The KL term is added to the loss directly rather than folded into the reward. The paper argues this keeps the advantage calculation simple.

The KL estimator

The KL divergence from the policy to the reference is estimated per token with a non-negative estimator. Writing r=πref(oi,t∣q,oi,<t)/πθ(oi,t∣q,oi,<t)r = \pi_{ref}(o_{i,t} \mid q, o_{i,\lt t}) / \pi_\theta(o_{i,t} \mid q, o_{i,\lt t}), the estimator is

DKL[πθ ∥ πref]≈r−log⁡r−1\mathbb{D}_{KL}\left[\pi_\theta \,\|\, \pi_{ref}\right] \approx r - \log r - 1

This is the form in Kullback–Leibler Divergence that is guaranteed positive, and it is zero exactly when r=1r = 1, that is, when the two models agree on that token. It is an unbiased estimator of the KL when the tokens are sampled from πθ\pi_\theta, which is why it is preferred to the simpler penalty that appears in the PPO reward.

Process supervision

The same machinery accepts step-level rewards. Each reasoning step gets a score, the scores are normalised across all steps of all answers in the group, and each token's advantage is the sum of normalised scores from the steps that follow it. Credit flows back from later steps to earlier tokens, which gives denser supervision than a single end-of-answer reward.

Worked examples

Example
Four answers, binary correctness

A question has group size G=4G = 4. The checker gives reward 1 for a correct final answer and 0 otherwise. Suppose the sampled answers are correct, wrong, wrong, correct.

  1. Rewards: r=(1,0,0,1)r = (1, 0, 0, 1).
  2. Mean: (1+0+0+1)/4=0.5(1 + 0 + 0 + 1)/4 = 0.5.
  3. Standard deviation (population form): 14[(0.5)2+(−0.5)2+(−0.5)2+(0.5)2]=0.25=0.5\sqrt{\tfrac{1}{4}\left[(0.5)^2 + (-0.5)^2 + (-0.5)^2 + (0.5)^2\right]} = \sqrt{0.25} = 0.5.
  4. Advantages: (1−0.5)/0.5=+1(1 - 0.5)/0.5 = +1, (0−0.5)/0.5=−1(0 - 0.5)/0.5 = -1, −1-1, +1+1.

Interpretation: the two correct answers each receive +1 on every token and are reinforced. The two wrong answers receive −1 and are pushed down. The baseline needed no critic, only the four rewards. A sample standard deviation would give 1/3≈0.577\sqrt{1/3} \approx 0.577 and slightly smaller advantages, so implementations differ on this convention.

Example
A group where every answer is correct

Same setup, but now all four answers are correct, so r=(1,1,1,1)r = (1, 1, 1, 1).

  1. Mean: 11.
  2. Standard deviation: 00.
  3. The advantage (1−1)/0(1 - 1)/0 is undefined as written.

Interpretation: when a question is too easy, or too hard, every answer in the group gets the same reward and the group carries no comparative signal. Implementations add a small constant to the denominator, which makes every advantage zero, so the question contributes nothing to the update. This is a real cost of the method: a large share of questions can sit at 0 or 1 pass rate and waste compute. Filtering or re-weighting such questions is a common response.

Example
Reading the KL penalty

Take one token where the reference model gives probability 0.4 and the current policy gives 0.5, so r=0.4/0.5=0.8r = 0.4 / 0.5 = 0.8.

  1. Estimator: r−log⁡r−1=0.8−log⁡(0.8)−1r - \log r - 1 = 0.8 - \log(0.8) - 1.
  2. log⁡(0.8)≈−0.2231\log(0.8) \approx -0.2231, so −log⁡(0.8)≈0.2231-\log(0.8) \approx 0.2231.
  3. Sum: 0.8+0.2231−1=0.02310.8 + 0.2231 - 1 = 0.0231.
  4. Repeat with the policy moved the other way: policy probability 0.32 gives r=1.25r = 1.25 and estimator 1.25−0.2231−1=0.02691.25 - 0.2231 - 1 = 0.0269.

Interpretation: both drifts from the reference produce a small positive penalty, and the penalty grows as the ratio moves away from 1. A policy that has drifted far on many tokens pays a large total KL cost, which holds it near the model it started from. The coefficient β\beta sets how much that matters against the reward.

Example
A realistic training configuration

In the DeepSeekMath experiments, GRPO started from a supervised instruction-tuned 7B model. The RL data was about 144K chain-of-thought questions drawn from GSM8K and MATH training sets. For each question the model sampled 64 answers. The policy learning rate was 10−610^{-6}, the KL coefficient was 0.04, the training batch size was 1024, the maximum length was 1024 tokens, and each batch of samples received a single gradient update before new samples were drawn. Each question therefore contributed a group of 64 advantages computed in the same way as the four-answer example above, only with a larger group.

Tradeoffs and failure modes

SituationProblemBetter choice
Reward is a learned model trained on comparisonsGroup-relative ranking matches how such models are trained, which is a strengthGRPO fits well
Reward is sparse and binary, and most questions are too easy or too hardGroups with identical rewards produce zero advantage, wasting computeFilter or re-weight questions, or use a larger group
Long reasoning chains where credit is hard to assignEnd-of-answer reward gives one scalar per answerProcess supervision, or a value model that gives per-token estimates
Small group size, such as 2 or 4The mean and standard deviation are noisy, so advantages are noisyLarger groups, at the cost of more sampling
Memory is tight and a critic would not fitGRPO needs no critic, only the policy and reference modelsGRPO
Rewards come from a changing reward modelThe group baseline shifts with the reward scaleNormalise rewards per batch, or retrain the reward model iteratively

The failure modes follow from the design. Because the baseline is an average over only GG samples, it is biased toward the samples the old policy happened to produce, so the method can favour answers the current model already finds easy. Length normalisation by ∣oi∣|o_i| changes the effective weight of each token. The reward is also the only supervision: a poorly designed checker or a reward model that can be gamed will be optimised faithfully, and the KL term limits but does not prevent this.

History

Policy gradient methods that reinforce sampled actions in proportion to their returns date to the late 1980s and early 1990s, and Williams's REINFORCE is the standard reference. Proximal Policy Optimization, introduced by Schulman and colleagues in 2017, made the method stable enough for large-scale use by clipping the probability ratio. It became the default for fine-tuning language models with human feedback, as in the InstructGPT line of work, and its value network was a standard part of that recipe.

GRPO appeared in February 2024 in DeepSeekMath, from a team at DeepSeek. The paper's goal was a 7B open model that was strong at competition mathematics, and RL was one stage of that effort. The authors motivated GRPO by the cost of the value model in PPO and by the match between group comparisons and how reward models are trained on pairwise preferences. The method was used again in 2025 in DeepSeek-R1, where RL with rule-based rewards on verifiable tasks was a central part of training the reasoning behaviour.

Check yourself

QuestionRecall: what does GRPO use as the baseline for the advantage, in place of PPO's learned value function?Show answer

It uses the mean reward of the group of GG answers sampled for the same question, normalised by the group standard deviation. No separate network is trained to predict value. The baseline is recomputed from scratch for each question at each step.

QuestionCompute: a group of G=4G = 4 answers has rewards (0,0,1,0)(0, 0, 1, 0). What are the advantages of the four answers? Use the population standard deviation.Show answer

Mean is 0.250.25. Deviations are −0.25-0.25, −0.25-0.25, 0.750.75, −0.25-0.25. Population variance is (0.0625+0.0625+0.5625+0.0625)/4=0.1875(0.0625 + 0.0625 + 0.5625 + 0.0625)/4 = 0.1875, so the standard deviation is 0.1875≈0.433\sqrt{0.1875} \approx 0.433. Advantages are −0.25/0.433≈−0.577-0.25/0.433 \approx -0.577, −0.577-0.577, 0.75/0.433≈1.7320.75/0.433 \approx 1.732, and −0.577-0.577. The single correct answer receives a large positive advantage, and the three wrong ones share a small negative one. This is the normalisation doing its job: a rare success is weighted strongly.

QuestionWhy does GRPO compute the KL penalty directly in the loss rather than subtracting it from the reward, as PPO does?Show answer

Subtracting a per-token KL term from the reward would change the reward at every token, and the advantage would then be computed from the modified rewards. Because GRPO's advantage is a single group-relative number per answer, adding per-token KL to the reward would complicate the calculation of that advantage. Placing the KL term in the loss keeps the advantage defined only by the task reward, while still penalising drift from the reference model.

QuestionWhy does a question where every answer is correct contribute nothing to the update, and what would you do about it in a training run?Show answer

When all rewards are equal, the mean equals each reward and every deviation is zero, so the advantage is zero or undefined. The gradient from that group is therefore zero. In a training run, a large fraction of such questions wastes samples. Common responses are to drop questions whose pass rate is 0 or 1 for several rounds, to resample them with a harder variant, or to increase the group size so that occasional failures appear among the answers.

QuestionApplied: you are training a code model with unit tests as the reward, which is binary and cheap to compute. Your group size is 8 and most generated programs either pass all tests or fail. What do you monitor, and what would make you switch to a critic-based method?Show answer

Monitor the fraction of groups with mixed rewards, since only those carry signal, and the KL divergence and reward trajectory together. If mixed groups become rare, the run has stalled, and you would lengthen the training problems or raise the group size. You would consider a critic-based method, such as PPO with a value network, if the answers were long enough that the single end-of-answer reward gave too little credit assignment, or if per-token value estimates were needed for a dense signal that group comparisons cannot provide.

Sources