> ## Documentation Index
> Fetch the complete documentation index at: https://aegean.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Group Relative Policy Optimization

> PPO without a value model, using a group of samples as the baseline.

[PPO for language models](https://aegean.ai/aiml-common/lectures/reinforcement-learning/policy-based-algorithms/PPO/index.md#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 $q$, GRPO samples a group of $G$ responses $o_1, \dots, o_G$ from the old policy $\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 $r_1, \dots, r_G$. With *outcome supervision*, every token of response $i$ gets the same advantage, the reward normalized within its group:

$$
\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^{-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:

$$
\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 $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 $t$ of response $i$. 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 $\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](https://mintcdn.com/aegeanaiinc/WNDPFdbxFiDHVImn/aiml-common/lectures/reinforcement-learning/policy-based-algorithms/GRPO/images/grpo-loop.svg?fit=max\&auto=format\&n=WNDPFdbxFiDHVImn\&q=85\&s=fd9e1de2eee35a4217e35d76a3226906)

*GRPO training loop. The policy (trainable, ⬤) samples $G$ responses to the query $q$. 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](https://aegean.ai/aiml-common/lectures/reinforcement-learning/policy-based-algorithms/reinforce/index.md) 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 - 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](https://aegean.ai/aiml-common/lectures/reasoning/grpo-math-reasoning/grpo-math-reasoning.md) section fine-tunes a small instruction model this way.

| | PPO for language models | GRPO |
| - | - | - |
| Models in memory | policy, value, reward, reference | policy, reward (or rule), reference |
| Baseline | learned value $\hat v$ per token | mean reward of $G$ samples |
| Advantage | GAE over tokens | group-normalized reward |
| KL to reference | subtracted from the reward | added to the loss |
| Samples per prompt | 1 | $G$ |

> [accordion] GRPO talk
>
> [GRPO talk](https://www.youtube.com/embed/xT4jxQUl0X8?start=188)

**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](http://arxiv.org/abs/2402.03300)
* 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](http://arxiv.org/abs/2501.12948)

***

Found an error on this page? [Report an issue](https://github.com/aegean-ai/eaia-feedback/issues/new?template=page-issue.yml\&page=/aiml-common/lectures/reinforcement-learning/policy-based-algorithms/GRPO).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.