LearnTopic guide

Distributed training and parallelism

Once a model, its optimiser state or its activations exceed one accelerator, you need sharding and parallelism. Interviewers expect quick memory arithmetic (about 16 bytes per parameter for mixed-precision Adam, before activations), the menu of techniques from cheap to complex (bf16, gradient accumulation, activation checkpointing, ZeRO/FSDP, tensor, pipeline, sequence or context, and expert parallelism), what each technique splits and communicates, what collectives cost, how to keep convergence as the global batch grows, and the operational side: topology-aware placement, stragglers, failures and checkpoints. Applied roles meet the same ideas when sizing fine-tuning jobs and multi-GPU serving.

Research · ML engineering · Applied LLM8 key concepts18 questions

Start: Key concepts 6 lessons · about 17 min
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

  1. 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.

  2. 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.

  3. About 16 bytes per parameter means 7B needs about 112 GB and 70B about 1.1 TB before activations.

  4. ZeRO stage 1 shards optimiser state, stage 2 also shards gradients, and stage 3 (equivalent to PyTorch FSDP) shards parameters too.

  5. 8-bit optimisers and FP8 training shrink the totals.

Memory splits into model states at about 16 bytes per parameter, activations that scale with batch, sequence and hidden size, and the sharding or low-precision choices that shrink both.Diagram drafted by a local AI model (Inkling 2 Mini) from this page's text and drawn from data. Checked by an independent reviewer.

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.

Next: Worked examples Lesson 3 of 6 · about 6 min

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.

Next: What changed Lesson 4 of 6 · about 2 min

What changed recently

  1. 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.

    Source

  2. 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.

    Source

  3. 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.

    Source

  4. 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.

    Source

  5. 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.

    Source

Next: Pitfalls and interview angles Lesson 5 of 6 · about 1 min

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.
Next: Quiz Lesson 6 of 6 · about 3 min

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.

  1. Question 1 of 3 · Applied LLM · Technical · Medium

    Roughly how much GPU memory does full fine-tuning of a 7B model with Adam in mixed precision need, compared with LoRA and QLoRA?

  2. Question 2 of 3 · Applied LLM · Technical · Hard

    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.

  3. Question 3 of 3 · ML engineering · Technical · Hard

    Your model plus optimiser state exceeds one GPU’s memory. List the options, from cheapest to most complex.

Reading

Practise this topic

  1. Roughly how much GPU memory does full fine-tuning of a 7B model with Adam in mixed precision need, compared with LoRA and QLoRA?Applied LLM · Technical · Medium
  2. 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.Applied LLM · Technical · Hard
  3. Your model plus optimiser state exceeds one GPU’s memory. List the options, from cheapest to most complex.ML engineering · Technical · Hard
  4. Compare data parallelism, FSDP/ZeRO, tensor parallelism and pipeline parallelism: what is split, what is communicated, and when to combine them.ML engineering · Technical · Hard
  5. How does ring all-reduce scale with the number of workers? How do you keep convergence when the global batch grows 8×?ML engineering · Technical · Hard
  6. 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?Research · Technical · Hard
  7. 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.Research · System design · Hard
  8. 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.Research · Technical · Very hard
  9. 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.Research · Technical · Medium
  10. 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?Research · Technical · Hard
  11. 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?Research · Technical · Hard
  12. 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?Research · Technical · Very hard
  13. Explain DiLoCo-style low-communication training and what the 2025 scaling-law results showed. When would you use it instead of standard data parallelism?Research · Technical · Hard
  14. 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.ML engineering · Technical · Hard
  15. 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?ML engineering · Technical · Hard
  16. 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?Research · Technical · Hard
  17. 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.Research · Technical · Hard
  18. 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.Research · System design · Hard

Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.