TL;DR
I set out to train a DeepSeek-V4-style mixture of experts from pretraining to RL, and to know which results to trust. Its shape came from a configuration already trained on the same hardware: 6.86B parameters in total, 1.22B active per token. The work climbed from a laptop RTX 3060 (6 GB) to one H100 and then to 8×H100, with a written gate at each step.
Three rules were fixed before their data, among them the control run’s pass bar of +11.5 points. An audit of my notebook found about 90 problems, each corrected in place.
What you’ll learn
- How to scope a training project around fixed hardware, and why I copied a tested model shape.
- How to write a decision rule before the data, with three real rules, one of which blocked a result I wanted.
- What a laptop, one GPU and eight GPUs can each prove, and the gate between them.
- How to keep a lab notebook that survives an audit.
The goal and the scope
One question runs through this series. Can one engineer, starting on a laptop, train a DeepSeek-V4-style mixture of experts end to end, and know which results to trust? A run that finishes but cannot be trusted teaches little.
A mixture of experts (MoE) is a transformer whose feed-forward layers are split into many small networks, the experts. A router sends each token to a few of them. The model therefore stores far more parameters than it uses for any one token. Part 2 explains it from scratch.
The pipeline has three training stages:
- pretraining: next-token prediction on web text, here FineWeb-Edu;
- supervised fine-tuning (SFT): training on worked question–answer pairs, to teach the answer format;
- reinforcement learning (RL): sampling answers, grading them, and making the good ones more likely, here with GSPO (Part 9).
Evaluation, a serving test, distillation and 4-bit training sit around them. The plan ranked every stage before the run. Pretraining, a router study, SFT and GSPO could not be cut; 4-bit training would go first, then distillation. On the 8×H100 run both were cut, as the order said (Part 12).
The hardware fixed the rest. It came in three tiers: a laptop RTX 3060 with 6 GB, one H100, and one node of eight H100s joined by NVLink. The 6.86B-parameter model only ever ran on the eight-GPU node. Everything before it existed to make that run safe.
A few working rules held for the whole project:
- measured numbers only, never a forecast stated as a result;
- the GPU run is the main work, and laptop work only makes it safe;
- every reported number is recomputed from the logs;
- if anything slips, the write-up moves, not the run’s quality.
The schedule gave each day one job and one gate:
| Day in the plan | Job | Gate at the end of the day |
|---|---|---|
| Wed 25 Nov | Megatron-LM checked; pretraining data prepared | Megatron’s verdict known; data ready |
| Thu 26 Nov | Every launch script; the GSPO code; a first step-by-step guide | Every script tested where the laptop can test it |
| Fri 27 Nov | A rehearsal on one H100 | Go or no-go |
| Sat 28 Nov | The 8×H100 run, one notebook entry per stage | Every stage measured and saved |
Megatron-LM is NVIDIA’s library for training large transformers (Part 4). One more rule moved the calendar: if a day’s work finished early, the next day’s came forward. The rehearsal ran on 26 November (UTC), and the 8×H100 run started that afternoon and ended early on 27 November.
Choosing the model size
I did not design the model’s shape. I copied one. The rule dates from the project’s first day: “Never use an untested hyperparameter configuration in a comparison study. Use what worked.”
The configuration came from Hugging Face’s Ultimate MoE Training Handbook [1]. Its second chapter trains a small MoE on one node of eight 80 GB GPUs, with a launch script the authors had run. The model has 16 layers, a hidden size of 2,048, and 64 experts per layer with 8 chosen per token. It holds 6.86B parameters, 1.22B of them active per token.
Copying it bought three things:
- It fits. The handbook had trained this exact shape on 8×H100.
- It has reference numbers. The handbook measured 149 TFLOP/s per GPU with perfectly even routing, and 125 with its tested router.
- It has a clean control. Eight experts 1,024 wide match one dense layer 8,192 wide, so a dense twin does the same feed-forward work.
DeepSeek V4’s changes went on top as flags: its router scores, a normalization of queries and keys, and a clamp inside each expert. Part 2 gives the architecture and its parameter arithmetic.
How many tokens?
I prepared 2.60B tokens of FineWeb-Edu: 634,880 sequences of 4,096 tokens, or 1,240 steps of 512 sequences. That is few for this model. A rule of thumb from the Chinchilla study [3] sets the compute-optimal amount of data at about 20 tokens per parameter:
where \(D_{\text{opt}}\) is the number of training tokens and \(N\) the number of parameters. For an MoE I take the active count, $N = 1.22$B, the smaller target. In words: for the lowest loss at a fixed amount of compute, a model should see about 20 tokens for every parameter.
Eq. 1 asks for about 24B tokens, so 2.60B is about a tenth. The plan wrote the consequence down in advance: GSM8K accuracy might be about 0% even after SFT. RL learns by comparing right and wrong answers, so a model with no right answers gives it nothing. So the plan put RL on a curriculum of easier problems, with GSM8K held out as a test; in the main run GSPO trained on its medium tier, the ASDiv and SVAMP word problems.
The plan, graded against the run
Numbers written before a run can be graded after it. One of them is MFU, model FLOPs utilization, the share of the GPUs’ peak arithmetic that the model’s own math uses:
where \(6N_{\text{active}}\) estimates training FLOPs per token, 2 for the forward pass and 4 for the backward. \(B_{\text{tok}} = 512 \times 4{,}096 = 2{,}097{,}152\) tokens per step, \(n_{\text{GPU}} = 8\), \(F_{\text{peak}} = 989.5\) TFLOP/s (an H100’s bf16 peak), and \(t_{\text{step}}\) is the step time. In words: the share of the hardware’s arithmetic spent on useful model math, leaving out attention’s own FLOPs.
The measured median step of 10.93 s gives 17.7%.
| Quantity | Written in the plan | Measured on 8×H100 |
|---|---|---|
| Pretraining time, 2.60B tokens | 5.2–6.5 h, from the handbook’s 0.4–0.5B tokens per hour | 4.09 h |
| Steps completed | 1,240 | 1,240 (100%) |
| MFU, Eq. 2 | 13–15%, the handbook’s range | 17.7% |
| Memory per GPU | Fits in 80 GB: ~18 GB of weights, gradients and optimizer state, plus activations | 58.8 GiB peak allocated (router study) |
| GSM8K after SFT | Possibly about 0% | 2.0%, greedy |
Two guards stood behind the time estimate. A time cap was written down before the run, and Megatron’s own time limit would save and stop the job 15 minutes after it. Neither fired: pretraining ended on schedule at step 1,240.
One proposal failed the check: a dense first layer, like DeepSeek-V3’s first three. The draft’s flag for it does not exist in Megatron. The change would also have made the model about 6.51B parameters and left the tested shape. Every layer stayed MoE.
The plan documents, and how they changed
The plan was a chain of dated revisions, each saying what changed and why.
| Date (2026) | Document | What changed |
|---|---|---|
| Before 23 Nov | Original plan | 8×A100; pretraining, SFT, 8-bit QAT, GRPO, distillation; targets such as “GSM8K 0 → 35%” with no source |
| 23 Nov | Plan review | 8×H100; RL on an arithmetic curriculum, GSM8K held out; a dense student for distillation; 4-bit QAT; an NVLink-off test instead of a second node; a one-H100 rehearsal; measured numbers only |
| 23 Nov | Plan of record | V4’s router for the main run; GSPO instead of GRPO |
| 25 Nov | Agreed plan | Every decision in one file; 21 open decisions, each with a recommendation |
| 25 Nov | Execution spec v2 | Checked line by line against Megatron’s source; 925 lines changed |
| 26 Nov | Execution spec v3 | The rehearsal’s fixes and a metrics audit |
| 30 Nov | Control-run plan | A pass bar for the RL pipeline, fixed before any data |
The router. The review had leaned towards the handbook’s tested softmax router, which converts to a standard Hugging Face model class. I chose V4’s router, since without it the model would not be V4-style at all. The trade-off was known: RL would run inside Megatron, because no standard inference engine could load the model as is. Part 10 returns to that choice.
The execution spec. It was meant to hold every parameter, threshold and abort rule in one place. I checked all 1,392 lines of version 1 against Megatron’s source at the pinned commit, our code and our notes. Five findings would have broken or changed the run, four from that check and one found while writing version 2:
- Its flag block left out the tested model flags. Megatron’s defaults would have built LayerNorm, dropout 0.1, no SwiGLU, learned positions and RoPE base 10,000.
- One of its flags does not exist in Megatron, so the launch would have failed.
- Its data flag would have split the training file again and ignored the validation file.
- Its study runs shared one checkpoint folder: each would have written about 110 GB and resumed from the last one’s weights.
- Its pretraining time, 3.5 h, did not fit its tokens; the handbook’s rate gives 5.2–6.5 h.
Version 2 differs from version 1 in 925 lines. Version 3 added the rehearsal’s fixes: 7 problems that would have stopped a stage, 4 that would have lost metrics. The lesson I kept: “Reading the code behind a flag found a bug that reading the document line by line did not.”
The oldest build documents had a worse problem. They described results in the past tense before any run, such as “GSM8K went from 0% to 35%”. I listed every such line so that none could leak into a write-up.
Decision rules written before the data
A decision rule says, before the data exist, which result leads to which action. Without one, it is easy to read a result the way you hoped. With one, the data decide.
Plan entries carried predictions, each with a confidence and, from the second day, a one-line reason. They went into git before the run. From 24 November, a guard script refused to start a run while the notebook had uncommitted changes. In-run decisions could use only development splits, never a test set.
Rule 1: the laptop’s held-out test
On the laptop I trained MiniMind, a 64M-parameter model, with GSPO for 300 steps. Before the run I wrote down how I would decide whether it had learned. Each of 200 held-out problems, never used in training, got 8 sampled answers at step 0 and at step 300:
where \(a_j^{(t)}\) is the share of problem \(j\)’s 8 answers that are correct at step \(t\). \(\bar{\Delta}_{\text{low}}\) is the lower end of a 95% bootstrap interval, from 10,000 resamples of the 200 problems. In words: claim learning only if even the pessimistic end of the interval is above zero.
A safety rule came with it. If the typical answer fell below 20 tokens, later results would not count. It fired at step 18, before the first evaluation. The test compared step 0 with step 0: no learning claim.
That hurt, because accuracy had moved. Counted anyway, it rose from 0.81% to 3.81%, a gain of 3.0 points, with an interval of [+1.375, +4.875]. But the rule was fixed in advance, so its verdict stood. The fault was the rule’s: “57 + 10 equals 67” is a complete answer of 8 tokens.
Before the next run, I dropped the safety rule, since a broken model fails the test on its own. A run with a new seed then passed: +4.37 points, [+2.44, +6.50]. An audit added two caveats. The claim depends on dropping the rule, and the grader reads only the final number, so the honest name is “final-answer accuracy”.
With the sampler later fixed, GSPO raised held-out final-answer accuracy in 3 of 3 seeds: +5.06, +5.06 and +4.62 points. The lesson: measure what normal output looks like before writing a threshold into a rule.
Rule 2: the router on the 8×H100 run
The plan’s abort rules were written on 25 November, the day before the run. After a 40-step test, the V4 router had to be healthy: no dead expert (one that receives no tokens), and its load imbalance under a threshold. If both routers failed, the rule said abort.
Load imbalance is measured by MaxVio, defined in Part 2. It is 0 for an even load, and 7 when every token picks the same 8 of 64 experts. Within 10 steps, the V4 router and the handbook’s auxiliary-loss router both hit 7.0 in all 16 layers.
A first fix, a bias updating ten times faster, was already running. I wrote the next rule at 17:00 UTC, before its step-20 to step-40 counts, and numbered its middle branch at 17:03:
where \(\overline{M}_{40}\) is the MaxVio at step 40, averaged over the 16 layers, and \(n_{<7}\) the number of layers below 7.0. In words: keep V4’s router if the faster bias clearly works, and otherwise test one alternative named in advance.
The faster bias read 7.000 at step 40, so the third branch applied. The quantile-balancing run reached 5.186, with 15 of 16 layers below 7.0 and its loss within 0.2 of the auxiliary-loss run’s. Its own reading, also written first, called that clearly falling, so it became the main run’s router. At step 200 its MaxVio was 0.44, far inside the re-check’s limit of 2 (Part 6).
This rule had a flaw too. The 40-step health bar was set too early for this recipe. The handbook’s own 120-step comparison shows every router starting collapsed; all but the sign-rule bias at 1e-3 recover over about 100 steps, while that one stays flat.
Rule 3: the control run’s pass bar
GSPO gained little on my model, while PocketRL [5], a similar RL recipe on Qwen’s math models, gained far more. Was my model to blame, or my RL code? On 30 November, before any of it ran, I fixed the test. My pipeline would run on PocketRL’s base model, Qwen2.5-Math-1.5B, against their full-Adam arm.
The measure is avg@8 on MATH-500: the share of 8 sampled answers per problem that are correct, averaged over 500 problems.
where \(\Delta_{50}\) is in percentage points. PocketRL’s arm gained about 23 points by update 50, read off their figure; 11.5 is half of that, and 5.75 a quarter. In words: reach half the published gain and the pipeline works; a quarter or less, and it is losing something.
A simpler 10-point rule was considered and rejected. The result was +19.65 points, with a paired t of 17.3. Part 14 tells that run in full.
Smaller rules worked the same way. The SFT checkpoint was the one with the lowest validation loss across both SFT runs, a rule fixed before the data; it chose step 175. Pretraining’s end checks, written before the run ended, passed.
From a laptop to 8×H100: what each step had to prove
A single jump in scale hides bugs until they are hardest to find. I went in three steps. Each had a gate: a written list of what it had to show before the next began.
| Step | Hardware and model | Had to show | What it found |
|---|---|---|---|
| 1. Laptop, 23–25 Nov | RTX 3060 (6 GB); MiniMind 64M dense and 198M MoE | The RL maths is exact; GSPO learns on held-out problems; data and scripts ready | A batch bug in the scores, fixed; gains in 3 of 3 seeds; the MoE’s RL sampling does not fit 6 GB |
| 2. One H100, 26 Nov | Shrunk models: 2 layers, hidden 512, 8 experts, top-2 | Every stage runs end to end and logs its metrics; save, resume and restart work | Two failures that looked like success; a crashed run that hung; drift with nothing to learn |
| 3. 8×H100, 26–27 Nov | The full model: 6.86B total, 1.22B active | Each stage passes its written checks before the next | A router collapse; a failed RL signal check; an inexact first update |
Step 1: the laptop
The laptop could not run the real model, but it could run the RL loop on a small one. That is where the hardest bug was. GSPO weighs each answer by how much more likely the trained weights make it than the weights that sampled it [4]:
where \(\pi_\theta(y_i \mid x)\) is the probability that weights \(\theta\) give answer \(y_i\) to prompt \(x\). \(|y_i|\) is the answer’s length in tokens, and \(\theta_{\text{old}}\) are the weights that sampled it. In words: before the first update both weight sets are the same, so the ratio must be exactly 1.
It was not. The same weights scored 8 answers differently alone than inside a batch of 32, by 0.028 nats per token on average. A nat is a log-probability unit with base \(e\); the audit notes that this measurement also counted positions after each answer ended.
Scoring the old, new and reference models in identical mini-batches fixed it. The first ratio became exactly 1, and the KL divergence from the reference model exactly 0.
The laptop showed two more things. GSPO learned, in 3 of 3 seeds. The MoE’s RL sampling, not its update, was too big for 6 GB. Then, following “the GPU run is the main work”, I cut a planned three-seed laptop study.
Step 2: one H100
The rehearsal ran every script on shrunk models: 2 layers, hidden size 512, 8 experts with 2 per token. Their speeds and losses say nothing about the real model; they show that each step runs and logs its metrics.
It caught the worst kind of failure: the kind that looks like success. An evaluation that silently loaded random weights exited with code 0. Its loss was 11.85, near \(\ln 128{,}256 \approx 11.76\), a uniform guess over the vocabulary. A restart flag made an RL run start over instead of resuming.
A crashed RL run hung for 24 minutes at 0% GPU use instead of exiting. Each of these now fails loudly at start-up or is stopped by a guard.
The gate was a readiness report, written before the 8×H100 node existed. Every stage had run end to end, and every problem found was fixed and tested. 442 unit tests passed, and so did every launch script under the flag checker. GSPO’s reward rose 6.5 standard errors more than a control run’s, and each of 281 tracked metrics had a named producer.
The report also listed what one GPU could not show, and what would cover it on eight:
| Only 8 GPUs can show | Covered by |
|---|---|
| Batch invariance across GPUs | The first RL update’s ratio, which must be exactly 1 (Eq. 6) |
| Overlapping expert communication with compute | One 40-step test, skipped if it fails |
| NVLink and all-to-all bandwidth | nccl-tests before any training |
| The full model’s RL signal | The SFT → RL gate: at least 30% of answer groups mixed |
| Hangs | A stall guard: any run whose logs go quiet for 15 minutes is stopped |
Step 3: eight H100s
On the real run, every stage had written checks. Three failed, and each failure changed the plan in the open:
- The router study found the routers collapsed, and Rule 2 chose quantile balancing (Part 6).
- The SFT → RL gate needed at least 30% of answer groups to hold both right and wrong answers. GSPO learns nothing from a group that is all right or all wrong. After 3 epochs of SFT it read 6.3%; on a longer SFT run’s checkpoint, 1.6%. On the medium tier with 32 answers per problem it read 43.8%, a pass; two other first-step draws from the same weights read 31.3% and 12.5%, so one batch of 16 groups is a noisy gate (Part 7).
- The first-update check of Eq. 6 failed on 8 GPUs. The median \(\lvert\log s_i\rvert\) was 4.9e-3 (99th percentile 0.034), where one GPU gave a ratio of exactly 1. I set GSPO’s clip above that noise, at 2e-2 / 2.7e-2, and recorded why (Part 9).
Other checks passed as written, though one recorded pass, the fp32 expert combine, was later found wrong: at this Megatron commit the combine is a bf16 sum. The overlap test ran out of memory at its first step, 78.8 of 79.2 GiB, and was skipped as planned.
Keeping a lab notebook
Everything above lives in one file, the lab notebook, which grew past 10,000 lines. It opens: “Running record of every measured run: what ran, the exact command and config, raw results, what we learned and what we would change.” It follows a fixed form:
- Dated entries, appended in order, with a results list at the top that points each result to its entry.
- Plans before runs: the question, the test, the checks that would void a run, and predictions with reasons.
- Decisions with their options. “Every decision has its reason and alternatives.”
- Investigations in one shape: symptom; each issue with how it was found, the fix and how it was verified; what is open; lessons.
- Corrections in place. A wrong sentence is never deleted. It stays, with a dated correction beside it.
Here is the start of one results-list row as it reads now:
Confirmed: GSPO raises held-out accuracyGSPO raised final-answer accuracy (test fixed in advance, passed) …2026-11-24, audit: the grader reads only the final number, so this says “the model gets the final answer right more often”, not “it got better at arithmetic”.
The run rules are enforced in code. A guard script at the top of every laptop run script blocks sleep, refuses a busy GPU, and refuses uncommitted code or notebook. It also takes start and end times from the clock. Each rule answers a lapse that the audit below found.
What an audit of my own notes found
On 24 November I found a claim in the notebook that its data did not support. Before more runs could build on it, the notebook was frozen at one commit and audited. Every entry was checked against the logs, the code at each commit and the system journal. About 90 findings came back, each re-checked against the logs before it was corrected beside the original text.
Nine findings changed a conclusion. Four of them:
- What the gain measured. At step 300, 47 of 81 correct answers to one-operation problems also stated a wrong result. One read “29 × 3 = 77. So, 29 × 3 = 87.”
- A misread rule. An entry said the dropped safety rule would have fired late, at step 261. It would have fired at step 14, so the claim depended on dropping it.
- A suspend nobody noticed. The laptop slept for 23 minutes in the middle of a run, which explained its slow steps.
- Predictions that were not. Some “predictions written before the run” first reached git after it.
Each lesson became a rule, and most became code:
- block sleep for the length of a run;
- commit predictions before the run, and take entry times from the logs;
- a check must be able to fail, so test it first with a broken input;
- name a metric after what it computes (“re-scoring gap”, “final-answer accuracy”).
The checking went on. An external review the same day caught a statistics error. With three paired seeds, “all three favour the teacher” happens by chance 1 time in 8, not 1 in 20. A later check of the rehearsal day found 19 gaps and 6 contradictions, all fixed in place.
Run it yourself
Hardware and time. The checks below need only a CPU. The stages they protect ran on a laptop RTX 3060 (6 GB) and on one H100 for a 5.6-hour rehearsal. The full model ran on one 8×H100 node for about 14 hours.
# From the repository root.
# 1. The unit tests: 541 test functions in 59 files. No GPU needed.
python -m unittest discover -s code/tests
# 2. Every launch script through Megatron-LM's own parser, its cross-flag checks
# and its TransformerConfig. MEGATRON_PATH is a Megatron-LM checkout at commit
# d6316eb45 (the setup guide shows how to get it).
python -I code/scripts/megatron/check_flags.py --validate "$MEGATRON_PATH"
# 3. The same checks with the one-H100 rehearsal's shrunk models.
python -I code/scripts/megatron/check_flags.py --validate --rehearsal "$MEGATRON_PATH"
To put your own run under the guard, make this the first command of a run script in code/scripts/:
source "$(dirname "$0")/run_guard.sh" "$@"
What to expect. The tests and the flag checks should report no failures; at the rehearsal, every launch script passed in both modes. A guarded run refuses to start while code/ has uncommitted changes. It records the commit it ran from, so a plan committed earlier provably came first.
The files:
- code/scripts/run_guard.sh: the run rules;
- code/scripts/stall_guard.py: stops a run whose logs go quiet;
- code/scripts/megatron/check_flags.py: the flag checker.
The setup guide and the testing guide go through them step by step. The monitoring guide lists every tracked metric and what produces it, and the results page holds every number in this post.
What to take away
- Copy a configuration already trained on your hardware, and add your changes on top as flags.
- Write each decision rule before its data. Measure normal output before choosing a threshold.
- Scale up in steps. For each step, write what it must show and what it cannot.
- A failed gate is a result. Change the plan in the open, with the reason, before the next data.
- Keep wrong text visible beside its correction, and audit your notes before building on them.
References
- Hugging Face. The Ultimate MoE Training Handbook. huggingface.co/spaces/huggingface/moe-blogpost; its tested launch scripts are in the companion gist.
- DeepSeek-AI. DeepSeek-V4: Towards Highly Efficient Million-Token Context Intelligence. arXiv:2606.19348, 2026. arxiv.org/abs/2606.19348
- J. Hoffmann et al. Training Compute-Optimal Large Language Models. arXiv:2203.15556, 2022. arxiv.org/abs/2203.15556
- C. Zheng et al. Group Sequence Policy Optimization. arXiv:2507.18071, 2025. arxiv.org/abs/2507.18071
- S. Chung and W. Du. PocketRL: Training a 7B Language Model with Reinforcement Learning on One RTX 5090. arXiv:2611.37942, 2026. arxiv.org/abs/2611.37942
- NVIDIA. Megatron-LM, at commit d6316eb45. github.com/NVIDIA/Megatron-LM
- MiniMind. github.com/jingyaogong/minimind
Cite this
@misc{aboagye2026minidsv4part01,
author = {Aboagye, Prince Osei},
title = {Mini DeepSeek V4, Part 1: Planning the project, and the rules I wrote before the data},
year = {2026},
howpublished = {\url{https://poaboagye.github.io/blog/01-planning/}}
}