Skip to content

DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models

Skip →DeepSeek-R1
main track #9corefundamentalpaperrubric 12/122024 · ~50 min

Zhihong Shao, Peiyi Wang, Qihao Zhu, … Daya Guo

Read first: Proximal Policy Optimization (PPO) · Back to Basics: Revisiting REINFORCE Style Optimization for Learning from Human Feedback in LLMs

Status

TL;DR. DeepSeekMath is mainly a math pretraining paper, but its RL section introduced Group Relative Policy Optimization (GRPO). GRPO keeps PPO’s clipped ratio but deletes the learned critic. For each question it samples a group of G answers, scores them, and uses each answer’s reward relative to the group mean (divided by the group’s standard deviation) as the advantage for every token. With this, a 7B model went from 46.8% to 51.7% on MATH.

Why it matters now. GRPO, or a close variant, is the default optimizer for RL with verifiable rewards (RLVR). It is used for reasoning models and for RL-trained search agents that rewrite queries and read documents. Almost every later paper on this page’s sidebar (Dr. GRPO, DAPO, GSPO, VAPO) is a diff against the equation below. For an IR person the idea is familiar: the advantage is a per-query score normalization, like standardizing a run’s scores before fusing them.

PPO needs an advantage AtA_t for each token. It gets one from a learned critic Vψ(st)V_\psi(s_t), a second network about as large as the policy, combined with Generalized Advantage Estimation (GAE). DeepSeekMath notes two problems with this for LLMs: the critic doubles memory and compute, and only the last token gets a reward, so a per-token value is hard to learn.

GRPO replaces the critic with a group baseline. For question qq, sample GG outputs o1,…,oGo_1,\dots,o_G from the old policy and score them, giving rewards r1,…,rGr_1,\dots,r_G. With outcome rewards, every token of output ii gets

A^i,t=r~i=ri−mean⁡(r1,…,rG)std⁡(r1,…,rG).\hat A_{i,t} = \tilde r_i = \frac{r_i - \operatorname{mean}(r_1,\dots,r_G)}{\operatorname{std}(r_1,\dots,r_G)}.

The objective (the paper’s eq. 3) is PPO’s clipped surrogate, averaged over tokens and then over the group, minus a KL term:

JGRPO=E[1G∑i=1G1∣oi∣∑t=1∣oi∣(min⁡(ρi,tA^i,t, clip⁡(ρi,t,1−ε,1+ε)A^i,t)−β DKL[πθ ∥ πref])]\mathcal J_{\text{GRPO}} = \mathbb E\Big[\frac1G\sum_{i=1}^{G}\frac{1}{|o_i|}\sum_{t=1}^{|o_i|}\Big(\min\big(\rho_{i,t}\hat A_{i,t},\ \operatorname{clip}(\rho_{i,t},1-\varepsilon,1+\varepsilon)\hat A_{i,t}\big) - \beta\,\mathbb D_{\text{KL}}[\pi_\theta\,\|\,\pi_{\text{ref}}]\Big)\Big]

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_\text{old}}(o_{i,t}\mid q,o_{i,\lt t}) is the per-token probability ratio. Keep an eye on the two normalizers, 1/∣oi∣1/|o_i| and the std. Dr. GRPO shows that each one adds a bias.

Worked example: one question, a group of four

Section titled “Worked example: one question, a group of four”

This is the running example for the reasoning pages. A math question is sampled G=4G=4 times. A checker gives 1 for a correct final answer and 0 otherwise, and only answer 1 is correct: r=[1,0,0,0]r=[1,0,0,0].

  1. Group mean: 0.250.25. Population std: 0.25⋅0.75≈0.433\sqrt{0.25\cdot0.75}\approx0.433.
  2. Correct answer: (1−0.25)/0.433≈+1.73(1-0.25)/0.433\approx+1.73. Each wrong answer: (0−0.25)/0.433≈−0.58(0-0.25)/0.433\approx-0.58.
  3. The advantages sum to zero (1.73−3×0.58≈01.73-3\times0.58\approx0). The update pushes probability toward the rare success and away from the three failures.
  4. Every token in answer 1, including filler such as “Let me compute”, gets +1.73+1.73. Every token in answers 2–4 gets −0.58-0.58.

Two other groups show the edges. If the question were easy, say r=[1,1,1,0]r=[1,1,1,0], the three correct answers get +0.58+0.58 each and the single failure gets −1.73-1.73. If all four fail, r=[0,0,0,0]r=[0,0,0,0], the std is zero, the advantage is set to zero, and the group teaches nothing. Many such groups mean wasted samples; DAPO filters them out.

The std convention matters for the numbers but not the signs. With the sample std (divide by G−1G-1), the first group gives +1.5+1.5 and −0.5-0.5.

Take the same correct answer under PPO with γ=λ=1\gamma=\lambda=1 and the reward only at the end. The GAE sum telescopes, and the token-tt advantage becomes At=R−V(st)A_t = R - V(s_t). The baseline now depends on the prefix.

Suppose the critic predicts V=0.5V=0.5 at the start, drops to 0.20.2 after a shaky step, and rises to 0.90.9 once the answer has corrected itself. Then the early tokens get advantage 0.50.5, the tokens just after the shaky step get 0.80.8, and the final tokens get only 0.10.1. The critic sends most of the credit to the part of the response that changed the outcome.

GRPO’s group mean is a Monte Carlo estimate of the prompt-level value V(s0)V(s_0) only, so it cannot make this distinction. It pays for that with coarser credit assignment and gains three things: no critic to train, no critic bias, and no need to predict the value of a half-written proof. It also costs GG samples per question; DeepSeekMath used 64.

PPO's learned critic versus GRPO's group baseline, on one math question Left: PPO samples one output, scores it with a reward model, and trains a critic of about the policy's size to predict the value of every prefix. Generalized advantage estimation turns the reward and critic predictions into an advantage that differs from token to token; a sketch shows one correct answer whose token advantages are large where the critic was pessimistic and small where it already expected success. The KL penalty is added to the per-token reward. Right: GRPO samples four outputs for the same question, with rewards 1, 0, 0, 0. The group mean is 0.25 and the standard deviation about 0.433, so the correct output gets advantage +1.73 and each wrong one gets −0.58. Every token of an output gets the same advantage, shown as flat bars, and the KL to the reference model is added to the loss instead of the reward. PPO: a critic gives a per-token baseline question q policy π_θ 1 output o reward model r_φscores the end only critic V_ψ(sₜ)≈ policy size Advantage via GAE δₜ = rₜ + γ·V(sₜ₊₁) − V(sₜ) Aₜ = Σₗ (γλ)ˡ · δₜ₊ₗ, differs per token KL: −β·log(π_θ / π_ref) added to each rₜ one correct answer, γ = λ = 1: Aₜ = 1 − V(sₜ) tall where the critic was pessimistic, short once it already expects success GRPO: the group mean is the baseline question q o₁ o₂ o₃ o₄ r = 1r = 0r = 0r = 0 Â = +1.73 Â = −0.58 Â = −0.58 Â = −0.58 mean = 0.25, std ≈ 0.433 (population) Âᵢ = (rᵢ − mean) / std, no critic KL to π_ref added to the loss (k3 form) every token of an output gets its Âᵢ tokens of o₁: +1.73 tokens of o₂: −0.58 cost: G samples per question (paper: 64)
Original sketch. PPO's critic gives each prefix its own baseline, so token advantages vary along one answer. GRPO uses the group's mean reward as one baseline, so every token of an answer shares the same advantage (here with G = 4 and rewards 1, 0, 0, 0).

Two more differences from PPO:

  • Where the KL goes. PPO, as written in the paper’s eq. 2, subtracts βlog⁡(πθ/πref)\beta\log(\pi_\theta/\pi_{\text{ref}}) from each token’s reward, so the KL leaks into the advantages. GRPO adds the KL to the loss instead. It uses the estimator k3=ρ−log⁡ρ−1k_3=\rho-\log\rho-1 with ρ=πref/πθ\rho=\pi_{\text{ref}}/\pi_\theta. This estimator is never negative and is unbiased for KL(πθ ∥ πref)\mathrm{KL}(\pi_\theta\,\|\,\pi_{\text{ref}}) when tokens are sampled from πθ\pi_\theta.
  • One update per batch. DeepSeekMath took a single gradient step per batch of samples. At that step πθ=πθold\pi_\theta=\pi_{\theta_\text{old}}, so every ratio is 1 and the clip never fires. The update is a plain policy gradient with a group baseline. The clip only matters when several minibatch steps reuse the same samples, as in DAPO.

The paper also defines process-supervised GRPO. A process reward model scores each step. The step scores are normalized across the group, and a token’s advantage is the sum of the normalized scores of the steps from that token onward. Iterative GRPO periodically retrains the reward model on fresh policy samples (with 10% replay of old data) and resets the reference model to the current policy.

Reproduce the worked example with G = 4, then try a group where every rollout fails, and switch to Dr. GRPO to see what dropping the std changes.

GRPO group advantages

One question, G sampled rollouts. Click a rollout's button to flip its reward between 1 (correct) and 0 (wrong), or type any number. Every token of rollout i gets the same advantage.

Normalization
Std convention
Presets:
  • mean =
  • std =
  • Σ advantages =

rolloutreward rᵢrᵢ − meanadvantagebar
  • Setup (§4.2). RL starts from DeepSeekMath-Instruct 7B, using about 144K chain-of-thought questions from GSM8K and MATH. The reward is a learned reward model, not a rule checker. Settings: policy learning rate 1e-6, KL coefficient 0.04, 64 samples per question, maximum length 1024, batch size 1024.
  • Main numbers (Table 5, chain-of-thought). GSM8K went from 82.9% to 88.2% and MATH from 46.8% to 51.7%. The Chinese benchmark CMATH, which was not in the RL data, went from 84.6% to 88.8%.
  • Ablations (§5.2, Figs. 5–6). Online sampling beat offline RFT, and GRPO beat Online RFT. RFT only reinforces correct samples, while GRPO also pushes wrong ones down. Process supervision beat outcome supervision. A second round of iterative RL helped, with most of the gain in the first iteration.
  • Unified view (§5.2.1, Table 10). SFT, RFT, DPO, PPO and GRPO are written as one gradient: (data source) × (reward) × (gradient coefficient). In this view, STaR-style RFT gives a coefficient of 1 to correct samples and 0 to wrong ones, while GRPO’s coefficient is the advantage plus a KL term, so it can be negative.
  • Maj@K vs Pass@K (Fig. 7). RL raised majority-vote accuracy but not Pass@K. The paper reads this as RL making the output distribution more robust rather than adding new abilities. The RL-boundary paper tests this question at much larger k.
  • The RL gains are modest and come from one 7B model with in-distribution questions and a learned RM. It is hard to separate the effect of GRPO from that of the RM.
  • Every token in a response gets the same advantage. Filler tokens and decisive steps are reinforced equally; the process-supervision variant only partly fixes this.
  • The two normalizers in eq. 3 were not ablated in this paper. Later work found they bias length and difficulty (Dr. GRPO) and changed how the loss is aggregated (DAPO).
  • The token-level ratio and clip were kept from PPO without justification at the sequence level. GSPO argues this is the wrong unit.
  • How large G should be for a given compute budget, and what to do with zero-variance groups, is left open.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    One math question, G = 4 samples, outcome rewards, population std. Compute every GRPO advantage for (a) r = [1, 0, 0, 0], (b) r = [1, 1, 1, 0], (c) r = [0, 0, 0, 0], and (d) learned-RM scores r = [0.9, 0.6, 0.5, 0.2]. Check that each group's advantages sum to zero and say what the policy learns from (c).

    What a strong answer covers
    • (a) mean 0.25, std = √(0.25·0.75) ≈ 0.433. Correct: 0.75/0.433 ≈ +1.73. Each wrong: −0.25/0.433 ≈ −0.58. Sum: 1.73 − 3·0.58 ≈ 0.
    • (b) mean 0.75, std ≈ 0.433. Each correct: +0.58. The wrong one: −1.73. A rare failure is punished as hard as a rare success is rewarded in (a).
    • (c) mean 0 and std 0. Implementations add a small constant or define  = 0, so the group gives no policy-gradient signal at all (only the KL term acts). Those 4 samples were wasted compute.
    • (d) mean 0.55; deviations ±0.35 and ±0.05; variance (2·0.1225 + 2·0.0025)/4 = 0.0625, std 0.25. Advantages +1.4, +0.2, −0.2, −1.4. A graded reward gives a graded signal; binary rewards only say which side of the mean you are on.
    • With the sample std (divide by G − 1), (a) becomes +1.5 and −0.5. The convention changes the scale, not the sign, and should be stated when comparing papers.
  2. Mechanism

    For a sparse end-of-sequence reward with γ = λ = 1, show that PPO's GAE advantage at token t reduces to R − V(sₜ), and compare it with GRPO's (R − mean)/std. Which quantity does the group mean estimate, and what credit-assignment ability is lost by replacing the critic with it?

    What a strong answer covers
    • With γ = λ = 1 the δ terms telescope: Σ δₜ₊ₗ = R − V(sₜ) (ignoring the per-token KL in the reward). So PPO uses a different baseline V(sₜ) at every prefix.
    • The group mean is a Monte Carlo estimate of V(s₀), the expected reward of the policy from the prompt alone. GRPO uses this one number for every token.
    • Lost: a critic can give large credit to the tokens after which success became likely (for example a self-correction) and small credit where success was already expected. GRPO gives every token of a response the same advantage.
    • Gained: no critic bias, no extra model to train, and no need to predict values of half-finished proofs. DeepSeekMath argues a per-token value is hard to learn when only the last token is scored.
    • Dividing by std rescales each prompt's gradient, which a critic-based advantage does not do. Dr. GRPO later argues this term biases training by question difficulty.
  3. Derive / compute

    GRPO estimates the KL to the reference with k3 = ρ − log ρ − 1, where ρ = π_ref/π_θ for the sampled token. Evaluate k3 for ρ = 0.5, 1 and 2. Show that k3 ≥ 0 and that its expectation under π_θ equals KL(π_θ‖π_ref). Then contrast where PPO (in the paper's eq. 2) and GRPO put the KL term.

    What a strong answer covers
    • ρ = 0.5: 0.5 + 0.693 − 1 ≈ 0.193. ρ = 1: 0. ρ = 2: 2 − 0.693 − 1 ≈ 0.307.
    • x − log x − 1 ≥ 0 for x > 0 with equality at x = 1 (log x ≤ x − 1), so every sample is non-negative, unlike the plain −log ρ estimate.
    • Under π_θ, E[ρ] = Σ π_ref = 1, so E[k3] = 1 − E[log ρ] − 1 = E[log(π_θ/π_ref)] = KL(π_θ‖π_ref).
    • PPO subtracts β·log(π_θ/π_ref) from each token's reward, so the KL flows through GAE and into the advantages. GRPO adds β·k3 to the loss, so the advantage depends on the task reward only.
    • Side effect: in PPO a longer answer collects more KL penalty in its return, an implicit length cost that DeepSeek-R1 later points out.
  4. What if…

    Section 5.2 compares RFT, Online RFT, GRPO with outcome supervision, GRPO with process supervision, and iterative GRPO. For each step in that ladder, state what single factor changes, what the paper found, and one confound that keeps the comparison from being clean.

    What a strong answer covers
    • RFT → Online RFT: offline samples from the SFT model versus samples from the current policy. Online RFT pulls ahead later in training (Fig. 5).
    • Online RFT → GRPO: rewarding only correct samples with weight 1 versus reward-dependent positive and negative weights. GRPO is better, which the paper attributes to also pushing down wrong answers.
    • Outcome → process supervision: one normalized reward per answer versus a sum of normalized step rewards after each token. GRPO+PS beats GRPO+OS.
    • Iterative GRPO: retrain the RM on new policy samples (10% replay) and reset the reference. It helps most in the first iteration (Fig. 6).
    • Confounds: these runs use a learned RM, so gains mix policy learning with RM quality; process and outcome differ in RM type as well as granularity; results come from one 7B model and two benchmarks.
  5. Critique

    The paper reports that RL raises Maj@K but not Pass@K on GSM8K and MATH. What does that pattern say about what GRPO changed in the output distribution, and what experiment would show whether this is a property of GRPO or of this particular setup?

    What a strong answer covers
    • Maj@K rising means correct answers became more frequent among samples. Pass@K flat means the set of questions solvable within K samples barely grew.
    • So RL here mostly re-weights answers the SFT model could already produce, which the paper itself describes as making the distribution more robust.
    • Setup factors: 144K in-distribution questions, max length 1024, a single update per batch, a learned RM, and a strong SFT start.
    • Test: rerun with longer budgets, harder or out-of-distribution prompts, and many more steps, then plot pass@k for k up to hundreds with the unbiased estimator. The later RL-boundary paper does this.
  6. Design

    You want to RL-train a query-rewriting agent for BrowseComp-Plus with GRPO, using recall@100 of the gold documents as the reward. Choose G, decide whether to normalize by std, and say how you would handle questions where all G rewrites get the same recall. Argue when you would keep a PPO critic instead.

    What a strong answer covers
    • Recall is graded, so groups rarely tie exactly, but easy questions (all 1.0) and hopeless ones (all 0) give zero-variance groups. Filter or down-sample them before spending compute.
    • Std normalization blows tiny recall differences in near-tied groups up to unit scale. Consider mean-only centering (Dr. GRPO) or a minimum std.
    • G trades baseline noise against generation cost: G = 8 to 16 is a typical starting point; measure the fraction of zero-variance groups and the advantage variance.
    • Keep a critic if episodes are multi-turn with intermediate retrieval steps, where per-step credit matters, or if sampling G full trajectories per question is the bottleneck.
    • Guard against hacking: recall@100 rewards long, keyword-stuffed rewrites, so cap length and audit samples.

Done with this page?

Status