Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

~8 min readDeepSeek · 2024

GRPO,
explained.

Teaching a model with reinforcement learning used to require a second model — a "critic" as big as the student — just to judge how good each answer was expected to be. DeepSeekMath asked a disarmingly simple question: what if the answers judged each other? Sample a group, grade them, and reward whoever beat the group average. That one move halved the cost of RL, and a year later it was the engine inside DeepSeek-R1.

The delta

What changes against PPO and DPO: keep the RL, drop the critic

Rung 6 removes reinforcement learning because it is expensive and unstable. This rung keeps it and removes the part that made it expensive. Policy gradients need a baseline — an estimate of how good a state already is — so that an action can be credited for being better than expected rather than merely for preceding a positive outcome. PPO supplies it with a learned value network, which for a language model means a second network of comparable size to hold in memory and train.

The change is to get the baseline from the samples instead of from a model. Sample a group of answers to the same prompt, score them all, and use the group's own mean as the baseline — each answer's advantage is how much better it did than its siblings. This is available because of a property of the tasks involved: all the method needs is a scalar score per sample. DeepSeekMath itself scored samples with a learned reward model; for mathematics and code a score can instead come from checking the answer (the route DeepSeek-R1 later took), which makes generating twenty attempts and grading all of them cheap and harder to game.

Stated in units: one model of policy size leaves memory and one training process disappears, and the compute that was spent maintaining a critic moves into sampling more attempts per prompt. That is a favourable exchange for a specific and important reason — sampling is embarrassingly parallel and needs no state, while training a critic alongside a policy is a coupled optimisation that can fail in ways that are hard to diagnose.

01

Why RL on LLMs was so expensive

Reinforcement learning is how you teach a model from outcomes instead of examples: generate an answer, score it, nudge the weights toward what scored well. The catch is the nudging. A policy gradient needs to know not just "was this good?" but "was this better than expected?" — otherwise every sample looks equally worth reinforcing and training is hopelessly noisy.

"Better than expected" requires a baseline: an estimate of the expected reward. The standard answer — PPO, inherited from InstructGPT and the RLHF lineage — learns that baseline with a value network (the critic). For LLMs, the critic is typically another copy of the model. Training one 7B policy means holding a 7B critic beside it, training both, syncing both. The bill doubles before you generate a single token.

02

PPO in sixty seconds

Four networks sit in memory during classic RLHF-style PPO: the policy being trained, the frozen reference model (to keep outputs from drifting too far), the reward model (what scores answers), and the critic (what predicts expected score, token by token). The critic exists purely to compute the advantage — how much better this output was than the expectation.

PPO's cast of characters — the critic is the expensive one
Policy
being trained
Reference
KL anchor
Reward model
scores answers
Critic
≈ policy-sized

The critic is also the fragile one: it must learn to predict rewards for partial generations — a moving target that shifts every time the policy improves. A mis-trained critic silently poisons the advantages, and with them, the whole run.

03

The GRPO move: let the group be the baseline

Group Relative Policy Optimization deletes the critic with one observation: if you sample several answers to the same prompt, you already have an estimate of the expected reward — the group's average. No learned predictor needed; the cohort grades itself.

One GRPO step
Prompt
→
Sample G answers
e.g. G = 16
→
Score each
reward model (or a checker)
→
Advantage =
(r − group mean) / std
↺
Update policy

Each answer's advantage is simply its reward minus the group mean (normalized by the group's spread). Beat your siblings → reinforced. Trail them → suppressed. A KL penalty against the reference model still keeps the policy from wandering off. The result is PPO's learning signal with roughly half the memory footprint and none of the critic's training instability.

The key idea

The baseline doesn't have to be learned — it can be sampled. Sixteen attempts at the same problem tell you what "expected" looks like better than a second neural network trying to predict it.

The whole advantage computation is one line — no network, just the group's own statistics:

Two properties fall straight out of that formula. Subtracting the mean makes the advantages sum to zero — every step reinforces the above-average answers exactly as much as it suppresses the below-average ones, a built-in baseline. And dividing by the group's spread means an answer is judged only against its own siblings, so problem difficulty cancels: a mediocre answer to a brutal problem can still be reinforced if it beat the pack. The runnable version below shows the same 0.5 reward earning a positive advantage on a hard prompt and a negative one on an easy prompt.

04

Why it works so well for reasoning

GRPO's sweet spot is domains with verifiable rewards: math answers check, code runs or doesn't, proofs verify. The signal is crisp and ungameable, so the group comparison measures something real. This pairing — group-relative advantages plus checkable correctness — is what later let reasoning be incentivized into existence rather than imitated.

The within-group comparison is also exactly the right granularity. An absolute score can't distinguish "hard problem, decent attempt" from "easy problem, sloppy attempt." Comparing attempts at the same prompt cancels problem difficulty out — the model learns which of its own strategies works, prompt by prompt. It's a tournament among siblings, not a grade against an absolute curve.

05

DeepSeekMath: small model, frontier math

The paper's vehicle was DeepSeekMath 7B. Step one had nothing to do with RL: continue pretraining a code model for 500B tokens, 56% of them from a 120B-token corpus of carefully filtered math scraped from the web — a data-curation feat in itself. Step two: instruction-tune. Step three: GRPO.

StageWhat it added
Math continued pretraining (500B tokens, 120B-token math corpus)raw mathematical competence
Instruction tuningusable problem-solving format
GRPO51.7% on MATH — up from 46.8%, no critic needed

A 7B open model approaching the math performance of vastly larger closed models was the headline. The quieter, more consequential result was the recipe: quality data plus cheap, stable RL substitutes for scale.

06

The R1 connection — and everything after

A year later, DeepSeek pointed GRPO at a stronger base model, used rule-based accuracy and format rewards, and skipped supervised reasoning data entirely. The result was DeepSeek-R1-Zero — chain-of-thought reasoning, self-checking, the famous "aha moment," all emerging from GRPO pressure toward correct answers. GRPO wasn't a footnote in that story; it was the engine that made RL cheap and stable enough to run at that scale.

The broader field followed. Group-relative, critic-free RL became the default recipe for reasoning training across open labs, spawning a family of refinements, and "RL with verifiable rewards" became the standard phrase for the whole paradigm — the training-side twin of test-time compute.

07

The limits

GRPO inherits RL's oldest failure mode: reward hacking. If the reward is even slightly gameable — a weak checker, a length bias, a format loophole — group pressure will find and exploit it ruthlessly. It also leans on cheap sampling: every training prompt costs G full generations, trading the critic's memory for extra inference compute.

And it shares outcome-based RL's boundary: where correctness isn't checkable — taste, judgment, open-ended writing — the crisp signal disappears, and you're back to learned reward models with all their softness. GRPO didn't solve alignment for fuzzy domains; it made RL practical where the answer key exists.

How it works

How GRPO trained DeepSeekMath, step by step

GRPO was the last of three stages that produced DeepSeekMath 7B. DeepSeek-Coder-Base-v1.5 7B was first continually pretrained for 500B tokens, 56% of them from the 120B-token DeepSeekMath Corpus filtered out of Common Crawl, then instruction-tuned on 776K math examples in chain-of-thought, program-of-thought and tool-integrated formats. GRPO then ran on about 144K chain-of-thought questions drawn from that instruction data, all related to GSM8K and MATH.

64 answers to one q Learned reward model Group mean and std Advantage per token, one answer 0 outcome: +0.4 on every token process: this step + all later steps step 1: Â = +0.2 step 2: Â = −0.6 step 3: Â = +0.6 normalized step rewards +0.8, −1.2, +0.6
Outcome and process advantages for the same answer, with illustrative normalized rewards. Outcome supervision gives every token the same credit; process supervision credits each step differently.
  1. Train a reward model. The reward came from a learned model, not from checking answers. It was initialized from DeepSeekMath-Base 7B and trained at a learning rate of 2e-5 on data built following Math-Shepherd, a method that labels reasoning steps automatically. The experiments use both outcome rewards for whole solutions and process rewards for individual steps.
  2. Sample a group. For each question q, the current policy samples G = 64 solutions of up to 1,024 tokens.
  3. Score every sample. Under outcome supervision each solution gets one reward from the reward model; under process supervision each reasoning step gets its own.
  4. Normalize inside the group. With outcome supervision, every token of solution i gets the same advantage: its reward minus the group mean, divided by the group standard deviation. With process supervision, all step rewards in the group are normalized together, and a token's advantage is the sum of the normalized rewards of its own step and every later step.
  5. Take a clipped policy-gradient step. Each token's update uses the PPO probability ratio, clipped to [1 − ε, 1 + ε]; per-token terms are averaged over each solution's length and then over the group. The training batch size was 1,024, the policy learning rate 1e-6, and each exploration stage was followed by a single policy update.
  6. Regularize with KL in the loss. PPO-style RLHF subtracts a KL penalty inside the reward. GRPO instead adds β·DKL(πθ ‖ πref) directly to the loss, with β = 0.04, using a per-token estimator that is unbiased and never negative. Keeping the KL out of the reward keeps it out of the advantage calculation too.
  7. Iterate, optionally. In iterative GRPO, the policy's samples become new training data for the reward model, which keeps 10% of its earlier data in a replay buffer, and the reference model is reset to the current policy before the next round.

Where the reward came from

DeepSeekMath's GRPO ran against a learned reward model. Rule-based rewards that check the final answer and the output format belong to DeepSeek-R1, published about a year later, which paired GRPO with such verifiable rewards. The group baseline needs only one scalar per sample, so it works with either kind; what changes is how far the reward can be trusted and how easily it can be gamed.

One formula for several methods

The paper also writes SFT, rejection-sampling fine-tuning, its online variant, DPO, PPO and GRPO as one gradient: a per-token coefficient times ∇log πθ. SFT's coefficient is always 1; rejection sampling's is 1 for a correct answer and 0 otherwise; GRPO's is the group-normalized advantage plus a KL term. The methods differ in where the data comes from (a fixed set or fresh samples from the current policy), which reward they use, and how the coefficient is computed.

The math

The GRPO objective and its KL estimator

JGRPO(θ) = Eq, {oi} ~ πθold (1/G) Σi=1^G (1/|oi|) Σt=1|oi| { min[ ρi,t Âi,t, clip(ρi,t, 1 − ε, 1 + ε) Âi,t ] − β · DKL[πθ ‖ πref] }
ρi,t = πθ(oi,t | q, oi,<t) / πθold(oi,t | q, oi,<t)
DKL[πθ ‖ πref] ≈ πref(oi,t | ·)/πθ(oi,t | ·) − log[ πref(oi,t | ·)/πθ(oi,t | ·) ] − 1
  • G — samples per question, 64 in the paper; 1/|oi| averages over each answer's own length, so every answer carries equal weight whatever its length.
  • Âi,t — the group-normalized advantage: (ri − mean)/std for outcome rewards, or a sum over the current and later steps for process rewards.
  • ρi,t, ε — the per-token probability ratio and PPO's clip range.
  • β = 0.04 — weight of the KL term. The estimator x − log x − 1, with x the reference-to-policy probability ratio, is zero when the two agree and positive otherwise.

At the extremes: if all G answers get the same reward, every advantage is zero and the question teaches nothing; with G = 1 there is no group to compare against. Later analyses, notably the Dr. GRPO paper, argued that the 1/|oi| length average and the division by the group's standard deviation introduce biases toward particular response lengths and question difficulties.

The evidence

What GRPO achieved in DeepSeekMath, and the ablations

The headline results are 7B models with chain-of-thought prompting and no external tools unless noted. GRPO started from DeepSeekMath-Instruct 7B and saw only GSM8K- and MATH-related questions during RL.

ModelGSM8KMATH
DeepSeekMath-Base 7B (few-shot)64.2%36.2%
DeepSeekMath-Instruct 7B82.9%46.8%
DeepSeekMath-RL 7B (GRPO)88.2%51.7%

With tool-integrated reasoning, MATH went from 57.4% to 58.8%, and self-consistency over 64 samples from DeepSeekMath 7B reached 60.9% on MATH. RL also lifted benchmarks it never trained on, such as the Chinese CMATH, from 84.6% to 88.8%.

The ablations are the most reusable part. On the smaller DeepSeekMath-Instruct 1.3B, process supervision beat outcome supervision under GRPO, which the authors attribute to finer, step-aware credit; rejection-sampling fine-tuning on fresh samples from the current policy pulled ahead of the same method on a fixed set as training went on; and GRPO surpassed that online version. On the 7B model, iterating the reward model helped, most of all in the first iteration.

The negative result reframes the gain. RL raised Maj@K, the accuracy of a majority vote over K samples, but not Pass@K, the chance that any of K samples is right. The authors read this as RL making the output distribution more robust, moving answers the model could already produce to the top, rather than adding fundamentally new ability. One pretraining finding is negative too: arXiv papers, a staple of math corpora, brought no notable improvement on the math benchmarks tested and sometimes made results worse, a conclusion the authors flag as limited to their setup.

Since then

What the authors admit, and what happened next

The precondition is the limitation: the method needs a scalar reward you can trust, and the cleanest source of one is a verifier. DeepSeekMath itself used a learned reward model, but where correctness can be checked by a program, as in the later R1 work, the reward is hard to game. Where it cannot — helpfulness, tone, judgement, taste — you are back to a learned reward model and rung 6's arguments apply again. The method did not make reinforcement learning cheap in general; it made it cheap for the class of tasks that come with an oracle.

Later analyses found biases in the normalisation: dividing by the group's spread, and averaging over tokens in particular ways, introduces preferences for longer or shorter responses that nobody intended, and several corrections have been proposed. Worth treating the exact normalisation as an open implementation detail rather than as part of the idea — which is precisely the caution the PPO reproducibility studies established for this whole family.

How it held up: this is the optimiser under the reasoning-model wave, and its significance is larger than its arithmetic. It is the rung where post-training stops being about eliciting what pretraining already put in the model and starts being about buying new capability with reinforcement learning at scale — which is the claim the reasoning ladder is built on, and the reason the compute budget of a frontier model is no longer dominated by pretraining alone.

SOLVE IT YOURSELF

Compute a group-relative advantage

The idea that deleted the critic is small enough to run in a breath. This scores a group of sampled answers to one prompt and computes each one's advantage — reward minus the group mean, over the group's spread. Watch the advantages sum to zero (the sampled baseline), and then watch the punchline: the same 0.5 reward is reinforced on a hard prompt and suppressed on an easy one, because difficulty cancels within the group. No value network anywhere. Change the rewards and re-run.

YOUR TASK

Write the body of advantages. Everything else in the file is already written; this is the function the paper is about. Press ▶ Run to check it against the 5 assertions below — they start red.

WHAT IT HAS TO SATISFY — 5 ASSERTIONS
  1. Mean-centering makes the advantages sum to zero
  2. Dividing by the spread normalizes to unit std
  3. Beating the group mean earns a positive advantage
  4. Difficulty cancels: same reward, opposite sign by group
  5. The best answer in a group has the highest advantage
CPython · WebAssembly
Questions

Questions people ask about GRPO

What is the GRPO loss function, term by term?

For each question, GRPO samples a group of G answers from the current policy, 64 in DeepSeekMath, and scores them. Each answer's advantage is its reward minus the group mean, divided by the group standard deviation, applied to all of its tokens under outcome supervision. The loss then averages, over the tokens of each answer and over the group, a PPO-style clipped term: the probability ratio between the new and old policy times the advantage, clipped to a narrow range around one. It subtracts beta times a per-token estimate of the KL divergence from a reference model, with beta of 0.04. There is no value network anywhere; the group's own statistics provide the baseline a critic would.

Which KL estimator does GRPO use, and why is the KL not in the reward?

GRPO uses the estimator x minus log x minus 1, where x is the reference model's probability of the sampled token divided by the policy's probability. It is unbiased for the KL divergence when tokens are sampled from the policy, and it is never negative, which makes it better behaved than the plain log-ratio, whose single-sample values can be negative. PPO-based RLHF usually subtracts a KL penalty from the reward at every token, which mixes it into the advantages. GRPO adds the KL term to the loss instead, so the group-normalized advantage reflects only the reward, and the regularization acts separately with its own coefficient, 0.04 in DeepSeekMath.

Did DeepSeekMath's GRPO use rule-based rewards?

No. In DeepSeekMath, GRPO optimized against a learned reward model, initialized from DeepSeekMath-Base 7B and trained on data built the way the Math-Shepherd paper builds it, and the paper compares outcome rewards for whole answers with process rewards for individual steps. Rule-based rewards that check the final answer and the output format came with DeepSeek-R1 about a year later, where GRPO was paired with such verifiable rewards and the R1-Zero model was trained without supervised reasoning data. The two are often conflated because R1 made GRPO famous. The group-relative baseline works with any scalar reward; where the reward comes from is a separate choice.

How does GRPO compute advantages with process supervision?

Process supervision gives a reward at the end of every reasoning step instead of one reward per answer. GRPO collects all step rewards from all answers in the group, normalizes them together by subtracting their mean and dividing by their standard deviation, and then assigns each token an advantage equal to the sum of the normalized rewards of its own step and every step after it. Early tokens therefore carry credit for everything that follows, and a bad step lowers the advantage of every token up to and including it. In DeepSeekMath's experiments this step-aware credit beat outcome supervision, where every token of an answer receives the same advantage.

Does RL with GRPO make a model more capable or just more reliable?

DeepSeekMath's own analysis points to reliability. After GRPO, majority-vote accuracy over K samples, Maj@K, went up, but Pass@K, the chance that at least one of K samples is correct, did not. If RL had taught new problem-solving ability, more problems would become solvable at least once. Instead, answers the model could already produce some of the time became its most frequent answers, which the authors describe as making the output distribution more robust. Later reasoning-model work, which runs RL far longer on stronger base models, has reopened the question, but the DeepSeekMath result is a useful check on any claim that a short RL run created a new capability.

How large should the GRPO group size be?

DeepSeekMath sampled 64 answers per question. The group has to be large enough for its mean and standard deviation to be meaningful, and large enough that a hard question contains at least one answer whose reward differs from the rest: if every answer receives the same score, all advantages are zero and the question contributes no learning signal. Larger groups cost proportionally more generation per question, which is the compute GRPO spends instead of training a critic. Many later implementations use smaller groups to save sampling, accepting noisier baselines. The right size depends on how often a question yields a mix of good and bad answers at the model's current skill.

Check yourself

4 questions to test what you just read

Work each one out before you open it — a number, a prediction or a reason, not a definition. Producing the answer is what makes it stick. Your progress is kept on this device.

A group of four answers receives rewards 1, 0, 0 and 1. Using the population standard deviation, what is each answer's outcome advantage?

Show answer

Mean = 0.5 and every deviation is ±0.5, so std = 0.5. Advantages: +1, −1, −1, +1. They sum to zero, and every token of an answer gets that answer's value. (With the sample standard deviation, n − 1 = 3, std ≈ 0.577 and the advantages become ±0.87.)

All 64 answers to one question receive the same reward. What does that question contribute to the GRPO update, and why?

Show answer

Nothing through the advantage term. Every reward equals the mean, so every advantage is 0 (implementations add a small constant to the standard deviation to avoid dividing by zero). Only the KL term still acts. Questions that are always solved, or never solved, waste their samples, which is why the group must be large enough to contain a mix.

Under process supervision, a three-step answer has normalized step rewards +0.5, −1.0 and +0.3. What advantage do the tokens of each step receive?

Show answer

Each token gets the sum of its own step and all later steps: step 1 → 0.5 − 1.0 + 0.3 = −0.2; step 2 → −1.0 + 0.3 = −0.7; step 3 → +0.3. The bad second step drags down everything before it, while the recovery in step 3 is still credited.

For one token the reference model gives probability 0.2 and the policy gives 0.4. What KL estimate does GRPO compute?

Show answer

x = πref/πθ = 0.5, so x − log x − 1 = 0.5 + 0.693 − 1 = 0.193. It is positive, as the estimator always is unless the two probabilities match, and it enters the loss multiplied by β = 0.04.

Where this sits

Teaching a base model to follow

A pre-trained model completes text; it does not take instructions. Nine papers on getting from one to the other, from RLHF to a loss with no reward model in it.

  1. 1InstructGPT2022
  2. 2Constitutional AI2022
  3. 3Self-Instruct2023
  4. 4LoRA2022
  5. 5QLoRA2023
  6. 6Direct Preference Optimization2023
  7. 7GRPO2024
  8. 8STaR2022
  9. 9Let's Verify Step by Step2023

All 110 papers, in 19 ladders →

Finished this one? 0 / 110 Paper Breakdowns done
NextSTaR Next on the “Teaching a base model to follow” ladder · rung 8 of 9

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns