Skip to main content
PPO for language models trains a value model next to the policy. That critic is about as large as the policy, so it roughly doubles the memory and compute of training. It is also hard to train well: the reward arrives only once, at the end of the response, yet the critic has to predict a value at every token. Group relative policy optimization (GRPO), introduced with the DeepSeekMath model (Shao et al., 2024), removes the value model and estimates the baseline from samples instead.

Group sampling

For each prompt qq, GRPO samples a group of GG responses o1,…,oGo_1, \dots, o_G from the old policy πθold\pi_{\theta_{old}}, typically 8 to 64 of them. A reward model, or a rule that checks the final answer, scores each response, giving rewards r1,…,rGr_1, \dots, r_G. With outcome supervision, every token of response ii gets the same advantage, the reward normalized within its group: 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) + \epsilon}, where the small constant ϵ\epsilon (for example 10−410^{-4}) keeps the fraction defined when the standard deviation is zero. A response that beats the other responses to the same prompt gets a positive advantage, and one that falls behind gets a negative advantage. If all responses in a group get the same reward, for example when every answer fails the check, the numerator is zero for every response, every advantage is zero, and the prompt contributes no gradient. With process supervision, a reward model scores each reasoning step, the step rewards are normalized across the group the same way, and the advantage of a token is the sum of the normalized rewards of the steps from that token on.

The objective

GRPO keeps PPO’s clipped ratio, applied token by token, and averages over tokens and over the group: J(θ)=E[1G∑i=1G1∣oi∣∑t=1∣oi∣{min⁡(ri,t(θ) A^i,t, clip⁡(ri,t(θ),1−ϵ,1+ϵ) A^i,t)−β DKL[πθ ∥ πref]}],\begin{aligned} J(\theta) = \mathbb E\Bigg[ \frac{1}{G} \sum_{i=1}^{G} \frac{1}{|o_i|} \sum_{t=1}^{|o_i|} \Big\{ &\min\big( r_{i,t}(\theta)\, \hat A_{i,t},\ \operatorname{clip}(r_{i,t}(\theta), 1 - \epsilon, 1 + \epsilon)\, \hat A_{i,t} \big) \\ &- \beta\, \mathbb D_{KL}\big[ \pi_\theta \,\|\, \pi_{ref} \big] \Big\} \Bigg], \end{aligned} where ri,t(θ)=πθ(oi,t∣q,oi,<t)/πθold(oi,t∣q,oi,<t)r_{i,t}(\theta) = \pi_\theta(o_{i,t} \mid q, o_{i,<t}) / \pi_{\theta_{old}}(o_{i,t} \mid q, o_{i,<t}) is the probability ratio of token tt of response ii. Two details differ from PPO for language models:
  • The KL penalty to the reference model is a term of the loss, not a deduction from the reward. The advantages therefore stay pure group comparisons.
  • The KL divergence is estimated per token with the unbiased, always nonnegative estimator πrefπθ−log⁡πrefπθ−1\frac{\pi_{ref}}{\pi_\theta} - \log \frac{\pi_{ref}}{\pi_\theta} - 1, evaluated at the sampled token.
GRPO training loop: query q enters the Policy Model, which samples G outputs o_1 to o_G; a frozen Reward Model scores each output into r_1 to r_G; Group Computation normalizes the scores into advantages A_1 to A_G; a frozen Reference Model provides a per-token KL penalty fed back to the Policy Model GRPO training loop. The policy (trainable, ⬤) samples GG responses to the query qq. The frozen (❄) reward model scores them, the group computation normalizes the scores into advantages, and the frozen reference model supplies the KL penalty. There is no value model.

Relation to REINFORCE with baseline

The group mean is a Monte Carlo baseline. REINFORCE with baseline subtracts a learned estimate of the state value from the return. GRPO subtracts the average return of other samples from the same state, which here is the prompt. The baseline needs no training, at the cost of generating several responses per prompt. Because the mean includes the response being scored, it is slightly correlated with that response’s own reward; a leave-one-out mean over the other G−1G - 1 responses avoids this. Dividing by the group’s standard deviation rescales the advantages per prompt, so easy and hard prompts contribute updates of similar size. This is a choice of weighting, not part of the policy gradient, and later work has questioned it.

Context

DeepSeekMath used GRPO with a learned reward model to improve mathematical reasoning. DeepSeek-R1 (DeepSeek-AI et al., 2025) applied GRPO to a base model with rule-based rewards: one for a correct final answer, checked by a program, and one for following the required output format. The model learned long chains of reasoning without supervised examples of them. Rewards that can be checked by a program are hard for the policy to game, and they make the group comparison cheap, which is a large part of why GRPO spread quickly. The GRPO math reasoning section fine-tunes a small instruction model this way.
Key references: (Shao et al., 2024; DeepSeek-AI et al., 2025)

References

  • Shao, Z., Wang, P., Zhu, Q., Xu, R., Song, J., et al. (2024). DeepSeekMath: Pushing the limits of mathematical reasoning in open language models. arXiv [cs.CL]. Link
  • DeepSeek-AI, Guo, D., Yang, D., Zhang, H., Song, J., et al. (2025). DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning. arXiv [cs.CL]. Link

Found an error on this page? Report an issue.