TL;DR
I trained a 6.86B-parameter mixture of experts with Megatron-LM on one node of eight H100 GPUs. Each GPU held 8 of the 64 experts per layer plus a copy of everything else, and tokens reached their experts by an all-to-all. That needs about 18 GB of model state per GPU, and the study runs peaked at 58.84 GiB allocated. Pretraining ran at 10.93 s per step and 194.7 TFLOP/s per GPU, a model-FLOPs utilization of 17.7–19.7%. The worst slowdown was not the GPUs: the dense baseline ran 3.3× slower until I moved its data from the network volume to RAM.
What you’ll learn
- What data, tensor, pipeline, context and expert parallelism each split, and how much each communicates.
- How to count GPU memory per parameter, and how the distributed optimizer divides the optimizer state.
- How much data one MoE layer’s all-to-all moves, and how utilization follows from “6 × parameters × tokens”.
- Which checks to run on a new multi-GPU node, and the failures that appeared only on eight GPUs.
Why Megatron-LM
Megatron-LM is NVIDIA’s open-source library for training large transformers on many GPUs. The Ultra-Scale Playbook describes it as “NVIDIA’s framework for training large language models, featuring various parallelism strategies”. I pinned one commit, d6316eb45, and used it for every stage of the project.
Three reasons
One framework for pretraining, SFT and RL. At that commit, Megatron had flags for every DeepSeek-V4 feature I kept. It also had a data mode for supervised fine-tuning (SFT), two inference engines and a reinforcement-learning (RL) loop. The model is defined once, in the code that pretrains it, so nothing has to be converted between stages.
Real mixture-of-experts support. A mixture of experts (MoE) replaces each feedforward block with many small ones, the experts. A router sends each token to a few of them. Megatron puts experts on different GPUs, moves tokens with an all-to-all dispatcher, and runs each GPU’s experts as one grouped matrix multiplication (a grouped GEMM). It also had DeepSeek-V4’s sqrt-softplus router scores, quantile balancing, an fp32 router and per-expert token counts.
Its own inference engine routes exactly like the trainer. RL writes answers with an inference engine and learns from them with a trainer. In an MoE, any routing difference between the two becomes a gap between the policy that sampled and the policy being trained. vLLM and SGLang could not load our router as they stood: our quantile bias is added to the logits before the top-k, not to the scores. Megatron’s engine runs the trainer’s own router code, though the router’s inputs can still differ in their last bits (Part 5).
What it lacked
Megatron lacked two things: GSPO’s sequence-level ratio, and a converter from Megatron to Hugging Face for a GPT-style MoE. I added GSPO as a patch to Megatron’s RL loss (Part 9). The patch changes 7 files. Beside GSPO, it fixes failures found in testing, among them a missing pad token, an inference coordinator that kept a crashed run alive, and a checkpoint-logging race that only 8 GPUs showed. The converter mattered only for a fallback path or a Hugging Face release of the MoE, so I never wrote it.
Every launch script starts from a tested script, the one in Hugging Face’s MoE training handbook, with V4’s router on top. The handbook’s first run used this exact model shape and parallel layout on one node of 8 H100s.
Five ways to split training across GPUs
A training step has a forward pass, a backward pass that computes gradients, and an optimizer step that updates the weights. With several GPUs, we decide which GPU holds which weights, which tokens and which activations, the intermediate values the backward pass needs. Every split saves memory or time and pays for it in communication. I use the terms of the Ultra-Scale Playbook (Tazi et al., 2025).
Data parallelism
Data parallelism (DP) gives every GPU a full copy of the model and a different slice of the batch. After the backward pass the GPUs average their gradients, so every copy takes the same step. The Playbook calls it “just a parallel version of gradient accumulation”. Its limit: every GPU must hold the whole model, its gradients and its optimizer state.
Tensor parallelism
Tensor parallelism (TP) splits each weight matrix across GPUs, so every GPU computes part of every matrix multiplication. The partial results are combined inside every layer, in both passes. That communication sits on the critical path, an “exposed communication overhead” that cannot be fully hidden behind compute. TP is usually kept inside one node, on the fastest links.
Pipeline parallelism
Pipeline parallelism (PP) splits the layers: each GPU holds a few consecutive layers, and activations flow from one GPU to the next. GPUs wait while the pipeline fills and drains, and this idle time is called the bubble. With \(p\) stages and \(m\) micro-batches per step, the bubble is \((p-1)/m\) of the useful time. PP also “usually requires rather extensive modifications to training code as well as modeling code”.
Context parallelism
Context parallelism (CP) splits each sequence along its length. Most layers treat each token on its own, but attention must exchange keys and values between GPUs. The Playbook keeps CP for “extreme sequence lengths (128k+ tokens)”. Our sequences are 4,096 tokens long.
Expert parallelism
Expert parallelism (EP) puts different experts on different GPUs. The Playbook puts it simply: “we just need to route the hidden states of a token to the right expert”. The routing is an all-to-all: each GPU sends every other GPU the tokens bound for its experts, then receives the results. EP touches only the MoE layers, so it is combined with data parallelism for everything else.
Our layout: experts split eight ways, everything else data-parallel
Our settings are tensor 1, pipeline 1, context 1 and expert 8. Each MoE layer has 64 experts: GPU 0 holds experts 0–7, GPU 1 holds 8–15, and so on up to GPU 7 with 56–63. Attention, embeddings, routers and norms are copied on all eight GPUs.
One MoE layer, for the tokens on one GPU:
- Attention runs locally, on the GPU that holds the sequence.
- The router scores all 64 experts for each token and keeps the top 8.
- Dispatch: an all-to-all sends each token’s hidden state to the GPUs that hold its 8 chosen experts.
- Experts: each GPU runs its own 8 experts on the tokens it received, as one grouped GEMM.
- Combine: a second all-to-all returns the outputs, and each token’s expert outputs are summed with the router’s weights.
Every step processes 512 sequences of 4,096 tokens. Each GPU takes 8 sequences per forward pass, its micro-batch, and accumulates gradients over 8 micro-batches, since \(512 = 8 \text{ GPUs} \times 8 \text{ sequences} \times 8\).
The replicated parts train with data parallelism: their gradients are summed across all 8 GPUs every step. The experts need no such sum. Each expert lives on exactly one GPU, which sees every token routed to it. So its gradient is complete where it is computed: in Megatron’s terms, the expert data-parallel size is 1.
Why no tensor, pipeline or context parallelism
- It fits without them. The model state is about 18 GB per GPU, and the study runs peaked at 58.84 GiB of the 80 GB.
- It matches the Playbook’s advice: “For models under 10B parameters, you can use a single parallelism technique, e.g. tensor parallelism or ZeRO-3/DP with full recompute across 8 GPUs.” Ours has 6.86B parameters.
- TP would add communication inside every layer, and change the order of sums. Microsoft AI’s RL team runs its learner without TP. Their reason: “Row-parallel projections under tensor parallelism (TP) require summing partial outputs across GPUs, a known source of numerical discrepancies”. Part 5 shows why that matters for RL.
- PP would add a bubble and code changes, and CP is for sequences far longer than ours.
What EP buys is clearest against the alternative. With all 64 experts on every GPU and the optimizer state still split eight ways, the state would be about 51 GB per GPU. EP 8 cuts it to about 18 GB, because each GPU keeps the weights, gradients and optimizer state of only one eighth of the experts.
The collectives, in plain words
A collective is a communication step in which every GPU of a group takes part. NCCL, NVIDIA’s collective communications library, runs them over NVLink, the direct GPU-to-GPU links inside the node. Four of them matter here:
- All-reduce: every GPU starts with a tensor, and every GPU ends with the sum.
- Reduce-scatter: the same sum, but each GPU keeps only its own slice of it.
- All-gather: each GPU starts with one slice, and every GPU ends with all of them.
- All-to-all: each GPU sends a different chunk to every other GPU. MoE dispatch and combine are all-to-alls.
An all-reduce is usually built as a reduce-scatter followed by an all-gather, passing chunks around a ring of GPUs. Its traffic per GPU is
where \(N\) is the number of GPUs and \(K\) is the size of the tensor in bytes.
In words: each GPU sends and receives almost twice the tensor’s size, and each half of the ring moves about one tensor.
How much an MoE layer moves
Each dispatch sends every token’s hidden state to \(k\) experts, and only the copies bound for experts on the same GPU stay home. Per GPU, per layer, per micro-batch and per direction, the all-to-all moves
where \(T\) is the number of tokens in the GPU’s micro-batch, \(k\) the experts per token, and \(h\) the hidden size. \(b\) is the bytes per value and \(E_p\) the expert-parallel size.
In words: the exchange grows with tokens, experts per token and hidden size, and all but one \(E_p\)-th of it leaves the GPU.
With our numbers, \(T = 8 \times 4{,}096 = 32{,}768\), \(k = 8\), \(h = 2{,}048\), \(b = 2\) (bf16) and \(E_p = 8\), so \(V_{\text{A2A}} \approx 0.94\) GB. This assumes the router spreads tokens evenly across the GPUs.
How many such exchanges does a step make? Count dispatch and combine in every layer, in every pass:
where \(m\) is the number of micro-batches per GPU per step and \(L\) the number of MoE layers. The 2 counts dispatch and combine, and the 3 counts the passes: forward, forward recomputed during the backward pass, and backward.
In words: every layer exchanges tokens twice in each of three passes, for every micro-batch.
For us, \(m = 8\) and \(L = 16\), so \(n_{\text{A2A}} = 768\). The profile assumes this count: with perfectly even routing it measured 3,042.5 ms of all-to-all per step and divided it by 768, giving 3.96 ms per exchange. The main run’s profile found the expected number of all-to-all kernels, 1,152 per step, three per layer and pass. By equations (2) and (3), each GPU sends about 720 GB per step (my arithmetic: 768 × 0.94 GB).
nccl-tests measured 314.6–341.1 GB/s of bus bandwidth for 512 MB to 2 GB messages. At that rate, one 0.94 GB exchange takes about 2.8–3.0 ms (my arithmetic). In training it took 3.96 ms, and my plan had expected about 2–3 ms.
GPU memory: where 80 GB goes
Each H100 has 80 GB of memory. Training keeps four things in it: the weights, the gradients, the optimizer state, and the activations.
Bytes per parameter
Megatron trains with mixed precision. The forward and backward passes use bf16 weights, 2 bytes each, and gradients are accumulated in fp32, 4 bytes, which Megatron sets by default for bf16 runs (only --grad-reduce-in-bf16 turns it off). The optimizer, Adam, updates an fp32 master copy of every weight (4 bytes). It also keeps two fp32 running averages, its first and second moments (4 + 4 bytes).
where Adam’s two moments are its running averages of the gradient and of the squared gradient.
In words: before any sharding, each parameter takes 18 bytes, and only 2 of them are the weight the model computes with.
Megatron’s documentation gives the same 18 bytes. The Playbook counts 20, because it also keeps a bf16 copy of each gradient. Megatron instead copies each gradient into the fp32 buffer as soon as it is computed.
The distributed optimizer
Plain data parallelism keeps an identical copy of the optimizer state on every GPU. Megatron’s distributed optimizer shards it instead, “as described in the ZeRO paper”. Each of the \(d\) data-parallel GPUs owns \(1/d\) of the fp32 master weights and Adam moments, and a step goes like this:
- The backward pass fills each GPU’s fp32 gradient buffer.
- A reduce-scatter sums the gradients, and each GPU keeps the fully summed slice it owns.
- Each GPU runs Adam on its slice only, then copies the new fp32 values into bf16.
- An all-gather sends every GPU the full set of bf16 weights for the next forward pass.
where \(d\) is the data-parallel size of the parameter: the number of GPUs that share its optimizer state.
In words: the bf16 weight and the fp32 gradient stay whole on every GPU, and only the 12 bytes of optimizer state are divided.
Our numbers
The two kinds of parameter have different values of \(d\), so the state per GPU is
where \(P_{\text{rep}}\) counts the replicated parameters (attention, embeddings, routers, norms), with \(d_{\text{rep}} = 8\). \(P_{\text{exp}}\) counts the expert parameters stored on one GPU, with \(d_{\text{exp}} = 1\), the expert data-parallel size.
In words: replicated parameters share their optimizer state eight ways, while each expert’s state sits whole on the one GPU that holds that expert.
| Item | Parameters per GPU | Bytes per parameter | Memory per GPU |
|---|---|---|---|
| bf16 weights | 1.22B | 2 | 2.4 GB |
| fp32 gradients | 1.22B | 4 | 4.9 GB |
| Optimizer state, experts (\(d = 1\)) | 805M | 12 | 9.7 GB |
| Optimizer state, the rest (\(d = 8\)) | 416M | 12 / 8 | 0.6 GB |
| Total | ≈ 18 GB |
The surprise is the experts’ row. The distributed optimizer cannot shard their state, because no other GPU holds a copy of the same expert. Expert parallelism does the sharding instead: each GPU stores only 805M expert parameters, 8 of the 64 experts in each of the 16 layers.
Checked against the run
Megatron prints its own estimate of the weights and optimizer state, using the same rule as equation (5). For the MoE it printed 16.40 GiB per GPU, which is the 17.6 GB above; for the 1.22B dense baseline, 8.51 GiB. Measured after iteration 40, the MoE had 21.45 GiB allocated; the dense model had 9.46 GiB after iteration 120. I did not break down the MoE’s 5 GiB above the formula.
The checkpoint is a second check. It stores the bf16 weights, the fp32 master weights and both Adam moments, 14 bytes per parameter, but not the gradients. For 6.86B parameters that is 96.0 GB, or 89.4 GiB (my arithmetic), and each of the main run’s 7 saves was 89.46 GiB.
Activations and recomputation
The state is the smaller part. Megatron estimated 44.12 GiB of activations per GPU for a micro-batch of 8 × 4,096 tokens. The measured peak was 58.84 GiB, 0.97 of its 60.52 GiB total estimate.
Activation recomputation trades compute for memory. Full recomputation stores only each layer’s input and recomputes the layer during the backward pass. The Playbook says it saves the most memory but typically adds up to 30–40% to compute and time. The tested script recomputes every layer in full, and so did I.
bf16 in one paragraph
bf16 is a 16-bit format with fp32’s 8 exponent bits but only 7 fraction bits, so it has fp32’s range with less precision. Matrix multiplications run in bf16, while gradient accumulation, the master weights, Adam’s moments and the router run in fp32. On this node, the health check’s bf16 matrix-multiply test reached a median of 682.3 TFLOP/s, 69% of the H100’s dense bf16 peak of 989. What bf16 rounding does to RL is the subject of Part 5.
Overlapping communication with compute
A GPU can compute and communicate at the same time, so communication hidden behind compute adds no time. Two flags from the tested script do this for the replicated weights:
--overlap-grad-reduceruns the reduce-scatter of a layer’s gradients during the backward pass, while earlier layers are still computing.--overlap-param-gatherruns the all-gather of the updated bf16 weights during the next forward pass.
The MoE all-to-all was not hidden. Megatron can overlap it (--overlap-moe-expert-parallel-comm with --delay-wgrad-compute), but that needs selective recomputation, which stores more and recomputes only the parts that are quick to redo. The test run ran out of memory at its first step: 78.83 GiB of 79.18 GiB in use, with 738 MiB more requested. Selective recomputation needed at least about 19 GB of extra memory here, not the 5–10 GB I had assumed.
The rule, written before the test, was to keep the overlap only if it is faster and fits. So the main run kept full recomputation without it. The effect shows in the profile. With even routing, communication took 30.8% of the step (the all-to-all alone 3,042.5 ms, 27.9%), and for 30.7% of the step communication ran with no compute beside it.
FLOPs and utilization
How fast could a step be? Count the floating-point operations (FLOPs):
where \(P_{\text{active}}\) is the number of parameters each token passes through and \(D_{\text{step}}\) is the number of tokens per step.
In words: each token needs about six operations per parameter it touches, two in the forward pass and four in the backward pass.
Model-FLOPs utilization (MFU) compares that count with what the GPUs could have done:
where \(N\) is the number of GPUs, \(F_{\text{peak}}\) one GPU’s peak rate, and \(t_{\text{step}}\) the time per step.
In words: MFU is the share of the hardware’s peak that went into the model’s own arithmetic.
For main pretraining, \(P_{\text{active}} = 1.22 \times 10^{9}\), \(D_{\text{step}} = 512 \times 4{,}096 = 2{,}097{,}152\), \(N = 8\), \(F_{\text{peak}} = 989.4\) TFLOP/s and \(t_{\text{step}} = 10.93\) s. Equation (7) gives about \(1.54 \times 10^{16}\) FLOPs per step (my arithmetic), and equation (8) gives 17.7%. Megatron’s own count, which includes attention and the output layer, gave 194.7 TFLOP/s per GPU, or 19.7%.
Two notes on what the number means. MFU counts model FLOPs, not hardware FLOPs. With full recomputation each forward pass runs twice, so the GPUs did about 8 operations per parameter per token: 2 + 2 + 4. And equation (7) leaves out attention’s own FLOPs, about 11–22% at 4,096 tokens.
Derivation
Multiplying an \(n_1 \times n_2\) matrix by an \(n_2 \times n_3\) matrix takes \(2 n_1 n_2 n_3\) FLOPs: one multiply and one add per term. For one token passing through a weight matrix of \(n_2 \times n_3\) parameters, that is 2 FLOPs per parameter. The backward pass does two products of the same size. One gives the gradient with respect to the layer’s input, passed to the layer below; the other gives the gradient with respect to the weights.
That adds 4 FLOPs per parameter, for 6 in total. Megatron’s FLOP counter says the same: “Each GEMM in the model needs to be performed 3 times”.
Checking the node before training
The node had eight “NVIDIA H100 80GB HBM3” GPUs, with ECC memory protection on and a 700 W power limit each. It also had 224 CPU cores and 2 TB of RAM. Its work directory was a network volume, mounted over NFS 4.1. Three checks ran before any training: the setup script, a GPU health check and an NCCL test.
NVLink, and a check that failed with NVLink present
NVLink is NVIDIA’s direct GPU-to-GPU link; on this kind of node an NVSwitch connects all eight GPUs. The setup script checks the output of nvidia-smi topo -m for NVLink. On the 8-GPU node it stopped in its first second: “FAIL: no NVLink between the GPUs”.
NVLink was there: NV18 between every pair of GPUs. The check was a pipeline, nvidia-smi topo -m | grep -q "NV1[0-9]", in a script with set -o pipefail.
grep -q exits at its first match. nvidia-smi then dies writing into the closed pipe, with exit code 141 (SIGPIPE), and pipefail turns that into a failure. It failed three times out of three, and the one-GPU rehearsal never ran the line, which needs more than one GPU.
set -o pipefail
nvidia-smi topo -m | grep -q "NV1[0-9]" # exit 141: grep stops reading, nvidia-smi gets SIGPIPE
topo=$(nvidia-smi topo -m); grep -q "NV1[0-9]" <<< "$topo" # the fix: search a captured output
A new unit test fails on any | grep -q, | grep -m or | head in a script that sets pipefail. The lesson I wrote down: a check that runs only on the real hardware is untested until then.
GPU health
DCGM, NVIDIA’s diagnostic tool, was not in the container image, so code/scripts/gpu_health_check.py stood in for it. Per GPU it reads ECC errors, retired memory pages, NVLink, temperature, power and clocks. It also runs a 20-second bf16 matrix-multiply burn, and a GPU more than 10% slower than the median fails.
The first run failed on one item: GPU 6 peaked at 706.3 W against a limit of 700 W plus 5 W of tolerance. It was one 1-second reading as the load started, and a re-run passed, with every GPU within −0.6% to +1.7% of the median speed. Everything else passed at once: NVLink on all 28 pairs, no memory errors, 63 °C at most, and a median burn of 682.3 TFLOP/s.
NCCL all-to-all
nccl-tests measures a collective’s speed at each message size. Its bus bandwidth (busbw) counts the bytes each GPU sends to other GPUs per second. On 8 GPUs that is 7/8 of the buffer rate, algbw: 346.18 against 395.64 GB/s at 8 GB. I ran it with NVLink on, then with peer-to-peer transfers off, which sends the traffic through host memory instead.
| Message size | NVLink on: busbw (out of place / in place) | NVLink off (NCCL_P2P_DISABLE=1) |
|---|---|---|
| 8 MB | 56.1 / 63.1 GB/s | 12.2 / 9.5 GB/s |
| 32 MB | 224.6 / 226.5 GB/s | 8.2 / 8.1 GB/s |
| 128 MB | 286.4 / 288.0 GB/s | 8.6 / 10.1 GB/s |
| 512 MB | 314.6 / 309.0 GB/s | 10.8 / 10.9 GB/s |
| 2 GB | 341.1 / 340.8 GB/s | 11.4 / 11.8 GB/s |
| 8 GB | 346.2 / 345.3 GB/s | not run |
Every size returned zero wrong values. At 2 GB, NVLink carried about 30 times the bandwidth of the path without it.
What went wrong
The dense baseline ran 3× slow, with idle GPUs
The first run on the node was the dense baseline: the same model with one wide feedforward block in place of the experts. Its loss fell smoothly, but its step time ranged from 5.7 to 30.5 s and averaged 18.6 s. At one sample, 5 of the 8 GPUs sat at 0% utilization. A GPU waiting inside an NCCL collective reads 100%, so 0% meant nothing had been launched on it: the problem was on the host.
The host told the story. 24 Python processes were in state D, uninterruptible input/output, and the kernel showed them waiting on NFS calls. Over 10 s the NFS counters showed 1,296 file opens and 1,555 closes at about 150 ms per close, but only 1 read. The data itself came from the page cache; the time went into opening and closing the file.
The cause was a flag from the tested script, --no-mmap-bin-files. Without memory-mapping, Megatron’s reader opens and closes the data file for every document it reads, and a step reads about 512 samples × 5 documents. At 150 ms per close, the data-loading workers fell behind the GPUs. The one-GPU rehearsal had used different storage, so it never showed.
The fix: copy the data, 10,666,878,638 bytes in 96 files, and its index cache to /dev/shm, which lives in RAM. I checked the copy against the dataset’s 21 SHA-256 sums and its byte and file counts, then pointed the runs at it. The setup script now does this by itself whenever the work directory is network storage.
The restarted baseline gave the same first loss, 12.15001. It then ran at 5.74 s per step and 371.6 TFLOP/s per GPU, against 19.15 s and 123.3 TFLOP/s before: 3.3× faster.
The same mistake hid in the RL logging. Opening, appending and closing a file per record took 11.1 ms a line on the network volume. Through one open handle it took 0.046 ms, so the old way lost about 11 s per GSPO step. The logger now keeps one handle open per file.
A race only eight GPUs could show
Rank 0 writes the checkpoint’s tracker file, and the last rank logs that file to the experiment tracker (W&B), with no barrier between them. On one GPU both are rank 0, so the rehearsal never raced. Left alone, it would have stopped the main run at its first save, at step 200. Our patch now waits for the file and turns any failure into a warning.
Throughput as recorded
Before pretraining, a balancing study compared short runs with the same seed, data and optimizer. Forced-even routing ignores the router’s choice and spreads tokens evenly over the experts: the speed ceiling for this MoE.
| Run | Step time | TFLOP/s per GPU | MFU (Megatron’s count / equation 8) | Peak allocated |
|---|---|---|---|---|
| Dense baseline (1.22B, no experts) | 5.70 s | 373.1 | 37.7% / 34.0% | 50.9 GiB |
| MoE, forced-even routing | 10.69 s | 199.0 | 20.1% / 18.1% | 58.8 GiB |
| MoE, aux-loss router (collapsed) | 17.63 s | 120.7 | 12.2% / 11.0% | 58.8 GiB |
| MoE, V4 router (collapsed) | 17.80 s | 119.6 | 12.1% / 10.9% | 58.8 GiB |
| MoE, V4 scores + quantile balancing (first 40 steps) | 17.04 s | 124.9 | 12.6% / 11.4% | 58.8 GiB |
| Main pretraining, steps 11–1,240 | 10.93 s | 194.7 | 19.7% / 17.7% | — |
The study’s numbers are medians over iterations 11–40 (dense: 11–120), from one run per arm. Three readings:
- The MoE runs at about half the dense throughput even when perfectly balanced: 0.533× in TFLOP/s per GPU. The handbook measured 13–15% MFU for its MoE on H100, and balanced, ours reached 18–20%.
- Imbalance is slow. In the collapsed arms, tokens piled onto the GPUs holding the few experts the router favoured. The aux-loss arm spent 52.8% of its step in communication, at 11.65 ms per all-to-all instead of 3.96 ms. Part 6 tells the router’s story.
- Balanced, the main run came close to the ceiling. After step 100 its steps took about 11.0 s, 97% of the forced-even speed. It ran 1,240 steps on 2.6 billion tokens in 4.09 h, at 1.92 × 10⁵ tokens per second across the node.
The main run saved 7 checkpoints of 89.46 GiB, each in 44.6–54.3 s, about 1.8 GB/s to the network volume. The RL stage’s timings are in Part 10.
Run it yourself
Hardware and time. One node with eight H100 SXM 80 GB GPUs connected by NVLink. Setup took about 9 minutes, and the health and NCCL checks about 5 more. The dense baseline runs 120 iterations at about 5.7 s each, and main pretraining took 4.09 h. Preparing the data is covered in the data guide, and the full sequence of commands in the setup guide and the pretraining guide.
Set up and check the node (from the repository’s top folder):
# 1. Setup: GPUs and NVLink, pinned packages, Megatron at d6316eb45 with our patch,
# data checksums, and a RAM copy of the data if the work directory is network storage.
HF_DATASET=<your-user>/<your-dataset> WORKDIR=/workspace EXPECT_GPUS=8 MIN_FREE_GB=1000 \
bash code/scripts/pod_setup.sh
source /workspace/env.sh
mkdir -p /workspace/runs
wandb login # or: export WANDB_MODE=offline (the launch scripts log to W&B)
# 2. GPU health, a stand-in for dcgmi diag: it must exit 0.
python -I code/scripts/gpu_health_check.py --expect 8 --out /workspace/runs/gpu_health.json
# 3. NCCL all-to-all with NVLink on, then off (nccl-tests v2.21.1, built for the H100 only).
git clone -q https://github.com/NVIDIA/nccl-tests.git /workspace/nccl-tests
git -C /workspace/nccl-tests checkout -q --detach afd59abab774a6a4b492eb344bd0c845a0b7bb4d
make -C /workspace/nccl-tests -j 16 NVCC_GENCODE="-gencode=arch=compute_90,code=sm_90"
/workspace/nccl-tests/build/alltoall_perf -b 8M -e 8G -f 4 -g 8 -c 1 | tee /workspace/nccl_alltoall.txt
NCCL_P2P_DISABLE=1 /workspace/nccl-tests/build/alltoall_perf -b 8M -e 2G -f 4 -g 8 -c 1 \
| tee /workspace/nccl_alltoall_p2p_off.txt
Train. Each launch script needs RUN_NAME and RUN_DIR; with DRY_RUN=1 it prints its arguments instead of launching. For long runs, wrap each launch in the stall guard, code/scripts/stall_guard.py, which stops a run whose logs go quiet.
M=code/scripts/megatron
# Check every launch script against Megatron's own argument parser and config checks (no GPU needed).
python -I $M/check_flags.py --validate "$MEGATRON_PATH"
# The dense baseline (120 iterations) and the speed ceiling (40 iterations).
RUN_NAME=dense RUN_DIR=/workspace/runs/dense bash $M/dense_baseline.sh
RUN_NAME=forced_even RUN_DIR=/workspace/runs/forced_even bash $M/moe_forced_even.sh
# Main pretraining: V4 scores with quantile balancing, 1,240 steps, a checkpoint every 200.
MAIN_ROUTER=qb RUN_NAME=pretrain RUN_DIR=/workspace/runs/pretrain CKPT_DIR=/workspace/ckpt/pretrain \
bash $M/moe_pretrain.sh
# Step time, TFLOP/s, MFU, memory and the NCCL numbers, as in the tables above.
python -I code/scripts/run_report.py --run dense=/workspace/runs/dense \
--run forced_even=/workspace/runs/forced_even --nccl /workspace/nccl_alltoall.txt \
--json /workspace/runs/study_report.json > /workspace/runs/study_report.md
The configuration: every flag is in code/scripts/megatron/common.sh, and each run is a short script beside it, such as moe_pretrain.sh. Our changes to Megatron are in code/patches/megatron-d6316eb45.patch. The checks and reports are pod_setup.sh, gpu_health_check.py and run_report.py.
Results to expect (ours, one run each): NCCL bus bandwidth of 341.1 GB/s at 2 GB with NVLink and 11.4 GB/s without, and a health-check burn near 682.3 TFLOP/s per GPU. For training, the throughput table above. A dense step far above 5.7 s, with idle GPUs, points at the storage first.
What to take away
- Use the simplest layout that fits. For a 6.86B MoE on one node, that was expert parallelism 8 plus data parallelism, with no tensor, pipeline or context parallelism.
- Count bytes per parameter first: 18 without the distributed optimizer and \(6 + 12/d\) with it. For the experts, expert parallelism does the sharding.
- An MoE layer moves a lot of data: about 0.94 GB per all-to-all per GPU, 768 times per step. In the forced-even study run, communication was exposed for 30.7% of the step.
- Balance is throughput. The balanced MoE ran at 199.0 TFLOP/s per GPU and the collapsed ones at about 120.
- Check the node, then read the step time over many steps. A GPU at 0% points at the host. On network storage, a reader that opens a file per record is limited by open and close latency.
References
- Nouamane Tazi, Ferdinand Mom, Haojun Zhao, Phuc Nguyen, Mohamed Mekkouri, Leandro Werra and Thomas Wolf, “The Ultra-Scale Playbook: Training LLMs on GPU Clusters”, Hugging Face, 2025. huggingface.co/spaces/nanotron/ultrascale-playbook
- NVIDIA, Megatron-LM, commit d6316eb45. github.com/NVIDIA/Megatron-LM
- NVIDIA, “Distributed Optimizer”, Megatron-LM documentation at commit d6316eb45. docs/user-guide/features/dist_optimizer.md
- Mohammad Shoeybi et al., “Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism”, arXiv:1909.08053, 2019. arxiv.org/abs/1909.08053
- Samyam Rajbhandari et al., “ZeRO: Memory Optimizations Toward Training Trillion Parameter Models”, arXiv:1910.02054, 2019. arxiv.org/abs/1910.02054
- Vijay Korthikanti et al., “Reducing Activation Recomputation in Large Transformer Models”, arXiv:2205.05198, 2022. arxiv.org/abs/2205.05198
- Hugging Face, “The Ultimate MoE Training Handbook”, with its companion launch scripts. huggingface.co/spaces/huggingface/moe-blogpost · scripts
- NVIDIA, nccl-tests, v2.21.1. github.com/NVIDIA/nccl-tests
- The Microsoft AI Team, “RL infrastructure at Microsoft AI”, Microsoft AI, November 2026. microsoft.ai/news/rl-infrastructure-at-microsoft-ai
Cite this
@misc{aboagye2026minidsv4part04,
author = {Aboagye, Prince Osei},
title = {Mini DeepSeek V4, Part 4: The training system: Megatron-LM on 8×H100},
year = {2026},
howpublished = {\url{https://poaboagye.github.io/blog/04-training-system/}}
}