Qwen 3 GSPO & DeepSeek GRPO — LLM Reasoning

See how DeepSeek's GRPO turns a group's rewards into advantages, and how Qwen's GSPO swaps token ratios for one length-normalized sequence ratio.

Ask a model the same arithmetic question four times. A checker gives reward 1 for a correct final answer and 0 otherwise. Suppose the rewards are [1, 0, 1, 0].

The model produced both successful and unsuccessful attempts. We can compare them within this group to form a learning signal, instead of training a separate model to predict the expected reward.

This is the starting idea of Group Relative Policy Optimization, or GRPO, introduced in DeepSeekMath. We will compare its outcome-reward version with Group Sequence Policy Optimization, or GSPO, from the Qwen team. Both adjust a language model using sampled responses and rewards; they weight those responses differently.

First, compare each reward with its group

Our four rewards have mean 0.5. Each reward lies 0.5 away from that mean. Square those distances, average them, and take the square root: √0.25 = 0.5. That is their population standard deviation, a measure of spread. Subtract the mean and divide by that spread:

$$\widehat A_i=\frac{R_i-\operatorname{mean}(R)}{\operatorname{std}(R)}$$

Rᵢ is response i's reward. The resulting advantages are [1, −1, 1, −1]. Positive means better than this group's average, not “proved good in every sense.” For outcome supervision, each generated token in one response receives that response's advantage.

What happens if all four responses earn 0? What if all four earn 1?

A final-answer checker also cannot establish that every intermediate reasoning step was correct. A response can reach the correct answer through flawed reasoning; the reward only measures what the checker actually checks.

The difference is where we form the ratio

Save the probability assigned to each generated token by the old model that sampled it. After an update, recompute the probability of that same token at the same prefix under the current model.

For one two-token response, suppose those probabilities are:

Token positionOld probabilityCurrent probabilityCurrent / old
10.200.402.0
20.500.250.5

These are conditional probabilities at different prefixes; a column is not a probability distribution that must sum to 1.

GRPO forms a separate ratio for each token. GSPO forms a ratio from the likelihood of the whole response, then normalizes it by response length. If the token ratios are r₁ through r_T:

$$s=\left(\prod_{t=1}^{T}r_t\right)^{1/T}$$

For our response, s = √(2 × 0.5) = 1. This is a geometric mean, not the arithmetic mean 1.25. The first token became more likely, the second less likely, and the full response likelihood happened to stay unchanged.

Calculate the difference before training anything

Both methods use a clipped policy term: take the smaller of ratio × advantage and clipped-ratio × advantage, then maximize it. The clipping interval in this arithmetic example is [0.8, 1.2]. Clipping leaves values inside unchanged and replaces values outside with the nearer endpoint: 2 becomes 1.2, while 0.5 becomes 0.8.

For a response with advantage +1, GRPO's two terms are 1.2 and 0.5. Their mean is 0.85. GSPO instead uses the length-normalized sequence ratio 1, giving a term of 1.

Run that comparison. The code also handles a group with zero spread. It is a calculation of the policy terms, not an RL trainer or a performance comparison.

We use +1 exactly for the comparison; the printed normalized advantages differ from ±1 by a tiny amount because of the stabilizer. Real implementations also mask padding and compute response length from actual generated tokens, not the padded array width.

Change the advantage in both clipped_term calls to −1. Can you predict which token term stays unclipped?

What the papers establish

DeepSeekMath's §4.1.2 describes the group-normalized outcome rewards. Look at its Figure 4 to see which separate value model GRPO removes. Removing that model does not remove the need to score responses, and the paper's complete objective includes a reference-policy KL term that our calculation omits.

The GSPO paper's §4.1, equations 5–7 defines the sequence objective and length normalization. Its §5.1 reports better training efficiency than its GRPO baseline for the tested Qwen3-30B-A3B-based setup. Inspect Figure 1 alongside the stated experimental settings; this is empirical evidence for that comparison, not a guarantee that GSPO wins on every task.

The paper uses substantially different clipping ranges for GSPO and GRPO. Our shared 0.2 was chosen only to make the arithmetic visible; it is not a training recommendation. Sequence-level clipping also does not mean every individual token probability stays close to its old value—the [2, 0.5] example already shows why.

  • Outcome-based GRPO compares rewards within a group of responses to the same prompt, avoiding a separately trained value model.
  • A response's normalized reward supplies its tokens' advantage. Zero reward spread needs explicit handling and gives no relative preference signal.
  • GRPO uses token probability ratios; GSPO uses a length-normalized sequence-likelihood ratio, the geometric mean of token ratios.
  • For ratios [2, 0.5], GSPO's ratio is 1, not the arithmetic mean 1.25.
  • Both use clipped objectives. Actual clipping settings differ; sequence clipping does not bound every token ratio.
  • The tiny comparison omits reference-policy KL and a training loop. Paper results depend on the tested setup and reward quality.