Distributed Training

How one training step is split across many GPUs (data, sharded data, tensor, pipeline, expert and context parallelism), what each GPU holds, what crosses which wire, and how the splits are composed. Part of Topic: llm-training-and-post-training. Sources are linked inline; data as of October 2026. Reading: 32 min, plus 5 in closed details.

The idea in one screen

A training step can be cut along six dimensions: the batch, the stored state, each weight matrix, the layers, the experts or the sequence. Each cut lowers what one GPU holds or computes and pays for it in bytes that a collective must move between GPUs, so a layout puts the chattiest cut on the fastest wire: NVLink inside a server, about nine times faster per GPU than the network between servers on an H100 cluster.

You need: what a training step holds in memory (weights, gradients, Adam's state, activations), which the parent Topic: llm-training-and-post-training sets out in its Machinery section. The links themselves (NVLink, InfiniBand, rings and trees) are owned by Interconnects and scaling; mixture-of-experts design by Mixture of experts.

Collective
an operation every GPU in a group calls together; NCCL implements them on NVIDIA hardware (section 2).
Model states
weights, gradients and optimiser state, the part of memory that does not depend on the batch.
Micro-batch
the slice of the batch one GPU processes in one forward and backward; gradient accumulation sums several before the update.
Bubble
the time pipeline stages sit idle while the pipeline fills and drains.
ZeRO stage
how much of the model states is sharded over the data-parallel GPUs: 1 optimiser state, 2 plus gradients, 3 plus weights (FSDP).
MFU
model FLOPs utilisation: useful FLOPs per second over the GPU's peak.
The six splits in one table, with the bytes each sends (reference)

Ψ is the parameter count, n the number of GPUs in the group, s the sequence length, b the micro-batch in sequences, h the hidden size; bytes are bf16 (2 per value) unless stated.

SplitWhat is cutEach GPU holdsCollective in one stepBytes sent per GPU per stepLink it needsReach for it when
Data (DDP)The batchThe whole model, its gradients and optimiser state; its own micro-batchAll-reduce of the gradients, in buckets, overlapped with backward2(n−1)/n × 2ΨEither; tolerates latencyThe model and its optimiser fit on one GPU
ZeRO-1, ZeRO-2The batch, plus optimiser state (and gradients)Full weights; 1/n of the optimiser state (and of the gradients)Reduce-scatter of gradients, all-gather of updated weightsSame as DDPEitherOptimiser state is what does not fit
ZeRO-3, FSDPEverything stored1/n of weights, gradients, optimiser state; one layer's full weights at a timeAll-gather of each layer's weights before forward and again before backward; reduce-scatter of gradients3(n−1)/n × 2Ψ, 1.5 times DDPFast; hybrid sharding keeps it in the serverThe weights themselves do not fit; the usual choice below about 10B
Tensor (TP, + SP)Every weight matrix1/t of each matrix; the whole micro-batchTwo all-reduces per layer forward, two backward (with sequence parallelism, reduce-scatter plus all-gather of the same size)4 × 2(t−1)/t × 2sbh per layer per micro-batchNVLink, inside one server (t ≤ 8)One layer, or its activations, does not fit
Pipeline (PP)The layersL/p consecutive layers; activations of the micro-batches in flightSend and receive between neighbouring stages2 × 2sbh per micro-batch per boundarySlow links are fineThe model does not fit in one server; across servers
Expert (EP)An MoE model's expertsE/e experts; attention replicated or split another wayAll-to-all dispatch and combine around every MoE layer, forward and backward4 × k × tokens × h × bytes × (e−1)/e per MoE layerNVLink, or InfiniBand with routing limited to a few nodesThe model is a mixture of experts
Context (CP)The sequence1/c of every sequence's tokens; full weightsAll-gather (or ring pass) of keys and values forward, reduce-scatter of their gradients backward; gradient all-reduce as in DDP2 × (c−1)/c × K,V bytes per layer per micro-batchFast preferredA single long sequence's activations do not fit

Formulas: ring collectives from nccl-tests; ZeRO's 2Ψ against 3Ψ from ZeRO §7; tensor-parallel all-reduces from Megatron-LM; the other rows are derived in src/recompute.py. Numbers are published with the source linked unless marked derived, illustrative, reported (the maker's own figure) or unconfirmed. The one-line version of this table, beside precision and clusters, is in the parent page's Machinery section.

Fig. 1 · Six ways to cut one step over four GPUs: who holds what, and what has to cross the wire

Data (DP)

Cuts the batch; every GPU holds the whole model. Sends an all-reduce of the gradients: 24.1 GB. Any link.

Sharded data (ZeRO-3, FSDP)

Cuts the stored state as well. Sends each layer's weights twice and the gradients once: 36.1 GB. A fast link.

Tensor (TP)

Cuts every matrix; every GPU sees the whole batch. Sends four all-reduces inside every layer: 51.5 GB. NVLink only.

Pipeline (PP)

Cuts the layers. Sends one activation and one gradient per micro-batch: 0.54 GB. Any link, but stages idle in the bubble.

Expert (EP)

Cuts the experts of an MoE model. Sends tokens to their experts and back by all-to-all: 13.6 GB. NVLink, or a few servers.

Context (CP)

Cuts the sequence. Sends keys and values in every layer, plus the gradient all-reduce: 30.5 GB. A fast link.

GPU 0GPU 1GPU 2GPU 3a full copy on every GPUstored as a quarter, gathered when used

Left: the batch, four sequences in chunks of tokens. Right: the model, eight rows of layers, each an attention and a feed-forward half in four slices. Bytes are per GPU for one step of Llama 3 8B on four GPUs, from each section's stage (Figs. 4 to 12) derived.

1. The memory every split is fighting

Take Llama 3 8B (8.03B parameters recounted from its config.json, an unsloth mirror of the gated repository) and train it with Adam in mixed precision on one 80 GB H100. Fig. 2 stacks what one GPU must hold, to scale, against its 80 GB: Llama 3 8B does not fit on one H100 before a single activation is stored.

  1. bf16 weights. 8.03B parameters at 2 bytes each: bf16 weights 16.1 GB, a fifth of the GPU.
  2. bf16 gradients. Backward produces one gradient per weight, the same size again: bf16 gradients 16.1 GB.
  3. Optimiser state. Mixed-precision Adam keeps an fp32 master copy of the weights and two fp32 moments, 12 bytes per parameter: fp32 master weights and two Adam moments 96.4 GB. Model states 128.5 GB, 16 bytes per parameter, are now well past the 80 GB line.
  4. Activations. Backward also needs what forward computed: activations of one 8,192-token sequence 36.5 GB, from the GPT-style estimate below derived (src/recompute.py). About 165 GB in all, twice what the GPU holds, before a second sequence.

The rule behind the bar: mixed-precision Adam holds about 16 bytes per parameter before activations, 2 for bf16 weights, 2 for bf16 gradients and 12 for the fp32 master weights and the two Adam moments (ZeRO §3.1). So plain data parallelism stops fitting above about 5B parameters on an 80 GB GPU (80 / 16 derived), and a 7.5B model needs 120 GB on every GPU. Activations come on top and grow with sequence length and micro-batch: about 34sbh bytes per layer for a GPT-style layer once the attention score matrix is not stored (Korthikanti et al. 2022), 36.5 GB for one 8,192-token sequence through Llama 3 8B's 32 layers derived. Every split below removes one of these four blocks from each GPU, or a share of it.

Sixteen bytes is one convention, not a constant (depth)

MT-NLG counts fp32 gradient copies and gets 20 (Smith et al. 2022 §2.1.1); Llama 3 accumulates and reduces gradients in FP32 (§3.3.2), about 18 on our reading derived; DeepSeek-V3 keeps fp32 master weights and gradients but bf16 Adam moments (§3.3), about 14 with a bf16 working copy derived; an 8-bit optimiser is less. The Layout calculator offers all four. Training against LoRA and QLoRA fine-tuning, model by model, is PEFT's memory calculator (section "Memory: full fine-tuning, LoRA and QLoRA").

2. Collectives: the five shapes communication takes

Every split talks through five operations that all GPUs in a group call together. Fig. 3 runs them on four GPUs, each holding four chunks of a buffer:

  1. Four GPUs, four chunks each. Each GPU holds one buffer cut into four chunks, coloured by the GPU that computed them. Every GPU in the group calls the collective together.
  2. Reduce-scatter. Chunk j of every GPU travels to GPU j and is summed there: each GPU ends with the sum of one chunk only (Σ). Sends (n − 1)/n of the buffer. ZeRO and FSDP gradients.
  3. All-gather, and so all-reduce. Each GPU contributes its chunk and ends with all of them. Sends (n − 1)/n. FSDP weights; context-parallel keys and values. A reduce-scatter followed by an all-gather leaves every GPU with the element-wise sum: an all-reduce, which sends 2(n − 1)/n of the buffer. Data-parallel gradients; tensor-parallel partial sums.
  4. All-to-all. Each GPU sends a different chunk to every other: GPU i's chunk j lands on GPU j. Sends (n − 1)/n, nothing summed. Expert dispatch and combine; DeepSpeed Ulysses.
  5. Send and receive. One GPU to its neighbour. Pipeline stages pass activations forward and gradients back.

The ring factors are nccl-tests'; since the bytes per GPU barely change with the group size, the slowest link sets the time. Because a ring all-reduce is exactly a reduce-scatter followed by an all-gather, ZeRO-1 and ZeRO-2 cost what DDP costs (Ultra-Scale Playbook). Inside an H100 server NVLink gives each GPU 450 GB/s each way; between servers each GPU has its own 400 Gb/s card, 50 GB/s, nine times less (Llama 3 used RoCE and InfiniBand at 400 Gb/s per GPU, §3.3.1); DeepSeek's export-limited H800s have NVLink at 160 GB/s, "roughly 3.2 times that of IB (50 GB/s)" (DeepSeek-V3 §3.2.2). That ratio pins each split to a level of the network.

Per GPU per step, for Llama 3.1 8B on 8 GPUs (BF16): DDP all-reduces 28.1 GB of gradients; FSDP moves 42.2 GB (1.5 × DDP: two weight gathers and a gradient reduce-scatter); tensor parallelism 0.47 GB per layer, on the critical path; a pipeline boundary 67 MB per micro-batch; expert parallelism at most 229 KB per token per MoE layer (DeepSeek-V3). The formulas behind each number and the time on each link: Performance math, section 8.

Implemented in: Interconnects and scaling section 7 and its Collective simulator (ring, tree and other algorithms timed on each link; a gradient all-reduce carries 16.1 GB for Llama 3 8B, 141 GB at 70B); Distributed PyTorch section 2; Launching distributed training section 6 (the NCCL communicator and its timeouts).

3. Data parallelism (DP, DDP)

Replicate the model on every GPU and give each replica a different micro-batch. After backward, an all-reduce averages the gradients, so every replica takes the identical optimiser step. Fig. 4 plays one step of Llama 3 8B on four GPUs, four sequences of 8,192 tokens (given one sequence of 32,768 instead, three GPUs would have nothing to do: data parallelism cannot cut a single sequence). The same step, on the same four GPUs, returns under every split below:

  1. Setup: four full copies. Every GPU holds the whole model, its gradients and its optimiser state: 16 bytes per parameter, 128.5 GB, past the 80 GB line of an H100. This is the memory ceiling the other splits remove. Each GPU gets its own sequence.
  2. Forward. Each GPU runs its own sequence through all 32 layers and keeps the activations for backward, so the green slab grows. No communication.
  3. Backward, with the all-reduce starting. Gradients appear from the last layer back. DDP groups them into buckets of 25 MiB and starts an all-reduce on each bucket as soon as it is ready, so the dots start flowing round the ring while backward is still running.
  4. All-reduce finishes. Every GPU now holds the average gradient. A ring all-reduce sends 2(n − 1)/n of the buffer per GPU: 1.5 × 16.1 GB = 24.1 GB each, whatever the number of GPUs.
  5. Optimiser step. Every GPU applies the same update to its own copy, so the four copies stay identical. Four times the optimiser work and memory for one result: the redundancy ZeRO removes.

DDP sends the gradients in buckets (25 MiB by default in PyTorch's DistributedDataParallel) as soon as each is ready, so the all-reduce overlaps the rest of backward. PyTorch's old DataParallel was a single process driving the GPUs of one machine by threads; DDP runs one process per GPU, works across machines, and is the baseline everything else builds on (Li et al. 2020). It scales nearly linearly while the all-reduce hides behind backward, and that has a size condition: a replica sends about 2 × 2Ψ bytes and computes 6Ψ FLOPs per token, so the transfer hides when each replica processes T ≥ 2I/3 tokens per step, where I is the GPU's sustained FLOP/s over the link's bytes per second. For an H100 at 40% of its BF16 peak over a 400 Gb/s card that is about 5,300 tokens per replica (Interconnects and scaling section 9 derived); Llama 3 405B's 16M-token batches over 128 replicas give 131,072 tokens each, far above it.

Its cost is memory: the full 16 bytes per parameter on every GPU, the ceiling ZeRO and FSDP remove. The global batch is micro-batch × gradient-accumulation steps × data-parallel degree (Playbook), so DP is also how a layout reaches its target batch once the model fits, and a fixed token budget per step caps it: Llama 3's 16K-GPU run had fewer sequences per DP rank than its 8K-GPU run and a lower MFU (41% against 43%, §3.3.2).

Implemented in: Distributed PyTorch section 3 (DDP's reducer, buckets, comm hooks); Sharding and scale (JAX); Launching distributed training (torchrun, rendezvous).

4. ZeRO and FSDP: sharded data parallelism

Data parallelism stores the same 16 bytes per parameter n times. ZeRO (paper page, Rajbhandari et al. 2019) shards them across the data-parallel group instead, in three stages.

Predict: the ZeRO paper's 7.5B model needs 120 GB per GPU under plain data parallelism. Shard only the optimiser state over 64 GPUs (ZeRO-1). About how much is left per GPU?

ZeRO-1 shards the optimiser state: each GPU updates its 1/n of the fp32 master weights, then an all-gather shares the updated bf16 weights. ZeRO-2 also shards the gradients, reduce-scattered as backward produces them; stages 1 and 2 send what DDP sends. ZeRO-3 also shards the parameters: each layer's weights are all-gathered just in time for forward and again for backward, then freed. Communication is 3Ψ against DP's 2Ψ, 1.5 times (§7), and model-state memory falls as 1/N.

Fig. 5 · Each stage shards one more block; the part left whole sets the floor

bf16 weightsbf16 gradientsfp32 optimiser state80 GB

Model states per GPU for 7.5B parameters, full bar 120 GB. ZeRO-1 keeps 4 + 12/n bytes per parameter, ZeRO-2 2 + 14/n, ZeRO-3 16/n. At n = 64 the bars reproduce ZeRO Table 1 independently: 31.4, 16.6 and 1.88 GB.

Fig. 6 plays the same step as Fig. 4 under each stage, and under hybrid sharding (HSDP) across two servers. Pick one; the readout under the steps compares it with DP: the slabs fall to a quarter under ZeRO-3 while the bytes grow by half, and HSDP sends only 8.0 GB per GPU across InfiniBand.

  1. Setup: everything sharded. Each GPU holds a quarter of every layer's weights, gradients and optimiser state: 16/4 = 4 bytes per parameter, 32.1 GB. This is FSDP's default (FULL_SHARD).
  2. Forward, layer by layer. Before each layer runs, its quarters are all-gathered into a full copy (the pale layer climbing the stack), used, and freed. One layer's full weights exist at a time. 32 all-gathers, (n − 1)/n × 16.1 GB = 12.0 GB sent per GPU.
  3. Backward: gather again, then reduce-scatter. Each layer is all-gathered again for backward (12.0 GB), and its gradients are reduce-scattered straight away so each GPU keeps only its quarter (12.0 GB).
  4. Optimiser step, no final gather. Each GPU updates its own quarter. The weights stay sharded until the next forward gathers them. Total 36.1 GB per GPU: 1.5 times DP, the price of holding a quarter of the weights.

The extra gathers are not free: with gradient accumulation ZeRO-3 gathers the weights again for every micro-batch, forward and backward, and across servers that traffic lands on the slow link; HSDP or ZeRO-2 are the usual fixes. Re-gathering for backward is itself a choice: keeping each layer's gathered weights from forward to backward saves the second all-gather (2Ψ again instead of 3Ψ) for activation-like memory. FSDP2's reshard_after_forward controls it (by default every module reshards except the root); XLA kept the weights on the Sharding and scale (JAX) page's measured run; Llama 3's FSDP shards optimiser state and gradients but keeps weights gathered after forward (§3.3.2).

FSDP is PyTorch's native version, "motivated by" ZeRO with a design aligned with the rest of PyTorch (Zhao et al. 2023); its default full sharding is ZeRO-3, and it has a ZeRO-2-like mode as well. FSDP2 (fully_shard) shards each parameter on its own dimension 0 as a DTensor, so it composes with TP, PP and EP on a device mesh. The 2026 default: on PyTorch, without a need for NVMe offload, use FSDP2 rather than DeepSpeed; the arithmetic is the same, the composition cleaner.

Hybrid sharding (HSDP) builds "a 2-D DeviceMesh that contains replica groups on one dimension and shard groups on the other" (torchtitan paper): FSDP-shard within a server (or a small group), DDP-replicate across groups. The heavy per-layer all-gathers stay on NVLink and only the gradient all-reduce crosses servers (8.0 GB per GPU on InfiniBand against 36.1 GB for ZeRO-3 across both servers). It also bounds the blast radius of a failure: a lost server leaves complete replicas, which is how torchft does "fault tolerance across the replicated dimension". Use it when the model fits in one server's (or group's) aggregate memory.

Offload, and what FSDP2's per-parameter sharding buys (depth)
  • ZeRO-Offload moves optimiser state and its update to CPU memory (Ren et al. 2021); ZeRO-Infinity adds NVMe, enough to "fine-tune trillion parameter models on a single NVIDIA DGX-2 node" (Rajbhandari et al. 2021).
  • FSDP2 "replac[ed] the original FSDP1 FlatParameter sharding. Specifically, parameters are now represented as DTensors sharded on the tensor dimension 0" (torchtitan paper). A 2026 framework survey reaches the same split as the default above: DeepSpeed remains the pragmatic choice mainly for memory-bound runs that need ZeRO-Infinity offload.
  • Because every FSDP2 parameter keeps its own identity, state_dict handling is sane through Distributed Checkpoint (DCP), and partial freezing works, so LoRA-style fine-tuning is straightforward.
  • FSDP2 "records an average of 7% lower GPU memory versus FSDP1" and "an average gain of 1.5% faster throughput" reported (torchtitan paper).
  • The stage names across DeepSpeed, FSDP1 and FSDP2 are matched on the ZeRO page's Then and now tab; the stages layer by layer on 2 to 8 GPUs are stepped through in its Communication section.

Implemented in: Distributed PyTorch section 4 (FSDP2, HSDP, prefetching, state dicts); Sharding and scale (JAX) (FSDP along a mesh axis, measured).

5. Tensor parallelism and sequence parallelism

Tensor parallelism splits individual weight matrices across GPUs (Megatron-LM): a column-parallel matrix followed by a row-parallel one, in the feed-forward block and in attention (heads are divided among GPUs). Fig. 7 runs one feed-forward block on two GPUs, in Megatron-LM's notation (Y = GeLU(X·A), Z = Y·B), first as plain TP, then with sequence parallelism:

  1. The input, whole on both GPUs. Both GPUs hold every token of X. Megatron's f operator is the identity going forward (its backward is an all-reduce).
  2. Column split of A. GPU 0 holds the first half of A's columns, GPU 1 the second (the outline is the half it does not hold). X·A₀ and X·A₁ are independent, so GeLU runs locally with no communication.
  3. Row split of B. Each GPU holds the matching half of B's rows, so Zᵢ = Yᵢ·Bᵢ is only a partial sum of the output.
  4. One all-reduce. Z₀ + Z₁ = Z needs a sum, one all-reduce of the block's output (b × s × h values; Megatron's g). Then LayerNorm and dropout run on all tokens on both GPUs: duplicated work and duplicated activation memory.

Sequence parallelism (Megatron-style) extends TP to the regions TP leaves replicated, LayerNorm and dropout, by splitting their activations along the sequence. The all-reduce becomes a reduce-scatter plus an all-gather of the same total size, so communication is unchanged and the duplicated activation memory disappears: activations per layer fall from sbh(34 + 5as/h) to sbh/t(34 + 5as/h), and with selective recomputation to 34sbh/t (Korthikanti et al. 2022). One small collective appears: each GPU ran the LayerNorm on its own tokens, so the LayerNorm weights' gradients are partial sums and need an all-reduce over the TP group (recorded on Distributed PyTorch section 6). It is not context parallelism (section 8): it lives inside the TP group and leaves attention whole.

That is two all-reduces per layer forward and two backward, inside every layer, in small latency-bound messages on the critical path: the next matmul needs the result, so overlap cannot hide them. Fig. 8: four GPUs, the same step as before:

  1. Setup: every matrix cut in four. Each GPU holds a quarter of every weight matrix: query, key and value heads and the first feed-forward matrices by columns, the attention output and second feed-forward matrix by rows. 4 bytes per parameter, 32.1 GB. The four GPUs act as one model replica, so the whole batch, four 8,192-token sequences, goes through all four.
  2. Layer 1, attention. Column-parallel QKV gives each GPU 8 of the 32 heads, so attention runs locally. The row-parallel output projection leaves a partial sum on each GPU: one all-reduce of the batch's hidden states, 0.40 GB per GPU. With sequence parallelism this is a reduce-scatter plus an all-gather of the same size, and LayerNorm activations are split by tokens.
  3. Layer 1, feed-forward. Column-parallel W1 and W3, the SwiGLU applied locally (the reason for the column-then-row pairing: no sync in between), row-parallel W2, then the second all-reduce.
  4. Layers 2 to 32. Two all-reduces per layer: 64 in the forward pass, 25.8 GB per GPU.
  5. Backward. The mirror image: two all-reduces of input gradients per layer, 64 more, 25.8 GB. Each GPU computes the weight gradients for its own slices only.
  6. Optimiser step, no gradient sync. There is one replica, so nothing to average. Total 51.5 GB per GPU, more than any other split, in 128 small, latency-bound pieces inside every layer: tensor parallelism only works on NVLink.

TP sends 51.5 GB per GPU for this step, more than any other split, and its bytes per FLOP do not depend on the batch at all, only on the degree, the hidden size and the link, so a slow link cannot be bought back with bigger batches: for Llama 3.1 70B at TP 8 over a 400 Gb/s card the communication is 141% of the compute (Interconnects and scaling section 9 derived). Hence Megatron's guidance, TP "up to degree g when using g-GPU servers", then pipeline parallelism across servers (Narayanan et al. 2021); the Playbook measured "around 43% performance degradation" when TP crosses nodes, against 14% for PP. Keep the degree a divisor of the number of heads (of KV heads, with grouped-query attention): otherwise the attention has to be reshuffled, and the JAX page measured 1.33 times the predicted bytes for 4 heads over 8 devices.

Implemented in: Distributed PyTorch sections 5 and 6 (DTensor, TP and SP on a real block); Sharding and scale (JAX); the Megatron-LM page's section Method: the f and g operators, which splits a layer on real matrices.

6. Pipeline parallelism

Pipeline parallelism splits the model into stages of consecutive layers, one per GPU or group. Only activations (forward) and their gradients (backward) cross a stage boundary, 2sbh bytes per micro-batch each way, so PP is cheap on bandwidth and is the preferred way to split a model across servers. Run naively, one batch at a time, only one stage works while the others wait: the bubble. Cutting the batch into m micro-batches lets stages work on different micro-batches at once. Fig. 9: four stages, four micro-batches, the 1F1B schedule, with the timeline on the floor:

  1. Setup: eight layers per GPU. GPU 0 holds layers 1 to 8 with the embedding, GPU 3 layers 25 to 32 with the output head: 4 bytes per parameter of the whole model each, 32.1 GB (the end stages a little more). The batch is cut into four micro-batches, one sequence each; the timeline on the floor fills as the step runs.
  2. Warm-up. Micro-batch 1 enters stage 1, then its activations are sent to stage 2, and so on. The later stages wait: the start of the bubble.
  3. Steady state: one forward, one backward. 1F1B: once the last stage starts backward, each stage alternates a forward and a backward, so it never holds more than p micro-batches of activations (GPipe holds all m). Gradients flow back by send and receive.
  4. Cool-down. The pipeline drains; the first stage waits for the last gradients. Idle share of the timeline: (p − 1)/(m + p − 1) = 43%; in Megatron's terms the bubble is (p − 1)/m = 75% of the ideal time.
  5. Optimiser step. Each stage updates its own layers; nothing to average. The traffic was tiny, 0.54 GB per GPU at most, one activation per micro-batch per boundary: pipeline parallelism is the split to put on slow links.

The idle share of the timeline is (p − 1)/(m + p − 1), 43% here; Megatron writes the same bubble as (p − 1)/m of the ideal time, 75%.

A schedule decides the order of forwards and backwards:

  • GPipe (Huang et al. 2019): all forwards, then all backwards. Bubble time fraction (p − 1)/m of the ideal time, and every stage holds the activations of all m micro-batches.
  • 1F1B (from PipeDream, Harlap et al. 2018; Megatron uses its flushing variant, PipeDream-Flush): after a warm-up, each stage alternates one forward and one backward. The bubble is the same as GPipe's; what changes is memory, at most p micro-batches in flight instead of m (Narayanan et al. 2021).
  • Interleaved 1F1B: each GPU holds v non-adjacent chunks of layers, cutting the bubble to (p − 1)/(v·m) for v times more point-to-point traffic. Llama 3 used it, with a tunable number of consecutive micro-batches per stage, and states the same ratio, (PP − 1)/(V × M) (Llama 3 §3.3.2).
  • Zero bubble, ZB-H1 (Qi et al. 2023): backward is split into the gradient for the input (B), which the previous stage is waiting for, and for the weights (W), which nobody is, so W fills the gaps. "The bubble size is reduced to a third of 1F1B's size" at the same peak memory; ZB-H2 removes it for about twice the activations.
  • DualPipe (DeepSeek-V3, paper page): micro-batches enter from both ends, each forward chunk is overlapped with a backward chunk, and the all-to-all and pipeline communication hide inside the computation. Bubble (PP/2 − 1)(F&B + B − 3W), for two copies of the parameters and PP + 1 micro-batches of activations (Table 2). The V-shaped variants (DualPipeV, ZBV) give rank 0 both the first and the last stage, so the pipeline turns round on one GPU (both run on Distributed PyTorch section 8).
Predict: 8 stages, 20 micro-batches. Switching from GPipe to 1F1B does what to the bubble?

Fig. 10 · The bubble falls with more micro-batches and with interleaving; 1F1B alone changes only memory

The default is DeepSeek's DualPipe README example, 8 stages and 20 micro-batches; at m = 8 the GPipe and 1F1B rows rise to 88% of the ideal time. Rows use illustrative chunk times (forward 1, full backward 2, weight-gradient part 1), which is what makes ZB-H1 exactly a third of 1F1B.

The price of PP is the bubble, a batch-size constraint (enough micro-batches per step), uneven memory (the first stage holds the most activations, and the embedding) and invasive code changes. Rank-by-rank schedule animations are linked rather than rebuilt: the DeepSeek page (Training systems section) runs 1F1B, ZB1P, DualPipe and DualPipeV, and the Llama 3 page's Run the 16K-GPU job tab simulates Llama 3's interleaved schedule with its tunable micro-batch grouping.

Implemented in: Distributed PyTorch section 8 (every PyTorch schedule, measured); Sharding and scale (JAX) (by hand with shard_map).

7. Expert parallelism

In a mixture-of-experts model each token visits only k of E feed-forward experts, so the experts can live on different GPUs. Tokens travel to their experts in an all-to-all dispatch and come back in an all-to-all combine, around every MoE layer, forward and backward; attention and the other dense parts stay replicated (data parallel) or are split another way. The step uses an MoE twin of Llama 3 8B illustrative: every feed-forward block becomes four experts the size of the original, each token routed to one (Switch-style top-1), so each token costs the same compute and the model grows to 24.9B parameters. Fig. 11 plays its step:

  1. Setup: the MoE twin, one expert per GPU. Every feed-forward block is now four experts; GPU i holds expert i of every layer (orange, the back half of its stack) and a full copy of attention, embeddings and norms (the front half). 128.5 GB per GPU, the same as dense DP, while the model holds 24.9B parameters: experts add parameters without adding memory per GPU. Each GPU holds its own sequence.
  2. Layer 1: attention and the router. Attention runs where the tokens are. The router picks one expert per token; with balanced routing three quarters of each GPU's tokens belong to experts on other GPUs.
  3. All-to-all dispatch. Every GPU sends each token to the GPU holding its expert: 3/4 × 8,192 tokens × 4,096 × 2 bytes = 0.05 GB per GPU.
  4. Experts, then all-to-all combine. Each expert processes the tokens it received, then a second all-to-all returns the outputs to where their tokens live.
  5. Layers 2 to 32. Two all-to-alls per MoE layer: 64 in the forward pass.
  6. Backward. The same route in reverse: 64 more all-to-alls carry gradients to the experts and back.
  7. All-reduce of the shared parts. Attention, embeddings and norms are replicated, so their gradients (2.39B parameters) are all-reduced as in DP: 7.2 GB per GPU. Expert gradients stay where their expert lives.
  8. Optimiser step. Each GPU updates its experts and its copy of the shared parts. Total 13.6 GB per GPU; at DeepSeek-V3's scale the all-to-alls cross servers, which is why it limits each token to 4 nodes.

Per GPU the twin needs what the dense model needed, 128.5 GB, while holding three times the parameters: expert parallelism spreads the experts but does not shrink the dense state, so it is combined with FSDP, ZeRO-1 or TP for that. As Mixtral's paper puts it, tokens "are routed to the corresponding GPU for processing, and the expert's output is returned to the original token location", and EP "introduces challenges in load balancing" (Mixtral §2.1): the busiest GPU sets the pace. Given one 32,768-token sequence on GPU 0 instead of four sequences, GPU 0 would send 20.1 GB in the step, against 13.6 GB each when the tokens are spread: a hot spot (the busiest GPU's count derived, src/recompute.py).

At scale. DeepSeek-V3's layout (256 fine-grained routed experts per layer, 8 per token, 64-way EP over 8 nodes, each token capped at 4 nodes so it crosses InfiniBand once and NVLink forwards it, dispatch in FP8) is worked through on Mixture of experts, section 7, and on the DeepSeek-V3 paper page (§3.2). What it means for the training layout: 20 of each H800's SMs drive the communication, and even so cross-node EP gave "an inefficient computation-to-communication ratio of approximately 1:1", the reason DualPipe (section 6) overlaps the two. The Layout calculator's DeepSeek-V3 preset recomputes that ratio independently as 1.39 : 1.

Lineage, Qwen3's practice, and MoE training memory (depth)

Experts were sharded across devices with all-to-all routing by GShard (Lepikhin et al. 2020, the work DeepSeek-V3 cites for EP); Switch Transformers simplified routing to one expert and laid out how expert, data and model parallelism combine (§5, its Figure 9 redrawn on that page). Qwen3's MoE models (Qwen3-235B-A22B: 128 experts, 8 per token, config.json) are trained and fine-tuned with expert parallelism in Megatron-based stacks (ms-swift guide); Qwen has not published its own pretraining layout unconfirmed. The memory side of long-context MoE training (dispatch buffers, the vocabulary projection, checkpoints, optimiser state) is worked through on the MoE training memory bottlenecks paper page.

Implemented in: Mixture of experts section 7; Interconnects and scaling section 8 (all-to-all on the wire); Sharding and scale (JAX) (by hand).

8. Context parallelism

Context parallelism shards the sequence dimension of the activations across GPUs, for long-context training where activation memory, which grows with sequence length, is what no longer fits. Token-wise layers (the feed-forward block, norms) need nothing from other GPUs; attention does, because every query needs the keys and values of earlier tokens. Causal attention makes late tokens more expensive than early ones, so the sequence is cut into 2 × CP chunks and rank i takes chunks i and 2 × CP − 1 − i (Llama 3). Fig. 12 plays the step:

  1. Setup: every sequence cut in eight. Each sequence is cut into 2 × 4 = 8 chunks and GPU i keeps chunks i and 7 − i (the two lit chunks in each of its four rows), so every GPU gets one early and one late chunk and the causal mask gives each the same work (Llama 3's load balancing). Weights are whole on every GPU: 128.5 GB. Context parallelism cuts activations, not weights; in practice it is combined with FSDP or TP.
  2. Layer 1: gather keys and values. Each GPU computes Q, K, V for its own tokens, then all-gathers K and V (Llama 3's variant; Ring Attention passes the blocks round a ring instead). With grouped-query attention K and V are 4 times smaller than Q: 0.10 GB per GPU per layer.
  3. Attention for local queries, then the feed-forward. Each GPU computes attention for its own query chunks against all keys; the feed-forward block works token by token and needs nothing from the others.
  4. Layers 2 to 32. One all-gather per layer.
  5. Backward. Gradients of K and V are reduce-scattered back to the GPUs that own those tokens: 32 reduce-scatters, 3.2 GB.
  6. All-reduce of the weight gradients. Every GPU computed gradients for all weights from its own tokens, so they are averaged as in DP: 24.1 GB. Total 30.5 GB.
  7. Optimiser step. Identical update everywhere. Each GPU held a quarter of the activations, 36.5 GB, whether the batch was four sequences or one.

Each GPU holds a quarter of the activations whether the batch is four sequences or one, but the weights stay whole (128.5 GB), so CP is combined with FSDP or TP.

There are three ways to bring the keys and values to the queries:

  • Ring Attention (Liu et al. 2023): each GPU merges the partial outputs from each block with their log-sum-exp, the online softmax FlashAttention uses inside one GPU, so no GPU ever holds all the keys or a full score matrix. The cost is n sequential steps whose transfers must hide behind compute; a plain causal ring leaves GPU 0 with work in 1 of 8 steps, which the chunk ordering above fixes. The JAX page measured 123 MB of temporary memory per device for the ring against 273 MB for the all-gather at 8,192 tokens.
  • DeepSpeed Ulysses (Jacobs et al. 2023): its communication volume stays constant when sequence length and GPU count grow together, and it trained "2.5x faster with 4x longer sequence length" than the baseline it compared with reported; because it splits by heads, its degree is bounded by the head count derived.
  • All-gather, Llama 3's choice: the gather is exposed rather than overlapped, but with grouped-query attention keys and values are much smaller than queries and the gather is O(S) against attention's O(S²); it also handles document masks easily (§3.3.2).

Fig. 13 · Ring, all-gather or all-to-all: the same attention, three traffic patterns

Ring Attention

K,V blocks travel round the ring, n − 1 passes, each overlapped with attention on the block already received.

All-gather (Llama 3)

Every GPU gathers all keys and values once, then attends its own queries. Exposed, but small with GQA.

Ulysses (DeepSpeed)

An all-to-all swaps the split: tokens by GPU become heads by GPU, ordinary attention runs, a second all-to-all swaps back.

Llama 3 used CP = 16 for its 128K-context phase (Table 4). PyTorch's context parallel, shipped in torchtitan, implements Ring Attention with two rotation methods, ring passing and all-gather, defaulting to all-gather, and trained Llama 3 8B on 1M-token sequences on 32 H100s (PyTorch).

Correction
The old page said torchtitan "ships both" Ring Attention and Ulysses. Its context parallel is Ring Attention (with an all-gather rotation as the default); Ulysses is DeepSpeed's. It also implied Llama 3 used Ring Attention: Llama 3 chose an all-gather variant instead, for document masks and simplicity (§3.3.2).

Implemented in: Distributed PyTorch section 7 (ring attention on a CPU); Sharding and scale (JAX) (ring against all-gather, measured).

9. Composing them: 4D and 5D parallelism

Real runs stack the splits on a mesh of GPUs. The standard order, outermost to innermost: DP (FSDP or HSDP) × PP × CP × TP (+SP), with EP as a further axis for MoE layers. Llama 3 orders its groups [TP, CP, PP, DP] from innermost to outermost because "the innermost parallelism requires the highest network bandwidth and lowest latency, and hence is usually constrained to within the same server", while DP tolerates latency by prefetching weights and reducing gradients asynchronously (§3.3.2).

Fig. 14 draws two published layouts as meshes of GPUs, axis by axis, with the bytes and seconds per GPU per step that the Layout calculator computes for each axis:

  1. One server: TP 8 on NVLink. Eight GPUs of one server form a tensor-parallel group, the chattiest axis: 236.8 GB per GPU per step, but on NVLink, 0.53 s.
  2. Sixteen servers: the pipeline. Sixteen servers in a row are the 16 pipeline stages; between them pass only activations and their gradients, 1.07 GB per GPU per step, 0.02 s over the network.
  3. 128 replicas: data parallel. The whole pipeline is replicated 128 times (three copies drawn); the gradient reduce crosses the network, 18.9 GB, 0.38 s. TP moves twelve times the bytes DP does, but on a link nine times faster and inside the server; PP sends almost nothing, so it can span servers.
  4. All 16,384 GPUs against compute. 8 × 16 × 128 GPUs. All three axes together take under a sixth of the 6.15 s of compute at 41% MFU, before any overlap.

Fig. 14's numbers are from the Layout calculator's presets derived: Llama 3 405B at TP 8 × PP 16 × DP 128 sends 236.8 GB per GPU per step over NVLink for TP (0.53 s), 18.9 GB over the network for DP (0.38 s) and 1.07 GB for PP (0.02 s), against 6.15 s of compute at 41% MFU; DeepSeek-V3's 64-way EP sends 704 GB over InfiniBand (14.1 s) against 20.4 s of compute. Peak bandwidths, no overlap credited.

RunGPUsTPCPPPEPDPNotes
Llama 3 405B, 8K, first stage8,192811616416M tokens per batch; 43% BF16 MFU
Llama 3 405B, 8K16,3848116112841%; FSDP shards optimiser state and gradients but keeps weights gathered after forward
Llama 3 405B, 128K16,384816161838%
DeepSeek-V3 671B2,048111664128ZeRO-1 data parallel; DualPipe; "without using costly tensor parallelism"

Sources: Llama 3 Table 4 (the 41% row computes to 40.4%, 400 / 989.5, a rounding the Llama 3 page also flags); DeepSeek-V3 §3.2, DP = 2,048 / 16 derived, with the 64-way EP carved out of each stage's 128 data-parallel GPUs. The Megatron-LM page's Then and now tab lays out more runs from 2019 to 2026, and the Llama 3 page maps every rank of its mesh.

Rules of thumb, from the Ultra-Scale Playbook's 4,100 benchmarked runs on up to 512 GPUs (step 1, "Fitting a training step in memory"):

  • Fit the model first. Under 10B parameters one technique is enough, "tensor parallelism or ZeRO-3/DP with full recompute across 8 GPUs". From 10B to 100B: TP = 8 with PP, TP = 8 with ZeRO-3, or ZeRO-3 alone. At 512+ GPUs pure ZeRO-3 starts to lose efficiency to communication cost; at 1,024+ a recommended setup is TP = 8 with ZeRO-2 and PP. Add CP across nodes for very long sequences, and EP across nodes for MoE.
  • Keep the bandwidth-hungry axes (TP, EP dispatch) inside NVLink domains; PP and DP gradient sync can cross InfiniBand.
  • Then reach the target global batch (step 2) by scaling DP or gradient accumulation, or CP for long sequences.
  • Then optimise throughput (step 3): scale TP up to about the server size, increase DP with ZeRO-3 while keeping the batch, move to PP when DP communication becomes the bottleneck, and tune the micro-batch. Short of GPUs: full activation recomputation and more gradient accumulation.
Correction
The old page's first rule read "FSDP alone up to tens of billions of parameters on H100 nodes; add TP when a layer no longer fits; add PP across nodes for 100B+". The Playbook's own thresholds are lower and different in kind: one technique under 10B, three combinations from 10B to 100B, and the switch away from pure ZeRO-3 is set by GPU count (512+), not by model size.

Implemented in: Distributed PyTorch section 10 (the torchtitan order); Sharding and scale (JAX) (choosing a mesh); Interconnects and scaling section 9 (why the network picks your parallelism); Launching distributed training; Fault tolerance at scale (checkpoint, restart, goodput).

10. Activation checkpointing

Instead of storing every activation for backward, store a few and recompute the rest. One 8,192-token sequence through Llama 3 8B, no tensor parallelism:

Full recomputation (keep only each layer's input) costs 30 to 40% more execution time (36% measured); selective recomputation of only the attention core, the large but cheap part, cuts activation memory about 5 times for 2.7% (GPT-3) or 1.6% (MT-NLG) extra FLOPs (Korthikanti et al. 2022; the Playbook quotes 70% less activation memory for 2.7% compute). FlashAttention already recomputes attention in its backward pass instead of storing the score matrix, which is why selective checkpointing pairs naturally with it. Llama 3 trained 8K sequences with no activation checkpointing at all, after deallocating stage inputs and outputs it no longer needed (§3.3.2).

Fig. 15 · Selective recomputation removes nine tenths of the activations for 2 to 3% more compute

Store all380 GB
Selective36.5 GB
Full3.3 GB

Per layer sbh(34 + 5as/h) bytes when the attention scores are stored, 34sbh when the attention core is recomputed (selective, or FlashAttention), 2sbh plus one layer's working set with full recomputation (Korthikanti et al. 2022), times 32 layers at s = 8,192, h = 4,096, a = 32 derived, a GPT-style estimate (Llama's SwiGLU and GQA change the constants).

Correction
The old page said activation checkpointing "(full or selective) trades about 30% compute". That figure is full recomputation's (30 to 40%); selective recomputation costs about 2 to 3%.

11. Frameworks (2026)

  • torchtitan: PyTorch's native reference for pretraining, composing FSDP2, TP (including async TP), PP (including zero-bubble schedules), CP, activation checkpointing, torch.compile and low-precision training. The 2026 survey's advice is to "use torchtitan as a pattern source, not as a dependency".
  • Megatron-Core / NeMo: NVIDIA's production stack and the most mature TP and PP kernels, with expert parallelism and a distributed optimiser; the survey calls it "the ceiling for NVIDIA training".
  • DeepSpeed: still relevant for ZeRO-Offload and ZeRO-Infinity and for its Hugging Face Trainer integration. nanotron: Hugging Face's lightweight pretraining library, the Ultra-Scale Playbook's companion.

FSDP2 with HSDP covers the great majority of fine-tuning and pretraining below about 70B; full 4D parallelism is needed only at frontier scale. Schedulers, checkpoint cadence and fault tolerance at 16,000 GPUs are summarised in the parent's "Running the job" section (Topic: llm-training-and-post-training) and owned by Fault tolerance at scale; number formats for training (FP8, MXFP4) on Quantization and Precision.

torchtitan's full feature list and its paper's speed-ups (depth)

FSDP2 with per-parameter sharding, tensor parallel (including async TP), pipeline parallel (including zero-bubble schedules), context parallel, DDP and HSDP, per-op selective and full activation checkpointing, torch.compile, low-precision training (MXFP8 and NVFP4 today; the paper's Float8), Distributed Checkpoint with async saves, torchft fault tolerance (README). Its paper reports 65.08% speed-up on Llama 3.1 8B at 128 GPUs (1D), 12.59% on 70B at 256 GPUs (2D) and 30% on 405B at 512 GPUs (3D) over its own baselines reported.

12. Depth

Four mistakes the sections above do not already show (depth)
  • "Context parallelism (or expert parallelism) shrinks the weights." Neither does by itself: CP cuts activations; EP spreads experts but each GPU still holds a dense model's worth of state (both steps above stay at 128.5 GB). They are combined with FSDP, ZeRO-1 or TP for the weights.
  • "Sequence parallelism and context parallelism are the same thing." Megatron's sequence parallelism splits only the regions tensor parallelism leaves replicated (norms, dropout) and lives inside the TP group. Context parallelism splits attention itself across its own group and can be used without TP.
  • "Tensor parallelism across servers is just slower." It is much slower: four latency-bound collectives per layer per micro-batch, on the critical path. The Playbook measured about 43% degradation crossing nodes, against 14% for pipeline parallelism over the same boundary.
  • "16 bytes per parameter is a law." It is the ZeRO paper's convention for bf16 with fp32 Adam. FP32 gradients make it 18 to 20, bf16 moments 14, an 8-bit optimiser less; activations come on top.
How the step-throughs count (provenance)

All counts are for Llama 3 8B in bf16 with fp32 Adam (16 bytes per parameter), 4 GPUs on NVLink (HSDP: two servers joined by InfiniBand). Bytes are per GPU and sent, not received, from the ring formulas; activations use Korthikanti et al.'s 34sbh per layer, a GPT-style estimate, and in the EP step its 15 : 19 split between attention and MLP illustrative. Bars are to scale with a full bar = 280 GB. With one 32K sequence, DP and ZeRO leave three GPUs idle, PP idles 75% of the time, and only TP and CP split the sequence's 146 GB of activations. Every number is recomputed in src/recompute.py, and src/check_calc.mjs confirms the page's JavaScript gives the same numbers.