Group Sequence Policy Optimization (GSPO) is a critic-free reinforcement-learning algorithm for language models that keeps GRPO's group-normalised advantage but moves the importance ratio, and therefore the clipping, from individual tokens to whole responses. Each sampled response gets one ratio, the length-normalised likelihood ratio between the current and the sampling policy, and the PPO-style clip either keeps or drops that response as a unit. It sits in the same slot as GRPO and DAPO: after SFT or a cold-start stage, training a reasoning model against verifiable rewards with several gradient steps per batch of rollouts. Its practical selling point is stability, especially for Mixture-of-Experts models, where token-level ratios become unreliable once expert routing shifts between the sampling and training passes.
Where GSPO came from#
GSPO was published in July 2025 by Chujie Zheng, Shixuan Liu, Mingze Li, Xiong-Hui Chen, Bowen Yu and colleagues on the Qwen team at Alibaba (Zheng et al., 2025). The paper is short and opinionated. Its claim is that GRPO's instability when training very large models on long responses, often ending in collapse that the authors could not recover from even by reverting to an earlier checkpoint and retuning, is not bad luck or bad hyperparameters but a design error: GRPO "misapplies" importance sampling.
The argument runs as follows. Importance sampling corrects an expectation under a target distribution using samples from a behaviour distribution, and it works by averaging the reweighted samples over many draws. GRPO computes a ratio at every token position, but each position contributes exactly one sampled token from its next-token distribution. One draw cannot correct a distribution mismatch; it only multiplies that token's gradient by a random factor. Over thousands of tokens those factors add noise, and clipping, which zeroes some tokens and not others inside the same response, makes the noise worse. The authors' principle is that "the unit of optimization objective should match the unit of reward": the reward is given to the whole response, so the off-policy correction and the clipping should be applied to the whole response too.
The paper credits GSPO for the RL behind the later Qwen3 releases and reports two infrastructure wins. On Qwen3-30B-A3B, a 48-layer MoE model, about 10% of the experts activated for a given rollout change after a single gradient update, which made GRPO depend on a workaround called Routing Replay (caching the old routing and replaying it when computing the new probabilities). GSPO trains without it. And because a sequence-level likelihood is far more tolerant of small numerical differences than a per-token one, GSPO opens the door to using the inference engine's log-probabilities directly instead of recomputing them in the training engine.
The objective#
For a query from the dataset , sample a group of responses from the old policy . A verifier or reward model scores each one, . The advantage is GRPO's group-standardised reward, one scalar per response:
The new ingredient is the sequence-level importance ratio, defined as the geometric mean of the token ratios:
Here is the response length in tokens and is the full sequence likelihood. The GSPO objective, which is maximised, applies PPO's clipped surrogate once per response:
Compare GRPO, written in the same notation (KL term omitted, as the GSPO paper does):
The advantage is identical. What changes is where the ratio and the clip live: inside the token sum for GRPO, outside it for GSPO.
Why the ratio is length-normalised
The raw sequence ratio is a product of token ratios. For a 4,000-token response, a log-ratio of 0.001 per token compounds to ; a few tokens moving a lot would swing it by orders of magnitude, and responses of different lengths would need different clip ranges. Taking the -th root turns the product into the exponential of an average log-ratio, which keeps near 1 for every length and puts all responses on one scale. The cost is that is no longer an unbiased importance weight for the sequence; it is a trust-region signal, and GSPO uses it as one.
The gradient: equal weight for every token
Ignoring clipping, and using , the GSPO gradient is
while GRPO's is
This is the whole difference. In GRPO each token's score-function gradient is multiplied by its own ratio , which can range over for a positive advantage and for a negative one. In GSPO every token in a response is multiplied by the same scalar . A practical consequence the paper does not spell out: GSPO can rescale a response's gradient but never rotate it. Noise in the log-probabilities changes how much a response counts, not which of its tokens are pushed. With GRPO, the same noise reshuffles the relative weight of tokens inside the response.
GSPO-token, for per-token advantages
Multi-turn or tool-use training sometimes wants different advantages for different tokens. The paper defines a variant using a stop-gradient :
Numerically , so the clip decision is still made per response, but the gradient of token is , which accepts a token-specific advantage. With for all it is identical to GSPO in value, clipping and gradient. This is also the form most implementations use internally, because it lets a token-level loss tensor carry a sequence-level ratio.
Worked example: one response, both methods#
Take a four-token response. Under the sampling policy its tokens had probabilities . After one minibatch update the current policy gives them . The token ratios are
GSPO averages the log-ratios: , so . The response as a whole has become about 2.1% more likely per token.
Positive advantage, . GRPO with clips token 4, whose ratio 1.25 is above 1.2, so that token stops contributing; tokens 1, 2 and 3 keep pushing with weights 1.16, 0.75 and 1.00 (divided by 4). GSPO with the paper's range sees and drops the entire response from the gradient. The response has already moved far enough, by GSPO's standard.
Negative advantage, . GRPO now clips on the low side: token 2, at 0.75, is below 0.8, so it is excluded, while tokens 1, 3 and 4 are pushed down with weights , and . Token 4, which the policy has already raised by 25%, gets the largest push. GSPO's lower bound is , and is above it, so the response is active, and every token receives the same weight .
Two things are worth noticing. First, the clip ranges differ by roughly three orders of magnitude, which is not a typo: the average of many small log-ratios has a far narrower distribution than any single one. Second, GSPO's decision is coarser, all or nothing per response, and that is the point. The paper reports that GSPO clips about two orders of magnitude more tokens than GRPO and still learns faster, which the authors read as evidence that GRPO's token-level gradient contributions are mostly noise.
Why the clip range is so small#
Suppose each token's log-ratio carries independent noise with standard deviation , from routing changes, numerical differences between engines, or simply the stochastic update. Then has spread at any length, while , an average of such terms, has spread . We checked this with 20,000 simulated responses per length at : the token log-ratio spread stayed at 0.100, and the sequence log-ratio spread fell from 0.0250 at 16 tokens to 0.0031 at 1,024 and 0.0016 at 4,096, exactly the law (Figure 2). A fixed token-level range clipped 2.1% of tokens at every length.
The same simulation is a warning about copying hyperparameters. With per token, more than 80% of even 4,096-token responses fall outside on one side or the other. The paper's range works because, in its setting, per-token log-ratio drift between minibatches is far smaller than that. In yours it may not be. Measure the distribution of on your first few batches before fixing .
The algorithm step by step#
for step in range(num_steps):
prompts = sample_batch(dataset, B)
with no_grad():
groups = [policy_old.generate(x, n=G) for x in prompts] # B*G responses
rewards = [[verifier(x, y) for y in g] for x, g in zip(prompts, groups)]
adv = [(r - mean(r)) / (std(r) + 1e-6) for r in rewards] # one scalar per response
logp_old = token_logprobs(policy_old, prompts, groups) # or the inference engine's
for mb in split(prompts, groups, adv, logp_old, n_minibatches=4): # off-policy after the first
logp = token_logprobs(policy, mb) # (N, T)
log_s = masked_mean(logp - mb.logp_old, mb.mask) # (N,) mean over tokens
s = exp(log_s)
surr = minimum(s * mb.adv, clip(s, 1 - eps_low, 1 + eps_high) * mb.adv)
loss = -surr.mean() # one term per response
loss.backward(); optimizer.step(); optimizer.zero_grad()
policy_old.load_state_dict(policy.state_dict())
The rollout phase is GRPO's: sample responses per prompt, score them, standardise within the group. The difference is three lines in the loss. The first minibatch of every batch is exactly on-policy, so , nothing is clipped, and GSPO's update equals GRPO's up to the token weighting (on the first minibatch both weightings are 1). The behaviour only diverges on the second and later minibatches, when has moved away from . The paper splits each rollout batch into four minibatches; if you run fully on-policy, one gradient step per batch, GSPO and GRPO are the same algorithm.
Data it needs
The same as GRPO: prompts with whatever the reward function needs, such as reference answers for maths, test cases for code, or a reward model for open-ended tasks. GSPO adds no data requirements. The paper trained a cold-start model fine-tuned from Qwen3-30B-A3B-Base and evaluated on AIME'24, LiveCodeBench and CodeForces, regularly refreshing the query set and extending generation length during training. The usual advice carries over: filter prompts so that the starting policy's pass rate is spread across the middle of the range, because groups where every response gets the same reward have zero advantage under GSPO exactly as under GRPO.
Hyperparameters that matter#
| Parameter | Paper value | Notes |
|---|---|---|
| , | , | Sequence-level; not comparable to GRPO's 0.2. Tune by watching the fraction of responses clipped. |
| GRPO baseline clip (for comparison) | 0.2 low, 0.27 high | What the authors tuned GRPO to for their comparison. |
| Minibatches per rollout batch | 4 | GSPO only differs from GRPO when this is above 1. |
| KL coefficient | 0 (not used) | The paper omits the KL term; TRL's reproduction config sets beta=0.0. |
| Loss aggregation | mean over responses | Each response is one term. verl recommends seq-mean-token-mean for GSPO. |
| Group size , learning rate | not stated | Start from your GRPO settings; GSPO does not change their role. |
The clip range is the only genuinely new knob, and it behaves differently from GRPO's. Because the sequence log-ratio concentrates as responses get longer, a fixed is effectively looser for short responses and tighter for long ones. Log three quantities per step: the fraction of responses clipped on each side, the mean and spread of , and the same split by response length. If more than roughly half the responses with positive advantage are clipped from the second minibatch onward, you are wasting rollouts; widen or cut the learning rate. If almost nothing is ever clipped, the trust region is not doing anything and you might as well run fewer, larger steps.
Compute and memory#
GSPO costs the same as GRPO. The policy, an optional frozen reference (unused if ), the generation engine and a verifier are the only components; there is no critic. For full fine-tuning with Adam in mixed precision, a rough budget for an -parameter policy is
with more if you keep a reference model for a KL term. The loss itself adds one reduction over the token dimension. The savings are elsewhere. For MoE models, dropping Routing Replay removes the memory and communication needed to cache and replay expert assignments, and, as the authors note, removes a constraint that kept the model from using its full routing capacity during training. For asynchronous or disaggregated setups, the paper argues that sequence-level ratios are tolerant enough of numerical differences to use the inference engine's log-probabilities for , saving a full forward pass over every rollout in the training engine. That claim is stated as a possibility, not measured, so validate it on your stack by comparing computed both ways.
Relative to DPO or SFT, GSPO has the cost profile of any online RL method: generation dominates, typically several times the cost of an SFT step on the same number of tokens.
A toy run with noisy log-probabilities#
We wanted to see whether the sequence-level ratio buys anything in a setting small enough to run in seconds and honest enough not to rig the result. The toy model: 64 prompts, each with a target string of tokens over a 6-token vocabulary, and an independent softmax per position (no shared parameters). The reward is the fraction of positions that match the target, so groups almost always have reward variance. Each step samples 16 prompts with responses, standardises rewards within the group, and takes four minibatch steps, so three of the four are off-policy. To mimic routing changes or engine mismatch we add independent Gaussian noise with standard deviation to every behaviour log-probability before computing ratios. GRPO uses clip (0.2, 0.27) as in the paper's baseline; GSPO uses (0.0225, 0.03), scaled to this toy because the paper's range clipped about 39% of responses here even without noise (and reached 0.728 instead of 0.764 at ). Learning rate 1,000 for both, 100 steps, 5 seeds; numbers are mean per-token accuracy, starting at 0.167.
| Setting | GRPO final | GSPO final | GRPO tokens clipped | GSPO responses clipped |
|---|---|---|---|---|
| , | 0.759 ± 0.007 | 0.764 ± 0.003 | 7.4% | 23.1% |
| , | 0.723 ± 0.006 | 0.733 ± 0.003 | 25.1% | 38.1% |
| , | 0.432 ± 0.004 | 0.436 ± 0.003 | 4.8% | 9.8% |
| , | 0.384 ± 0.003 | 0.403 ± 0.002 | 23.8% | 21.0% |
Without noise the methods tie, which is what you would expect: in this toy every token has its own parameters, so token-level credit is actually correct and GRPO is not handicapped. With noise, both degrade, but GRPO degrades more, and the gap widens with length: 0.010 at 32 tokens, 0.019 at 128. That matches the mechanism in the gradient section. Noise rescales a GSPO response's update but leaves its direction alone, while under GRPO it reweights tokens within the response at random. The toy cannot show the dramatic, irreversible collapse the paper describes on a 30B MoE model. It has no shared parameters, no routing and no long horizon, so take it as evidence about the mechanism, not about the size of the effect at scale.
Failure modes and what to watch#
Everything clipped. If the fraction of clipped responses climbs towards 100% on minibatches two to four, GSPO has silently become one-step-per-batch training with three wasted passes. The cause is almost always a clip range copied from the paper into a setting with more per-token drift (higher learning rate, LoRA with a large rate, shorter responses). Plot the histogram of and set the range from it.
Short responses dominate the clip. Since the spread of shrinks with length, short responses are clipped more often for the same per-token drift. If response length correlates with correctness on your task, this skews which responses can learn. Log clip rates by length bucket.
A few tokens drive the ratio. One token whose probability moves from 0.001 to 0.1 contributes to the sum of log-ratios. In a 100-token response that alone shifts by 0.046, enough to clip the whole response under the paper's range. This is GSPO's version of outliers; GMPO (Zhao et al., 2025), a geometric-mean variant that clips per token in log space before averaging, is one response to it.
Inherited GRPO problems. GSPO does not change the advantage, so zero-variance groups, the std-division difficulty weighting discussed in Dr. GRPO, entropy collapse and reward hacking all apply unchanged. Track the zero-variance group rate, token entropy and a held-out score with a stricter grader.
Training-inference mismatch you did not measure. If you adopt the paper's suggestion of using inference-engine log-probabilities, a systematic bias between engines (not noise) shifts every in one direction and, with a range of , can clip one side of the advantage distribution wholesale. Compare the two log-probability sources on a sample before switching.
When to use GSPO#
| Situation | Recommendation | Why |
|---|---|---|
| MoE policy, RL with several minibatch steps per rollout batch | GSPO | Removes the need for Routing Replay; the main motivating case in the paper. |
| Dense model, long responses, off-policy minibatches, instability seen with GRPO | GSPO, or DAPO-style token-level loss with clip-higher | Both target the same instability; GSPO is the simpler change. |
| Fully on-policy, one gradient step per rollout batch | GRPO, RLOO or REINFORCE++ | With ratio 1 everywhere GSPO adds nothing. |
| Per-token or per-step rewards (process rewards, multi-turn tools) | GSPO-token, or PPO with a critic (VAPO) | Sequence clipping with token-level advantages; or real per-token credit from a value model. |
| Asynchronous rollouts, trainer and generator on different engines | GSPO, after measuring log-prob agreement | Sequence ratios tolerate small numerical mismatch better. |
| No verifier or reward model, only preference pairs | DPO or online DPO | GSPO needs a scalar reward per response. |
Minimal implementation#
A PyTorch loss in the GSPO-token form, so the tensor shapes match a standard token-level trainer. Inputs are per-token log-probabilities and a completion mask.
import torch
def gspo_loss(logp, logp_old, adv, mask, eps_low=3e-4, eps_high=4e-4):
"""logp, logp_old, mask: (N, T); adv: (N,) group-normalised, one per response."""
lengths = mask.sum(1).clamp(min=1)
log_s = ((logp - logp_old) * mask).sum(1) / lengths # (N,) mean token log-ratio
# GSPO-token: value equals s_i, gradient flows through each token's logp
log_s_tok = log_s.detach().unsqueeze(1) + logp - logp.detach()
s = torch.exp(log_s_tok.clamp(max=10.0))
a = adv.unsqueeze(1)
surr = torch.minimum(s * a, torch.clamp(s, 1 - eps_low, 1 + eps_high) * a)
per_seq = (surr * mask).sum(1) / lengths # every token equal weight
clipped = ((s.detach() > 1 + eps_high) & (a > 0)) | ((s.detach() < 1 - eps_low) & (a < 0))
stats = {"clip_frac_seq": clipped[:, 0].float().mean().item(),
"log_s_mean": log_s.mean().item(), "log_s_std": log_s.std().item()}
return -per_seq.mean(), stats
In TRL, GSPO is a configuration of GRPOTrainer. The library's paper index gives this reproduction of the paper's setting:
from trl import GRPOConfig
args = GRPOConfig(
importance_sampling_level="sequence", # the GSPO ratio
loss_type="grpo",
beta=0.0,
epsilon=3e-4, epsilon_high=4e-4,
gradient_accumulation_steps=1,
steps_per_generation=4, # 4 minibatch updates per rollout batch
)
verl exposes it as actor_rollout_ref.actor.policy_loss.loss_mode=gspo with clip_ratio_low, clip_ratio_high and loss_agg_mode=seq-mean-token-mean, and OpenRLHF as --actor.policy_loss_type gspo. In POFE, switching a GRPO recipe to GSPO is a single setting, and the run dashboard shows the clip fraction by length so the range can be checked rather than assumed.
Further reading#
Zheng et al. (2025) is the primary source and is short enough to read in full. Shao et al. (2024) defines the GRPO objective GSPO modifies, and Schulman et al. (2017) the clipped surrogate both inherit. Yu et al. (2025) attacks the same long-sequence instability from the token side with DAPO's token-level loss and asymmetric clipping. Zhao et al. (2025) proposes GMPO, the closest sibling, which takes a geometric mean of clipped token ratios. MiniMax (2025), cited by the GSPO paper for the same collapse phenomenon, proposes CISPO, which clips the importance weight rather than the update.
Frequently asked questions#
What is the difference between GSPO and GRPO?
Both use the same group-normalised advantage. GRPO computes an importance ratio and applies PPO clipping at every token; GSPO computes one ratio per response, the geometric mean of the token ratios, and clips the whole response at once. Every token in a response then receives the same gradient weight.
Why is GSPO's clip range so small (3e-4 and 4e-4)?
The sequence ratio is the exponential of an average of per-token log-ratios, so its spread shrinks roughly with one over the square root of the response length. A range of 0.2, sensible for single tokens, would never bind. Measure the distribution of the log ratio in your own runs before copying the paper's values.
Does GSPO help if I train fully on-policy?
No. With one gradient step per batch of rollouts the ratio is exactly 1 for every response, nothing is clipped and GSPO reduces to the same update as GRPO. It only changes behaviour on the second and later minibatches of a rollout batch, or with asynchronous rollouts.
Why is GSPO recommended for Mixture-of-Experts models?
After a gradient update, the experts selected for the same tokens can change (about 10% of activated experts on Qwen3-30B-A3B per the paper), which makes token-level ratios fluctuate. GRPO needed Routing Replay to converge on MoE models; GSPO depends only on sequence likelihood, which stays stable, and trains without it.
How do I run GSPO in TRL?
Use GRPOTrainer with importance_sampling_level="sequence". TRL's paper index reproduces the paper with loss_type="grpo", beta=0.0, epsilon=3e-4, epsilon_high=4e-4 and steps_per_generation=4 so that each rollout batch is split into four minibatch updates.
What is GSPO-token?
A variant that keeps the clip decision per response but lets each token carry its own advantage, using a stop-gradient so the ratio's value equals the sequence ratio while the gradient flows through each token's log-probability. With equal advantages for all tokens it is identical to GSPO.
References#
- Chujie Zheng, Shixuan Liu, Mingze Li, Xiong-Hui Chen, Bowen Yu, Chang Gao, Kai Dang, Yuqiong Liu, Rui Men, An Yang, Jingren Zhou, Junyang Lin (2025). Group Sequence Policy Optimization. arxiv.org/abs/2507.18071
- Zhihong Shao, Peiyi Wang, Qihao Zhu, Runxin Xu, Junxiao Song, Xiao Bi, Haowei Zhang, Mingchuan Zhang, Y. K. Li, Y. Wu, Daya Guo (2024). DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models. arxiv.org/abs/2402.03300
- John Schulman, Filip Wolski, Prafulla Dhariwal, Alec Radford, Oleg Klimov (2017). Proximal Policy Optimization Algorithms. arxiv.org/abs/1707.06347
- Qiying Yu, Zheng Zhang, Ruofei Zhu, Yufeng Yuan, Xiaochen Zuo, Yu Yue, et al. (2025). DAPO: An Open-Source LLM Reinforcement Learning System at Scale. arxiv.org/abs/2503.14476
- Yuzhong Zhao, Yue Liu, Junpeng Liu, Jingye Chen, Xun Wu, Yaru Hao, Tengchao Lv, Shaohan Huang, Lei Cui, et al. (2025). Geometric-Mean Policy Optimization. arxiv.org/abs/2507.20673
- MiniMax (2025). MiniMax-M1: Scaling Test-Time Compute Efficiently with Lightning Attention. arxiv.org/abs/2506.13585
- An Yang et al. (Qwen Team) (2025). Qwen3 Technical Report. arxiv.org/abs/2505.09388
- von Werra, L. et al. (Hugging Face) (2020). TRL: Transformer Reinforcement Learning (GRPOTrainer, importance_sampling_level). github.com/huggingface/trl
- ByteDance Seed and verl contributors (2024). verl: Volcano Engine Reinforcement Learning for LLMs (GSPO policy loss). github.com/volcengine/verl