Planning a Sparse-Expert LLM Training Run on 256 GPUs
System DesignModel answerLast updated
Plan an end-to-end training setup for a bilingual sparse-expert language model on about 1T tokens and 256 A100-80GB GPUs, including a path to 1,024 GPUs.
You are asked to plan the pretraining of a bilingual sparse Mixture-of-Experts language model on roughly 1 trillion tokens, using a cluster of 256 NVIDIA A100-80GB GPUs (32 nodes of 8 GPUs, NVLink within a node, InfiniBand between nodes).
Walk through your design and justify the trade-offs. Cover at least:
- Budget and sizing: the compute estimate, expected wall-clock time and rough cost.
- Model architecture: number of experts, router design, top-k, whether to use shared experts.
- Parallelism plan: how you combine data, tensor, pipeline and expert parallelism, and where the all-to-all traffic runs.
- Memory: optimizer and gradient sharding (ZeRO/FSDP), activation recomputation, and a per-GPU memory estimate.
- Routing mechanics: capacity factor, token-dropping policy, load-balancing and router stabilization losses, and how routing behaves at evaluation and inference time.
- Data: corpus mix across the two languages, filtering, deduplication, decontamination, tokenizer design and sequence packing.
- Training recipe: batch size, optimizer, learning-rate schedule, and how you de-risk the recipe before the full run.
- Reliability: checkpointing, fault detection, automatic recovery.
- Observability and evaluation: which metrics you track and what alerts you set.
- Failure modes: router collapse, stragglers, expert overload, loss spikes, each with concrete mitigations.
- Scale-out: what changes when you move the same system to 1,024 GPUs, and how you keep cost under control.
State your assumptions explicitly (context length, target quality, language pair) and use numbers wherever you can.
Hints
Hint 1
Start from the compute budget: training FLOPs are roughly 6 x active parameters x tokens, and a realistic MFU for MoE on A100s is far below the 312 TFLOPS peak. Work backward to an active-parameter count that fits your time limit.
Hint 2
Think about where the all-to-all should run. If the expert-parallel group fits inside one NVLink node, token dispatch avoids the slower inter-node network, and TP/PP may be unnecessary at this model size.
Hint 3
Separate dense parameters from expert parameters when reasoning about data-parallel group sizes and optimizer sharding, since they are replicated over different numbers of ranks.
Hint 4
For each failure mode (router collapse, overload, stragglers, node failures, loss spikes), name the signal you would monitor, the threshold that triggers action, and the automated or manual response.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Size the budget first
- Hardware: 256 GPUs = 32 nodes x 8, NVLink in-node, about 8x200 Gb/s InfiniBand per node.
- Throughput: A100 bf16 peak is 312 TFLOPS. Assume about 35% MFU for MoE, so about 110 TFLOPS per GPU and about 2.8e16 FLOP/s cluster-wide.
- Training FLOPs: about 6 x N_active x D. With D = 1e12 and a budget of three to four weeks, N_active comes out around 8B.
- Cost: roughly 150k GPU-hours, so about $300k at $2 per GPU-hour.
Clarify the second language, context length (assume 4K), and whether the objective is quality per training FLOP or per inference dollar. Sparse models favor the latter.
2. Architecture
- 32 layers, d_model 4096, pre-norm RMSNorm, RoPE, GQA (32 query heads, 8 KV heads).
- MoE feed-forward in every layer: 16 SwiGLU experts, top-2 routing, optionally plus one always-on shared expert for stability and less redundancy.
- 128K byte-level BPE vocabulary, untied embeddings.
- Result: about 53B total parameters, about 8B active per token. Training cost is 6 x 8e9 x 1e12 = 4.8e22 FLOPs, about 20 days at the throughput above, and about 24 days with restarts and evals.
- Router: linear layer in fp32, softmax, top-2, renormalize the two weights. Initialize with a small std so early routing is near-uniform.
3. Parallelism and memory
Expert parallelism = 8, inside a node. Each GPU holds 2 experts per layer, so dispatch and combine all-to-alls ride NVLink.
Data parallelism: dense weights (attention, embeddings, router) replicate across 256 ranks; expert weights replicate across 32 ranks (one GPU per node holds the same experts).
TP = PP = 1. The model fits comfortably, and TP/PP would add bubbles and communication for no gain.
ZeRO-2 memory per GPU (approximate):
| Item | Size |
|---|---|
| bf16 weights (dense plus local experts) | about 17 GB |
| Sharded gradients | a few GB |
| Sharded fp32 master and Adam state | about 2.5 GB |
| Activations with selective recompute | 20-30 GB |
| Total | about 50-55 GB |
This fits in 80 GB without ZeRO-3, which avoids per-layer parameter all-gathers.
Communication: per layer, 8K tokens x top-2 x 4096 x 2 bytes is about 134 MB each for dispatch and combine. That is only a few ms per layer on NVLink, and it can be overlapped with attention or shared-expert compute. Gradient reduce-scatters run over InfiniBand in buckets overlapped with backward.
4. Routing mechanics
- Capacity factor 1.25 in training: capacity = 1.25 x tokens x k / E. Overflow tokens skip the expert and flow through the residual path. Alert if drops exceed about 1%.
- Eval and inference: use capacity 2.0 or dropless grouped-GEMM kernels, because dropping makes outputs depend on batch composition.
- Load-balancing loss (Switch style): alpha x E x sum(f_i x P_i), alpha about 0.01, where f_i is the token fraction and P_i the mean router probability for expert i.
- Router z-loss: about 1e-3 x mean(logsumexp(logits)^2) to keep logits bounded and avoid bf16 instability.
5. Data and tokenizer
- Mix: for example 60% English, 40% second language, with about 8% code and math. Upsample high-quality sources for at most 2-4 epochs.
- Pipeline (Spark or Ray, run once, versioned): language ID, heuristic filters (length, symbol ratio, repetition, boilerplate), a model-based quality classifier, PII scrubbing, exact dedup by hash, near-dedup with MinHash LSH (5-grams, Jaccard about 0.8), and decontamination against eval sets using 13-gram overlap.
- Tokenizer: train on a language-balanced sample and measure fertility (tokens per word) per language. A poor tokenizer for the second language silently reduces its effective data and raises its inference cost.
- Loading: pre-tokenized, packed 4K shards with document-boundary masks; deterministic and resumable, with loader state stored in checkpoints.
6. Recipe
- Global batch about 4M tokens (1024 x 4K), so about 250K steps at roughly 7 s/step (about 600K tokens/s).
- AdamW, betas (0.9, 0.95), weight decay 0.1, clip 1.0, bf16.
- Peak LR 3e-4, 2K warmup steps, warmup-stable-decay schedule with a 10% decay phase. WSD allows branching and extending training without restarting.
- De-risk with about 1B-active ablations on 32 GPUs: router init, aux-loss weights, capacity factor, LR.
7. Checkpointing and fault tolerance
- Full state is about 850 GB (53B x 16 bytes). Use asynchronous sharded checkpoints: write to local NVMe, upload to object storage in the background, every 30 minutes, retaining recent ones plus milestones.
- Expect a hardware or NCCL fault every day or two. Run pre-flight and periodic checks (DCGM, NCCL all-reduce tests, ECC and thermals), keep 1-2 hot-spare nodes, and use an orchestrator that evicts bad nodes, swaps in spares and auto-resumes.
- Set NCCL timeouts so hung collectives fail fast.
8. Monitoring
- Throughput: tokens/sec, step time and its breakdown (compute, all-to-all, gradient sync, data wait), MFU, per-rank step-time variance.
- Routing health: per-expert load, router entropy, drop rate, max/mean load ratio per layer.
- Stability: loss, gradient norm, router logit magnitude, loss-spike count.
- Evaluation: periodic held-out perplexity in each language plus downstream benchmarks in both languages.
9. Failure modes and mitigations
| Failure | Signal | Mitigation |
|---|---|---|
| Router collapse | Low router entropy, a few experts dominate | Raise aux-loss weight, small init, z-loss, add shared expert, restart from earlier checkpoint with adjusted settings |
| Expert overload | Drop rate above 1%, high max/mean load | Raise capacity factor, tune balance loss, use dropless kernels |
| Stragglers | One rank's step time well above median | Health checks, replace the node, balance data lengths, overlap communication |
| Loss spikes | Sudden loss or grad-norm jump | fp32 router, clipping, skip bad batches, roll back and reshuffle data |
| Node failure | Hung collective, ECC errors | Hot spares, fast timeouts, auto-resume |
10. Scaling to 1,024 GPUs
- Keep EP = 8 in-node and increase data parallelism to 128 for experts and 1,024 for dense weights. Grow global batch moderately (for example 8-16M tokens) rather than blindly, to protect sample efficiency.
- Gradient and all-to-all traffic across more nodes raises InfiniBand pressure: use hierarchical collectives, topology-aware placement and more overlap. Consider hybrid-sharded ZeRO (shard within a pod, replicate across pods).
- For a larger model, add more experts or EP across a small number of nodes, accepting inter-node all-to-all, and introduce PP or TP only when memory forces it.
- Cost control: track MFU, use spot or preemptible capacity only with fast checkpoints, run ablations at small scale, and stop or branch from WSD stable-phase checkpoints instead of restarting runs.
Common mistakes
- Ignoring MFU and promising peak FLOPs.
- Placing expert parallelism across nodes when it could stay on NVLink.
- Evaluating with training-time capacity and token dropping.
- Dropping the tokenizer-fertility check for the second language.
- No automated recovery, so a single bad GPU stalls the whole job.