TL;DR
The project moved through four stages: a laptop RTX 3060 (6 GB), a one-H100 rehearsal, 8×H100, and a control run on one H100. The failures that hurt most were silent: a random-weights evaluation exited cleanly, and a crashed RL run hung for 24 minutes, holding 25.9 GB. The main run found the faults that need eight GPUs or the full model, from a router collapse to RL ratio noise.
The biggest lesson was not a bug: RL sharpens answers a model already finds, and mine found them in 2–3% of its RL tries. So the next step is a stronger base, pretrained with math in the mix, before any more RL.
What you’ll learn
- How a laptop → one GPU → eight GPUs → control path finds failures early, and what each stage cannot see.
- The twelve failures that mattered most, as symptom, cause and fix, and the patterns behind them.
- Why RL gained so little on my model, in one formula: the share of groups that carry a learning signal.
- What I would do differently, and the five next steps the results point to.
The path, and what each stage caught
The 8×H100 run was the step that had to go right, so everything before it existed to make it uneventful. Each stage ran closer to the real thing than the last. Each also had a blind spot, which the next stage had to cover.
Stage 1: a laptop RTX 3060 (6 GB)
What it was for: testing the RL loop’s maths on MiniMind, a 64M-parameter dense model, before touching Megatron or the real model.
What it caught:
- An answer’s score depended on which other answers shared its batch, so GSPO’s ratio was off before any learning.
- An fp16 checkpoint in bf16 compute put 13.04% of the weights on rounding ties, so one tiny update looked huge.
- MiniMind’s sampling defaults made every early GSPO run off-policy.
- The fixes became invariants checked at every later stage: the first update’s ratio exactly 1, the KL exactly 0.
What it proved: on-policy GSPO raised held-out final-answer accuracy in 3 of 3 seeds, from 0.81% to 5.4–5.9%.
What it could not see: Megatron, several GPUs, and RL on a mixture of experts. Even a 198M-parameter MoE’s RL rollout ran out of memory on the 6 GB card.
An audit of my own notebook belongs here too. Checked against the logs and the code, it found about 90 problems, and nine changed a conclusion. One of them: the grader reads only the final number, and at step 300, 47 of 81 correct answers to one-operation problems also stated a wrong result. So the claim became “the final answer is right more often”, not “it got better at arithmetic”.
Stage 2: the data, on the laptop
- About 11% of NVIDIA’s new GSM8K-style questions, 7,997 of 73,643, had no exact answer. At least half of the teacher’s own solutions had to round.
- NVIDIA’s decontamination kept copies of test questions with new numbers: 2 of 10 sampled overlaps were template copies of GSM8K test questions.
- Unit tests passed while two of my filters were wrong. Each was found only by reading real samples.
- My answer checker rejected 0 of 20,528 correct gold answers and accepted 0 wrong ones, but 6 of 2,698 LaTeX problems had real holes.
Stage 3: one H100 with shrunk models (the rehearsal)
What it was for: running every stage of the real pipeline, Megatron and all, with a 2-layer model of hidden size 512. The question was only “does it run and record its metrics?”
What it caught, across 63 run logs:
- An SSH shell had 12 environment variables against the container’s 114, so Triton could not find
cuda.h. - A configured metric is not a recorded one: the router study would have saved no expert counts, and throughput never reached the dashboard.
- Seven RL start-up failures, from missing packages to a call to a function Megatron does not define.
- A failure that looked like success, a hung run, and a policy that drifted with nothing to learn: rows 5–7 of the table below.
Its verdict: every stage ran end to end, and 442 unit tests passed. GSPO learned from a real signal: z = 6.5 against its control.
What it could not see: anything that needs several GPUs, and the full model’s speed and learning signal. Before the main run, I listed each such item with the check that would cover it on 8 GPUs.
Stage 4: 8×H100, the full model
Here is that list, and what the full run showed:
| What one GPU could not test | The check set beforehand | What 8×H100 showed |
|---|---|---|
| Batch invariance across GPUs | The first update’s ratio, exactly 1 | Not exactly 1: median absolute log-ratio 4.9e-3, KL 0.0027 |
| The full model’s RL signal | The SFT → RL gate: at least 30% of groups mixed | 6.3%, then 1.6% with groups of 8 on the easy tier; 43.8% with groups of 32 on the medium tier, on one batch of 16 groups (two more draws from the same weights: 31.3% and 12.5%) |
| The learning rate | A three-rate calibration | Its clipping statistic fell as the rate rose 10× (13.0%, 12.0%, 4.2%): it measured noise, not the rate |
| NVLink and all-to-all bandwidth | nccl-tests | At 2 GB messages, 341 GB/s with NVLink and 11.4 GB/s without |
| The communication-overlap arm | Run it, and skip it if it fails | Out of memory at its first step: 78.8 of 79.2 GiB |
| Expert balance with no balancing in RL | Counts every step; an alarm at 2× the step-1 value | Flat at 6.29–6.41 (1.01×), but dominated by padding tokens |
The rehearsal had also shown the router collapse in miniature. Its shrunk V4 arm reached MaxVio 3.000, the maximum for top-2 of 8 experts, by step 40. I decided to keep the 40-step arms and report the trajectory. At full size, the V4 and aux-loss routers hit their maximum, 7.0, in all 16 layers by step 10.
Other faults that only the real node could show:
- The NVLink check failed with NVLink present.
grep -qexits at its first match,nvidia-smidies writing to the closed pipe, andpipefailfails the pipeline with exit 141. - Megatron’s experiment-tracker hook raced between rank 0 and the last rank; on one GPU both are rank 0. It would have stopped the main run at its first save.
- Megatron’s RL inference demands an expert-padding flag at expert parallelism above 1, so every RL launch would have stopped at start-up.
- My monitor compared one GPU’s MaxVio with another GPU’s baseline, and raised 7 false alarms on a healthy run.
- The network volume refused a folder named
aux, a reserved Windows device name.
And the base model: 0 on every test set after pretraining, and 1.6% of RL groups mixed after SFT. No rehearsal could have shown that.
Stage 5: one H100, the control run
What it was for: testing the RL pipeline itself against a published curve, with a pass line fixed before the run.
What it caught:
- Megatron decoded greedily because of a config file copied with the model: 1.44 distinct answers per group of 8 instead of 8.
- The grader hung training at update 16.
- One gradient spike at update 36: norm 5.77, against 0.18–1.04 around it. Megatron’s re-run check reproduced it, so the batch caused it, not the GPU, and the clip at 1.0 contained it.
- A miscalibrated check: my converter’s greedy-text test failed, with 11 of 20 openings agreeing where 16 were needed. A log-prob test passed at 0.034 nats per token.
Its verdict: the pipeline works. MATH-500 avg@8 gained 19.65 points by update 50, against a pass line of 11.5.
The top failures
Twelve failures, chosen because each could have sunk a run or a result. Troubleshooting has the full list, every one as symptom, cause and fix.
| # | Where caught | Symptom | Cause | Fix |
|---|---|---|---|---|
| 1 | Laptop | First GSPO run: about 50% of tokens clipped, ratios 0.81–1.12, where theory requires exactly 1 | An answer’s score depended on the other answers in its batch: two attention code paths, chosen by padding | Score old, new and reference log-probs in identical mini-batches: ratio exactly 1, KL exactly 0 |
| 2 | Laptop | KL 6.4 after one update at 1e-6; the bf16 change was the same at 1e-7 | An fp16 checkpoint in bf16: 13.04% of weights on rounding ties, which any update tips | Compute every training log-prob in fp32 |
| 3 | Laptop | Every one of 128 answers outside GSPO’s window, by about 480× | MiniMind’s sampler (temperature 0.8, top-k 50, top-p 0.85) was off-policy | My own rollout engine at temperature 1, no truncation: gap 4.5e-6 nats per token |
| 4 | Data | Unit tests passed | Two filters were wrong: 9 of 10 sampled “LaTeX” rejects were good solutions | Read real samples of every filter’s rejects |
| 5 | Rehearsal | An evaluation exited 0 | Its checkpoint was missing, so it ran on random weights (loss 11.85, about ln of the vocabulary size) | --exit-on-missing-checkpoint; the flag checker refuses a load without it |
| 6 | Rehearsal | A crashed RL run sat 24 min at 0% GPU, holding 25.9 GB | Megatron’s inference coordinator is a non-daemon process, and Python’s exit waits for it | daemon=True in my patch (exit ~1 s after the error), plus a guard that stops any run quiet for 15 min |
| 7 | Rehearsal | With every advantage 0 and the bias frozen, KL still reached 0.079 after 64 updates | The router’s balance loss (coefficient 1e-4) was the only gradient, and Adam made it a full-size step | RL with no bias update and no balance loss: gradient exactly 0, KL exactly 0 |
| 8 | 8×H100 | Dense baseline 3× slow, with 5 of 8 GPUs at 0% | Without memory-mapping, the reader opened and closed the data file per document; each close took ~150 ms on network storage | Data copied to RAM: 5.74 s per step, 3.3× faster |
| 9 | 8×H100 | Every router recipe at MaxVio 7.0 in all 16 layers by step 10 | The sign rule moves a bias at most 1e-3 per step; balance needed ±4–6 logits | Quantile balancing, by a rule written before the test: mean MaxVio 0.437 by step 200 |
| 10 | 8×H100 | First RL update off-policy: median absolute log-ratio 4.9e-3, 16× the clip; noise alone clipped up to 19.5% of answers | Not routing, batch composition or dropout (each ruled out in Megatron’s code); left by elimination, and untested: kernel-level differences between Megatron’s log-prob pass and its training pass at expert parallelism 8 | Clip raised above the noise (2e-2 / 2.7e-2); the root fix, batch-invariant kernels, is next |
| 11 | Control run | 1.44 distinct answers per group of 8 | Qwen’s generation_config.json (do_sample: false) made Megatron decode greedily |
Never copy that file; check the logged sampling defaults and distinct answers first: 8.0 after |
| 12 | Control run | Training silent after update 16, the GPU at 0% while holding 64 GB | The grader’s sympy.simplify spun with no timeout, on the thread that drives generation |
No grading of cut-off answers; a 10 s CPU-time limit per grading: 0 timeouts since |
The patterns behind the failures
The failures that hurt most were silent
A failure with a traceback in the first minute is found in a minute. The ones that hurt exit 0, or never exit at all. An RL restart silently started over: it reloaded “at iteration 0” and overwrote the checkpoint tracker, 61 → 13. A sampler–learner metric compared the trainer against zeros, and still gave steady numbers of the right order.
The cure has two halves. First, every limit I hit now fails at start-up with its reason, mostly in one flag checker. Second, open the output of a run that “succeeded”: that is how the random-weights evaluation was found.
The same weights do not always give the same numbers
This one returned at every stage. On the laptop, an answer’s score changed with its batch. On 8 GPUs, the first RL update’s ratio missed 1 by a median 4.9e-3 in log terms. In the control run, two evaluations of the same weights gave identical greedy text on only 198 of 500 problems.
On the laptop and in evaluation the cause was the same: kernels whose arithmetic changes with the batch. On 8 GPUs, batch composition was ruled out, and the remaining suspect, kernel differences between Megatron’s log-prob pass and its training pass at expert parallelism 8, is untested. The cures differed. On the laptop I made the layouts identical, and on 8 GPUs I raised the clip above the noise. For evaluation I report avg@8, which moved only 0.33 points between the two evaluations.
With Adam, a small coefficient is not a small effect
The drift in failure 7 came from a loss weighted 1e-4. Adam explains why that weight did not matter. It scales each weight’s step by that weight’s own recent gradient size:
In words: multiply every gradient by \(10^{-4}\), and Adam’s step stays the same size, apart from \(\epsilon\); only the direction comes from the gradient.
On the laptop I measured it directly: one Adam update moved about 90–91% of the weights by the full learning rate, to within 1%. So when the main RL gradient vanishes, any auxiliary loss sets both the direction and the full step size. A control run with nothing to learn is the test that exposes this: it must not move at all.
A check must be able to fail
Several of my checks could not fail, or failed for the wrong reason:
- A check that evaluations leave training’s random state alone compared that state with the value just restored, so it could never fail.
- A collapse rule, “median answer under 20 tokens”, fired at step 18, yet a complete, correct direct answer is 6–12 tokens long.
- My 40-step router bar, MaxVio at most 2, was too early for a recipe whose routers all start collapsed.
- The converter’s greedy-text test failed a correct conversion; the log-prob test was the calibrated one.
The rule I follow now: test every check against a deliberately broken input, and set every threshold from a baseline. My answer-checker audit does the first. Its own test swaps in a checker that accepts anything containing “52”, and the audit must call it slack.
Mistakes of my own
- I stopped processes by a name pattern three times. On 8×H100 one pattern killed the next run’s new ranks and another matched my own shell and cut the SSH session; in the control run a pattern matched its own SSH command and cut the session again.
- A wait looked for
"step": 100in files that write"iter": 100, so an update due at step 100 came at step 276. - I read a run as finished from its error line, while it hung for 24 minutes.
- My first stall guard slept a full 30 s poll interval, so every run would have ended up to 30 s late. Its first test caught it.
- CPU-only analyses placed between two GPU stages left all 8 GPUs idle until I moved them aside.
- My first explanation of the greedy decoding blamed CUDA graphs, the change I had just made. A rerun without them refuted it.
Why RL gained so little: the arithmetic of a learning signal
GSPO, like GRPO, learns only from mixed groups: groups with at least one right and one wrong answer. Suppose each answer to a problem is right with probability \(p\), independently. Then a group of \(G\) answers is mixed unless all are wrong or all are right:
In words: the chance that a group holds both a right and a wrong answer. When right answers are rare, it is roughly the group size times the solve rate.
The table puts this illustrative formula next to what my runs measured. The formula’s column is arithmetic, not data: it assumes every problem has the same \(p\).
| Run, tier (group size \(G\)) | Measured solve rate \(p\) | Formula \(1-(1-p)^G-p^G\) (illustrative) | Measured share of mixed groups |
|---|---|---|---|
| Main run, after 3-epoch SFT, easy tier (8) | 0.8% | 6.2% | 6.3% |
| Main run, after 6-epoch SFT, easy tier (8) | 0.2% | 1.6% | 1.6% |
| Main run, medium tier (32) | 2.73% | 58.8% | 43.8% |
| Control run, updates 1–10 (8) | 24.1% | 89.0% | 71% |
At low solve rates the formula matches closely: after SFT, \(8 \times 0.2\% = 1.6\%\), the measured share. At higher rates the measured share falls below it.
That is expected: some problems are never solved and some always are. The curve is concave in \(p\), so spreading the same average solve rate unevenly can only lower the expected share. The formula is therefore an upper bound.
Counting right answers tells the same story. GSPO-A’s updates held about 3 right answers per 128, a solve rate of 2.1–2.8%. At the 30.2% sampled MATH-500 accuracy of PocketRL’s 7B base, a 128-answer update would hold about 38: \(128 \times 0.302 \approx 38\). That is a stand-in, since their training set is different.
For 78% of the medium-tier problems, my SFT model got none of 16 tries right, and such problems rarely yield a mixed group.
Even on a strong base, RL mostly sharpened. In the control run, MATH-500 avg@8 rose 32 points, while reach, a problem solved in any of 9 tries, rose about 12. All of the new reach came in the first 50 updates. RL makes a model reliable at what it can already sometimes do.
What I would do differently
- Build the base for the RL I want. Pretrain with math in the mix, and on more tokens: 2.6B was about a tenth of the compute-optimal amount for 1.2B active parameters. The control run showed that the base, not the RL code, limited the gain.
- Plan RL from the base’s pass@k, not its greedy score. After SFT, greedy accuracy on the curriculum’s dev tiers was 0–8.6%, but pass@8 reached 11–17% on the word-problem sets. With the formula above, that number sizes the group before the run.
- Give SFT the skills the RL tiers need. My SFT data had no bare arithmetic, by design. The warm-up tier of bare sums was the model’s worst: 0 of 43 at every epoch. Worse, the curriculum steps easier below a 10% solve rate, so it would have drifted toward that tier.
- Judge routers on the recipe’s own timescale. In a comparison from the MoE handbook, every router of this recipe starts collapsed; most recover over about 100 steps, while the sign-rule bias router stayed flat. A 40-step health bar was too early.
- Keep training data in RAM or on local disk from the first run. On network storage, a reader that opens a file per record is limited by open and close latency, not bandwidth.
- Read the step time over many steps before calling a run healthy. The stalled baseline’s first samples, 7.3 s per step, looked fine.
- Evaluate with avg@k, more samples per problem and several seeds. avg@8 found GSPO-A’s gain at p = 0.002 where pass@8 gave p = 0.038. My GSPO-A against GSPO-B verdict rests on one run per arm.
- Treat every third-party default as untrusted. A model’s
generation_config.json, a grader without timeouts and a flag that passes Megatron’s checks each failed only once a run was under way.
What’s next
These five come from the open items and backlog rows that the main run and the control run left behind.
1. A stronger base: continued pretraining with math in the mix
The control run points here first: the lever is the base. The plan is to continue pretraining the saved checkpoint on 10B tokens with math in the mix. At the main run’s measured rate, that is about 14.5 hours on 8×H100:
In words: the number of tokens to train on, divided by the tokens per second that pretraining actually sustained on 8×H100.
2. Batch-invariant RL on 8 GPUs
Raising the clip hid the expert-parallel noise; it did not remove it. Megatron’s batch-invariant mode is the principled fix: batch-invariant kernels and an ordered expert-parallel combine. It requires FlashAttention 3 or 4, where my stack had 2.7.4, and Megatron’s own warning says it “will significantly affect speed” [8].
3. RL at expert parallelism 1
Memory was not my limit; expert parallelism 8 was a choice. With the distributed optimizer over 8 GPUs, I estimate the RL state at expert parallelism 1 at \(13.7 + 27.4 + 10.3 \approx 51\) GB per GPU. Those are the weights, the fp32 gradients and the optimizer’s share. The inference buffer comes on top, and the estimate is unmeasured.
It would drop the 8-way all-to-all and test whether expert parallelism causes the ratio noise. The control run’s exact ratio on one GPU is partial evidence, since its model is dense.
4. CUDA graphs and shorter RL sequences
My RL generation ran about 40× slower per GPU than PocketRL’s, with a 6× smaller active model. Two causes are fixable:
- Padding. RL rows were padded to 1,536 tokens against about 160 real ones, so about 90% of the routed tokens were padding. Shorter sequences with a padding mask fix both the waste and the misleading MaxVio.
- No CUDA graphs. Decoding ran at 68.3 ms per token for a single request. Megatron refuses full recomputation with CUDA graphs, so my MoE needs a recomputation change first.
5. Asynchronous RL
My RL loop is synchronous: generating and grading took 57.5% of the logged time, and each step waits for its longest answer. The longest answer per step had a median of 865 tokens, while the mean answer was 90 tokens. Asynchronous RL generates and trains at the same time, so it can win back only the time a synchronous step wastes:
In words: if a fraction \(x\) of each synchronous step is wasted waiting, removing all of it gives at most \(1/(1-x)\). At \(x = 20\%\), that is 1.25×.
I measured \(x\) only in part, so the shorter sequences and CUDA graphs come first. The order: Megatron’s own in-flight rollouts (a config change), then an asynchronous stack with rollout routing replay. Neither vLLM nor SGLang supports my exact router as it stands, and any routing difference between engine and trainer becomes sampler–learner gap. Routing replay records the engine’s expert choices and reuses them in training.
Also on the list: several seeds per RL arm, a Dr. GRPO arm beside GSPO, difficulty filtering at a larger scale, and rejection-sampling SFT on the model’s own correct answers.
What this project does not show
- Training luck. Each RL arm of the main run ran once, and the control run ran once.
- PocketRL’s exact curve. Its Dense arm’s values at updates 50 and 100 are read off its plots.
- Full-size distillation and 4-bit results. Both ran only on shrunk models, and the 4-bit models’ accuracy was not measured.
- The laptop bug’s exact size. Its diagnostic’s output was not saved, and its mask included positions after each answer’s end.
Run it yourself
Hardware and time. The first checks run on a laptop’s CPU. The node’s infrastructure checks take about 5 minutes on 8×H100, before its first training run.
Before any GPU, check every launch script against Megatron’s parser, cross-flag checks and model config. Then run the unit tests: 541 test functions in 59 files. Several guards in this post have their own tests, such as the shell-pipe, stall-guard and grader-timeout tests.
python -I code/scripts/megatron/check_flags.py --validate "$MEGATRON_PATH"
.venv/bin/python -m unittest discover -s code/tests
On the node, check the GPUs, then wrap every run in the stall guard:
python -I code/scripts/gpu_health_check.py --expect 8 --out /workspace/runs/gpu_health.json # must exit 0
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 -- "$@"; }
For RL, check the invariants, the learning against a control with nothing to learn, and the sampling:
python -I code/scripts/gspo_run_report.py /workspace/runs/gspo # first-update ratio and KL, clipping, alarms
python -I code/scripts/learning_check.py --test <run_dir> --control <control_run_dir>
grep "Sampling defaults" /workspace/runs/control_base.log # must show top_k=0, not top_k=1
Config. code/scripts/megatron/common.sh holds the routers, including the RL router with its balancing frozen.
Results to expect. The flag checker printed OK for all 50 configurations on my 8×H100 node. On one GPU, the first update’s KL reads exactly 0 with no ratio alarm. On the rehearsal’s shrunk model, the learning check said “learned” at z = 6.5.
Code. code/scripts/megatron/check_flags.py, code/scripts/stall_guard.py, code/scripts/gpu_health_check.py, code/scripts/gspo_run_report.py, code/scripts/learning_check.py, code/rl/rewards.py (the grader’s guards), code/tests/test_shell_pipes.py and code/tests/test_score_boxed_guards.py. The Guide has the commands in order.
What to take away
- Rehearse on the smallest hardware that runs the real code path. Then list what it cannot show, and the full-scale check for each item.
- The failures that hurt most are silent: make every run fail loudly at start-up, guard against silence, and read real outputs.
- The same weights do not always give the same numbers; measure your noise floor before you read a gain.
- With Adam, a small loss coefficient is not a small effect when the main gradient vanishes.
- RL needs a base that already finds the answer sometimes: check \(1-(1-p)^G-p^G\) before you plan the run.
References
- Chung and Du. “PocketRL: Training a 7B Language Model with Reinforcement Learning on One RTX 5090”. arXiv:2611.37942
- Zheng et al. “Group Sequence Policy Optimization”. arXiv:2507.18071
- Kingma and Ba. “Adam: A Method for Stochastic Optimization”. arXiv:1412.6980
- Hugging Face. “The Ultimate MoE Training Handbook”. huggingface.co/spaces/huggingface/moe-blogpost
- Rollout routing replay (R3). arXiv:2510.11370
- Miles. arXiv:2609.08368
- Thinking Machines. “Defeating Nondeterminism in LLM Inference”. thinkingmachines.ai/blog/defeating-nondeterminism-in-llm-inference
- NVIDIA. Megatron-LM. github.com/NVIDIA/Megatron-LM
Cite this
@misc{aboagye2026minidsv4part15,
author = {Aboagye, Prince Osei},
title = {Mini DeepSeek V4, Part 15: Lessons: what broke, what I'd change, what's next},
year = {2026},
howpublished = {\url{https://poaboagye.github.io/blog/15-lessons/}}
}