Prince Osei Aboagye
← All posts
Mini DeepSeek V4 / Part 09·Dec 2026

Reinforcement learningGRPO and GSPO

Spoiler: On 8×H100, 45 GSPO steps lifted held-out avg@8 from 1.46% to 2.04% (p = 0.002) and pass@8 from 10.5% to 13.2%: a real gain, and a small one, because the model rarely found a right answer to reinforce.

TL;DR

In RL with a verifiable reward, a model answers each problem several times, a program grades the answers, and training favours the better ones. GSPO, the variant I used, keeps GRPO’s group baseline but measures and clips the policy’s change once per answer, not once per token.

On an RTX 3060 laptop GPU (6 GB), GSPO lifted a 64M model’s held-out final-answer accuracy by 4.6–5.1 points in all 3 seeds. On 8×H100, 45 GSPO steps raised my 6.86B mixture-of-experts model’s held-out avg@8 by 0.58 points (p = 0.002), and pass@8 from 10.5% to 13.2%. The gain is real but small: only about 2–3% of the training answers were right, so there was little to reinforce.

// § 01

What you’ll learn

  • How a grader becomes a gradient: the RL objective, the policy-gradient identity, and why subtracting a baseline changes nothing on average.
  • What GRPO and GSPO compute, equation by equation, and what the clip does to a single answer.
  • Why the first update’s importance ratio must be exactly 1, and what that check caught on a laptop and on 8 GPUs.
  • How I chose the learning rate and the clip with rules written before the runs.
  • What GSPO did to a weak 6.86B mixture-of-experts model, and why the gain was small.
// § 02

RL with a verifiable reward

A language model is a policy: given a prompt, it gives every possible answer a probability. Sampling from it writes an answer one token at a time. In reinforcement learning (RL) the model answers, the answer gets a score, and the weights change to make high-scoring answers likelier. A verifiable reward is one a program computes exactly, here by checking the final number against the known answer.

No learned judge is involved, so the only thing the policy can game is the checker, which Part 8 audits. The goal is the expected reward:

\[J(\theta) = \mathbb{E}_{x \sim \mathcal{D}}\; \mathbb{E}_{y \sim \pi_\theta(\cdot \mid x)} \big[\, r(x, y) \,\big] \tag{1}\]

Here \(\theta\) are the model’s weights, \(x\) is a prompt from the training set \(\mathcal{D}\), and \(y\) is an answer sampled from the model. \(\pi_\theta(y \mid x)\) is the probability the model gives that whole answer, and \(r(x, y)\) is its score.

In words: \(J\) is the model’s average score on its own answers, and RL climbs it.

An answer’s probability factorises over its tokens:

\[\log \pi_\theta(y \mid x) = \sum_{t=1}^{|y|} \log \pi_\theta(y_t \mid x, y_{<t}) \tag{2}\]

Here \(|y|\) is the answer’s length in tokens, \(y_t\) is its \(t\)-th token and \(y_{<t}\) the tokens before it.

In words: an answer’s log-probability is the sum of its tokens’ log-probabilities, which one forward pass computes.

On 8×H100 the reward had three parts:

\[r(x, y) = \mathbf{1}[\text{correct}] + 0.1\cdot\mathbf{1}[\text{format}] + \ell(|y|), \qquad \ell(n) = \begin{cases} 0 & n \le 768 \\ (768 - n)/256 & 768 < n \le 1024 \\ -1 & n > 1024 \end{cases} \tag{3}\]

Here \(\mathbf{1}[\cdot]\) is 1 when its condition holds and 0 otherwise, and \(\ell\) is a soft length penalty with the shape DAPO introduced [5]. “Format” means one <think>…</think> block followed by exactly one <answer>…</answer> block.

In words: a point for the right number, a tenth for the format, and a penalty that falls to −1 between 768 and 1,024 tokens.

On the laptop the grader read the answer’s last number, with no format bonus and a penalty from 192 to 256 tokens.

// § 03

The policy gradient

To climb \(J\) we need its gradient. But \(J\) averages over answers the model samples, and sampling has no gradient. The policy-gradient identity moves the gradient onto the log-probability, which has one:

\[\nabla_\theta J(\theta) = \mathbb{E}_{x}\, \mathbb{E}_{y \sim \pi_\theta}\big[\, r(x, y)\, \nabla_\theta \log \pi_\theta(y \mid x) \,\big] \tag{4}\]

Here \(\nabla_\theta\) is the gradient with respect to the weights; the other symbols are as in (1) and (2).

In words: sample answers, then raise each answer’s log-probability in proportion to its score.

Equation (4) is noisy. With scores of 0 and 1, it pushes every right answer up and never pushes a wrong one down. Subtracting a baseline \(b(x)\) fixes that without changing the average:

\[\nabla_\theta J(\theta) = \mathbb{E}_{x}\, \mathbb{E}_{y \sim \pi_\theta}\big[\, \big(r(x, y) - b(x)\big)\, \nabla_\theta \log \pi_\theta(y \mid x) \,\big] \tag{5}\]

Here \(b(x)\) is any number that depends on the prompt only, such as the average score on that prompt.

In words: push up the answers that beat the prompt’s usual score, and push down the ones below it.

Derivation

For one prompt, write the expectation as a sum over answers and use \(\nabla_\theta \pi_\theta = \pi_\theta\, \nabla_\theta \log \pi_\theta\):

\[\nabla_\theta \sum_{y} \pi_\theta(y \mid x)\, r(x, y) = \sum_{y} \pi_\theta(y \mid x)\, r(x, y)\, \nabla_\theta \log \pi_\theta(y \mid x) \tag{6}\]

Here the sum runs over every possible answer \(y\), and \(r\) does not depend on \(\theta\).

In words: the right-hand side is an average over the model’s own samples, so sampling estimates it, which gives (4).

The baseline term vanishes because the probabilities of all answers sum to one:

\[\mathbb{E}_{y \sim \pi_\theta}\big[\, b(x)\, \nabla_\theta \log \pi_\theta(y \mid x) \,\big] = b(x)\, \nabla_\theta \sum_{y} \pi_\theta(y \mid x) = b(x)\, \nabla_\theta 1 = 0 \tag{7}\]

Here \(b(x)\) moves out of the sum because it does not depend on \(y\).

In words: on average a baseline adds nothing to the gradient, so we may pick one that cuts the noise.

// § 04

GRPO: the group is its own baseline

PPO [4], the classic RL algorithm for language models, trains a second network, a value model, to supply \(b(x)\). GRPO, introduced with DeepSeekMath [2], drops it. Its baseline is the group: “the average reward of multiple sampled outputs, produced in response to the same question” [2].

\[A_i = \frac{r_i - \operatorname{mean}(r_1, \dots, r_G)}{\operatorname{std}(r_1, \dots, r_G) + \epsilon} \tag{8}\]

Here \(A_i\) is the advantage of answer \(i\) and \(r_i = r(x, y_i)\) is its score. The mean and standard deviation run over the \(G\) answers to one prompt, and \(\epsilon\) prevents division by zero.

In words: an answer’s advantage is how many group standard deviations it scored above its group’s mean.

My code uses the population standard deviation (dividing by \(G\), not \(G - 1\)), with \(\epsilon = 10^{-6}\) in the laptop code and \(10^{-4}\) in Megatron. Every token of answer \(i\) gets the same advantage. On top of (8) sits a filter by correctness:

\[\hat A_i = \begin{cases} A_i & \text{if } 0 < \sum_{j=1}^{G} c_j < G \\ 0 & \text{otherwise} \end{cases} \tag{9}\]

Here \(c_j\) is 1 if answer \(j\) is correct and 0 if not.

In words: a group whose answers are all right or all wrong teaches nothing, so its advantages are set to zero.

The filter tests correctness, not the reward. With the format bonus and the length penalty, an all-wrong group can still have unequal rewards, and (8) would then teach format or length alone.

Two properties of (8) matter later. The advantages in a group sum to zero. And a lone right answer gets a large push: in GSPO-A’s early rollouts the median mixed group had 1 right answer of 32. With scores of 1 and 0, that answer’s advantage is +5.57 and each wrong answer’s is −0.18.

How often does a group carry a signal?

If each answer to a prompt is right with probability \(p\), independently, a group of \(G\) is mixed with probability

\[P_{\text{mixed}}(p, G) = 1 - (1-p)^G - p^G \tag{10}\]

Here \((1-p)^G\) is the chance that all \(G\) answers are wrong and \(p^G\) the chance that all are right.

In words: this is the share of groups that produce any gradient at all.

A worked line, illustrative: with \(p = 0.03\), groups of 8 are mixed 21.6% of the time, and groups of 32 62.3%. For a weak model, larger groups are a direct way to get more signal. And (10) is concave in \(p\) for \(G \ge 2\). So with problems of mixed difficulty, the average mixed share is at most \(P_{\text{mixed}}\) at the average \(p\) (Jensen’s inequality).

// § 05

On-policy, off-policy, and importance ratios

Equation (5) assumes the answers came from the current policy \(\pi_\theta\). Training that meets this assumption is on-policy. Three things make the answers come from a slightly different distribution, which makes training off-policy:

  • Mini-batches. A step samples one batch of answers, then makes several optimizer updates on slices of it: 4 in the main run; on the laptop up to 4, one per slice of the groups that carry a signal; 1 in the control run. After the first update the weights have moved, so later slices were sampled by older weights.
  • Sampling settings. Temperature, top-k and top-p reshape the distribution the sampler draws from.
  • Numerics. Two code paths that compute “the same” probability can disagree in the last bits.

Importance sampling corrects for the first:

\[\mathbb{E}_{y \sim \pi_\theta}\big[\, f(y) \,\big] = \mathbb{E}_{y \sim \pi_{\text{old}}}\Big[\, \frac{\pi_\theta(y \mid x)}{\pi_{\text{old}}(y \mid x)}\, f(y) \,\Big] \tag{11}\]

Here \(\pi_{\text{old}}\) is the policy that sampled the answers, the weights at the start of the step. The function \(f\) is any function of an answer, and the fraction is the importance ratio.

In words: weighting each old sample by how much likelier the current policy finds it turns an old-policy average into a current-policy average.

PPO-style methods also clip the ratio, so one batch of answers cannot drag the policy far from the one that produced it. GRPO applies the ratio and the clip to every token:

\[J_{\text{GRPO}}(\theta) = \mathbb{E}\Big[\frac{1}{G}\sum_{i=1}^{G}\frac{1}{|y_i|}\sum_{t=1}^{|y_i|}\min\big(w_{i,t}\hat A_i,\ \operatorname{clip}(w_{i,t},\, 1-\varepsilon,\, 1+\varepsilon)\,\hat A_i\big)\Big], \qquad w_{i,t} = \frac{\pi_\theta(y_{i,t} \mid x, y_{i,<t})}{\pi_{\text{old}}(y_{i,t} \mid x, y_{i,<t})} \tag{12}\]

Here \(w_{i,t}\) is the importance ratio of token \(t\) in answer \(i\), \(\operatorname{clip}(w, a, b)\) limits \(w\) to the interval \([a, b]\), and \(\varepsilon\) is the clip width. GRPO also subtracts a KL penalty, which I add back below.

In words: each token is pushed by its advantage times its ratio, but gains nothing from moving past \(1 \pm \varepsilon\) in its advantage’s direction.

// § 06

GSPO: one ratio per answer

The reward scores a whole answer, yet (12) weighs each token by a ratio computed from a single sample of that token’s distribution. The GSPO authors argue that these token weights add noise that grows with length. In their words, “the unit of optimization objective should match the unit of reward” [1]. So GSPO uses one ratio per answer:

\[s_i(\theta) = \left(\frac{\pi_\theta(y_i \mid x)}{\pi_{\text{old}}(y_i \mid x)}\right)^{1/|y_i|} = \exp\!\Big(\frac{1}{|y_i|}\sum_{t=1}^{|y_i|}\log\frac{\pi_\theta(y_{i,t} \mid x, y_{i,<t})}{\pi_{\text{old}}(y_{i,t} \mid x, y_{i,<t})}\Big) \tag{13}\]

Here \(s_i\) is answer \(i\)’s sequence ratio; the power \(1/|y_i|\) makes it the geometric mean of the answer’s token ratios.

In words: \(s_i\) says how much the policy’s probability for the whole answer has changed since sampling, per token.

The objective clips \(s_i\) instead of the token ratios:

\[J_{\text{GSPO}}(\theta) = \mathbb{E}\Big[\frac{1}{G}\sum_{i=1}^{G}\min\big(s_i(\theta)\,\hat A_i,\ \operatorname{clip}\big(s_i(\theta),\, 1-\varepsilon_{\text{low}},\, 1+\varepsilon_{\text{high}}\big)\,\hat A_i\big)\Big] \tag{14}\]

Here \(\varepsilon_{\text{low}}\) and \(\varepsilon_{\text{high}}\) set an asymmetric clip window, \([1-\varepsilon_{\text{low}},\, 1+\varepsilon_{\text{high}}]\).

In words: each answer counts once, its advantage scaled by its ratio, until it moves past the window in its advantage’s direction.

On the laptop I used the paper’s window, \(\varepsilon_{\text{low}} = 3 \times 10^{-4}\) and \(\varepsilon_{\text{high}} = 4 \times 10^{-4}\). On 8×H100 I used \(2 \times 10^{-2}\) and \(2.7 \times 10^{-2}\), for a reason the main run explains. For an answer that is not clipped, the gradient is

\[\nabla_\theta\big(s_i\, \hat A_i\big) = s_i\, \hat A_i\, \frac{1}{|y_i|}\sum_{t=1}^{|y_i|}\nabla_\theta \log \pi_\theta(y_{i,t} \mid x, y_{i,<t}) \tag{15}\]

Here the symbols are those of (13) and (14); the form comes from \(\nabla_\theta s_i = s_i\, \nabla_\theta \log s_i\).

In words: every token of an answer gets the same weight, \(s_i \hat A_i / |y_i|\), so the push no longer varies from token to token.

An answer is clipped, and gives no gradient, when \(\hat A_i > 0\) and \(s_i > 1 + \varepsilon_{\text{high}}\), or when \(\hat A_i < 0\) and \(s_i < 1 - \varepsilon_{\text{low}}\). Past the other edge, the minimum keeps the unclipped term and the gradient still flows. So the clip stops an answer from overshooting, but never stops the update from undoing a move in the wrong direction.

Because \(s_i\) is a per-token geometric mean, it stays very close to 1. The paper’s window is about 670 times narrower than the 0.2 / 0.27 of its GRPO baseline. It reports clipping 15% of tokens on average with GSPO, against 0.13% with GRPO.

The \(1/|y_i|\) in (15) is the factor Dr. GRPO criticises in GRPO: each token of a long answer gets a smaller push, which can favour short right answers and long wrong ones [3]. I did not test its effect.

Why I chose GSPO

My model is a mixture of experts (MoE): each layer has 64 expert sub-networks, and each token uses 8 of them. A small weight change can send a token to different experts. In the GSPO paper’s 48-layer MoE, roughly 10% of the experts activated for the same answer changed after each gradient update.

There GRPO needed “Routing Replay”, which replays the old policy’s expert choices, to converge; GSPO did not. The authors’ reason: “the sequence likelihood will not fluctuate drastically” [1]. Two more reasons: the reward is per answer, and the Qwen team used GSPO to train its Qwen3 models.

Two caveats: the paper’s comparisons are its own runs, and its claim that GSPO tolerates precision mismatch better is argued, not measured.

// § 07

The KL penalty and the reference model

The reference model \(\pi_{\text{ref}}\) is a frozen copy of the starting point: the model after supervised fine-tuning (SFT, Part 7). A penalty on the KL divergence from \(\pi_{\text{ref}}\) keeps the policy near the model whose format and fluency we trust. Like GRPO, I estimate it per sampled token with the “k3” estimator [2, 6]:

\[\hat k_3(y_t) = \frac{\pi_{\text{ref}}(y_t)}{\pi_\theta(y_t)} - \log\frac{\pi_{\text{ref}}(y_t)}{\pi_\theta(y_t)} - 1 \tag{16}\]

Here \(\pi(y_t)\) is short for \(\pi(y_t \mid x, y_{<t})\), the probability of the token that was actually sampled.

In words: a per-token number that is never negative, is zero where the models agree, and averages to the KL divergence.

Both claims are short to check. With \(u = \pi_{\text{ref}}/\pi_\theta\), the function \(u - \log u - 1\) is at least 0 for every \(u > 0\). Over tokens drawn from \(\pi_\theta\), \(\mathbb{E}[u] = 1\) and \(\mathbb{E}[-\log u] = \mathrm{KL}(\pi_\theta \,\|\, \pi_{\text{ref}})\), so \(\mathbb{E}[\hat k_3] = \mathrm{KL}\). The loss I minimise, over the \(N\) answers of one optimizer update, is

\[\mathcal{L}(\theta) = -\frac{1}{N}\sum_{i=1}^{N}\min\big(s_i \hat A_i,\ \operatorname{clip}(s_i,\, 1-\varepsilon_{\text{low}},\, 1+\varepsilon_{\text{high}})\,\hat A_i\big) + \frac{\beta}{N}\sum_{i=1}^{N}\frac{1}{|y_i|}\sum_{t=1}^{|y_i|}\hat k_3(y_{i,t}) \tag{17}\]

Here \(\beta\) is the KL weight, 0.01 in every run, and \(N\) was 128 on 8×H100.

In words: the negative GSPO objective, averaged over the update’s answers, plus a small per-token pull toward the reference.

DeepSeekMath used \(\beta = 0.04\). Megatron loads the SFT checkpoint as \(\pi_{\text{ref}}\) at the start and keeps it for the whole run, even after a restart. In GSPO-A the KL to the SFT model ended near 0.028, so the penalty was about \(0.01 \times 0.028 = 2.8 \times 10^{-4}\): it barely held the policy back.

// § 08

Why the first update’s ratio must be exactly 1

At the start of each step, \(\pi_{\text{old}}\) is by definition the current policy. So on a step’s first update the policy has not moved yet:

\[\theta = \theta_{\text{old}} \;\Rightarrow\; s_i = e^{0} = 1 \ \text{for every } i, \qquad \nabla_\theta J_{\text{GSPO}} = \frac{1}{G}\sum_{i=1}^{G}\hat A_i\,\frac{1}{|y_i|}\,\nabla_\theta \log \pi_\theta(y_i \mid x) \tag{18}\]

Here \(\theta_{\text{old}}\) are the weights that sampled the answers; the gradient is (15) with \(s_i = 1\), and (2) turns the token sum into \(\log \pi_\theta(y_i \mid x)\).

In words: the first update of every step is the policy gradient (5), with the group mean as the baseline, scaled by \(1/\text{std}\) and \(1/|y_i|\).

Three facts follow. Nothing is clipped, because 1 lies inside every window. The objective’s value is \(\frac{1}{G}\sum_i \hat A_i = 0\), since advantages sum to zero, yet its gradient is not zero. And on the run’s very first update the policy also equals the reference, so every \(\hat k_3\) is exactly 0.

In exact arithmetic this is trivial. On a GPU it holds only if the “old” and “new” log-probabilities come from bit-identical computations: the same kernels, batch layout and precision. So \(|\log s_i|\) on the first update is an exact test of the pipeline’s numerics that needs no extra computation. Violations of it exposed a batch-composition bug on the laptop and noise between two Megatron passes on 8 GPUs.

// § 09

A worked example (illustrative)

Every number in this section is illustrative. I chose them to show the arithmetic of (8), (13), (14) and (15); none comes from a run.

One prompt, “What is 12 × 6?” (answer 72), and a group of \(G = 4\) answers, scored 1 or 0. The group’s mean score is 0.25 and its standard deviation 0.433, so (8) gives +1.732 to the right answer and −0.577 to each wrong one. The four advantages sum to zero.

Suppose the group is trained in the step’s second update, after the first update has moved the weights. Each answer then has a non-zero mean token log-ratio, \(\log s_i\). The clip window is the main run’s, \([1 - 0.02,\ 1 + 0.027] = [0.980,\ 1.027]\).

Answer Text \(r_i\) \(\hat A_i\) \(\log s_i\) \(s_i\) Where \(s_i\) sits Term in (14) Gradient weight \(s_i \hat A_i / G\)
1 “12 × 6 = 72” 1 +1.732 +0.035 1.0356 above, \(\hat A > 0\): clipped \(1.027 \times 1.732 = 1.7788\) 0
2 “12 × 6 = 62” 0 −0.577 −0.010 0.9900 inside \(0.9900 \times (-0.577) = -0.5716\) −0.143
3 “12 times 6 is 78.” 0 −0.577 −0.030 0.9704 below, \(\hat A < 0\): clipped \(0.980 \times (-0.577) = -0.5658\) 0
4 “12 + 6 = 18” 0 −0.577 +0.040 1.0408 above, \(\hat A < 0\): not clipped \(1.0408 \times (-0.577) = -0.6009\) −0.150

The products use unrounded values: the advantages are exactly \(\sqrt{3}\) and \(-1/\sqrt{3}\). The group’s objective is \((1.7788 - 0.5716 - 0.5658 - 0.6009)/4 = 0.0101\).

Answer 1 has already become likelier than the window allows, so this update leaves it alone, and answer 3 has already been pushed down enough. Answer 2 sits inside the window and is pushed down further. Answer 4 moved the wrong way, a wrong answer becoming likelier, so the minimum keeps its unclipped term and the update pushes it back.

In the step’s first update the same group looks different. Every \(s_i\) is exactly 1, nothing is clipped, the objective is 0, and the gradient weights are \(\hat A_i / G\): +0.433, −0.144, −0.144 and −0.144. Under the paper’s window, \([0.9997,\ 1.0004]\), the table’s log-ratios would clip answers 1, 2 and 3, and only answer 4 would move.

The KL term is small next to these. For one token with \(\pi_\theta = 0.50\) and \(\pi_{\text{ref}} = 0.45\), (16) gives \(0.9 - \ln 0.9 - 1 = 0.0054\), which \(\beta\) scales to \(5.4 \times 10^{-5}\).

One GSPO update for one promptIllustrative numbers: G = 4 answers, trained in the step's second update; clip window [0.980, 1.027]promptanswersscoreadvantagesequence ratio s (window shaded)updateWhat is12 × 6?answer: 72112 × 6 = 721+1.732212 × 6 = 620−0.577312 times 6 is 78.0−0.577412 + 6 = 180−0.577mean 0.25, std 0.4330.98011.0271.0356clipped:no gradient0.9900pushed downweight −0.1430.9704clipped:no gradient1.0408pushed downweight −0.150The same group in the step's first updateThe weights have not moved yet, so every s = 1:nothing is clipped and the objective is 0, yet all fouranswers get a gradient: the right one up, the rest down.0.98011.027weight +0.4331weight −0.1442weight −0.1443weight −0.1444
Figure 1. the clip removes the gradient only from answers that already moved past the window in their advantage’s direction. The illustrative group from the table above, in the step’s second update; the inset shows it in the first update, where every s = 1. Source: this post.
// § 10

The laptop phase: GSPO on a 64M model

Before the 8×H100 run, I tested the whole RL loop on an RTX 3060 laptop GPU with 6 GB. The model was MiniMind [9], a 64M-parameter dense model, starting from its released SFT weights. The tasks were generated arithmetic of four types: a + b, a − b, a + b − c and a × b.

Each step drew 16 prompts with 8 answers each and split the groups that carried a signal into up to 4 mini-batches, one update each, with \(\beta = 0.01\), the paper’s clip window and at most 256 new tokens. Held-out accuracy came from 200 problems, each answered 8 times at every evaluation.

Plumbing, and two bugs in the log-probabilities

After a plumbing test of the whole loop, the first run from the released weights showed two impossible numbers. The KL to the reference averaged 0.94 over steps 1–20, though policy and reference were the same file. And 44–56% of tokens were clipped, against the paper’s average of 15%.

Bug 1: batch-dependent scores. The same weights scored a group of answers 0.028 nats per token differently alone than inside the full batch. Different batch layouts ran different kernels; MiniMind’s attention, for one, takes another code path when any row is padded. The fix: compute the old, new and reference log-probabilities on identical mini-batches. Afterwards the first mini-batch’s ratio was exactly 1 and the KL exactly 0.

Bug 2: rounding made a tiny update look huge. After one update at \(10^{-6}\), the KL on the next mini-batch was still 6.4. The checkpoint was stored in fp16, and 13.04% of its weights sat exactly halfway between two bf16 values (bf16 keeps 3 fewer mantissa bits). So one update at \(10^{-7}\) moved 6.52% of the bf16 values by a full step.

The deciding test: a real change shrinks 10× when the rate does, and in fp32 it shrank 10.3×, in bf16 not at all. The fix: compute every training log-probability in fp32. Part 5 tells both stories in full.

My own on-policy rollout engine

Reading the sampler’s code later showed every rollout drawn at temperature 0.8 and cut to the 50 likeliest tokens and the top 85% of probability. These were MiniMind’s hidden defaults, and the loss treated the samples as draws from the untempered policy: every update was off-policy. The ratio test could not see it, because old and new log-probabilities came from the same scorer.

I wrote a rollout engine, code/rl/rollout.py, that repeats MiniMind’s sampling loop operation for operation, with every setting explicit. For each sampled token it records \(\log q\), under the distribution actually sampled, and \(\log \pi\), under the plain policy. With MiniMind’s settings it reproduced all 128 answers of a real batch token for token.

At temperature 1 without truncation, sampler and trainer differed by 4.5e-6 nats per token on average. The largest answer-level log-ratio sat about 70× inside the window. With the old settings, \(\log q - \log \pi\) averaged 0.121 nats per token, and the mean answer-level log-ratio was about 480× the window.

Generating in fp32 took 1.65× as long as in bf16. I kept fp32 anyway, because bf16 adds a 0.02–0.26 nats-per-token gap.

Choosing the learning rate with a rule written first

On-policy sampling changes how far each update moves the model, so I chose the rate again. The rule, committed before the runs, used training signals only; evaluation was off, so the choice could not flatter the held-out test. A rate was too fast if any of these held:

  • K: the 10-step mean KL to the reference passed 0.1;
  • C: over 30% of tokens in later mini-batches were clipped;
  • L: the 10-step median answer fell below 20 tokens.

The rule took the highest rate that was not too fast.

Rate K (max 10-step KL) C (later mini-batches clipped) L (min median length, tokens) Verdict
1e-7 0.019 0.096 64.0 passes
3e-7 0.1019 0.292 51.0 too fast, on K by 2%
1e-6 0.427 0.522 21.9 too fast, on K and C

The rule chose \(10^{-7}\). The least stable rate, \(10^{-6}\), had the largest early rise in training solve rate (0.8% to 3.8%), so choosing by eye would have picked it.

On-policy, the same rate moved the model harder: K was 2.8–4.3× its off-policy value. And \(3 \times 10^{-7}\) failed by less than its own noise; I reported that rather than change the rule afterwards.

The held-out test, fixed in advance: 3 of 3 seeds

The test, also committed before the runs, took each held-out problem’s accuracy at step 300 minus its accuracy at step 0. A run passed if the 95% bootstrap interval of the mean change, over problems, lay above zero. The claim needed all 3 training seeds to pass. Evaluation kept the earlier sampling protocol (temperature 0.8, top-k 50, top-p 0.85), so results stayed comparable across runs.

Seed Correct of 1,600, step 0 → 300 Change in points, 95% interval
0 13 → 94 +5.06 [+3.19, +7.19]
1 13 → 94 +5.06 [+3.06, +7.31]
2 13 → 87 +4.62 [+2.75, +6.75]

All three passed, so the claim stands: on-policy GSPO at the rule’s rate raised held-out final-answer accuracy. Multiplication carried it: a × b rose 12.8 to 16.4 points, a + b 3.4 to 5.7, and a − b 1.8 to 3.4. The two-step type, a + b − c, gained 3–4 answers of 408, mostly wrong working that happened to end on the right number. Sampled at temperature 1 without truncation, the gain was smaller, +2.4 to +3.2 points, but above zero in every seed.

On-policy GSPO passed in 3 of 3 seeds; the withheld type did notHeld-out final-answer accuracy, step 0 to 300, with 95% bootstrap intervals; a laptop RTX 3060 (6 GB)02468change in accuracy (points)Arm A: on-policy, rate 1e-7 (the claim)seed 0+5.06 [+3.19, +7.19]seed 1+5.06 [+3.06, +7.31]seed 2+4.62 [+2.75, +6.75]Arm W: a × b withheld from trainingall problems, seed 0+3.50 [+1.94, +5.25]all problems, seed 1+3.12 [+1.50, +5.00]all problems, seed 2+2.50 [+1.19, +4.06]a × b only, seed 0+2.56 [+0.32, +5.13]a × b only, seed 1+2.88 [−0.64, +7.69]a × b only, seed 2+1.92 [0.00, +4.49]Outside the claimarm B, rate 3e-7, seed 0+5.94 [+3.56, +8.56]Run 3b, off-policy, seed 1+4.37 [+2.44, +6.50]
Figure 2. all three headline seeds clear zero; with multiplication withheld from training, its held-out problems clear zero in only 1 of 3 seeds. Change from step 0 to step 300 with 95% bootstrap intervals over problems; arm B and Run 3b, in grey, are outside the claim. Source: the laptop runs’ saved analyses (Results).

What this does not show. The seeds share one held-out set and its evaluation random numbers, so “3 of 3” covers training randomness only. The grader reads only the final number, so the claim is “the final answer is right more often”, not “better at arithmetic”. And a rate chosen on 60 steps did not bound 300: every seed’s 10-step KL passed 0.1 between steps 129 and 188 and reached 0.30–0.40.

The short-answer phase

In an early off-policy run at \(10^{-6}\), the median answer fell from 81–118 tokens to about 10 within 20 steps. My pre-written “collapse” rule, a median under 20 tokens, fired at step 18, so that test made no claim. But a complete direct answer here is 6–12 tokens. At step 50 the answers were bare equations, median 9 tokens; “a + b = c” and “a − b = c” made up 41%.

The rule measured a proxy that a correct change also moves. I dropped it before the confirmation run on a new seed, which passed with +4.37 points [+2.44, +6.50]. On-policy, the answers again became one-line equations, the held-out median falling from 89 tokens to 10–15.5.

Inside mixed groups, wrong answers were 10.1–14.0 tokens longer than right ones. That fits shorter right answers driving the shortening, but does not test it. The length penalty and GSPO’s \(1/|y_i|\) weighting remain untested candidates.

No transfer to a withheld problem type

Arm W repeated the training with all 357 a × b problems removed from training; the held-out a × b problems stayed. Transfer would be claimed only if held-out a × b passed in all 3 seeds.

Seed a × b correct of 312, step 0 → 300 Change in points, 95% interval
0 5 → 13 +2.56 [+0.32, +5.13]
1 5 → 14 +2.88 [−0.64, +7.69]
2 5 → 11 +1.92 [0.00, +4.49]

It passed in 1 of 3 seeds, so there is no transfer claim. With a × b in training it rose from 5 to 45–56 correct. So 54–63% of the headline gain’s new correct answers were a × b, from a fifth of the problems.

The withheld type’s answers got shorter but kept their wording, for example “37 times 6 is 241”. The right product appeared in 3.5–4.5% of them, against 3.2% before training.

The laptop’s limit

MiniMind’s 198M MoE did not fit RL on 6 GB. With every memory saving its update fit, in 4,653–4,702 MiB. But a full 128-answer rollout did not: the third step’s rollout ran out of memory. In RL on a small card, generating the answers sets the memory, not training on them.

// § 11

GSPO in Megatron: the patch

Megatron-LM [8] at commit d6316eb45 had a GRPO loss with per-token ratios, per-token clipping and the k3 KL, but no sequence-level option. It already recomputed the old log-probabilities with the training model, and its sampler defaulted to temperature 1 with top-k and top-p off. My scripts set all three sampling values explicitly.

The patch, code/patches/megatron-d6316eb45.patch, adds --grpo-importance-sampling-level sequence. In that mode every token of answer \(i\) carries GSPO’s token form of the ratio [1]:

\[s_{i,t}(\theta) = \operatorname{sg}\big[s_i(\theta)\big]\cdot\frac{\pi_\theta(y_{i,t} \mid x, y_{i,<t})}{\operatorname{sg}\big[\pi_\theta(y_{i,t} \mid x, y_{i,<t})\big]} \tag{19}\]

Here \(\operatorname{sg}[\cdot]\) is the stop-gradient: its value is used, but no gradient flows through it.

In words: each token carries the answer’s ratio \(s_i\) as its value, while its gradient is \(s_i\, \nabla_\theta \log \pi_\theta(y_{i,t} \mid x, y_{i,<t})\).

Megatron’s existing clip then sees one value per answer, so it decides once per answer. The patch also divides each token’s loss by \(|y_i|\), and Megatron’s sum by the number of answers instead of tokens. Summed over an answer’s tokens, the gradient is then exactly (15), and the loss is (17). A second flag, --grpo-filter-groups-by-correctness, implements (9) from a correct flag that my math environment sets on each answer.

The tests run the patched functions from Megatron’s own source and match code/rl/gspo.py’s loss and gradient in 3 seeds, with the KL on and off. My first version had two mistakes. It demanded agreement to 1e-12, though gspo.py’s float32 casts limit it to about 1e-8. And its batches never clipped an answer in its advantage’s direction, so it never compared the clipped branch.

The tolerance is now 1e-7, and every test batch forces one clip each way. On one H100 with a shrunk model, the patched loss held its invariants: the first update’s ratio exactly 1, the KL exactly 0. The same rehearsal showed the policy drifting with every advantage at zero. The router’s balancing was pushing it, so GSPO runs with that balancing frozen.

// § 12

The main run on 8×H100

The model has 6.86B parameters, 1.22B active per token (Part 2). The 8 GPUs split the experts 8 ways (expert parallelism 8: each GPU holds 8 of every layer’s 64 experts), and everything else ran data-parallel. GSPO started from the SFT checkpoint at step 175 (Part 7).

The gate: does a group carry a signal?

Before GSPO, a gate required at least 30% of groups to be mixed in one rollout step. On the easy tier with groups of 8, it failed: 6.3% after 3 epochs of SFT, and 1.6% after a longer SFT run. Yet pass@8 was 11–17% on the word-problem test sets, so right answers did appear with enough samples.

So I moved GSPO to the medium tier, word problems from ASDiv and SVAMP, and held it there. Each step sampled 32 answers for each of 16 prompts, the same 512 answers as before. The gate then passed: 43.8% of the 16 groups were mixed, with 14 of 512 answers right (2.73%). That pass was one draw of 16 groups. The first step of the other two calibration runs, sampled from the same SFT weights before any update, gave 31.3% and 12.5%; the second would have failed the gate.

At \(G = 8\) the measured shares fit (10) within one group of 64. Solve rates of 0.4%, 0.8% and 0.2% predict 3.2%, 6.2% and 1.6%; the gate measured 3.1%, 6.3% and 1.6%. At \(G = 32\) and \(p = 2.73\%\), (10) predicts 58.8%, against 43.8% measured. Jensen’s inequality predicts such a gap when difficulty varies, and it did: later, 78% of these problems had no right answer in 16 tries.

Bigger groups find more signal, but less than the formulaShare of mixed groups against the solve rate: equation (10) as lines, the gate checks on 8×H100 as dotsequation (10)measured, one rollout stepgroups with right and wrong answers (%)0204060801000.1%0.2%0.5%1%2%5%10%solve rate p, the share of right answers (log scale)gate: 43.8%equation (10): 58.8%G = 32G = 81.6%3.1% (twice)6.3%
Figure 3. larger groups find far more signal, and at G = 32 mixed difficulty keeps the measured share below the formula (43.8% against 58.8%). Equation (10) for G = 8 and G = 32, with each gate check’s measured share; the solve rate is on a log scale. Source: the gate checks’ saved rollout statistics on 8×H100 (Results).

The first update was not exactly on-policy

The calibration’s first update, before any weight change, failed the ratio test. The median \(|\log s_i|\) was 0.0049 (p99 0.034, maximum 0.038), and the KL to the reference was 0.0027. The one-GPU rehearsal had the ratio exactly 1 and the KL exactly 0. Megatron’s code ruled out three causes:

  • routing: expert choice uses the same stored bias in both passes;
  • batch composition: each GPU scores its rows one at a time, in the same order, in both passes;
  • dropout: it was zero.

What remains is kernel-level differences between the no-gradient log-probability pass and the training pass at expert parallelism 8. Megatron’s batch-invariant mode is the principled fix, but it needs FlashAttention 3 or 4, and the machine had 2.7.4; it went to the backlog. Later, on one GPU with a dense model, the same check held exactly: partial evidence that expert parallelism causes the noise, not proof.

On 8 GPUs the first update's ratio was not exactly 1|log s| on the first update, before any weight change: 384 answers in three calibration runsanswers02040608010012000.00010.0010.010.1|log s|, the size of the sequence log-ratio (log scale)← 94 answers, exactly 0paper's clip windowedges 0.0003, 0.000474% of answers outside →our clip windowedges 0.020, 0.0271.6% outside →first calibration run:median 0.0049, p99 0.034
Figure 4. on 8 GPUs, numerical noise alone put 74% of first-update ratios outside the paper’s clip window, and 1.6% outside the wider one. Absolute log sequence ratio on the first update of the three calibration runs, 384 answers, 94 of them exactly 0; the median and p99 in the text are the first run’s. Source: the calibration runs’ saved per-answer statistics (Results).

Calibrating the clip above the noise, then the rate

The noise was 16× the paper’s clip, so on the first update it alone clipped 19.5%, 13.3% and 3.9% of answers in the three runs. The rate rule’s C was 13.0%, 12.0% and 4.2% at \(10^{-7}\), \(3 \times 10^{-7}\) and \(10^{-6}\). It fell as the rate rose, so it measured the noise, not the rate. Recomputed offline from the logged ratios, a clip of \(2 \times 10^{-2}\) / \(2.7 \times 10^{-2}\) clipped 0% on the first update.

I chose that clip, at the rule’s rate of \(10^{-6}\). The paper’s clip would have let noise drop about 40% of the answers that carry a signal. The trade-off is a weaker trust region: in GSPO-A, 0–1.6% was clipped per update. The rate matches published recipes: PocketRL [7] and NVIDIA’s RL config for Qwen2.5-Math-7B also train at \(10^{-6}\).

GSPO-A: 45 steps on the medium tier

GSPO-A made 45 steps, 177 updates, in its 85-minute limit (5,277 s). Generating and grading the answers took 57.5% of the logged time, as Part 10 explains.

In training, the solve rate went from 2.25% over the first 22 steps to 2.79% over the last 23 (Welch t 1.68): suggestive, not significant. The policy did move: its KL to the SFT model rose from 0.0024 to 0.028. The mean −log π of the sampled tokens fell from 1.21 to 1.10, a sharpening.

The held-out evaluation scored the same 1,178 problems from six test sets before and after, paired problem by problem. Greedy decoding takes the likeliest answer. The metric pass@8 asks whether any of 8 answers sampled at temperature 1 is right. Its sibling avg@8 is the share of the 8 that are right (Part 13).

Six sets pooled SFT GSPO-A Paired test
Greedy 1.9% 2.6% p = 0.24
pass@8 10.5% 13.2% p = 0.038
avg@8 1.46% 2.04% +0.58 points, p = 0.002

SVAMP’s pass@8 rose from 11.0% to 21.5% (p = 0.0025) on its 200-problem subset. On all 300 problems it rose from 12.0% to 18.0% (p = 0.04). GSM8K and MATH, the far and harder sets, did not move. With two pooled measures, pass@8’s p = 0.038 becomes 0.075 after a Bonferroni correction: borderline.

avg@8 uses all 8 samples per problem, which is why it detects the gain at p = 0.002. Held-out perplexity went from 22.74 to 22.76, so RL added no forgetting.

GSPO-A's gain is clear in avg@8 and borderline in pass@8Paired change from SFT on 1,178 held-out problems, with 95% bootstrap intervals; 8×H100GSPO-A: the whole medium tierGSPO-B: learnable problems only-20246change from SFT (points)Greedy accuracyGSPO-A+0.76 [−0.34, +1.87]p = 0.24GSPO-B+1.44 [+0.34, +2.63]p = 0.02pass@8: any of 8 samples rightGSPO-A+2.63 [+0.17, +5.01]p = 0.038GSPO-B+1.02 [−1.19, +3.23]p = 0.40avg@8: share of 8 samples rightGSPO-A+0.58 [+0.21, +0.96]p = 0.002GSPO-B+0.29 [−0.05, +0.63]p = 0.11
Figure 5. GSPO-A’s gain is clear in avg@8, borderline in pass@8 and not significant in greedy accuracy. Paired differences per problem on the 1,178 held-out problems, with 95% bootstrap intervals over problems and each test’s p-value. Source: the main run’s saved per-problem evaluations (Results).

GSPO-B: training only on problems the model can sometimes solve

GSPO learns only from mixed groups, so I tried difficulty filtering. The SFT model first answered each of the 1,905 medium-tier problems 16 times. By a rule fixed before that pass, a problem was learnable if 1 to 15 answers were right. 418 problems (22%) were learnable, 1,487 (78%) were never right, and none were always right.

GSPO-B trained on the learnable problems with GSPO-A’s settings: 46 steps, 181 updates. It learned its pool much faster: its solve rate rose from 4.89% over the first 23 steps to 7.31% over the last 23. A Welch test gave t = 4.24, against 1.68 for GSPO-A. On the held-out tests it could not be told apart from GSPO-A (greedy p = 0.31, pass@8 p = 0.22).

Against SFT, its greedy accuracy rose from 1.9% to 3.3% (p = 0.02), but its avg@8 of 1.73% was not significant (p = 0.11). Its pool was small, about 410 problems, so part of its training rise is learning those problems. In a run this short, filtering gave faster training, not a better held-out model.

The router held through RL

During RL the router’s balancing was frozen, so nothing rebalanced the experts, and the routing barely changed. The router z-loss, a measure of the size of the router’s scores, rose from 25.3 to 25.9 (+2.4%). The entropy of the 8 selected expert weights went from 1.996 to 1.989 nats, against a maximum of ln 8 = 2.079. The largest change was a mild sharpening in layer 2, whose top expert weight rose from 0.525 to 0.659.

// § 13

Why the gain was small

The base model gave RL almost nothing to reinforce. Before SFT it scored 0 on every test set, and after SFT its greedy GSM8K accuracy was 2.0%. 78% of the medium-tier problems had no right answer in 16 tries, and GSPO-A’s updates held about 3 right answers per 128.

Equation (5) moves the model only through answers that beat their group. The Dr. GRPO authors make the same point: with no sampled right answer, “it is impossible for RL to improve the policy” [3].

The recipe was not the problem. PocketRL uses the same rate, update size and gradient clipping, and with full gradients (its Dense arm) its 1.5B model went from 10.0% to 30.3% six-set avg@8 over 700 updates; its ActGRA method reached 32.9%. I also ran this pipeline on Qwen2.5-Math-1.5B: its MATH-500 avg@8 went from 21.77% to 53.95% in 100 updates (Part 14). The pipeline works; the base model set the size of the gain.

// § 14

What went wrong, and the fixes

Problem How it showed Fix
Batch-dependent scores (laptop) KL 0.94 between identical models Old, new and reference scored on identical mini-batches
bf16 rounding of an fp16 checkpoint (laptop) KL 6.4 after one update fp32 log-probabilities
Hidden sampler defaults (laptop) 0.121 nats per token off-policy My own rollout engine at temperature 1
A length rule that flagged correct answers (laptop) “Collapse” at step 18 Rule dropped before the confirmation run
A test that never reached the clip (patch) “Equivalence” never compared clipped answers Every test batch forces both clips
Too little signal at G = 8 (8×H100) 1.6% of groups mixed Medium tier, groups of 32
Ratio noise at expert parallelism 8 (8×H100) Median \(\lvert\log s_i\rvert\) 0.0049 on the first update Clip above the noise; batch-invariant kernels later
// § 15

Run it yourself

The step-by-step version is in the RL guide.

On a 6 GB laptop GPU

Hardware and time: one RTX 3060 laptop GPU (6 GB). The learning-rate sweep took 31 minutes, arms A and B took 4 h 46 min, and arm W took 3 h 33 min.

# From the repository root: the pinned environment, MiniMind at its pinned commit,
# its released SFT weights and the RL curriculum, each checked against a manifest
mkdir -p logs
bash code/scripts/day1_setup.sh 2>&1 | tee logs/day1_setup.log
cd code
bash scripts/onpolicy_sweep.sh   # the learning-rate rule: 1e-7, 3e-7, 1e-6, 60 steps each
bash scripts/step3.sh ab         # arm A (1e-7, seeds 0, 1, 2) and arm B (3e-7, seed 0), 300 steps each
bash scripts/step3.sh w          # arm W (a x b withheld); runs only if arm A passed in at least 2 of 3 seeds

Each run script first sources a guard. It blocks sleep, and refuses to start if another process uses the GPU or if code/ or the lab notebook has uncommitted changes. The settings are the trainer’s flags in code/rl/minimind_gspo.py. The rules and tests live in code/scripts/analyze_onpolicy_sweep.py and code/scripts/analyze_step3.py.

Results to expect: the sweep picks 1e-7, and held-out correct answers rise from 13 to 94, 94 and 87 of 1,600 in seeds 0–2. In arm W, a × b ends at 13, 14 and 11 of 312. My runs used PyTorch’s deterministic mode on one laptop GPU; I have not tested other GPUs.

On 8×H100

Hardware and time: one 8×H100 node. The three calibration runs took 375, 357 and 421 s, GSPO-A 5,277 s, the filter pass 824 s and GSPO-B 5,182 s. You need Megatron-LM at d6316eb45 with the patch applied, the container from the setup guide, and the SFT checkpoint from Part 7. The commands follow the RL guide, from the repository root:

# One folder and one log per run; the guard stops a run whose logs stay unchanged for 15 minutes
run() { export RUN_NAME=$1 RUN_DIR=/workspace/runs/$1; mkdir -p "$RUN_DIR"; shift
        python -I code/scripts/stall_guard.py --log "$RUN_DIR.log" --watch /workspace/runs -- "$@"; }
M=code/scripts/megatron
# /workspace/ckpt/sft below is the SFT checkpoint, its tracker file pointing at the kept step
export CURRICULUM_DIR=$PWD/data/curriculum
export GROUP_SIZE=32 PROMPTS_PER_STEP=16 RL_ENV_CONFIG=$PWD/code/rl/curriculum_env_medium.yaml

# 1. Calibration: one GSPO step (4 updates) per rate from the SFT weights, and each run's first-update check
for lr in 1e-7 3e-7 1e-6; do
  CALIBRATION=1 GSPO_LR=$lr SFT_CKPT=/workspace/ckpt/sft run cal_$lr bash $M/gspo.sh
  python -I code/scripts/gspo_run_report.py /workspace/runs/cal_$lr
done
python -I code/scripts/gspo_calibration_report.py --run 1e-7=/workspace/runs/cal_1e-7 \
    --run 3e-7=/workspace/runs/cal_3e-7 --run 1e-6=/workspace/runs/cal_1e-6   # prints the chosen rate

# 2. GSPO-A: the clip just above the measured noise, at the chosen rate, for 85 minutes
GSPO_CLIP_LOW=2e-2 GSPO_CLIP_HIGH=2.7e-2 GSPO_LR=1e-6 EXIT_MINS=85 SFT_CKPT=/workspace/ckpt/sft \
    CKPT_DIR=/workspace/ckpt/gspo run gspo bash $M/gspo.sh
python -I code/scripts/gspo_run_report.py /workspace/runs/gspo

# 3. GSPO-B: the SFT model answers every medium-tier problem 16 times; keep 0 < correct < 16; train on those
STALL_MIN=30 EVAL_CKPT=/workspace/ckpt/sft EVAL_CONFIG=code/rl/medium_filter_env.yaml EVAL_PROMPTS=5000 \
    run medium_filter bash $M/eval.sh
python -I code/scripts/build_learnable_tier.py /workspace/runs/medium_filter/eval_results.jsonl \
    "$CURRICULUM_DIR" /workspace/data/curriculum_learnable
CURRICULUM_DIR=/workspace/data/curriculum_learnable GSPO_CLIP_LOW=2e-2 GSPO_CLIP_HIGH=2.7e-2 GSPO_LR=1e-6 \
    EXIT_MINS=85 SFT_CKPT=/workspace/ckpt/sft CKPT_DIR=/workspace/ckpt/gspo_filtered run gspo_filtered bash $M/gspo.sh

The held-out evaluation is in the evaluation guide. The config files:

Results to expect: about 43.8% of groups mixed on the first calibration step, and a first-update median \(|\log s_i|\) near 0.0049 at expert parallelism 8. For GSPO-A, held-out pass@8 from 10.5% to 13.2% and avg@8 from 1.46% to 2.04%. Expect small differences between repeats: the inference engine batches requests differently each time, and its kernels are not batch-invariant.

The code:

// § 16

What to take away

  • RL needs no differentiable reward: sample answers, grade them, and weight each answer’s log-probability gradient by its advantage, as in (5).
  • GSPO keeps GRPO’s group baseline but uses one length-normalised ratio per answer. Its clip window is about 670 times narrower than GRPO’s, so numerical noise matters.
  • Check that the first update’s ratio is exactly 1 and the KL exactly 0. The check needs no extra computation, and it caught real problems on a laptop and on 8 GPUs.
  • Write decision rules before the data. The rate rule rejected the rate with the best early numbers, and the held-out claim needed all 3 seeds.
  • RL sharpens what a model can already do some of the time. With 78% of the problems never solved, GSPO had little to work with; on a stronger base, the same pipeline worked.

References

  1. Chujie Zheng et al. (Qwen Team), “Group Sequence Policy Optimization”, arXiv:2507.18071, 2025. arxiv.org/abs/2507.18071
  2. Zhihong Shao et al., “DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models”, arXiv:2402.03300, 2024 (introduces GRPO). arxiv.org/abs/2402.03300
  3. Zichen Liu et al., “Understanding R1-Zero-Like Training: A Critical Perspective” (Dr. GRPO), arXiv:2503.20783, COLM 2025. arxiv.org/abs/2503.20783
  4. John Schulman et al., “Proximal Policy Optimization Algorithms”, arXiv:1707.06347, 2017. arxiv.org/abs/1707.06347
  5. Qiying Yu et al., “DAPO: An Open-Source LLM Reinforcement Learning System at Scale”, arXiv:2503.14476, 2025. arxiv.org/abs/2503.14476
  6. John Schulman, “Approximating KL Divergence”, 2020. joschu.net/blog/kl-approx.html
  7. Stephen Chung and Wenyu Du, “PocketRL: Training a 7B Language Model with Reinforcement Learning on One RTX 5090”, arXiv:2611.37942, 2026. arxiv.org/abs/2611.37942
  8. NVIDIA, Megatron-LM, commit d6316eb45. github.com/NVIDIA/Megatron-LM
  9. MiniMind, a small open language model with its training code. github.com/jingyaogong/minimind

Cite this

@misc{aboagye2026minidsv4part09,
  author       = {Aboagye, Prince Osei},
  title        = {Mini DeepSeek V4, Part 9: Reinforcement learning: GRPO and GSPO},
  year         = {2026},
  howpublished = {\url{https://poaboagye.github.io/blog/09-rl-grpo-gspo/}}
}