Group Sequence Policy Optimization
Zheng et al., Qwen Team, Alibaba — arXiv:2507.18071
GSPO is the RL post-training objective behind Qwen3. GRPO weights every token by its own importance ratio, but the reward it corrects for was given to the whole sequence. GSPO uses one length-normalized ratio per sequence and clips at that level. The ratio \(s_i\) is a geometric mean of the token ratios, so it tightens as responses get longer instead of compounding. That is why its clip range is \(\varepsilon \approx 3\times10^{-4}\) rather than GRPO's \(0.2\).
1 · Why \(\varepsilon\) is \(3\times10^{-4}\)
Each token gets an independent log-ratio drawn from \(\mathcal{N}(0, \sigma^2)\), the same noise model as test_gspo.py. GRPO clips each token ratio. GSPO clips one ratio per sequence, the exponential of the mean log-ratio, so its spread shrinks like \(\sigma/\sqrt{T}\). Drag T and watch the GSPO histogram narrow while GRPO's stays the same width.
Ratio spread vs. length
2 · Group-relative advantages
GSPO has no critic. It samples \(G\) responses to the same prompt, and each response's advantage is its reward standardized against the group. Set the rewards below. If every response scores the same, the group carries no signal and the advantages are exactly zero, which is what group_advantages returns instead of dividing by a near-zero std.
3 · Clipping, on both sides
The per-sequence objective \(\min\big(sA,\ \operatorname{clip}(s)\,A\big)\) as a function of \(s\). Once a sequence's ratio leaves the trust region in the direction its advantage pushes, the objective goes flat and its gradient is exactly zero (shaded). That sequence stops contributing until the next rollout.
\(A > 0\): increasing \(s\) helps until \(s = 1+\varepsilon_{\text{high}}\), then the gradient is zero.
\(A < 0\): decreasing \(s\) helps until \(s = 1-\varepsilon_{\text{low}}\), then the gradient is zero.
What this demo simplifies
This page covers the objective only. The token log-ratios are iid Gaussian noise, a toy stand-in for real policy drift, so the histograms show how ratios scale with length, not how a trained policy behaves. There is no rollout engine, no policy model, and no MoE. The paper's headline result is that GSPO removes the need for Routing Replay when training MoE models with RL, and that cannot be shown here. The repo's train.py runs the full loop on a tiny verifiable task in about 20 seconds.