DeepSeekMath: Math Corpus, GRPO and a Unified View of Reinforcement Learning
DeepSeekMath 7B continues pretraining on 120B tokens of web math, then uses GRPO, reinforcement learning without a value model, to reach 51.7% on MATH with no tools or voting. This post covers the corpus pipeline, ablations, GRPO's math and a unified view of SFT, RFT, DPO, PPO and GRPO.
On this page
- Why This Paper Matters
- What the Paper Contributes
- Math Pretraining: Where the Corpus Comes From
- Iterative Recall
- How Good Is the Corpus
- DeepSeekMath-Base 7B
- Two Ablations: Code Helps, arXiv Papers Do Not
- Instruction Tuning
- GRPO: Removing the Value Model
- From PPO to GRPO
- Outcome Supervision and Process Supervision
- Iterative Reinforcement Learning
- Checking Two Details with Code
- Reinforcement Learning Experiments
- A Unified View: SFT, RFT, DPO, PPO, GRPO
- Three Observations
- Why Reinforcement Learning Works
- Limitations
- What to Take Away from This Paper
- Further Reading
- FAQ
Why This Paper Matters
In February 2024, DeepSeek released DeepSeekMath. The question it asks is concrete: how far can mathematical reasoning be pushed at a scale like 7B? The abstract reports that DeepSeekMath 7B reaches 51.7% on the competition-level benchmark MATH with a single answer, no external tools and no voting, close to the Gemini-Ultra (53.2%) and GPT-4 (52.9%) results in the same table; with self-consistency voting over 64 samples it reaches 60.9%.
That number is not its most lasting influence, though. Two things in the paper became general techniques. One is the pipeline that mines domain corpora from Common Crawl with an iterative classifier. The other is GRPO (Group Relative Policy Optimization), which both the post-training of DeepSeek-V3 and DeepSeek-R1 use for reinforcement learning; see the DeepSeek-V3 explainer and the DeepSeek-R1 explainer. A third contribution also deserves a close read: the paper writes SFT, rejection-sampling fine-tuning, DPO, PPO and GRPO into one gradient formula, which turns “how exactly do these methods differ” into a question that can be answered term by term.
This post follows the paper’s order and uses code to check two details of GRPO that are easy to overlook: how the advantage is computed under process supervision, and why the KL estimator is written the way it is. A systematic treatment of the algorithm is in Reasoning RL; here the interest is in what the paper did, how to read the results and where to apply a discount.
What the Paper Contributes
- A math corpus. Starting from OpenWebMath as the seed, iterative fastText recall yields the DeepSeekMath Corpus from Common Crawl: 35.5M web pages and 120B tokens.
- DeepSeekMath-Base 7B. Continued training from DeepSeek-Coder-Base-v1.5 7B for 500B tokens; on MATH it is more than 10 percentage points above the other open base models in the same table.
- GRPO. A variant of PPO that replaces the value model with the average reward of a group of responses to the same question, which needs less memory; training DeepSeekMath-Instruct 7B with it gives DeepSeekMath-RL 7B.
- A unified view and experiments. It analyzes training methods through three elements, data source, reward and gradient coefficient, and compares online and offline training, outcome and process supervision, and single-round and iterative training.
Math Pretraining: Where the Corpus Comes From
Iterative Recall
Math pages are only a small fraction of Common Crawl, and they are scattered across all kinds of sites. The paper first trains a classifier on a small, clean seed corpus, then uses the classifier to fish for more pages, and what it catches is fed back to enlarge the seed (Figure 2).
The details of each step:
- Train a fastText classifier. Randomly take 500K pages from the seed corpus as positive examples and 500K random Common Crawl pages as negative examples.
- Recall math pages. First deduplicate Common Crawl by URL and near-duplicates, which leaves about 40B HTML pages, then score every page with the classifier, sort by score and keep only the top part. How much to keep was evaluated with four pretraining experiments, on the top 40B, 80B, 120B and 160B tokens; round 1 kept the top 40B tokens.
- Find math domains. Group all of Common Crawl by domain (the same base URL) and count the share of recalled pages under each domain; a domain above 10% is treated as math-related, for example mathoverflow.net.
- Annotate URL paths by hand. Within these domains, humans mark the URL paths related to math content, for example mathoverflow.net/questions, and the pages under those paths that were not yet recalled are added to the seed corpus.
Why several rounds? The paper’s explanation is that after round 1 many math pages are still not recalled, because fastText has only seen a set of positive examples that is not diverse enough; once newly discovered math sites are added to the seed, the next round’s classifier recognizes more kinds of math pages. In round 4, about 98% of the newly collected data had already appeared in round 3, so the process stopped. The paper adds that the same pipeline applies to other domains such as programming.
Decontamination. To avoid leaking evaluation data, the paper follows DeepSeek-Coder and filters out web pages that contain questions or answers from GSM8K, MATH, CMATH and AGIEval: any text segment that contains a 10-gram exactly matching the evaluation sets is removed from the training corpus, and for evaluation texts shorter than 10-grams but at least 3-grams, exact matching is used to filter whole web pages. Exact matching cannot catch rephrased questions, which is a general limit of this kind of decontamination.
How Good Is the Corpus
The paper trains DeepSeek-LLM 1.3B for 150B tokens on each corpus and evaluates with few-shot chain of thought (Table 1, excerpt):
| Math corpus | Size (tokens) | GSM8K | MATH | MMLU-STEM | CMATH |
|---|---|---|---|---|---|
| No math training | none | 2.9 | 3.0 | 19.5 | 12.3 |
| MathPile | 8.9B | 2.7 | 3.3 | 15.7 | 1.2 |
| OpenWebMath | 13.6B | 11.5 | 8.9 | 29.6 | 16.8 |
| Proof-Pile-2 | 51.9B | 14.3 | 11.2 | 29.2 | 19.9 |
| DeepSeekMath Corpus | 120.2B | 23.8 | 13.6 | 33.1 | 41.5 |
The numbers are accuracy (%). Three points matter when reading this table:
- The training amount is the same, so small corpora repeat. Every corpus is trained for 150B tokens, so by the sizes in the table OpenWebMath is seen about 11 times, MathPile about 17 times and Proof-Pile-2 about 3 times. The table therefore compares which corpus is more useful under a fixed training budget. The paper gives a control that does not depend on repetition: at 50B training tokens (about one pass over Proof-Pile-2), the DeepSeekMath Corpus is already better than Proof-Pile-2, which shows that its average quality is higher, and its learning curve is steeper and does not reach a plateau early.
- Chinese. A mostly English corpus barely helps; MathPile even pulls CMATH down from 12.3 to 1.2. The DeepSeekMath Corpus contains a lot of Chinese math content, and CMATH rises to 41.5.
- Scale itself is an advantage. The paper lists scale and quality side by side as strengths of this corpus, but Table 1 cannot separate the two.
DeepSeekMath-Base 7B
The base model starts from DeepSeek-Coder-Base-v1.5 7B and trains for another 500B tokens, with this data mix: 56% from the DeepSeekMath Corpus, 20% GitHub code, 10% arXiv, 4% AlgebraicStack, and the remaining 10% natural-language text in Chinese and English from Common Crawl. The maximum learning rate is and the batch size 10M tokens. By these proportions, about 280B tokens come from the math corpus, which is about 2.3 passes over the 120B-token corpus.
Table 2 excerpt (few-shot chain of thought, accuracy %):
| Model | Size | GSM8K | MATH | MMLU-STEM | CMATH |
|---|---|---|---|---|---|
| Mistral | 7B | 40.3 | 14.3 | 51.1 | 44.9 |
| Llemma | 34B | 54.0 | 25.3 | 52.9 | 56.1 |
| Minerva (closed) | 540B | 58.8 | 33.6 | 63.9 | n/a |
| DeepSeekMath-Base | 7B | 64.2 | 36.2 | 56.5 | 71.7 |
The paper says it leads the open base models on all eight benchmarks; on MATH it is more than 10 percentage points above the other open base models and also beats the closed Minerva 540B, a model 77 times larger, and it concludes that parameter count is not the only key factor for mathematical reasoning, because a small model pretrained on high-quality data can also be strong. One more sentence is needed when reading the table. The Minerva numbers are quoted from its original paper, and on MMLU-STEM Minerva 540B’s 63.9 is higher than DeepSeekMath-Base’s 56.5 (and on OCW it is 17.6 against 15.4). The paper’s wording applies only to MATH.
Math training also brought side benefits. Relative to the checkpoint before training, MMLU rises from 42.9% to 54.9% and BBH from 42.9% to 59.5%, while HumanEval (40.2% to 40.9%) and MBPP (52.6% to 52.6%) stay essentially unchanged, which the paper attributes to keeping code data in the continued training.
Two Ablations: Code Helps, arXiv Papers Do Not
The paper ran two groups of ablations, and both conclusions are somewhat counterintuitive. Note that in this section the DeepSeekMath Corpus means the 89B-token version obtained after round 2.
Code training. “Code improves reasoning” is a popular claim with little verification. The paper compares several training orders with DeepSeek-LLM 1.3B (Table 6, excerpt, accuracy %):
| Training setup | GSM8K | MATH | GSM8K+Python | MATH+Python |
|---|---|---|---|---|
| No continued training | 2.9 | 3.0 | 2.7 | 2.3 |
| Code only, 400B | 5.9 | 3.6 | 12.4 | 10.0 |
| Code 400B, then math 150B | 21.9 | 15.3 | 17.4 | 9.4 |
| General 400B, then math 150B | 19.1 | 14.4 | 14.3 | 6.7 |
| Math only, 150B | 20.5 | 13.1 | 11.4 | 6.5 |
| Code 400B mixed with math 150B | 17.6 | 12.1 | 19.7 | 13.5 |
Just 400B tokens of code lift the Python-assisted results from 2.7% and 2.3% to 12.4% and 10.0%. Learning code first and math second is the best of these settings without tools, and it also clearly leads math-only training when Python is used (the second-stage math training takes GSM8K+Python further up to 17.4%, while MATH+Python slips from 10.0% to 9.4%); the control group that uses a general corpus in the first stage does not show this effect. Mixed training is best with Python but gets worse without tools, which the paper guesses is because the capacity of a 1.3B model is not enough to digest code and math together. The paper’s own wording is cautious: it says this is only a “partial answer” to the hypothesis that code improves reasoning in the math domain.
arXiv papers. Many math corpora treat arXiv as standard equipment. The paper tests MathPile and ArXiv-RedPajama by training DeepSeek-Coder-Base-v1.5 7B on 40B tokens of each (Tables 8 and 9, excerpt, accuracy %):
| arXiv corpus trained on 7B | GSM8K | MATH | MMLU-STEM | miniF2F-test |
|---|---|---|---|---|
| No math training | 29.0 | 12.5 | 38.1 | 21.7 |
| MathPile | 23.6 | 11.5 | 35.8 | 16.4 |
| ArXiv-RedPajama | 28.1 | 11.1 | 35.2 | 11.9 |
Training on arXiv alone either gives no clear improvement or makes several benchmarks worse. The paper immediately lists the limits of this conclusion, which should be remembered along with it: it did not study arXiv mixed with other data, did not study other math tasks such as theorem informalization, and did not verify whether gains appear at larger model sizes.
Instruction Tuning
The instruction data of DeepSeekMath-Instruct 7B totals 776K examples, covering Chinese and English, different math areas and difficulty levels, with solutions in three formats: chain of thought (CoT), program of thought (PoT), and tool-integrated reasoning (calling Python while reasoning). In the English part, the authors added tool-integrated solutions to the GSM8K and MATH questions and also use a subset of MathInstruct and the training set of Lila-OOD; the Chinese part is K-12 math problems covering 76 sub-topics, with solutions in chain-of-thought and tool-integrated formats. Training runs for 500 steps with batch size 256 and a constant learning rate of , and samples are randomly concatenated to a 4K context. The general methods for constructing data are covered on the SFT data page, which is currently available in the Chinese edition only.
The results appear in Table 5 below. Without tools, the Instruct model gets 82.9% on GSM8K and 46.8% on MATH; with tools allowed, MATH reaches 57.4%. The paper says that on MATH it is at least 9 percentage points above all open-source models and most closed-source ones (such as Inflection-2 and Gemini Pro), including the much larger Qwen 72B and WizardMath-v1.1 7B, which was specifically trained with math reinforcement learning; it is on par with GLM-4 and Baichuan-3 and still below GPT-4 and Gemini Ultra.
GRPO: Removing the Value Model
From PPO to GRPO
PPO is an actor-critic algorithm: besides the policy model it trains a value model to estimate advantages, and it constrains the policy with a per-token KL penalty. The paper points out two troubles here. The value model is usually as large as the policy model, which brings a heavy memory and compute burden, and in large-model settings usually only the last token gets a score from the reward model, so training a value function that is accurate at every token is not easy.
GRPO does this instead: for each question , sample a group of responses from the old policy and use the average reward of that group as the baseline. The objective is:
Here is the probability ratio between the new and old policies, is the advantage of the -th token of the -th response, and and are hyperparameters. There are three differences from PPO:
-
The baseline comes from the other responses to the same question. The advantage is computed only from relative rewards within the group. The paper argues that this fits the way reward models are trained, since a reward model is trained by comparing several responses to the same question.
-
KL goes into the loss, not into the reward. PPO puts the KL penalty into the reward of every token:
GRPO adds the KL divergence directly to the loss, which avoids complicating the computation of the advantage .
-
KL is computed with an always-nonnegative estimator. The paper uses the estimator proposed by Schulman (from his 2020 blog post “Approximating KL Divergence”, which the paper describes as unbiased and always positive):
Outcome Supervision and Process Supervision
There are two ways to compute the advantage , depending on what the reward model provides.
Outcome supervision. The reward model gives only one score per response. After normalizing within the group, this value serves as the advantage of every token in that response:
Process supervision. The process reward model scores every reasoning step. Let be the position of the last token of step , and let be all step rewards of all responses in the group. First normalize the step rewards over the whole group, then define the advantage of a token as the sum of the normalized rewards of the step it belongs to and all later steps:
Iterative Reinforcement Learning
During training the policy changes, and the old reward model may stop being sufficient. In the paper’s iterative GRPO (Algorithm 1) every round does three things: set the reference model to the current policy; sample, score and update the policy with GRPO; then use the policy’s new samples to generate new training data for the reward model and keep training the reward model with a replay mechanism that mixes in 10% of historical data.
Checking Two Details with Code
The advantage under process supervision. The code below computes the advantages of the two kinds of supervision from hand-set rewards. For outcome supervision the standard deviation is the sample standard deviation (ddof=1, the same as the default of PyTorch’s std; the paper does not specify, and the two differ by a factor of ):
import numpy as np
def group_norm(x):
x = np.asarray(x, dtype=float)
return (x - x.mean()) / x.std(ddof=1) # sample std, like torch.std
# Outcome supervision: a group of 8 responses, a 0 or 1 at the end, and
# every token of a response shares one advantage
rewards = [1, 0, 0, 1, 1, 0, 0, 0]
print("outcome:", np.round(group_norm(rewards), 3))
# Process supervision: every step of every response has a reward, and
# all the steps in the group are normalized together
steps = [[0.9, 0.8, 0.9], [0.9, 0.2], [0.7, 0.8, 0.6, 0.9]]
flat = np.concatenate(steps)
for i, s in enumerate(steps):
norm = (np.array(s) - flat.mean()) / flat.std(ddof=1)
# advantage of the tokens in step j = normalized rewards of step j
# and of all later steps, summed
adv = np.cumsum(norm[::-1])[::-1]
print(f"process {i}:", np.round(norm, 3), "->", np.round(adv, 3))
Output:
outcome: [ 1.208 -0.725 -0.725 1.208 1.208 -0.725 -0.725 -0.725]
process 0: [0.677 0.242 0.677] -> [1.596 0.919 0.677]
process 1: [ 0.677 -2.37 ] -> [-1.693 -2.37 ]
process 2: [-0.193 0.242 -0.629 0.677] -> [0.097 0.29 0.048 0.677]
Under outcome supervision, every token of the three correct responses gets and every token of the wrong ones gets , so a whole response is rewarded or punished alike. Process supervision is different. The first response (process 0) is fine in all three steps, so the earlier the token, the larger its advantage (1.596, 0.919, 0.677). In the second response (process 1) the reward of step 1 is 0.9, which is positive after normalization (), but step 2 has only 0.2 (); because the advantage is “this step plus all later steps”, the tokens of step 1 are also penalized along with it, and their advantage is . That is the value of process supervision: it can tell “which step went wrong first”, but it also means that earlier tokens bear responsibility for later mistakes.
The KL estimator. The code below verifies three things on a toy model with 5 words: the value of the estimator, why this form was chosen, and the gradient obtained by differentiating it. The random seed is fixed to 0; random numbers may differ slightly between PyTorch versions, but the three conclusions do not depend on the specific values:
import torch
torch.manual_seed(0)
V = 5
theta = torch.randn(V, requires_grad=True) # logits of the current policy
ref = theta.detach() + 0.5 * torch.randn(V) # a nearby reference model
logp, logq = torch.log_softmax(theta, -1), torch.log_softmax(ref, -1)
p, q = logp.exp().detach(), logq.exp()
fwd = (p * (logp.detach() - logq)).sum().item() # KL(pi_theta || pi_ref)
o = torch.multinomial(p, 200_000, replacement=True) # sample from the policy
r = (q / p)[o] # pi_ref / pi_theta
k1, k3 = -r.log(), r - r.log() - 1
print(f"exact {fwd:.4f} k1 {k1.mean():.4f} k3 {k3.mean():.4f}")
print(f"min k1 {k1.min():.3f} min k3 {k3.min():.3f}")
print(f"negative samples: k1 {(k1 < 0).float().mean():.1%}, k3 0.0%")
def grad(loss):
return torch.autograd.grad(loss, theta, retain_graph=True)[0]
# Treat the samples as constants: the gradient of k3 is then
# (1 - r) times the gradient of the log-probability
x = o[:1000]
rx = (logq - logp).exp()[x]
g_k3 = grad((rx - (logq - logp)[x] - 1).mean())
g_coef = grad(((1 - rx.detach()) * logp[x]).mean())
print("grad of k3 == (1 - r) * grad log pi:", torch.allclose(g_k3, g_coef))
# Take the expectation over samples (a sum over the vocabulary) and compare
# with the gradients of the two KL directions
g_exp = grad(((p - q) * logp).sum())
g_fwd = grad((logp.exp() * (logp - logq)).sum()) # KL(pi_theta || pi_ref)
g_rev = grad((q * (logq - logp)).sum()) # KL(pi_ref || pi_theta)
print("expected grad == grad KL(pi_ref || pi):", torch.allclose(g_exp, g_rev))
print("expected grad == grad KL(pi || pi_ref):", torch.allclose(g_exp, g_fwd))
Output:
exact 0.0537 k1 0.0539 k3 0.0536
min k1 -0.859 min k3 0.003
negative samples: k1 38.8%, k3 0.0%
grad of k3 == (1 - r) * grad log pi: True
expected grad == grad KL(pi_ref || pi): True
expected grad == grad KL(pi || pi_ref): False
The first three lines show that the plain (k1 in the code) and the paper’s estimator (k3) both have means that match the exact KL divergence (0.0537), but 38.8% of the k1 samples are negative and a single sample has a large variance; every sample of k3 is at least 0, which makes it more stable as a loss term. The fourth line shows that if k3 is used as the loss term and the samples are treated as constants, the gradient is exactly with . In the objective this term carries in front, so the corresponding gradient coefficient is , exactly the second term in equation (21) of the paper’s appendix.
The last two lines are a side note, not a conclusion of the paper. After taking the expectation over samples, this gradient equals the gradient of the reverse KL (), not the gradient of the forward KL that k3 estimates. In other words, the value of the estimator estimates the forward KL, but differentiating it the way common implementations do actually optimizes the other direction. This does not mean GRPO’s results are in doubt, but when reading code or reproducing the method, it is worth being clear about which direction of KL you are constraining.
Reinforcement Learning Experiments
Setup. Reinforcement learning continues from DeepSeekMath-Instruct 7B. The training questions are only the chain-of-thought questions related to GSM8K and MATH in the instruction-tuning data, about 144K questions, and the other questions are deliberately excluded, to test whether reinforcement learning still works on benchmarks without training data. The reward model is initialized from DeepSeekMath-Base 7B with a learning rate of , and its training set follows the construction of Math-Shepherd; the policy model has a learning rate of and a KL coefficient of 0.04; 64 responses are sampled per question with a maximum length of 1024 and a training batch size of 1024; the policy is updated only once after each exploration. The old policy then equals the current policy, so the paper’s appendix derivation drops min and clip directly.
Results. Table 5 excerpt (accuracy %, single answer unless noted):
| Model | Size | GSM8K | MATH | MGSM-zh | CMATH |
|---|---|---|---|---|---|
| GPT-4 | undisclosed | 92.0 | 52.9 | n/a | 86.0 |
| Gemini Ultra | undisclosed | 94.4 (majority vote of 32 candidates) | 53.2 | n/a | n/a |
| Qwen | 72B | 78.9 | 35.2 | n/a | n/a |
| WizardMath-v1.1 | 7B | 83.2 | 33.0 | n/a | n/a |
| DeepSeek-LLM-Chat | 67B | 84.1 | 32.6 | 74.0 | 80.3 |
| DeepSeekMath-Instruct | 7B | 82.9 | 46.8 | 73.2 | 84.6 |
| DeepSeekMath-RL | 7B | 88.2 | 51.7 | 79.6 | 88.8 |
With tool-integrated reasoning, where Python may be called, DeepSeekMath-Instruct and DeepSeekMath-RL get 57.4% and 58.8% on MATH, and GPT-4 Code Interpreter gets 69.7%.
Reinforcement learning used only chain-of-thought questions related to GSM8K and MATH, yet it beats the Instruct model on every metric in the table. The paper treats the chain-of-thought results on GSM8K and MATH as in-domain tasks and the other benchmarks as out-of-domain, so the gains on MGSM-zh (73.2 to 79.6) and CMATH (84.6 to 88.8) are regarded as out-of-domain benefits.
Most numbers in the table are single-answer accuracies; only Gemini’s GSM8K is a majority vote of 32 candidates, which cannot be compared directly with the other cells. Tool-integrated reasoning lets the model write Python programs and cannot be compared with pure chain of thought. These are February 2024 results, and comparing with newer models requires aligning the evaluation settings again.
A Unified View: SFT, RFT, DPO, PPO, GRPO
The most instructive part of the paper is writing the various training methods in the same gradient form:
Every method increases or decreases the conditional probability of some token, and they differ only in three elements: the data source (where the training data comes from), the reward function (where the signal comes from) and the algorithm (how data and reward become the gradient coefficient , which decides how much each token is reinforced or penalized). Table 10 of the paper lists them side by side:
| Method | Where the data comes from | Reward | Gradient coefficient |
|---|---|---|---|
| SFT | (question, solution) pairs in the SFT dataset | None, equivalent to human selection | Constant 1 |
| RFT (rejection-sampling fine-tuning) | Samples of the SFT model on SFT questions, offline | Rule, whether the answer is right | 1 if the answer is correct, 0 if wrong |
| DPO | Positive and negative response pairs sampled from the SFT model, offline | Rule (math tasks) or human preference | Varies with the difference of the log-probability ratios of the positive and negative responses |
| Online RFT | Real-time samples from the current policy | Rule | Same as RFT |
| PPO | Real-time samples from the current policy | Reward model | Advantage , obtained from GAE and the value model |
| GRPO | A group of responses to the same question from the current policy | Reward model | Relative advantage within the group, plus a KL correction term |
The four nontrivial gradient coefficients (paper appendix A.1, equations 10, 14, 18 and 21):
The DPO coefficient takes a positive sign for the tokens of the positive example and a negative sign for those of the negative example. The second term in the GRPO formula is the gradient of the KL term that the previous section checked with code. The derivation of DPO is in Preference Optimization.
Three Observations
The paper tests three factors of this framework with small-scale experiments:
- Data source: online beats offline. RFT and DPO are offline (the data comes from the initial SFT model), and Online RFT and GRPO are online (the data comes from the live policy). On DeepSeekMath-Instruct 1.3B, Online RFT is on par with RFT early in training and clearly better later. The paper explains that the early policy is very similar to the SFT model, so the sampled data differs little, and the further training goes, the more the two differ and the more obvious the advantage of real-time sampling becomes.
- Gradient coefficient: being able to penalize and to distinguish strength is better. Online RFT only reinforces correct responses, with the same strength for all and no penalty for wrong responses; the coefficient of GRPO varies with the reward, both reinforcing and penalizing, with different strengths. Also on 1.3B, GRPO beats Online RFT, and within GRPO process supervision beats outcome supervision, which the paper attributes to the finer step-level coefficients.
- Iterative reinforcement learning works, mainly through the first round. Two iterations were run on DeepSeekMath-Instruct 7B, and the improvement is concentrated in the first round.
Why Reinforcement Learning Works
The paper evaluates Pass@K and Maj@K of the Instruct and RL models (temperature 0.7, K from 1 to 64): reinforcement learning raises Maj@K and does not raise Pass@K. This says that the gain mainly comes from making the output distribution more robust, that is, moving correct answers up from the Top-K, not from strengthening the basic capability of the model. The authors think this may be related to the experimental setup, which used only instruction-tuning-stage questions and simple nucleus sampling, and they plan to continue exploring with out-of-distribution questions and stronger sampling strategies (such as tree-search-based methods). The statistical meaning of Pass@K is in Statistics for Evaluation, and the definition of majority voting is in the glossary.
In its outlook the paper also raises three directions. On the data source, expand the question distribution and improve sampling, since inference-acceleration techniques decide the efficiency of policy exploration. On the algorithm, existing methods “fully trust” the reward signal, while rewards are not always reliable (for example, even the carefully annotated PRM800K has about 20% wrong labels), so algorithms more robust to noisy rewards are needed. On the reward model, generalization has to improve, uncertainty has to be modeled, and high-quality process reward models have to be built more efficiently.
Limitations
The limitations the paper points out itself:
- Geometry and theorem proving are weaker. The model lags behind closed-source models on these two kinds of problems, and in the paper’s trial it could not handle questions involving triangles and ellipses, which may indicate selection bias in the pretraining and fine-tuning data.
- Few-shot ability is not as good as GPT-4. GPT-4 improves with a few examples, while DeepSeekMath performs similarly zero-shot and few-shot, which the paper attributes to the limit of model size.
Things to keep in mind when reading this paper:
- Reinforcement learning used only in-domain questions. The RL training questions come from data related to GSM8K and MATH, and the paper also treats these two benchmarks as in-domain in the evaluation, so 51.7% cannot be taken directly as a measure of generalization.
- Pass@K did not improve. This suggests that reinforcement learning here mostly improves stability; whether it can truly extend capability in a larger exploration space is not answered by this paper.
- All numbers are from February 2024. Differences in evaluation method, prompts and voting settings change the ranking.
What to Take Away from This Paper
- A domain corpus needs a closed loop, not a one-shot classifier. Recall, discover new sites, add them to the seed, recall again; only after four rounds is there enough scale and diversity, especially in Chinese.
- The relationship between code and math is more complicated than “code helps reasoning”. Learning code first and math second helps a little for solving without tools and helps a lot for solving with Python; whether mixed training is beneficial depends on model capacity.
- GRPO uses several responses to the same question as each other’s baseline. It saves the memory of a value model and pays for it with multiple samples per question, so sampling cost becomes the bottleneck.
- To compare post-training methods, ask three questions first. Is the data sampled online or offline? Does the reward come from rules or a model? How does the gradient coefficient vary with the reward?
- Look at both Maj@K and Pass@K for the gains of reinforcement learning. Looking only at single-answer accuracy makes it easy to mistake “a sharper distribution” for “a stronger ability”.
Further Reading
- The paper: DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models (the code and model addresses are on the paper’s first page)
- Related wiki pages: Reasoning RL, Preference Optimization, Statistics for Evaluation, SFT Data Construction and Quality Control.
- Follow-up work: DeepSeek-R1 explainer, DeepSeek-V3 explainer
- Sources of data and methods: OpenWebMath (the seed corpus), fastText.zip (the classifier), Math-Shepherd (the process reward model), Let’s Verify Step by Step (PRM800K), Llemma (the math base model compared)
- Source of the KL estimator: John Schulman, Approximating KL Divergence (2020)
FAQ
- What is the main difference between GRPO and PPO?
- PPO trains a separate value model, usually as large as the policy, to estimate advantages. GRPO drops it. For each question it samples a group of G responses, uses the mean reward of the group as the baseline and the standard deviation for normalization, and gets an advantage for every response. Two other differences are that GRPO adds the KL penalty directly to the loss instead of to each token's reward, and that it computes KL with the always-nonnegative estimator π_ref/π_θ − log(π_ref/π_θ) − 1. The price is sampling many responses per question, 64 per question in the paper's reinforcement learning experiments.
- How was the DeepSeekMath corpus filtered out of Common Crawl?
- It uses iterative recall. First, with OpenWebMath as the seed, a fastText classifier is trained on 500K positive examples and 500K random web pages as negatives, and it scores about 40B deduplicated web pages, of which the top-ranked part is kept. Then the share of recalled pages is counted for every domain, domains above 10% are treated as math-related, humans mark the math URL paths within them, and pages not yet recalled are added to the seed to retrain the classifier. After 4 rounds the result is 35.5M web pages and 120B tokens, and since about 98% of what round 4 collected had already appeared in round 3, the process stopped. Finally, text that overlaps with the evaluation sets is removed by 10-gram exact matching.
- Why does the paper say reinforcement learning improves Maj@K and not Pass@K?
- The paper compares the instruction-tuned model with the reinforcement learning model on GSM8K and MATH (temperature 0.7, K from 1 to 64). After reinforcement learning the accuracy of majority voting (Maj@K) is higher, but the share of questions where at least one of K candidates is correct (Pass@K) does not improve. The authors read this as reinforcement learning moving correct answers up from the Top-K and making the output distribution more robust, not as strengthening the basic capability. They also note that this may depend on the experiment using only instruction-tuning-stage questions and simple nucleus sampling.
- Do code and arXiv papers help mathematical reasoning?
- The paper ran ablations with a 1.3B model. Training on 400B tokens of code and then 150B tokens of math is slightly better than training on math directly (GSM8K 21.9% vs 20.5%, MATH 15.3% vs 13.1%), and the gap is larger when solving with Python (GSM8K+Python 17.4% vs 11.4%). Training on arXiv papers alone gave no clear gains on GSM8K, MATH, MMLU-STEM and miniF2F, and sometimes did worse. The paper also lists the limits of this conclusion, since it did not study arXiv mixed with other data, larger model sizes or other mathematical tasks.
- How should the DeepSeekMath-RL 7B results be read?
- The paper reports 88.2% on GSM8K and 51.7% on MATH for a single answer without tools. The abstract also gives 60.9% on MATH with self-consistency voting over 64 samples and 58.8% when the model may write Python programs. In the same table GPT-4 gets 92.0% and 52.9%. These are February 2024 numbers, and the prompt, whether voting is used and whether tools are allowed all change the conclusion, so they cannot be compared directly with newer models.