Sam Babichenko

Reading notes / Reinforcement learning for reasoning

Group Sequence Policy Optimization

Zheng et al., 2025

Sampling
q;q; oi;o_i; oi,to_{i,t}question; ii-th sampled answer; its tt-th token
G;G; ∣oi∣|o_i|answers per question; length of oio_i in tokens
πθ;\pi_\theta; πold\pi_{\rm old}policy being trained; policy that sampled the batch
πθ(oi,t∣⋅)\pi_\theta(o_{i,t}\mid\cdot)probability of oi,to_{i,t} given qq and oi,<to_{i,\lt t}
μ\muoptimizer updates per sampled batch (4 here)
Rewards, ratios, gradients
Ri;R_i; A^i\hat A_ireward of oio_i; its group-normalized advantage
ρi,t\rho_{i,t}token ratio πθ(oi,t∣⋅)/πold(oi,t∣⋅)\pi_\theta(o_{i,t}\mid\cdot)/\pi_{\rm old}(o_{i,t}\mid\cdot)
sis_iGSPO's sequence ratio, the geometric mean of the ρi,t\rho_{i,t}
gi,t;g_{i,t}; wi,tw_{i,t}∇θlog⁡πθ(oi,t∣⋅)\nabla_\theta\log\pi_\theta(o_{i,t}\mid\cdot); its weight in the gradient (sis_i or ρi,t\rho_{i,t})
A^i,t;\hat A_{i,t}; si,t;s_{i,t}; sg⁡\operatorname{sg}per-token advantage; GSPO-token's ratio; stop-gradient (Step 5)
Constants
ε\varepsilonGRPO's symmetric clip range (0.2 by default)
εlow,\varepsilon_{\rm low}, εhigh\varepsilon_{\rm high}lower and upper clip ranges: 3×10−43\times10^{-4} and 4×10−44\times10^{-4} for GSPO, 0.2 and 0.27 for the GRPO baseline

Context. In reinforcement learning in which a program checks each answer (exact match, unit tests) and returns the reward, a group relative policy optimization: PPO without a value model, in which every token of an answer gets the answer's reward minus its group's mean reward, divided by the group's standard deviation, as advantage step samples a group of answers to each question, scores them, and then takes several gradient steps on that batch, one per minibatch. From the second minibatch on, the model being trained has moved away from the one that sampled the data. GRPO corrects for this as proximal policy optimization: a policy-gradient method whose objective multiplies each token's advantage by the token's probability ratio, current over sampling policy, and clips that ratio so each update moves the policy only a little does, token by token: each token's gradient is weighted by that token's probability ratio, and the token is clipped when its ratio leaves a narrow band around 1. Zheng et al. (2025) report that at large scale this training can collapse beyond repair (rolling back to an earlier checkpoint and retuning did not rescue it), that the problem grows with response length, and that for a transformer in which a learned router sends each token through a few of many feed-forward blocks (the experts) at each layer, so only part of the parameters is active per token models GRPO converged only with an extra fix, recording which experts the sampling policy used for each token of a sampled answer and forcing the trained policy to use the same experts when the ratio is computed. Their GSPO, group sequence policy optimization, computes one probability ratio per response and clips whole responses.

Zheng et al.'s principle is that the off-policy correction should act on the same unit as the reward. The reward is given to a whole response, so the ratio that corrects for stale samples, and that decides what is clipped, should also belong to the whole response. A long response has thousands of token ratios; each is computed from a single sampled token, each multiplies one token's gradient, and in a mixture-of-experts model each can jump when an update changes which experts the token is routed to. GSPO averages the token log-ratios over the response and exponentiates the average. This smooths out the token-level noise, gives every token of a response the same weight, and keeps or clips the response as a unit. On a mixture-of-experts model with 30B parameters, GSPO trained stably without Routing Replay and reached higher training reward and benchmark scores than GRPO for the same compute, while clipping about 15% of tokens against 0.13% for GRPO.

Setting. For a question qq, sample the number of answers sampled per question answers o1,…,oGo_1,\dots,o_G from the policy as it was when the batch was sampled; πθ\pi_\theta, with parameters θ\theta, is the policy being trained, write oi,to_{i,t} for token tt of oio_i and ∣oi∣|o_i| for its length in tokens, and score each answer with a reward Ri∈[0,1]R_i\in[0,1]. Every token of oio_i gets the advantage A^i=(Ri−Rˉ)/std⁡(R)\hat A_i=(R_i-\bar R)/\operatorname{std}(R), with Rˉ\bar R and std⁡(R)\operatorname{std}(R) the mean and standard deviation of the rewards in the group of qq. Each batch of answers is used for the number of optimizer updates made on one batch of sampled answers, one per minibatch; μ=1\mu=1 is fully on-policy updates (μ=4\mu=4 in the experiments), so within a batch πθ\pi_\theta drifts away from πold\pi_{\rm old}. Write πθ(oi,t∣⋅)\pi_\theta(o_{i,t}\mid\cdot) for the probability of oi,to_{i,t} given qq and the earlier tokens oi,<to_{i,\lt t}, and ρi,t\rho_{i,t}=πθ(oi,t∣⋅)/πold(oi,t∣⋅){}=\pi_\theta(o_{i,t}\mid\cdot)/\pi_{\rm old}(o_{i,t}\mid\cdot), the ratio of token tt. GRPO maximizes PPO's clipped objective token by token, with clip range the clip range: for a token with positive advantage the term stops contributing gradient once ρi,t>1+ε\rho_{i,t}\gt1+\varepsilon, and for negative advantage once ρi,t<1−ε\rho_{i,t}\lt1-\varepsilon and without the KL term, as in the paper:JGRPO(θ)=E[1G∑i=1G1∣oi∣∑t=1∣oi∣min⁡(ρi,tA^i,clip⁡(ρi,t,1−ε,1+ε)A^i)].\begin{aligned}&J_{\rm GRPO}(\theta)=\mathbb E\Big[\frac1G\sum_{i=1}^G\frac1{|o_i|}\sum_{t=1}^{|o_i|}\\&\quad\min\big(\rho_{i,t}\hat A_i,\\&\quad\operatorname{clip}(\rho_{i,t},1-\varepsilon,1+\varepsilon)\hat A_i\big)\Big].\end{aligned}GSPO replaces ρi,t\rho_{i,t} by one ratio per answer, the geometric mean of its token ratios,si(θ)=(πθ(oi∣q)πold(oi∣q))1/∣oi∣=exp⁡(1∣oi∣∑t=1∣oi∣log⁡ρi,t),\begin{aligned}s_i(\theta)&=\Big(\frac{\pi_\theta(o_i\mid q)}{\pi_{\rm old}(o_i\mid q)}\Big)^{1/|o_i|}\\&=\exp\Big(\frac1{|o_i|}\sum_{t=1}^{|o_i|}\log\rho_{i,t}\Big),\end{aligned}and maximizesJGSPO(θ)=E[1G∑i=1Gmin⁡(siA^i,clip⁡(si,1−εlow,1+εhigh)A^i)],\begin{aligned}&J_{\rm GSPO}(\theta)=\mathbb E\Big[\frac1G\sum_{i=1}^G\min\big(s_i\hat A_i,\\&\quad\operatorname{clip}(s_i,1-\varepsilon_{\rm low},1+\varepsilon_{\rm high})\hat A_i\big)\Big],\end{aligned}with lower and upper clip ranges GSPO's clip ranges in the experiments; the GRPO baseline uses 0.2 and 0.27 on its token ratios, several hundred times smaller than GRPO's because sis_i is a per-token average.

Main findings (empirical apart from the gradient comparison). (a) Without clipping, the two gradients differ only in how the tokens of an answer are weighted: GSPO gives every token of oio_i the weight sis_i, GRPO gives each token its own ρi,t\rho_{i,t}, and on the first minibatch, where both ratios are 1, the two gradients are equal. (b) On a mixture-of-experts model fine-tuned from Qwen3-30B-A3B-Base, GSPO trains stably and keeps improving as compute, fresh questions and longer generation limits are added, with higher training reward and higher scores on the 30 problems of the 2024 American Invitational Mathematics Examination, each with an integer answer; here pass@1 averaged over 32 samples per problem, a benchmark of recent competitive-programming problems scored by hidden tests; here problems from October 2024 to February 2025, pass@1 averaged over 8 samples and a competitive-programming site; the score is an Elo rating estimated from the model's solutions to its contest problems than GRPO at the same compute (curves only, no tables). (c) Averaged over training, GSPO clips 15% of tokens and GRPO 0.13%, so GSPO learns more from fewer tokens. (d) In this model about 10% of the experts used for a given answer change after one gradient update; GRPO fails to converge unless the routing is frozen with Routing Replay, while GSPO converges without it.

Consequences. For RL on long responses, and in particular on mixture-of-experts models, the change to a GRPO implementation is small: average each answer's token log-ratios, exponentiate, clip that number with ranges of order 10−410^{-4}, and weight all the answer's tokens by it. A clip fraction is not comparable between token and sequence clipping, so a high fraction under GSPO is not by itself a sign of trouble. The authors also expect GSPO to tolerate the small numerical differences between a training engine and an inference engine, since only an answer's average log-ratio enters, which would let one take πold\pi_{\rm old}'s log-probabilities from the inference engine instead of recomputing them with the trainer; this is argued without a measurement. Where tokens of one answer should get different advantages, as in multi-turn RL, a token-level variant keeps the sequence ratio (Step 5).

Step 1

The likelihood ratio of a whole answer is a product over its tokens, and GSPO uses that product's per-token geometric mean. Ez∼pf(z)=Ez∼b[p(z)b(z)f(z)]\mathbb E_{z\sim p}f(z)=\mathbb E_{z\sim b}\big[\tfrac{p(z)}{b(z)}f(z)\big]: estimating an average under a target distribution pp from samples of another distribution bb, each sample weighted by the ratio of the two densities corrects an average under one distribution using samples from another. The reward is a function of the whole answer, so the weight that corrects for sampling oio_i from πold\pi_{\rm old} is the answer's likelihood ratio πθ(oi∣q)/πold(oi∣q)=∏tρi,t\pi_\theta(o_i\mid q)/\pi_{\rm old}(o_i\mid q)=\prod_t\rho_{i,t}. GRPO instead multiplies each token's gradient by that token's ratio alone. The paper argues that a ratio computed from one sampled token per next-token distribution cannot perform the intended correction and instead adds high-variance noise, which accumulates over long answers and which clipping amplifies. The product itself is not usable either: it changes exponentially with length, so a few tokens whose probabilities moved can swing it by large factors, and answers of different lengths would need different clip ranges. Taking the ∣oi∣|o_i|-th root removes both problems. The scale of the clip range follows (my computation): on a 10,000-token answer, si≤1+4×10−4s_i\le1+4\times10^{-4} still allows the whole-answer likelihood ratio to reach e4≈55e^{4}\approx55, and si≥1−3×10−4s_i\ge1-3\times10^{-4} allows it to fall to about e−3≈0.05e^{-3}\approx0.05.

Step 2

The two gradients differ only in how the tokens of one answer are weighted. Write gi,t=∇θlog⁡πθ(oi,t∣⋅)g_{i,t}=\nabla_\theta\log\pi_\theta(o_{i,t}\mid\cdot), the gradient of the log-probability of token tt of oio_i for the gradient of a token's log-probability. Since ∇θρi,t=ρi,t gi,t\nabla_\theta\rho_{i,t}=\rho_{i,t}\,g_{i,t}, ∇θsi=si∇θlog⁡si\nabla_\theta s_i=s_i\nabla_\theta\log s_i, and log⁡si\log s_i is the average of the log⁡ρi,t\log\rho_{i,t}, whose gradients are the gi,tg_{i,t} because πold\pi_{\rm old} does not depend on θ\theta, both unclipped gradients have the form∇θJ=E[1G∑iA^i∣oi∣∑twi,t gi,t]\nabla_\theta J=\mathbb E\Big[\frac1G\sum_{i}\frac{\hat A_i}{|o_i|}\sum_{t}w_{i,t}\,g_{i,t}\Big]with token weight the weight of token tt of oio_i in the gradient: wi,t=siw_{i,t}=s_i for GSPO and wi,t=ρi,tw_{i,t}=\rho_{i,t} for GRPO equal to sis_i for GSPO and to ρi,t\rho_{i,t} for GRPO. On the first minibatch πθ=πold\pi_\theta=\pi_{\rm old}, every ρi,t\rho_{i,t} and sis_i equals 1, and the two are the same gradient. They part once the policy has moved: GRPO then weights the tokens of one answer unequally, by ratios that for the tokens still contributing lie in (0,1+ε](0,1+\varepsilon] when A^i>0\hat A_i\gt0 and in [1−ε,∞)[1-\varepsilon,\infty) when A^i<0\hat A_i\lt0, while GSPO scales the whole answer by one number. The paper's view is that these unequal token weights accumulate over training into the instability it observes; it shows the instability but does not measure the accumulation.

Step 3

At equal compute GSPO learns faster than GRPO while clipping about a hundred times more tokens. The model is a briefly fine-tuned on example solutions before RL, so that the base model starts RL already writing in the expected format fine-tune of Qwen3-30B-A3B-Base, a mixture-of-experts model with 30B parameters of which about 3B are active per token, and each batch of answers is split into four minibatches (μ=4\mu=4). GRPO is run with Routing Replay (Step 4) and clip ranges 0.2 and 0.27, which the authors tuned for a fair comparison. GSPO's training reward and its scores on AIME 2024, LiveCodeBench and CodeForces are higher than GRPO's at equal compute in the paper's curves, and keep rising as the authors add compute, refresh the question set and raise the generation limit. Averaged over training, GSPO clips 15% of tokens (as whole answers) against 0.13% for GRPO, and changing the clip ranges does not change the gap's order of magnitude. So GSPO learns more while using fewer tokens, which the authors read as evidence that GRPO's token-level gradient estimates are noisy and make poor use of the samples.

Step 4

In a mixture-of-experts model a token's ratio jumps when its routing changes; GRPO needs Routing Replay and GSPO does not. In the 48-layer Qwen3-30B-A3B-Base, after one gradient update about 10% of the experts activated for the same answer differ between πθ\pi_\theta and πold\pi_{\rm old}. A token's two probabilities are then computed by partly different networks, so its ratio ρi,t\rho_{i,t} can move far more than the size of the update would suggest; the effect is larger in deeper models. Routing Replay makes both probabilities come from the same experts; without it GRPO's training does not converge properly (the paper's Figure 3), and with it GRPO trains. It costs extra memory and communication and restricts which experts the model can use. GSPO trains normally without it. The authors' explanation is that the likelihood of a whole answer changes little when some of its tokens are routed differently, because the updated model still predicts the text about as well; only the per-token average enters sis_i.

Step 5

A token-level variant keeps the sequence ratio and allows a different advantage for each token. For settings such as multi-turn RL, where tokens of one answer should get different advantages A^i,t\hat A_{i,t}, GSPO-token usessi,t(θ)=sg⁡[si(θ)]⋅πθ(oi,t∣⋅)sg⁡[πθ(oi,t∣⋅)],s_{i,t}(\theta)=\operatorname{sg}[s_i(\theta)]\cdot\frac{\htmlData{gr=gn4}{\pi_\theta}(o_{i,t}\mid\cdot)}{\operatorname{sg}[\pi_\theta(o_{i,t}\mid\cdot)]},with stop-gradient: sg⁡[x]\operatorname{sg}[x] has the value of xx and passes no gradient (detach in PyTorch) the stop-gradient, in GRPO's token-level objective in place of ρi,t\rho_{i,t}. The fraction has value 1, so si,ts_{i,t} equals sis_i and is clipped exactly when sis_i is, and its gradient is si gi,ts_i\,g_{i,t}, so token tt is weighted by siA^i,t/∣oi∣s_i\hat A_{i,t}/|o_i|. With A^i,t=A^i\hat A_{i,t}=\hat A_i for every token it matches GSPO in value, clipping and gradient.

Limits. The evidence is one model (a 30B mixture-of-experts model after a cold start), one GRPO baseline and training curves, with no tables, seeds or error bars. Because GRPO needs Routing Replay in this setup, the main comparison is GSPO without it against GRPO with it; how much of GSPO's gain remains on a dense model, where there is no routing to change, is not shown. The claim that GSPO can use the inference engine's likelihoods directly is not tested, and the reason given for GRPO's collapse (token-level noise that accumulates with length) is an interpretation of the curves rather than a measurement of gradient variance.

Terms

Token ratio
ρi,t=πθ(oi,t∣⋅)/πold(oi,t∣⋅)\rho_{i,t}=\pi_\theta(o_{i,t}\mid\cdot)/\pi_{\rm old}(o_{i,t}\mid\cdot), one per token; GRPO weights and clips each token by it
Sequence ratio
si=(πθ(oi∣q)/πold(oi∣q))1/∣oi∣s_i=(\pi_\theta(o_i\mid q)/\pi_{\rm old}(o_i\mid q))^{1/|o_i|}, the geometric mean of the token ratios
Sequence clipping
clip sis_i to [1−εlow,1+εhigh][1-\varepsilon_{\rm low},1+\varepsilon_{\rm high}] and drop or keep the whole answer
Clip ranges
GSPO 3×10−43\times10^{-4} and 4×10−44\times10^{-4}; GRPO baseline 0.2 and 0.27
Gradient difference
GSPO weights every token of oio_i by sis_i; GRPO weights token tt by ρi,t\rho_{i,t}; equal when πθ=πold\pi_\theta=\pi_{\rm old}
Clip fraction
15% of tokens for GSPO, 0.13% for GRPO, yet GSPO learns faster
Expert volatility
about 10% of activated experts change after one update in the 48-layer 30B model
Routing Replay
reuse πold\pi_{\rm old}'s experts when computing πθ\pi_\theta's token probabilities; GRPO needs it, GSPO does not
GSPO-token
si,t=sg⁡[si] πθ(oi,t∣⋅)/sg⁡[πθ(oi,t∣⋅)]s_{i,t}=\operatorname{sg}[s_i]\,\pi_\theta(o_{i,t}\mid\cdot)/\operatorname{sg}[\pi_\theta(o_{i,t}\mid\cdot)]: sequence clipping, per-token advantages

Quiz

  1. What does Routing Replay do, and why is it unattractive?
  2. Which conclusion does the paper's evidence not support directly?

Sources