Group Relative Policy Optimization (GRPO)
Group Relative Policy Optimization (GRPO) trains LLMs with RL by scoring each sampled answer against its group, removing the critic model PPO needs.
Group Relative Policy Optimization (GRPO) is a reinforcement learning algorithm for fine-tuning large language models (LLMs). For each prompt it samples a group of responses, scores each one with a verifier or a reward model, and judges every response by how much better or worse it did than the rest of its group. That group average replaces the separate value network, or critic, that Proximal Policy Optimization (PPO), the algorithm behind classic RLHF, trains alongside the model, which saves the memory and compute of a second network about as large as the model being trained. DeepSeek introduced GRPO in its 2024 DeepSeekMath paper, and its use in DeepSeek-R1 in January 2025 made it a standard algorithm for training reasoning models, which work through a long chain of thought before answering. Those models learn from verifiable rewards, such as a checked math answer or a passing unit test.
How GRPO Works#
Each training step repeats the same procedure for a batch of prompts:
- Sample a group: The current model generates several responses to the same prompt; DeepSeekMath used 64 per question.
- Score each response: A rule-based verifier or a learned reward model assigns each response a reward.
- Compute group-relative advantages: Each reward minus the group mean, divided by the group standard deviation, becomes that response's advantage, shared by every token in the response.
- Update the policy: A PPO-style clipped objective raises the probability of tokens in above-average responses and lowers it for below-average ones, while a KL-divergence penalty, added directly to the loss, keeps the model close to a frozen reference copy.
Because advantages are relative, a group in which every response gets the same reward carries no learning signal at all. This is GRPO's main inefficiency. On a prompt the model always solves, or never solves, the whole group is wasted, so training sets are often filtered to problems of intermediate difficulty for the current model.
GRPO in Code#
Libraries such as Hugging Face's TRL GRPO trainer implement the full algorithm for language models. This PyTorch example runs the same update on a toy policy that chooses among six candidate answers to a single prompt, with a verifier that accepts only one of them:
import torch
torch.manual_seed(0)
# Toy policy over 6 candidate answers to one prompt; a verifier accepts only answer 4
logits = torch.zeros(6, requires_grad=True)
ref_log_probs = torch.log_softmax(torch.zeros(6), dim=0) # frozen reference policy
correct = torch.tensor([0.0, 0.0, 0.0, 0.0, 1.0, 0.0])
optimizer = torch.optim.Adam([logits], lr=0.05)
beta = 0.04 # KL weight used in DeepSeekMath
print(f"P(correct) before: {torch.softmax(logits, dim=0)[4]:.2f}")
for step in range(150):
answers = torch.distributions.Categorical(logits=logits).sample((8,)) # a group of 8 sampled answers
rewards = correct[answers]
advantages = (rewards - rewards.mean()) / (rewards.std() + 1e-4) # the group mean replaces a critic
log_probs = torch.log_softmax(logits, dim=0)[answers]
# Per-sample KL estimate to the reference policy, added to the loss: exp(d) - d - 1 with d = ref - new
d = ref_log_probs[answers] - log_probs
loss = -(advantages * log_probs - beta * (torch.exp(d) - d - 1)).mean()
optimizer.zero_grad()
loss.backward()
optimizer.step()
print(f"P(correct) after: {torch.softmax(logits, dim=0)[4]:.2f}")It prints P(correct) before: 0.17 and P(correct) after: 0.98. At the start, about 23% of groups of 8 contain no correct answer, (5/6)⁸, and those groups contribute only the small KL term; every group that contains a correct answer pushes probability toward it without any value network.
GRPO vs. PPO and Other Methods#
- Proximal Policy Optimization: PPO estimates each token's advantage with a learned critic, usually a network as large as the policy itself, and in RLHF pipelines it folds the KL penalty into the reward. GRPO drops the critic and moves the KL term into the loss, trading critic memory for the extra generations needed to fill each group.
- REINFORCE with baselines: Methods such as REINFORCE Leave-One-Out (RLOO) also use the other sampled responses as a baseline. GRPO adds PPO's clipping and divides by the group's standard deviation.
- Direct Preference Optimization (DPO): DPO learns offline from a fixed dataset of preferred and rejected response pairs. GRPO is online: the model generates fresh responses and receives new rewards at every step.
- Process reward models: GRPO usually gives one outcome reward per response, but the DeepSeekMath paper also tested a process-supervision variant in which a model scores each reasoning step and each step's tokens get their own advantage.
Applications#
- Math reasoning: In DeepSeekMath, GRPO raised the 7B instruction-tuned model from 46.8% to 51.7% on the MATH benchmark and from 82.9% to 88.2% on GSM8K. DeepSeek-R1-Zero, trained with GRPO and rule-based rewards directly from the base model, improved its AIME 2024 pass@1 score from 15.6% to 71.0% and learned to write long chains of thought that re-check its own work.
- Code generation: Rewards from running generated programs against unit tests fit GRPO naturally, since each sampled program either passes the tests or fails them.
- Agents and tool use: Multi-turn tasks such as web search or software engineering are scored on the final outcome, and the group comparison assigns credit across whole trajectories.
GRPO also reaches beyond text. Flow-GRPO applied it to text-to-image models built on flow matching, using object counts and positions from an object detector as rewards. An Ultralytics YOLO26 detector can supply that kind of reward, counting the objects in each generated image of a group so that the images matching the requested count receive positive advantages.
Variants and Known Issues#
The original algorithm has several known weaknesses, and newer variants patch them:
- DAPO: ByteDance Seed's 2025 recipe discards groups whose responses are all right or all wrong and refills the batch, loosens the upper clipping bound so rare useful tokens can grow faster, and averages the loss over tokens instead of responses. It reached 50 points on AIME 2024 with a Qwen2.5-32B base model.
- Dr. GRPO: A 2025 analysis found that dividing each response's loss by its length lets incorrect answers grow longer without penalty, and that dividing by the group's standard deviation overweights questions that are nearly always solved or nearly always failed. Dr. GRPO removes both normalizations.
- GSPO: Alibaba's Qwen team computes the importance ratio for the whole sequence instead of each token, which stabilizes RL training of mixture-of-experts models, and credits it for improvements in its Qwen3 models.
Like every method that optimizes a reward, GRPO amplifies flaws in the reward signal. A verifier that only checks the final answer format, or unit tests that can be special-cased, invites reward hacking at the scale of thousands of sampled responses per step.










