Contents
Key concepts
Memory accounting
Mixed-precision training with Adam holds bf16 weights (2 bytes per parameter), bf16 gradients (2), an fp32 master copy (4) and Adam’s two moments (8): about 16 bytes per parameter, so 7B needs about 112 GB and 70B about 1.1 TB before activations. Activations scale with micro-batch × sequence length × hidden size × layers, and attention scores add a term quadratic in sequence length unless a fused kernel such as FlashAttention avoids storing them. 8-bit optimisers and FP8 training shrink the totals.
Stack · 5 layersHow training memory is accounted for
Scale with micro-batch × sequence length × hidden size × layers; attention scores add a quadratic term unless a fused kernel such as FlashAttention avoids storing them.
Mixed-precision Adam holds bf16 weights (2 bytes per parameter), bf16 gradients (2), an fp32 master copy (4) and Adam's two moments (8): about 16 bytes per parameter.
About 16 bytes per parameter means 7B needs about 112 GB and 70B about 1.1 TB before activations.
ZeRO stage 1 shards optimiser state, stage 2 also shards gradients, and stage 3 (equivalent to PyTorch FSDP) shards parameters too.
8-bit optimisers and FP8 training shrink the totals.
Data parallelism
Every GPU holds a full replica and processes a different slice of the batch; gradients are averaged with an all-reduce, bucketed and overlapped with the backward pass. Throughput scales with GPU count, but per-GPU memory does not fall at all, so plain data parallelism cannot fit a model that is too big for one GPU.
ZeRO and FSDP
ZeRO stage 1 shards optimiser state across the data-parallel group, stage 2 also shards gradients, and stage 3 (equivalent to PyTorch FSDP) shards parameters too, all-gathering each layer’s weights just before use and reduce-scattering its gradients afterwards. Stages 1–2 communicate the same volume as plain data parallelism; stage 3 adds about 50%. CPU or NVMe offload trades speed for further memory savings.
Tensor parallelism
Megatron-style tensor parallelism splits weight matrices inside a layer: the first MLP matrix by columns, the second by rows, and attention by heads, so each transformer layer needs two all-reduces of the activations in the forward pass and two in the backward pass. That traffic needs NVLink-class bandwidth, so tensor parallelism normally stays within a node (up to 8 GPUs). It also cuts per-GPU activation memory and latency, which is why serving uses it.
Pipeline parallelism
Layers are split into p stages on different devices and each batch into m micro-batches that flow through the pipeline. Only stage-boundary activations are sent, point to point, so stages can span nodes. Idle “bubbles” occur while the pipeline fills and drains; with the 1F1B schedule the bubble overhead is about (p − 1)/m of the ideal compute time, and interleaved schedules divide it further at the cost of more communication.
Sequence, context and expert parallelism
Sequence parallelism splits the non-tensor-parallel parts of a layer (normalisation, dropout) along the sequence to save activation memory; context parallelism (for example ring attention) splits very long sequences across GPUs. Mixture-of-experts models add expert parallelism: experts live on different devices and tokens are routed with all-to-all exchanges. All experts must sit in memory, so memory scales with total parameters while compute scales with active parameters.
Collectives and their cost
A ring all-reduce is a reduce-scatter followed by an all-gather; each GPU sends and receives about 2(N − 1)/N × the message size, nearly constant in N, plus a latency term that grows with N. Tree and hierarchical algorithms cut latency to order log N. Bandwidth falls by roughly an order of magnitude from NVLink inside a node to InfiniBand or Ethernet between nodes, which drives where each kind of parallelism is placed.
Large-batch optimisation and reliability
When the global batch grows k-fold, scale the learning rate roughly linearly with warmup (Goyal et al.), or use layer-wise adaptive methods (LARS, LAMB) for very large batches; beyond a critical batch size, extra batch stops buying faster convergence. Gradient accumulation emulates large batches but must average correctly. At thousands of GPUs, failures are routine: checkpoint frequently and asynchronously, detect stragglers and plan for automatic restarts. Low-communication methods relax lock-step training: DiLoCo synchronises replicas only every H steps (2025 scaling laws show it matching data parallelism when tuned), and RL post-training often runs rollout workers asynchronously from the trainer, where policy lag and rollout–trainer numerics mismatch must be corrected (importance sampling) or removed (bitwise-matched kernels) to stay stable.
Worked examples
Memory budget for fine-tuning a 7B model, with activations
Estimate GPU memory to fine-tune a 7B, Llama-2-like model (32 layers, hidden size 4,096, 32 heads) at sequence length 4,096 and micro-batch 1: full fine-tuning with Adam, LoRA (rank 16 on the q, k, v, o projections) and QLoRA. Then estimate activation memory with and without FlashAttention and activation checkpointing.
Full fine-tune, model states. 7 × 10⁹ × 16 bytes = 112 GB: weights 14 + gradients 14 + fp32 master 28 + Adam moments 56. That exceeds one 80 GB GPU before any activations. With ZeRO-3 or FSDP over 8 GPUs: 112 / 8 = 14 GB per GPU, plus activations and the transient all-gathered layer.
LoRA. Each adapted matrix adds r × (d_in + d_out) = 16 × (4,096 + 4,096) = 131,072 parameters; 4 matrices × 32 layers → 16.8M trainable parameters (0.24% of the model). Their weights, gradients and Adam state at 16 bytes each ≈ 0.27 GB. The frozen bf16 base is 14 GB, so model states ≈ 14.3 GB.
QLoRA. The base in 4-bit NF4 ≈ 7 × 10⁹ × 0.5 bytes = 3.5 GB plus quantisation constants → about 3.6–4 GB of model states.
Activations. For a GPT-style layer storing 16-bit activations, Korthikanti et al. give about s·b·h·(34 + 5·a·s/h) bytes per layer (s = sequence length, b = micro-batch, h = hidden size, a = heads). Here s·b·h = 4,096 × 1 × 4,096 = 16.8M and 5·a·s/h = 5 × 32 × 4,096 / 4,096 = 160:
- No optimisation: 16.8M × 194 ≈ 3.25 GB per layer × 32 ≈ 104 GB
- FlashAttention (no stored s × s attention matrices): 16.8M × 34 ≈ 0.57 GB per layer × 32 ≈ 18 GB
- Plus full activation checkpointing (store only each layer’s input, 2·s·b·h bytes): 33.5 MB × 32 ≈ 1.1 GB, plus one layer’s activations rebuilt during backward, at the cost of about one extra forward pass (~33% more compute)
So LoRA with FlashAttention and checkpointing fits in roughly 14.3 + 1.1 + 0.6 + workspace ≈ 20 GB, a single 24–48 GB GPU, while full fine-tuning needs several GPUs with sharding. Exact constants differ for SwiGLU MLPs and grouped-query attention, so measure with the profiler before committing to a plan.
How long does the gradient all-reduce take?
You train the 7B model with ZeRO-2 (optimiser state and gradients sharded; same communication volume as plain data parallelism), reducing 14 GB of bf16 gradients per step. Estimate communication time on one 8-GPU node with about 200 GB/s of effective per-GPU bandwidth, and on 32 GPUs across 4 nodes with 50 GB/s per GPU (400 Gb/s networking). One optimiser step takes 1.5 s of compute.
Ring volume per GPU = 2(N − 1)/N × M.
- N = 8: 2 × 7/8 × 14 GB = 24.5 GB → 24.5 / 200 ≈ 0.12 s
- N = 32: 2 × 31/32 × 14 GB = 27.1 GB → 27.1 / 50 ≈ 0.54 s
Going from 8 to 32 GPUs barely changes the bytes per GPU (24.5 → 27.1 GB); the slower inter-node link is what quadruples the time. That is why the claim “ring all-reduce traffic per GPU grows linearly with N” is wrong.
Latency term. About 2(N − 1) sequential steps; at roughly 5 µs each, N = 32 adds 62 × 5 µs ≈ 0.3 ms, negligible for 14 GB but dominant for many small tensors. Hence gradient bucketing (PyTorch DDP defaults to 25 MB buckets) and tree or hierarchical algorithms at large N.
Overlap. Buckets are reduced while backward continues on earlier layers, so 0.54 s of communication can hide largely inside 1.5 s of compute. Exposed communication shows up as falling MFU when you add nodes. With ZeRO-3 the volume rises by about 50% (an extra parameter all-gather), to roughly 0.8 s across nodes.
Laying out a 175B model on 1,024 GPUs
Plan a layout for training a 175B dense transformer on 128 nodes of 8 GPUs (80 GB each, NVLink within a node, InfiniBand between nodes), with sequences of 2,048 tokens. Choose tensor, pipeline and data parallel degrees, estimate per-GPU model-state memory and the pipeline bubble, and state the global batch.
Model states. 175 × 10⁹ × 16 bytes = 2.8 TB, so sharding is mandatory.
Layout. Tensor parallelism t = 8 inside each node (its per-layer all-reduces need NVLink); pipeline parallelism p = 16 across nodes (only stage-boundary activations cross InfiniBand); data parallelism d = 1,024 / (8 × 16) = 8.
Per-GPU memory. Each GPU holds 175B / (t × p) = 175B / 128 ≈ 1.37B parameters.
- Without optimiser sharding: 1.37B × 16 bytes ≈ 21.9 GB
- With ZeRO-1 across the 8 data-parallel replicas (shard the 12 bytes of fp32 master weights and Adam state): 1.37B × (4 + 12/8) = 1.37B × 5.5 ≈ 7.5 GB, leaving room for activations (which tensor and sequence parallelism also divide by t) and selective recomputation.
Pipeline bubble. With the 1F1B schedule, bubble overhead ≈ (p − 1)/m of the ideal time:
- m = 64 micro-batches per step: 15 / 64 ≈ 23%
- Interleaved schedule with v = 4 model chunks per GPU: 15 / (4 × 64) ≈ 5.9%, at the cost of more point-to-point traffic
Global batch = d × m × micro-batch size = 8 × 64 × 1 = 512 sequences × 2,048 tokens ≈ 1.05M tokens per step. Raising m to 128 halves the bubble but doubles the batch to about 2M tokens, which is acceptable only if it stays below the critical batch size for this stage of training.
Operations. Place pipeline neighbours on nearby switches, checkpoint every few hundred steps asynchronously, watch for stragglers (one slow GPU stalls its whole pipeline) and keep spare nodes for automatic restarts.
What changed recently
Asynchronous RL made stable by matching numerics
NVIDIA Research and Inferact’s REINFORCE Zero aligns rollout and trainer kernels so both compute bit-identical log-probabilities, then corrects policy lag with unclipped importance sampling; it trained stably for 20,000 updates, learned at a policy lag of 64 and reached 2.4× the step throughput of synchronous training. With standard, mismatched kernels, online AIME24 accuracy fell from 34.3% to 14.0%. Rollout/trainer separation is now common in RL post-training, and numerics mismatch is the failure mode to know.
Decoupled DiLoCo: pre-training without lock-step
Google researchers, with Jeff Dean as final author, proposed splitting pre-training across independent learners that send parameter fragments asynchronously to a synchronizer, which merges them with a minimum quorum, a grace window and token-weighted averaging; simulations with millions of chips showed no global downtime from failures or stragglers. Low-communication training is moving into the design space for multi-datacentre runs.
INTELLECT-3: large-scale asynchronous agentic RL in the open
Prime Intellect post-trained INTELLECT-3, a 106B-total, 12B-active MoE built on GLM-4.5-Air-Base, using its open prime-rl framework for asynchronous, multi-turn, tool-using RL on up to 512 H200 GPUs. It is a reference design for decoupling inference workers that generate rollouts from the trainer that consumes them.
A 4-bit pretraining recipe at 10 trillion tokens
NVIDIA trained a 12B model on 10T tokens in NVFP4 with loss and downstream accuracy comparable to an FP8 baseline, using random Hadamard transforms, two-dimensional weight scaling, stochastic rounding of gradients and a few layers kept in higher precision. Low-precision training now changes memory, communication and kernel choices across the whole parallel layout.
Scaling laws for DiLoCo
Google researchers showed that DiLoCo, which synchronises replicas only every H inner steps, scales predictably with model size and, when well tuned, can match or beat data-parallel training even at small sizes, with larger optimal batch sizes. It answers the interview question of how to train across data centres with limited bandwidth.
Pitfalls
- Counting only the weights and forgetting gradients, the fp32 master copy, Adam state and activations.
- Assuming data parallelism reduces per-GPU memory; it only adds throughput.
- Running tensor parallelism across slow inter-node links.
- Ignoring pipeline bubbles, or using too few micro-batches to hide them.
- Growing the global batch 8× without adjusting learning rate and warmup, or mis-averaging accumulated gradients.
- Saying ring all-reduce traffic per GPU grows linearly with the number of workers, or claiming mixture-of-experts cuts memory.
How interviewers probe it
- ‘The model does not fit — list your options from cheapest to most complex’, with memory numbers for each.
- ‘What is split and what is communicated?’ for data, ZeRO/FSDP, tensor, pipeline and expert parallelism (all-reduce, all-gather, reduce-scatter, point-to-point, all-to-all).
- ‘Lay out a model of a few hundred billion parameters on this cluster’, including topology, bubbles and failures.
- ‘The global batch grows 8× — how do you keep convergence?’
- Research-maths variants: ring versus tree all-reduce cost, and bounding the rounds needed over noisy links.
- Applied variants: memory for full fine-tuning versus LoRA versus QLoRA, and tensor parallelism for serving a 70B model.
Quiz
Three questions from this guide. Answer each in your head or out loud, show the model answer, then rate yourself. The cards join your practice deck and come back when they are due.
Roughly how much GPU memory does full fine-tuning of a 7B model with Adam in mixed precision need, compared with LoRA and QLoRA?
Model answer, written in a candidate's voice
- Full fine-tune: ~16 bytes/param before activations (bf16 weights 2 + bf16 grads 2 + fp32 master 4 + Adam m/v 8) ≈112 GB for 7B, plus activations; needs sharding/ZeRO/FSDP, checkpointing, multiple GPUs.
- LoRA: frozen bf16 base ≈14 GB + tiny adapter weights/optimizer state + activations; one 24–48 GB GPU depending on sequence length and batch.
- QLoRA: 4-bit base ≈3.5–4 GB plus scales/overheads and LoRA state; fits consumer-class GPU.
- Activations scale with batch × sequence × layers; gradient checkpointing trades compute for memory.
Will a 70B dense model serve 32 concurrent users at 32k context on two 80 GB GPUs? Explain tensor, pipeline and data parallelism along the way.
Model answer, written in a candidate's voice
- No as stated: bf16 weights ~140 GB leave ~20 GB on 160 GB, while KV for 32 x 32k is ~320 GiB
- Weights: bf16 ~140 GB; FP8 ~70 GB; INT4 ~35–40 GB
- KV: 2 (K,V) x 80 layers x 8 KV heads x 128 dims x 2 B = 320 KiB/token; 32 x 32,768 = 1,048,576 tokens = 320 GiB (160 GiB in FP8)
- FP8 weights + FP8 KV ≈ 242 GB still exceeds 160 GB; four 80 GB GPUs fit
- Tensor parallel splits matmuls (needs NVLink, helps latency); pipeline splits layers (bubbles, low bandwidth, spans nodes); data parallel replicates for throughput; expert parallel for MoE
- Fixes: FP8 weights + FP8 KV, more GPUs, capped context, realistic length distribution, or fewer concurrent users
Your model plus optimiser state exceeds one GPU’s memory. List the options, from cheapest to most complex.
Model answer, written in a candidate's voice
- Cheap single-GPU wins first: bf16, small micro-batches + gradient accumulation, activation checkpointing; these mainly cut activation memory.
- Rough budget: ~16 bytes/param for bf16 weights + grads + fp32 master + Adam m and v (same as fp32 Adam), plus activations; e.g. 7B x 16 B = 112 GB.
- Then shard across GPUs: ZeRO-1 (optimiser states), ZeRO-2 (+ gradients), FSDP/ZeRO-3 (full sharding, ~16/N bytes/param per GPU); plain data parallelism does not reduce per-GPU memory.
- Add CPU/NVMe offload or 8-bit/factored optimiser states when still too big, accepting slower steps.
- For very large layers/depth, use tensor parallelism (within layers) and pipeline parallelism (across stages).
You have finished this topic.
Reading
- Transformer Math 101Compute and memory rules of thumb (bytes per parameter, activations, communication) for training transformers.
- The Ultra-Scale PlaybookA hands-on, measured walk through data, tensor, pipeline, context and expert parallelism on GPU clusters.
- How to Scale Your ModelA systems view of how hardware limits shape parallelism choices for training and inference.
- ZeRO: Memory Optimizations Toward Training Trillion Parameter ModelsThe stage-by-stage sharding of optimiser state, gradients and parameters, with communication analysis.
- Megatron-LM: Training Multi-Billion Parameter Language Models Using Model ParallelismThe column/row split of transformer layers that defines tensor parallelism.
- Efficient Large-Scale Language Model Training on GPU Clusters Using Megatron-LMCombining tensor, pipeline and data parallelism, with the 1F1B and interleaved schedules and bubble analysis.
- PyTorch FSDP: Experiences on Scaling Fully Sharded Data ParallelHow full sharding is implemented in PyTorch and what limits its performance.
- Pretraining Large Language Models with NVFP4The recipe for 4-bit pretraining at scale: Hadamard transforms, 2-D block scaling, stochastic rounding and which layers stay in higher precision.
Practise this topic
- Roughly how much GPU memory does full fine-tuning of a 7B model with Adam in mixed precision need, compared with LoRA and QLoRA?
- Will a 70B dense model serve 32 concurrent users at 32k context on two 80 GB GPUs? Explain tensor, pipeline and data parallelism along the way.
- Your model plus optimiser state exceeds one GPU’s memory. List the options, from cheapest to most complex.
- Compare data parallelism, FSDP/ZeRO, tensor parallelism and pipeline parallelism: what is split, what is communicated, and when to combine them.
- How does ring all-reduce scale with the number of workers? How do you keep convergence when the global batch grows 8×?
- How does a mixture-of-experts layer work, what problems does routing introduce, and how does MoE change the memory, compute and communication profile compared with a dense model of similar quality?
- You must train a model that doesn’t fit in one accelerator’s memory. Lay out your options and how you would combine them for a model of a few hundred billion parameters.
- Explain how all-reduce works across many nodes (ring vs tree) and what it costs in bandwidth and latency. Then reason about how many rounds you need for a target accuracy if the channels are noisy.
- Roughly how much accelerator memory do weights, gradients and Adam state need for a 70-billion-parameter model trained in mixed precision? Show the accounting and say which precision choices change it.
- Midway through a large pretraining run, the loss suddenly spikes and sometimes diverges. How do you diagnose the cause, and which mitigations would you consider?
- Explain the Muon optimiser. What does it do to the momentum update, which parameters does it apply to, and what extra changes were needed to use it for trillion-parameter pretraining?
- NVIDIA reported pretraining a 12B model on 10 trillion tokens in NVFP4 with loss and accuracy comparable to FP8. Explain the format, why naive 4-bit training diverges, and the techniques that made it work. Which parts of a training step would you keep in higher precision?
- Explain DiLoCo-style low-communication training and what the 2025 scaling-law results showed. When would you use it instead of standard data parallelism?
- Your GRPO run generates rollouts with a fast inference engine and computes gradients in a separate FSDP trainer, partly asynchronously. Reward climbs for a few hundred steps and then training collapses, although the same weights are loaded in both places. Explain training–inference mismatch, how you would confirm it is the cause, and what you would change.
- Qwen3.5-397B-A17B activates 10 of 512 routed experts plus one shared expert per token. Compared with Mixtral-style 2-of-8 routing, what do fine-grained and shared experts buy you, what do they cost in training and serving, and how does DeepSeek-V3’s auxiliary-loss-free load balancing work?
- During a pre-training run on thousands of accelerators you see occasional loss spikes with no NaNs and no hardware errors reported. How do you decide whether silent data corruption is the cause, and what would you build to detect and contain it?
- Muon has gone from small-scale experiments to training Kimi K2 and DeepSeek-V4. Explain what Muon computes and for which parameters, why it needed weight decay and update-scale matching to scale, and what instability Kimi K2 hit and how QK-Clip fixes it.
- You must shuffle a training set of hundreds of terabytes (for example, cached model activations) that cannot fit in memory on any one machine. Design an approach and analyse its cost.