Skip to content
LearnAI

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.

⏱ 17 minAdvanced

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 πθ\pi_\theta: 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:

∇θJ≈A⏟how much better than expected⋅∇θlog⁡πθ(y∣x).\nabla_\theta J \approx \underbrace{A}_{\text{how much better than expected}} \cdot \nabla_\theta \log \pi_\theta(y \mid x).

The weight AA 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.

ANALOGY· Three ways to coach a debate team

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:

  1. Roll out. Sample responses from the current policy for a batch of prompts.
  2. Score. The reward model scores each finished response; a per-token KL penalty against the reference model is added (see the previous lesson).
  3. 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 λ\lambda.
  4. 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 r=πθ(yt)/πold(yt)r = \pi_\theta(y_t) / \pi_{\text{old}}(y_t) be the ratio between the new and old probability of a token. The objective is min⁡(rA, clip(r,1−ϵ,1+ϵ) A)\min\big(r A,\ \text{clip}(r, 1-\epsilon, 1+\epsilon)\, A\big), with ϵ\epsilon typically around 0.2. Explore it:

INTERACTIVEPPO's clipped objective
Advantage A = +1 (good action)
00.511.52-2-1012ratio r = π_new / π_old
L = 1.20 · clipped: gradient = 0
Advantage A = −1 (bad action)
00.511.52-2-1012ratio r = π_new / π_old
L = -1.35 · gradient dL/dr = −1
clipped objective unclipped r·A [1−ε, 1+ε]

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.

The objective as a function of the probability ratio r, for a good token (A > 0) and a bad one (A < 0). Move r and ε. Flat stretches mean zero gradient: the update has gone far enough.

Things to notice:

  1. A > 0: raising the token’s probability helps, but only until r=1+ϵr = 1 + \epsilon. Beyond that the line is flat and the gradient is zero, so one lucky sample can’t drag the policy too far.
  2. A < 0: lowering the probability helps until r=1−ϵr = 1 - \epsilon, then stops.
  3. The other direction is never clipped. If a good token’s probability has fallen (r<1r < 1 with A>0A > 0), the full gradient still applies to fix it. The min always 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 β\beta times KL to the reference”) has a closed-form optimal policy:

π∗(y∣x)=1Z(x) πref(y∣x) exp⁡ ⁣(r(x,y)/β).\pi^*(y \mid x) = \frac{1}{Z(x)}\, \pi_{\text{ref}}(y \mid x)\, \exp\!\big(r(x, y)/\beta\big).

Read it as: take the reference model and re-weight each response by its exponentiated reward. You can’t compute Z(x)Z(x) (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: r(x,y)=βlog⁡π∗(y∣x)πref(y∣x)+βlog⁡Z(x)r(x,y) = \beta \log \frac{\pi^*(y \mid x)}{\pi_{\text{ref}}(y \mid x)} + \beta \log Z(x). Plug that into the Bradley–Terry preference probability, and the troublesome Z(x)Z(x) 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 β\beta, and apply a logistic loss. The quantity βlog⁡πθ(y∣x)πref(y∣x)\beta \log \frac{\pi_\theta(y \mid x)}{\pi_{\text{ref}}(y \mid x)} 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 GG responses, score each one, and define each response’s advantage relative to the group:

Ai=ri−mean⁡(r1,…,rG)std⁡(r1,…,rG).A_i = \frac{r_i - \operatorname{mean}(r_1, \dots, r_G)}{\operatorname{std}(r_1, \dots, r_G)}.

Every token of response ii 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.

INTERACTIVEGRPO group-advantage calculator
Reward
Advantage
Prompt: What is 17 × 24? · the policy sampled 6 answers
o1: 17 × 24 = 17 × 20 + 17 × 4 = 340 + 68 = 408.
A = +1.00 ▲ push up
o2: 17 × 24 ≈ 17 × 25 = 425.
A = -1.00 ▼ push down
o3: 24 × 17 = 24 × 10 + 24 × 7 = 240 + 168 = 408.
A = +1.00 ▲ push up
o4: 17 × 24 = 398.
A = -1.00 ▼ push down
o5: (20 − 3) × 24 = 480 − 72 = 408.
A = +1.00 ▲ push up
o6: 17 × 24 = 17 × 2 × 12 = 34 × 12 = 418.
A = -1.00 ▼ push down
mean reward
0.500
std of rewards
0.500
passed
3 / 6
Σ advantages
0.00

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.

One prompt, a group of sampled answers. Toggle the verifier's pass/fail (or switch to graded scores), change the group size, and watch mean, std and every advantage update live. Then try 'All pass'.

Things to try:

  1. Make one answer pass and the rest fail. The lone success gets a large positive advantage; each failure a small negative one.
  2. 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.
  3. Switch off the std scaling. Advantages become r−meanr - \text{mean}. 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).
  4. 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 r^θ(x,y)=βlog⁡πθ(y∣x)πref(y∣x)\hat r_\theta(x, y) = \beta \log \frac{\pi_\theta(y \mid x)}{\pi_{\text{ref}}(y \mid x)}. Substituting into Bradley–Terry, P(yw≻yl)=σ(r^θ(x,yw)−r^θ(x,yl))P(y_w \succ y_l) = \sigma(\hat r_\theta(x, y_w) - \hat r_\theta(x, y_l)), because the βlog⁡Z(x)\beta \log Z(x) terms cancel. Maximizing the likelihood of the observed preferences gives

LDPO(θ)=− E(x,yw,yl)[log⁡σ ⁣(βlog⁡πθ(yw∣x)πref(yw∣x)−βlog⁡πθ(yl∣x)πref(yl∣x))].\mathcal{L}_{\text{DPO}}(\theta) = -\,\mathbb{E}_{(x, y_w, y_l)} \left[ \log \sigma\!\left( \beta \log \frac{\pi_\theta(y_w \mid x)}{\pi_{\text{ref}}(y_w \mid x)} - \beta \log \frac{\pi_\theta(y_l \mid x)}{\pi_{\text{ref}}(y_l \mid x)} \right) \right].

Worked example. Sequence log-probabilities (summed over tokens), with β=0.1\beta = 0.1:

policy log⁡πθ\log \pi_\thetareference log⁡πref\log \pi_{\text{ref}}log-ratio
chosen ywy_w−10.0-10.0−11.0-11.0+1.0+1.0
rejected yly_l−12.0-12.0−11.5-11.5−0.5-0.5

Margin =0.1×(1.0−(−0.5))=0.15= 0.1 \times (1.0 - (-0.5)) = 0.15, so σ(0.15)=0.537\sigma(0.15) = 0.537 and the loss is −ln⁡0.537=0.621-\ln 0.537 = 0.621. The gradient pushes the chosen log-ratio up and the rejected one down, weighted by 1−σ=0.4631 - \sigma = 0.463: pairs the model already ranks confidently get little weight.

GRPO. For a prompt qq, sample GG outputs o1,…,oGo_1, \dots, o_G from πold\pi_{\text{old}} with rewards rir_i, and set Ai=(ri−mean(r))/std(r)A_i = (r_i - \text{mean}(r)) / \text{std}(r). With the per-token ratio ρi,t=πθ(oi,t∣q,oi,<t)/πold(oi,t∣q,oi,<t)\rho_{i,t} = \pi_\theta(o_{i,t} \mid q, o_{i,<t}) / \pi_{\text{old}}(o_{i,t} \mid q, o_{i,<t}), the DeepSeekMath objective (to be maximized) is

J(θ)=E[1G∑i=1G1∣oi∣∑t=1∣oi∣(min⁡(ρi,tAi, clip(ρi,t,1−ϵ,1+ϵ)Ai)−β DKL[πθ ∥ πref])].\mathcal{J}(\theta) = \mathbb{E}\left[ \frac{1}{G} \sum_{i=1}^{G} \frac{1}{|o_i|} \sum_{t=1}^{|o_i|} \Big( \min\big( \rho_{i,t} A_i,\ \text{clip}(\rho_{i,t}, 1-\epsilon, 1+\epsilon) A_i \big) - \beta\, \mathbb{D}_{\text{KL}}\big[\pi_\theta \,\|\, \pi_{\text{ref}}\big] \Big) \right].

The KL term is estimated per token as πrefπθ−log⁡πrefπθ−1\frac{\pi_{\text{ref}}}{\pi_\theta} - \log \frac{\pi_{\text{ref}}}{\pi_\theta} - 1, which is always ≥0\ge 0. The 1/∣oi∣1/|o_i| factor is the length normalization that Dr. GRPO removes.

Worked example. G=4G = 4 answers to a math problem; the verifier passes only one: r=(1,0,0,0)r = (1, 0, 0, 0). Then mean=0.25\text{mean} = 0.25 and (population) std=0.25×0.75=0.433\text{std} = \sqrt{0.25 \times 0.75} = 0.433:

answerrir_iri−0.25r_i - 0.25AiA_i
o1o_11+0.75+0.75+1.732+1.732
o2o_20−0.25-0.25−0.577-0.577
o3o_30−0.25-0.25−0.577-0.577
o4o_40−0.25-0.25−0.577-0.577

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.

COMMON MISCONCEPTIONS
  • “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

0/5 answered
  1. Q1.What does GRPO use instead of PPO's learned critic to compute advantages?

  2. Q2.In a GRPO group, all 8 answers to a prompt are correct (reward 1). What happens?

  3. 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?

  4. Q4.Why does the partition function Z(x) disappear in the DPO derivation?

  5. Q5.Which statement best describes DPO compared with PPO-based RLHF?

Further reading

Progress is saved in this browser only.
Type to search across all lessons and glossary terms.