TL;DR
Shao et al. (2024) continue pretraining a 7B code model on a math corpus filtered from web crawl data, then add a reinforcement learning step called GRPO. GRPO drops PPO's learned value model and uses the average reward of a group of sampled answers to the same question as its baseline. The 7B model reaches 51.7% on the MATH benchmark without tools or voting.
Where you'll see it: the reinforcement learning stage of reasoning models that are trained on answers with checkable correctness, such as math and code.
The problem
Reinforcement learning after supervised fine-tuning had been shown to help language models reason. The standard algorithm for it, PPO, has a cost. PPO trains a value model next to the policy. In an LLM that value model is usually about the same size as the policy, so training needs roughly twice the memory and compute.
The value model has a second problem. The reward model usually scores only the final token of an answer. A value model has to predict the return at every token from that single late signal, which is hard to learn well.
The authors set two goals: an open math model closer to closed models such as GPT-4 and Gemini Ultra on academic benchmarks, and an RL method cheap enough to run on it.
Key idea
GRPO replaces the learned baseline with a group baseline. For each question, sample a group of answers from the current policy. Score each answer with a reward model. Subtract the group mean from each reward and divide by the group standard deviation. The result is the advantage for every token of that answer. An answer that beats its siblings is reinforced; one that loses to them is pushed down. No value network is needed.
The group comparison fits the reward model well. Reward models are usually trained on pairs of answers to the same question, so judging answers relative to each other matches what the reward model learned.
flowchart LR Q[Question q] --> P[Current policy samples G answers] P --> R[Reward model scores each answer] R --> N[Subtract group mean, divide by group std] N --> A[Advantage for every token of each answer] A --> U[Clipped policy update plus KL penalty] U --> P
The method
Starting point: PPO. PPO maximises a clipped surrogate objective. The probability ratio between the current and old policy is clipped to and multiplied by an advantage . The advantage is estimated with generalised advantage estimation from a learned value function . The paper also puts a per-token KL penalty into the reward, , where is the initial supervised model. The reference model, the value model and the reward model are three separate networks in this setup.
GRPO objective. For each question , sample outputs from the old policy. The objective is
Here is the probability ratio . Two changes from PPO are visible in the formula. The advantage comes from the group, not a value model. The KL term sits in the loss rather than in the reward. The paper gives the KL estimator as
This is always non-negative, and the paper uses it in place of the per-token penalty of PPO.
Outcome advantage. Score the group with the reward model, giving . Normalise:
Every token of answer gets the same advantage . The main text does not say whether the standard deviation is the population or the sample version.
Process advantage. The paper also tries rewards at the end of each reasoning step. Each step gets a normalised score over all steps in the group. A token's advantage is the sum of the normalised scores of the steps that end at or after it. This gives finer credit, at the cost of a process reward model.
Iterative RL. Algorithm 1 in the paper alternates. It samples new answers from the current policy, uses them to retrain the reward model with a replay mechanism that keeps 10% of older data, and then resets the reference model to the current policy. Training then continues with the new reward model.
Relation to other methods. The paper argues that RFT, DPO, PPO and GRPO can all be written as one gradient form. The form has three parts: a data source, a reward function, and a gradient coefficient that the algorithm computes from the reward. In that view, GRPO differs from online rejection-sampling fine-tuning in one respect. Online RFT gives every correct answer the same weight and ignores wrong ones. GRPO's coefficient depends on the size of the reward, so it pushes down bad answers as well as pulling up good ones.
Worked example: group advantages
Take a group of four answers to one question, with binary rewards 1, 0, 0, 1. The mean is 0.5. Every answer is 0.5 from the mean, so the population standard deviation is 0.5. The advantages are
- answer 1: (1 minus 0.5) divided by 0.5 gives +1.
- answer 2: (0 minus 0.5) divided by 0.5 gives minus 1.
- answer 3: the same as answer 2, minus 1.
- answer 4: the same as answer 1, plus 1.
Now take rewards 1, 1, 1, 0. The mean is 0.75. The deviations are 0.25, 0.25, 0.25 and minus 0.75. Their squares average to 0.1875, so the standard deviation is about 0.433. The advantages are about +0.577 for each correct answer and about minus 1.732 for the wrong one. The wrong answer gets a larger magnitude because it is the only one that differs from the rest. These numbers are arithmetic on the rule in the paper, not results from it.
Results
The paper evaluates several models. The RL result is the one this node is about.
Base model. With few-shot chain-of-thought prompting, DeepSeekMath-Base 7B leads the open-source base models the paper compares against, and on MATH the paper says it outperforms Minerva 540B, a closed-source base model 77 times larger. The base is initialised from DeepSeek-Coder-Base-v1.5 7B and trained on 500B tokens, 56% of which come from the DeepSeekMath Corpus. That corpus has 120B tokens and was built by four iterations of filtering Common Crawl with a fastText classifier.
Instruction tuning. DeepSeekMath-Instruct 7B is supervised-tuned on chain-of-thought, program-of-thought and tool-integrated data. The paper says it beats the other 7B models and matches 70B open instruction-tuned models.
RL with GRPO. The RL stage starts from DeepSeekMath-Instruct 7B and uses only about 144K chain-of-thought questions drawn from GSM8K and MATH in the instruction data. The policy learning rate is 1e-6, the KL coefficient is 0.04, and each question gets 64 sampled outputs. The maximum length is 1024 and the batch size is 1024.
The numbers in the introduction are:
- GSM8K: 82.9% to 88.2%.
- MATH: 46.8% to 51.7%.
- CMATH (out of domain): 84.6% to 88.8%.
The paper says this surpasses all open-source models in the 7B to 70B range, as well as the majority of closed-source models, using chain-of-thought reasoning without tools. Self-consistency over 64 samples from DeepSeekMath 7B reaches 60.9% on MATH.
Ablations. Figure 5, on a 1.3B model, compares online RFT, GRPO with outcome supervision, and GRPO with process supervision. GRPO beats online RFT, and process supervision beats outcome supervision. Figure 6 shows that iterative RL improves performance, and the text says the largest improvement comes in the first iteration.
What RL changed. Figure 7 reports Maj@K and Pass@K. RL raises Maj@K, the accuracy of the majority answer, but not Pass@K, the chance that some sample is correct. The authors read this as RL making the correct answer more likely to be the top choice, rather than adding new ability. This is the paper's own interpretation, and it is measured on GSM8K and MATH only.
Why it mattered
GRPO is a change to PPO-style training that removes one network, which the paper says cuts training resources. The paper also raised questions it could not settle: whether reward models are reliable enough, whether RL adds capability or only sharpens the output distribution, and whether process rewards beat outcome rewards. This lesson does not survey work that followed.
The authors' own limits are direct. Geometry and theorem-proving are weaker than in closed models, which they attribute to data selection bias. At 7B, few-shot performance is weaker than GPT-4's. In their discussion they say the RL pipeline used only instruction-tuning questions with a naive sampling method, and that this may explain why it improved Maj@K more than Pass@K.
Reading guide
Read the paper in this order. Each step names the prerequisites it needs.
- Section 1, Introduction. Needs Language Model and Transformer. Read the numbers in the last paragraph of the first page before the method, so you know the target.
- Section 2, Math pre-training. Needs Transformer only at the level of "a decoder that predicts the next token". The data pipeline is a classifier and deduplication problem; no other prerequisite is needed.
- Section 3, Supervised fine-tuning. Needs Chain-of-Thought Prompting. The data formats (chain of thought, program of thought, tool-integrated) are the inputs to the RL stage.
- Section 4.1.1, From PPO to GRPO. Needs Policy Gradient, Proximal Policy Optimization (PPO), Advantage Function, Kullback–Leibler Divergence and Reward Model. Read PPO's objective first. The GRPO equation is PPO's clipped objective with the value model removed.
- Sections 4.1.2 to 4.1.4. Needs Reward Model for the outcome and process rewards. Iterative RL needs nothing new.
- Section 4.2 and Table 5. Needs only the terms defined above. The comparisons are easier to follow once you know the method.
- Section 5.2, Insights of RL. Needs Direct Preference Optimization for the comparison with DPO, and the unified gradient view in Table 10.
Check yourself
QuestionIn GRPO, why is the group mean used as the baseline in place of a value function, and what does PPO need that GRPO does not?Show answer
PPO needs a learned value model, usually about the size of the policy, to estimate the baseline at every token. GRPO samples a group of answers to the same question and uses their average reward as the baseline. This removes the value network and its memory and compute cost. It also avoids having to predict a return at each token from a reward that often arrives only at the end of the answer.
QuestionFour answers to one question get rewards 1, 0, 0, 0. Using the population standard deviation, what is the advantage of the answer with reward 1?Show answer
The mean is 0.25. The deviations are 0.75 for the first answer and minus 0.25 for each of the others. The squared deviations are 0.5625 and 0.0625 three times, which sum to 0.75. Their average is 0.1875, and the square root is about 0.433. The advantage of the first answer is 0.75 divided by 0.433, which is about 1.732. The three wrong answers each get minus 0.25 divided by 0.433, about minus 0.577. The correct answer gets a larger magnitude because it is the rare outcome.
QuestionThe paper reports that RL raises Maj@K but not Pass@K. What does that tell you about where the gain came from, and what would you measure to test the interpretation?Show answer
Maj@K is the accuracy of the most common answer among K samples, and Pass@K is the chance that at least one of K samples is correct. If RL raises Maj@K but leaves Pass@K flat, the model's correct answers were already in its sample distribution, and RL moved probability toward them. It did not add answers the model could not reach before. To test this, you would run the same comparison on problems the RL data never covered, and check whether Pass@K moves at all.
QuestionWhy does the paper compute the KL term as the estimator in Section 4.1.1 rather than inside the reward as PPO does?Show answer
Putting the KL penalty inside the reward would change the advantage calculation, which GRPO builds from group-normalised rewards. Adding the KL term to the loss keeps the advantage as a function of the reward model's scores only. The estimator used, which compares the reference and current probabilities of the sampled token, is always non-negative, so it acts as a smooth penalty on drift from the reference model.
Sources
- Zhihong Shao, Peiyi Wang, Qihao Zhu, Runxin Xu, Junxiao Song, et al. DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models. 2024. https://arxiv.org/abs/2402.03300
- John Schulman, Filip Wolski, Prafulla Dhariwal, Alec Radford, Oleg Klimov. Proximal Policy Optimization Algorithms. 2017. https://arxiv.org/abs/1707.06347