---
title: "GRPO Explained: Group Relative Policy Optimization for LLMs"
description: "GRPO is PPO without the critic: it samples a group of answers per prompt and scores each against the group average. DeepSeekMath, DeepSeek-R1, TRL code."
url: https://launchkudos.com/news/llm-fine-tuning-grpo
section: AI
author: "Arnab Gupta"
published: 2026-12-05T02:20:49.416Z
updated: 2026-12-05T02:20:49.416Z
tags: [llm-fine-tuning, grpo, alignment, reinforcement-learning, deepseek]
---

# GRPO Explained: Group Relative Policy Optimization for LLMs

*GRPO is PPO without the critic: it samples a group of answers per prompt and scores each against the group average. DeepSeekMath, DeepSeek-R1, TRL code.*

*Part 14 of 15 in [LLM fine-tuning techniques](https://launchkudos.com/news/llm-fine-tuning-techniques)*

Group Relative Policy Optimization (GRPO) is a reinforcement learning method that trains a language model by sampling several answers to the same prompt and rewarding the ones that score above the group's average. DeepSeek introduced it in its February 2024 DeepSeekMath paper and later used it to train DeepSeek-R1 ([arXiv](https://arxiv.org/abs/2402.03300)).

- 46.8% → 51.7% · MATH accuracy, DeepSeekMath-Instruct 7B → RL 7B · DeepSeekMath, Table 5
- 15.6% → 77.9% · DeepSeek-R1-Zero AIME 2024 pass@1 during GRPO training · DeepSeek-R1, Sec. 2.3
- 0 · Value (critic) models, vs one for PPO · DeepSeekMath, Sec. 4.1.1
## What is GRPO?

GRPO is a variant of PPO (Proximal Policy Optimization) that drops PPO's value model. In the DeepSeekMath paper's words, "GRPO foregoes the critic model, instead estimating the baseline from group scores, significantly reducing training resources" ([Shao et al., 2024](https://arxiv.org/abs/2402.03300)). The baseline is the average reward of several answers to the same question.

Why that matters: PPO's value model "is typically another model of comparable size as the policy model", which the paper says "brings a substantial memory and computational burden" (Sec. 4.1.1). Removing it leaves the policy being trained, a frozen reference model, and whatever produces the rewards.

## How does GRPO work?

For each question, GRPO samples a group of G answers from the current model, scores each one, and converts the scores into advantages by subtracting the group mean and dividing by the group standard deviation. Answers above the group average are reinforced; answers below it are discouraged ([DeepSeekMath, Sec. 4.1.2](https://arxiv.org/abs/2402.03300)).

![Diagram of GRPO: one prompt produces four sampled answers, each gets a reward, the rewards are normalized against the group mean and standard deviation to give advantages, and the policy is updated with a clipped objective plus a KL term](https://launchkudos.com/media/ef4e3b2c0917672c1d2b.webp)

Step by step, following Equation 3 and Algorithm 1 of the paper:

1. **Sample a group.** For question q, draw G outputs o₁…o_G from the current ("old") policy. DeepSeekMath used G = 64 (Sec. 4.2).
2. **Score each output.** A reward model, or in later work a rule, gives each output a reward r_i.
3. **Normalize within the group.** Advantage A_i = (r_i − mean(r)) / std(r). With outcome supervision, every token of output i gets the same advantage (Sec. 4.1.2).
4. **Update with a clipped objective.** As in PPO, the probability ratio between the new and old policy is clipped to [1 − ε, 1 + ε], so one update can't move the model too far.
5. **Stay close to the reference.** GRPO adds a KL-divergence penalty to the reference model "directly ... to the loss" instead of folding it into the reward as PPO does, weighted by β. DeepSeekMath used β = 0.04 (Sec. 4.2).

### Worked example: advantages for one prompt

Say G = 4 and a checker marks answers right (1) or wrong (0). Our arithmetic, using the paper's formula with the population standard deviation:

| Answer | Reward r_i | r_i − mean | Advantage A_i |
|---|---|---|---|
| o₁ | 1 | +0.75 | **+1.73** |
| o₂ | 0 | −0.25 | **−0.58** |
| o₃ | 0 | −0.25 | **−0.58** |
| o₄ | 0 | −0.25 | **−0.58** |

Mean = 0.25, standard deviation ≈ 0.433. The one correct answer is pushed up strongly; the three wrong ones are pushed down a little each. With the sample standard deviation (dividing by G − 1) the advantages become +1.5 and −0.5: the scale changes, the signs don't.

Two edge cases follow from the formula. If all four answers are right, or all are wrong, every r_i − mean is 0 and the prompt contributes no learning signal; TRL logs the share of such groups as `frac_reward_zero_std` ([TRL docs](https://huggingface.co/docs/trl/grpo_trainer)). And because only relative scores matter, adding a constant to every reward changes nothing.

## When was GRPO introduced, and by whom?

GRPO was introduced in "DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models" by Zhihong Shao, Peiyi Wang, Qihao Zhu, Runxin Xu, Junxiao Song, Xiao Bi, Haowei Zhang, Mingchuan Zhang, Y.K. Li, Y. Wu and Daya Guo of DeepSeek-AI, Tsinghua University and Peking University. It was posted to arXiv on February 5, 2024 ([arXiv 2402.03300](https://arxiv.org/abs/2402.03300)).

DeepSeek then used GRPO as the RL algorithm for DeepSeek-R1-Zero and DeepSeek-R1, described in "DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning", first posted January 22, 2025 and published in *Nature* volume 645 (2025) ([arXiv 2501.12948](https://arxiv.org/abs/2501.12948)).

## What results did the GRPO papers report?

In DeepSeekMath, GRPO took the 7B instruction-tuned model from 46.8% to 51.7% on MATH and from 82.9% to 88.2% on GSM8K, training only on chain-of-thought questions from those two benchmarks' SFT data, about 144,000 questions ([DeepSeekMath, Sec. 4.2, Table 5](https://arxiv.org/abs/2402.03300)).

| Benchmark (chain-of-thought) | DeepSeekMath-Instruct 7B | DeepSeekMath-RL 7B (GRPO) |
|---|---|---|
| GSM8K | 82.9% | 88.2% |
| MATH | 46.8% | 51.7% |
| MGSM-zh | 73.2% | 79.6% |
| CMATH | 84.6% | 88.8% |

*Source: DeepSeekMath, Table 5. MGSM-zh and CMATH were not in the RL training data; the paper treats them as out-of-domain.*

DeepSeek-R1 scaled GRPO up. Starting from DeepSeek-V3-Base with no supervised fine-tuning first, DeepSeek-R1-Zero's average AIME 2024 pass@1 rose "from an initial 15.6% to 77.9%", and 86.7% with self-consistency decoding ([DeepSeek-R1, Sec. 2.3](https://arxiv.org/abs/2501.12948)). The final multi-stage DeepSeek-R1 scored 79.8% on AIME 2024 and 97.3% on MATH-500 (Table 3).

| Setting | DeepSeekMath (2024) | DeepSeek-R1-Zero (2025) |
|---|---|---|
| Starting model | DeepSeekMath-Instruct 7B (after SFT) | DeepSeek-V3-Base (no SFT) |
| Reward | Neural reward model | Rule-based: accuracy + format |
| Outputs per question (G) | 64 | 16 |
| KL coefficient β | 0.04 | 0.001 |
| Learning rate | 1e-6 | 3e-6 |
| Max length | 1,024 tokens | 32,768, then 65,536 after step 8.2k |

*Sources: DeepSeekMath Sec. 4.2; DeepSeek-R1 Sec. 2.1–2.2.*

## How is GRPO different from PPO, DPO and RLVR?

GRPO differs from PPO in its baseline: PPO learns a value model and computes advantages with Generalized Advantage Estimation, while GRPO uses the mean reward of a sampled group. It also puts the KL penalty in the loss rather than in the per-token reward ([DeepSeekMath, Sec. 4.1.1](https://arxiv.org/abs/2402.03300)).

| | PPO (RLHF) | GRPO | DPO |
|---|---|---|---|
| Learns from | Rewards on fresh samples | Rewards on fresh samples (groups) | Fixed chosen/rejected pairs |
| Value (critic) model | Yes | No | No |
| Baseline for advantage | Learned value function (GAE) | Group mean, scaled by group std | n/a |
| KL to reference | Per-token penalty in the reward | Separate term in the loss | Built into the loss via β |
| Online or offline | Online | Online | Offline |

DeepSeek-R1's supplement compared the two directly on MATH with DeepSeek-Coder-V2-Lite (16B MoE, 2.4B active). With GAE λ = 0.95, "PPO performs considerably worse than GRPO"; tuned to λ = 1.0, PPO came close. The authors still call GRPO "a more practical alternative" because it avoids training a value model ([DeepSeek-R1, Supplementary A.3](https://arxiv.org/abs/2501.12948)).

[DPO](https://launchkudos.com/news/llm-fine-tuning-dpo) needs no rewards at all, only preference pairs, and does not sample during training. DeepSeekMath groups DPO with offline methods and GRPO with online ones (Sec. 5.2.1). [RLVR](https://launchkudos.com/news/llm-fine-tuning-rlvr) is about the reward, not the optimizer: a programmatic check of correctness. Tülu 3 ran RLVR with PPO; DeepSeek-R1-Zero's rule-based rewards are the same idea run with GRPO. [RLHF](https://launchkudos.com/news/llm-fine-tuning-rlhf) and [RLAIF](https://launchkudos.com/news/llm-fine-tuning-rlaif) describe where preference signals come from, people or an AI model.

## Which libraries support GRPO?

Hugging Face TRL implements GRPO as `GRPOTrainer` configured with `GRPOConfig`, citing the DeepSeekMath paper ([TRL docs](https://huggingface.co/docs/trl/grpo_trainer)). Rewards can come from a reward model or from plain Python functions passed as `reward_funcs`, and TRL ships ready-made functions such as `accuracy_reward` and `think_format_reward` in `trl.rewards`.

TRL's defaults differ from the original paper in documented ways: `beta` defaults to 0.0 (no KL term, so no reference model is loaded), `loss_type` defaults to `"dapo"`, and `num_generations` defaults to 8. TRL's docs list an asynchronous GRPO trainer too. Ai2's [Open Instruct](https://allenai.github.io/open-instruct/algorithms/grpo/) research codebase also has GRPO scripts (`grpo.py`, `grpo_fast.py`), used for its Olmo 3 RL runs. GRPO is also the RL step in our explainer on [distillation, LoRA and GRPO](https://launchkudos.com/news/distillation-lora-grpo-explained).

## How do you use GRPO in code?

With TRL, you give `GRPOTrainer` a model, one or more reward functions and a prompt dataset. The example follows TRL's quick start, which trains Qwen2.5-0.5B-Instruct on DeepMath-103K with the built-in math `accuracy_reward` (install with `pip install trl[math_verify]`) ([TRL GRPO Trainer docs](https://huggingface.co/docs/trl/grpo_trainer), v1.19.0).

```python
from datasets import load_dataset
from trl import GRPOConfig, GRPOTrainer
from trl.rewards import accuracy_reward

dataset = load_dataset("trl-lib/DeepMath-103K", split="train")

training_args = GRPOConfig(
    output_dir="Qwen2.5-0.5B-GRPO",
    num_generations=8,   # group size G
    beta=0.0,            # KL coefficient; DeepSeekMath used 0.04
)

trainer = GRPOTrainer(
    model="Qwen/Qwen2.5-0.5B-Instruct",
    reward_funcs=accuracy_reward,
    args=training_args,
    train_dataset=dataset,
)
trainer.train()
```

TRL's docs say this run, distributed across 8 GPUs, "takes approximately 1 day". To mirror DeepSeek-R1's two rewards, pass a list: `reward_funcs=[accuracy_reward, think_format_reward]`; TRL sums them, or weights them with `reward_weights` in `GRPOConfig`.

## Common pitfalls with GRPO

- **Groups with no spread teach nothing.** If every answer in a group gets the same reward, all advantages are 0 (see the worked example). Watch TRL's `frac_reward_zero_std`; prompts that are always solved or never solved waste compute.
- **Length bias in the original loss.** TRL's docs say averaging each answer's loss over its own length (the paper's 1/|o_i|) "introduces a response-level length bias", citing the Dr. GRPO paper. Its `loss_type` options `"dapo"` (default) and `"dr_grpo"` normalize differently ([TRL docs](https://huggingface.co/docs/trl/grpo_trainer)).
- **Std scaling and question difficulty.** Dividing by the group's standard deviation "may cause a question-level difficulty bias", per TRL's docs; `scale_rewards=False` turns it off and `"batch"` scales by the batch's standard deviation instead.
- **Batch size must fit the group.** TRL requires the effective batch size to be evenly divisible by `num_generations`.
- **Neural reward models get hacked.** DeepSeek-R1 avoided neural reward models for reasoning because they "are susceptible to reward hacking during large-scale reinforcement learning" (Sec. 2.2), and it limited model-based preference rewards to the final 400 of 1,700 steps of its second RL stage for the same reason (Sec. 3.2.2).
- **Clip ratio matters.** DeepSeek-R1 reports that a lower clip value "can lead to the truncation of gradients for a significant number of tokens", degrading performance (Sec. 3.2.1).
- **RL may sharpen rather than add ability.** DeepSeekMath found RL improved Maj@K but not Pass@K, suggesting gains came from "boosting the correct response from TopK rather than the enhancement of fundamental capabilities" (Sec. 5.2.2).
- **Readability.** DeepSeek-R1-Zero showed "poor readability and language mixing"; DeepSeek-R1 added cold-start data and a language-consistency reward to fix it (Sec. 1, 3.2.1).

> **> We read the full DeepSeekMath paper (arXiv 2402.03300v3) and the full DeepSeek-R1 paper (arXiv 2501.12948v2; its arXiv record lists the *Nature* journal reference) on December 4, 2026, and took every number from the cited sections and tables. The worked advantage example is our own arithmetic using the paper's formula. Class, function and argument names, and their defaults, were checked against the TRL GRPO Trainer and Reward Functions documentation (v1.19.0) and Ai2's Open Instruct GRPO page the same day.**

## FAQ

### Does GRPO need a reward model?
No. GRPO needs a reward for each sampled answer, which can come from a trained reward model or a function. DeepSeekMath used a reward model; DeepSeek-R1-Zero used rule-based accuracy and format rewards. TRL accepts both through `reward_funcs`.

### What does "group relative" mean in GRPO?
Each answer is judged against the other answers to the same prompt: its advantage is its reward minus the group mean, divided by the group standard deviation. That comparison replaces PPO's learned value model.

### How many answers per prompt does GRPO use?
DeepSeekMath sampled 64 outputs per question; DeepSeek-R1-Zero sampled 16. TRL's `num_generations` defaults to 8.

### Is GRPO better than PPO?
In DeepSeek-R1's comparison on MATH, PPO with default settings did considerably worse than GRPO, and nearly matched it once tuned (GAE λ = 1.0). DeepSeek calls GRPO more practical because it skips training a value model of similar size to the policy.

### Who invented GRPO?
Researchers at DeepSeek-AI, with co-authors from Tsinghua and Peking universities, in the DeepSeekMath paper posted February 5, 2024. Zhihong Shao is the first author.

### Did DeepSeek-R1 use GRPO?
Yes. The DeepSeek-R1 paper says GRPO "is the reinforcement learning algorithm that we adopt to train DeepSeek-R1-Zero and DeepSeek-R1".

### Does TRL's GRPO use a KL penalty?
Not by default. TRL sets `beta` to 0.0, citing studies that found the KL term "is not essential", so the reference model isn't loaded. Set `beta` above 0 to add it; DeepSeek-R1 used 0.001.

### Can you run GRPO with LoRA?
Yes. TRL's `GRPOTrainer` accepts a `peft_config` argument for PEFT adapters; see [LoRA](https://launchkudos.com/news/llm-fine-tuning-lora) and [QLoRA](https://launchkudos.com/news/llm-fine-tuning-qlora) for how adapters cut trainable parameters.

## Related techniques

- [RLHF](https://launchkudos.com/news/llm-fine-tuning-rlhf): reward model plus PPO, the setup GRPO simplifies
- [RLAIF](https://launchkudos.com/news/llm-fine-tuning-rlaif): preference labels from an AI model
- [DPO](https://launchkudos.com/news/llm-fine-tuning-dpo): offline preference optimization, no sampling
- [RLVR](https://launchkudos.com/news/llm-fine-tuning-rlvr): verifiable rewards, often optimized with GRPO
- [Distillation, LoRA and GRPO explained](https://launchkudos.com/news/distillation-lora-grpo-explained)
- [All 15 LLM fine-tuning techniques](https://launchkudos.com/news/llm-fine-tuning-techniques)

## Sources

1. Shao, Z., Wang, P., Zhu, Q., Xu, R., Song, J., Bi, X., Zhang, H., Zhang, M., Li, Y. K., Wu, Y., Guo, D. "[DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models](https://arxiv.org/abs/2402.03300)." arXiv 2402.03300, Feb. 5, 2024 (v3 Apr. 27, 2024). Read Dec. 4, 2026.
2. Hugging Face. "[GRPO Trainer](https://huggingface.co/docs/trl/grpo_trainer)." TRL documentation, v1.19.0. Read Dec. 4, 2026.
3. Hugging Face. "[Reward Functions](https://huggingface.co/docs/trl/rewards)." TRL documentation, v1.19.0. Read Dec. 4, 2026.
4. Ai2. "[Grouped Relative Policy Optimization (GRPO)](https://allenai.github.io/open-instruct/algorithms/grpo/)." Open Instruct documentation. Read Dec. 4, 2026.
5. DeepSeek-AI (Guo, D., et al.). "[DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning](https://arxiv.org/abs/2501.12948)." arXiv 2501.12948, Jan. 22, 2025 (v2 Jan. 4, 2026); *Nature* 645, 633–638 (2025). Read Dec. 4, 2026.

**Series:** [← Prev: DPO](https://launchkudos.com/news/llm-fine-tuning-dpo) · [All 15 techniques](https://launchkudos.com/news/llm-fine-tuning-techniques) · [Next: RLVR →](https://launchkudos.com/news/llm-fine-tuning-rlvr)
