3.8PPO vs DPO vs GRPO
Three ways to push a language model toward better answers. PPO's clipped updates and critic, DPO's closed-form shortcut, and GRPO's group-relative advantages.
The shared core: make good samples more likely
Every method in this lesson is a variation on one idea from reinforcement learning, the policy gradient. The LLM is the policy : given a prompt, it generates a response. Generate a response, find out how good it was, then nudge the parameters to raise the log-probability of that response in proportion to how good it was:
The weight is the advantageAdvantageHow much better an action or answer turned out than expected. Policy-gradient methods push up the probability of positive-advantage actions and push down negative ones.: not the raw reward, but how much better than expected the response turned out. Subtracting the expectation (the baseline) matters enormously. If every answer gets a reward between 8 and 10, using raw rewards would push all of them up and learning would be slow and noisy. Using “reward minus typical reward” pushes the 10s up and the 8s down.
So the central question for every algorithm is: where does the baseline come from? PPO learns it with a second neural network. GRPO computes it from a group of samples. DPO sidesteps the question with algebra.
PPO is a coach who watches each practice debate, consults a judge (the reward model), and also keeps an assistant (the critic) whose job is to predict how well each debate should have gone. Feedback is “you did better or worse than the assistant expected”, and the coach never lets a student change their style too drastically in one session (clipping).
DPO is a coach who never watches live debates at all. They study a stack of old transcripts where judges marked “this speech beat that one”, and drill the student to lean toward the winners and away from the losers, without drifting far from their original style. GRPO has each student give the same speech six times, then ranks the six attempts against each other: above the group average is good, below is bad. No assistant needed; the group is its own yardstick.
PPO: careful steps with a critic
Proximal Policy OptimizationPPOProximal Policy Optimization: an RL algorithm that limits how far each update moves the policy. It was the classic RLHF workhorse. (Schulman et al., 2017) was the original engine of RLHF. One training iteration looks like this:
- Roll out. Sample responses from the current policy for a batch of prompts.
- Score. The reward model scores each finished response; a per-token KL penalty against the reference model is added (see the previous lesson).
- Estimate advantages. A criticCritic (value model)A network that predicts expected future reward from a state. PPO uses it as a baseline to compute advantages; GRPO drops it in favor of group statistics. (value model), usually another LLM-sized network, predicts at every token how much reward is still to come. Comparing what actually happened with those predictions gives a per-token advantage, computed with Generalized Advantage EstimationGeneralized Advantage Estimation (GAE)A way to compute advantages from a critic's value estimates that blends short and long horizons with a parameter λ, trading bias for variance. (GAE), which blends one-step and long-horizon estimates through a parameter .
- Update, carefully. Take several gradient steps on the same batch, using the clipped objective below so the policy can’t move too far from the one that generated the data.
The clipping is PPO’s signature. Let be the ratio between the new and old probability of a token. The objective is , with typically around 0.2. Explore it:
Once a good action is already 20% more likely than under the old policy, PPO stops pushing it further; once a bad action is 20% less likely, it stops pushing it down. Outside that band the objective is flat, so this sample contributes no gradient. Moves in the “wrong” direction are never clipped: the min keeps the pessimistic branch.
Things to notice:
- A > 0: raising the token’s probability helps, but only until . Beyond that the line is flat and the gradient is zero, so one lucky sample can’t drag the policy too far.
- A < 0: lowering the probability helps until , then stops.
- The other direction is never clipped. If a good token’s probability has fallen ( with ), the full gradient still applies to fix it. The
minalways picks the more pessimistic estimate.
PPO works, but it’s heavy. A full RLHF-with-PPO setup juggles four LLM-sized models: the policy, the reference, the reward model and the critic. The critic must be trained alongside the policy, it’s hard to make it accurate for long text, and the whole loop has many interacting hyperparameters. That cost motivated the two alternatives.
DPO: preference learning without RL
Direct Preference OptimizationDPODirect Preference Optimization: learns from preference pairs directly with a classification-style loss, with no separate reward model or RL loop. (Rafailov et al., 2023) starts from a neat mathematical observation. The KL-constrained RLHF objective (“maximize reward, minus times KL to the reference”) has a closed-form optimal policy:
Read it as: take the reference model and re-weight each response by its exponentiated reward. You can’t compute (it sums over every possible response), so you can’t use this directly. But you can invert it to express the reward in terms of the policy: . Plug that into the Bradley–Terry preference probability, and the troublesome appears in both terms of the difference and cancels. What’s left is a loss on the policy alone, using nothing but preference pairs.
The result is almost embarrassingly simple: for each pair, compute how much more the policy likes the chosen answer than the reference does, subtract the same quantity for the rejected answer, scale by , and apply a logistic loss. The quantity acts as an implicit reward: the policy is the reward model.
DPO’s appeal is practical: no reward model to train, no sampling during training, no critic, and a loss you can drop into an SFT-style training loop. It became the default for open-model preference tuning almost overnight. Its limitations are the flip side of the same choices. It is offline, learning only from fixed pairs, usually generated by some other model, so it never sees or corrects its own new mistakes. It can lower the probability of both the chosen and rejected answers as long as the gap grows. And it can overfit small preference sets. Many follow-up variants (IPO, KTO, SimPO, online and iterative DPO) target these issues.
GRPO: let the group be the baseline
Group Relative Policy OptimizationGRPOGroup Relative Policy Optimization: samples a group of answers per prompt and uses each answer's reward relative to the group average as its advantage. No value network is needed. was introduced in the DeepSeekMath paper (Shao et al., 2024) and became famous as the RL algorithm behind DeepSeek-R1. Its idea is in the name: for each prompt, sample a group of responses, score each one, and define each response’s advantage relative to the group:
Every token of response gets that same advantage, and the update uses PPO’s clipped ratio plus a KL penalty to the reference. What’s gone is the critic. The group average is the baseline: an empirical estimate of “how well does the policy typically do on this prompt?”, computed fresh for every prompt at the cost of extra samples rather than an extra network.
This fits reasoning tasks perfectly. With a math problem and an automatic checker, rewards are often just 1 (correct) or 0 (wrong). The group tells you how hard the problem currently is for the model: if 5 of 6 attempts succeed, the one failure is pushed down hard and the successes up gently; if only 1 of 6 succeeds, that rare success gets a big boost.
Advantages always sum to zero: the group is its own baseline. Answers better than their siblings are reinforced, worse ones suppressed, with no critic network involved.
Things to try:
- Make one answer pass and the rest fail. The lone success gets a large positive advantage; each failure a small negative one.
- Click “All pass”. The std is zero and every advantage is zero. A prompt that’s too easy (or too hard: all fail) teaches nothing. This wasted compute is real; one of DAPO’s fixes is to filter such groups out and sample more.
- Switch off the std scaling. Advantages become . With std scaling, a prompt where answers barely differ gets its tiny differences amplified to unit size; without it, they stay tiny. Which is better is debated (see Dr. GRPO below).
- Notice that the advantages always sum to zero. Within a group, GRPO only redistributes probability among the sampled answers.
Newer variants (briefly)
GRPO set off a wave of refinements in 2025. A few that are well documented on arXiv, each described only at the level its paper supports:
- DAPO (ByteDance Seed and collaborators, March 2025, arXiv 2503.14476) combines four techniques: “Clip-Higher” (a larger upper clip bound so low-probability tokens can grow, helping exploration), dynamic sampling (dropping groups whose answers are all right or all wrong), a token-level policy-gradient loss (so long responses aren’t under-weighted), and overlong reward shaping. The authors report 50 points on AIME 2024 with a Qwen2.5-32B base model.
- Dr. GRPO (“Understanding R1-Zero-Like Training: A Critical Perspective”, March 2025, arXiv 2503.20783) argues that GRPO’s per-response length normalization and std normalization introduce biases, notably one that inflates the length of incorrect responses, and removes them.
- GSPO (“Group Sequence Policy Optimization”, July 2025, arXiv 2507.18071), from the Qwen team, computes the importance ratio and clipping at the level of the whole sequence rather than per token, and reports more stable training, especially for mixture-of-experts models.
The field moves quickly, and each paper’s reported gains come from its own setup, so treat these as directions rather than settled rankings.
MATH CORNER · optionalThe DPO loss and the GRPO objective, with numbers
DPO. Starting from the optimal-policy identity above, write . Substituting into Bradley–Terry, , because the terms cancel. Maximizing the likelihood of the observed preferences gives
Worked example. Sequence log-probabilities (summed over tokens), with :
| policy | reference | log-ratio | |
|---|---|---|---|
| chosen | |||
| rejected |
Margin , so and the loss is . The gradient pushes the chosen log-ratio up and the rejected one down, weighted by : pairs the model already ranks confidently get little weight.
GRPO. For a prompt , sample outputs from with rewards , and set . With the per-token ratio , the DeepSeekMath objective (to be maximized) is
The KL term is estimated per token as , which is always . The factor is the length normalization that Dr. GRPO removes.
Worked example. answers to a math problem; the verifier passes only one: . Then and (population) :
| answer | |||
|---|---|---|---|
| 1 | |||
| 0 | |||
| 0 | |||
| 0 |
The single success is reinforced three times as strongly as each failure is suppressed, and the four advantages sum to zero. (Implementations differ on sample vs population std; the demo uses population std.)
In code
The heart of GRPO is a few tensor operations. Here logp_new, logp_old and logp_ref are per-token log-probabilities of the sampled answers, shaped (G, T), and mask marks real (non-padding) tokens:
import torch
def grpo_loss(rewards, logp_new, logp_old, logp_ref, mask, eps=0.2, beta=0.04):
# 1. group-relative advantage, one scalar per answer
adv = (rewards - rewards.mean()) / (rewards.std(unbiased=False) + 1e-6)
adv = adv[:, None] # broadcast over tokens
# 2. PPO-style clipped surrogate per token
ratio = torch.exp(logp_new - logp_old)
surrogate = torch.min(ratio * adv, ratio.clamp(1 - eps, 1 + eps) * adv)
# 3. per-token KL to the reference (the 'k3' estimator)
log_r = logp_ref - logp_new
kl = torch.exp(log_r) - log_r - 1
per_token = surrogate - beta * kl
per_answer = (per_token * mask).sum(1) / mask.sum(1) # 1/|o_i| normalization
return -per_answer.mean() # minimize the negative
Compare a DPO step: it needs only four sequence log-probabilities per pair and one line, loss = -F.logsigmoid(beta * ((pc - rc) - (pr - rr))).mean(), with no sampling at all.
- “DPO is just as good as RL, always.” DPO optimizes the same objective in theory, assuming perfect coverage of preference data. In practice, being offline matters: it can’t learn from its own fresh outputs, and online methods often do better on tasks with checkable answers.
- “GRPO doesn’t need a reward.” It doesn’t need a critic. It still needs a reward for every sampled answer, from a verifier or a reward model.
- “Clipping stops the policy from changing much overall.” Clipping limits how far each batch moves the policy relative to the policy that sampled it. Over thousands of iterations the policy can travel very far; that’s what the KL penalty and monitoring are for.
- “A bigger group is always better.” Larger G gives a better baseline but costs proportionally more generation, which dominates RL compute for long reasoning traces. Groups where every answer gets the same reward are pure waste regardless of size.
Check your understanding
Q1.What does GRPO use instead of PPO's learned critic to compute advantages?
Q2.In a GRPO group, all 8 answers to a prompt are correct (reward 1). What happens?
Q3.In PPO, a token has positive advantage and its probability ratio r is already 1.5 with ε = 0.2. What does the clipped objective do?
Q4.Why does the partition function Z(x) disappear in the DPO derivation?
Q5.Which statement best describes DPO compared with PPO-based RLHF?
Further reading
- paperProximal Policy Optimization Algorithms — Schulman et al., 2017. The clipped surrogate objective.
- paperHigh-Dimensional Continuous Control Using Generalized Advantage Estimation — Schulman et al., 2015. GAE, the advantage estimator used with PPO.
- paperDirect Preference Optimization: Your Language Model is Secretly a Reward Model — Rafailov et al., 2023. The closed-form derivation and the DPO loss.
- paperDeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models — Shao et al., 2024. Introduces GRPO.
- paperDAPO: An Open-Source LLM Reinforcement Learning System at Scale — 2025. Clip-Higher, dynamic sampling and other GRPO refinements.
- paperUnderstanding R1-Zero-Like Training: A Critical Perspective (Dr. GRPO) — 2025. Biases in GRPO's normalization and how to remove them.