Naming rules:Reduce applies an associative/commutative op (sum, min, max) · Scatter is the inverse of Gather · All- means every rank receives the result.
Rooted Collectives: Broadcast and Scatter
Broadcast (rank 0 → all ranks)
Use case: rank 0 loads initial weights or checkpoint and broadcasts to all ranks
Scatter (split from rank 0 → all ranks)
Conceptual stepping stone to Reduce-Scatter
Rooted collectives have a single source or destination rank; training hot loops mostly use symmetric "All-" variants.
Rooted Collectives: Gather and Reduce
Gather (inverse of Scatter → rank 0)
Stepping stone to All-Gather
Reduce (combine with op, e.g. SUM → rank 0)
Stepping stone to All-Reduce ($0+1+2+3=6$)
Reduction operators must be associative and commutative (e.g., sum, min, max) so NCCL can reorder partial reductions freely.
Workhorse Collective: All-Gather
Performs a Gather whose destination is every rank, not just rank 0
FSDP / ZeRO use case: each GPU permanently stores only $1/W$ of a layer's weights, then runs All-Gather just before forward or backward compute
Tensor Parallelism use case: reassemble sharded activation columns across ranks
Every rank receives $W - 1$ shards from peers, so total data moved per rank is $\frac{W-1}{W} S$ for output size $S$.
Workhorse Collective: Reduce-Scatter
Reduces each slice across all ranks (column-wise sum here), then scatters one reduced slice to each rank
Rank $r$ receives the reduced value of slice $r$:
R0: $0+1+2+3 = 6$
R1: $1+2+3+4 = 10$
R2: $2+3+4+5 = 14$, R3: $18$
Use case: sum backward gradients across data shards while keeping storage distributed
Reduce-Scatter is the exact communication dual of All-Gather: each rank ends up with $1/W$ of the reduced tensor.
All-Reduce = Reduce-Scatter + All-Gather
DDP use case: after backward, sum gradients across data-parallel workers so every rank holds identical gradients
Key systems insight: breaking All-Reduce into Reduce-Scatter + All-Gather lets us insert the optimizer step in the middle—the foundation of ZeRO / FSDP
All-to-All: The Sparse MoE Routing Primitive
Most general collective: each rank sends a distinct tensor slice to every other rank
Essential for sparse Mixture-of-Experts (MoE): each rank holds a batch slice and a subset of experts; All-to-All routes tokens to their assigned experts
Supports unbalanced splits, though routing skew slows down the overloaded rank
All-to-All stresses every GPU's per-direction link bandwidth because every rank talks to every peer simultaneously.
Part 2: GPU Interconnects — Classic vs. Datacenter
Scope
Classic Workstation / Baseline
Blackwell Datacenter Fabric
Inside a GPU
On-chip SRAM ↔ HBM
B200 on-chip SRAM ↔ HBM at 8 TB/s
Intra-node / Rack
Shared PCIe bus (v7.0, 16 lanes = 242 GB/s)
NVLink 5.0 + NVSwitch (0.9 TB/s per direction per B200; up to 72 GPUs in GB200/GB300 NVL72)
Inter-node (Pod)
Standard Ethernet (~200 MB/s home baseline, via CPU)
InfiniBand (~0.05 TB/s, via HCA + RDMA) or RoCE across 256 nodes/pod
Inter-pod (Cluster)
N/A
Ethernet connecting $N$ pods
Classic workstations share a tree-structured PCIe bus and route network traffic through the CPU
Blackwell datacenter systems build dedicated all-to-all GPU switches (NVSwitch) and CPU-bypassing networks (RDMA)
Notice the orders-of-magnitude gap between NVLink 5.0 (0.9 TB/s per direction) and inter-node InfiniBand (~0.05 TB/s): 18×.
Blackwell Intra-Domain: 8-GPU Node to 72-GPU NVL72
Classic 8-GPU Node(Ampere/Hopper era & B200 server)
Bus bandwidth normalizes out $W$ so you can compare directly against link speed (e.g., NVLink 5.0)
Independent of world size $W$ and topology (ring or tree) in the large-message regime
All-Reduce moves $2\times$ the data of Reduce-Scatter in $2\times$ the time → same bus bandwidth
Each step sends one $S/W$-byte shard; $W-1$ steps for Reduce-Scatter plus $W-1$ steps for All-Gather give factor $2(W-1)/W$.
Part 4: Distributed Training — Axes of Parallelism
We implement each strategy from primitives on a deep MLP (batch_size=128, num_dim=1024, num_layers=4)—representative because MLPs are the compute bottleneck in Transformers.
Strategy
Dimension Sharded
Primary Communication
Interconnect Fit
Data (DDP)
Batch ($B \to B/W$)
All-Reduce gradients
Moderate (IB / NVLink)
Sharded Data (FSDP / ZeRO)
Batch + model state ($1/W$)
All-Gather params + Reduce-Scatter grads
Moderate (overlapped)
Tensor (TP)
Hidden width ($D \to D/W$)
All-Gather / All-Reduce activations per layer
Fast only (NVLink / NVL72)
Expert (EP)
MoE experts (width)
All-to-All token dispatch & combine
Fast (NVLink / NVL72)
Pipeline (PP)
Depth ($L \to L/W$ layers)
Point-to-point send / recv
Tolerates slow IB / RoCE
Sequence / Context
Sequence length ($T \to T/W$)
Ring / All-to-All attention states
NVLink / fast IB
Data Parallelism (DDP): Split the Batch
Each rank processes a distinct micro-slice of the batch ($128 / 4 = 32$ examples per rank)
Forward and backward passes require zero communication; only gradients synchronize via All-Reduce
Mathematically equivalent to single-GPU training on the full global batch $B$.
Data Parallelism (DDP): Bare-Bones PyTorch
local_bs = batch_size // world_size
x_local = data[rank * local_bs : (rank + 1) * local_bs].to(f"cuda:{rank}")
# Every rank holds all parameters and its own AdamW optimizer state
params = [get_init_params(num_dim, num_dim, rank)
for _ in range(num_layers)]
optimizer = torch.optim.AdamW(params, lr=1e-3)
for step in range(num_steps):
x = x_local
for param in params:
x = F.gelu(x @ param)
loss = x.square().mean()
loss.backward()
# ONLY difference from single-GPU training: average gradients
for param in params:
dist.all_reduce(param.grad, op=dist.ReduceOp.AVG)
optimizer.step()
optimizer.zero_grad()
Every rank initializes with the same seed (or receives a rank-0 broadcast) so parameters start identical.
DDP: Exact Semantics and the Memory Wall
Local losses differ across ranks because each rank sees a different slice of the batch
Averaged gradients match across all ranks after all_reduce(..., ReduceOp.AVG)
Parameters stay identical on every rank after optimizer.step()—no parameter broadcast is needed
Memory Component
Single GPU
DDP ($W$ GPUs)
Bottleneck?
Activations
Full batch $B$
$B / W$ (sharded)
Reduced by $W$
Parameters
Full model
Full model (replicated)
Redundant $W\times$
Gradients
Full model
Full model (replicated)
Redundant $W\times$
AdamW Optimizer States
Full model
Full model (replicated)
Redundant $W\times$
DDP speeds up training (more FLOPs), but cannot train a model whose parameters + optimizer states exceed one GPU's HBM.
From DDP to FSDP / ZeRO: Splitting All-Reduce
Because $\text{All-Reduce} = \text{Reduce-Scatter} + \text{All-Gather}$, sharding optimizer states and gradients costs no extra communication
Sharding parameters too (ZeRO-3 / FSDP) adds one All-Gather before backward (to rematerialize weights), trading bandwidth for HBM
Tensor Parallelism (TP): Shard Along Width
Every GPU holds $1/W$ of each layer's weight matrix and computes $1/W$ of the output channels
Elementwise nonlinearities (GeLU) apply locally because columns are independent
Production optimization: pair a column-sharded layer with a row-sharded layer so two MLP matmuls need only one All-Reduce instead of an All-Gather per layer
Tensor Parallelism (TP): Bare-Bones PyTorch
data = data.to(f"cuda:{rank}") # All ranks hold full batch (128x1024)
local_dim = num_dim // world_size # Shard hidden dim: 1024 // 4 = 256
# Each rank holds only 1/world_size of every layer's columns
params = [get_init_params(num_dim, local_dim, rank)
for _ in range(num_layers)]
x = data
for layer in range(num_layers):
# Local matmul + GeLU -> shape (batch_size, local_dim)
x = F.gelu(x @ params[layer])
# Gather activation shards from every rank
shards = [torch.empty(batch_size, local_dim, device=f"cuda:{rank}")
for _ in range(world_size)]
dist.all_gather(tensor_list=shards, tensor=x, async_op=False)
# Concatenate along feature dim -> shape (batch_size, num_dim)
x = torch.cat(shards, dim=1)
Every layer runs a blocking collective over full activations before the next layer can start.
Tensor Parallelism: Why NVLink Is Mandatory
Fine-grained, synchronous communication: activations must cross GPUs inside every Transformer block (forward and backward)
Latency and bandwidth sit directly on the critical path of matrix multiplication
Comparing fabrics on Blackwell:
NVLink 5.0 (0.9 TB/s per direction): fast enough to keep Tensor Cores fed during TP collectives
InfiniBand (~0.05 TB/s): crossing a node boundary stalls TP dramatically
Architectural shift on Blackwell:
Historical Ampere/Hopper baseline: TP stayed within an 8-GPU NVLink node
GB200/GB300 NVL72: a single 72-GPU NVLink domain removes the 8-GPU cliff for wide models and low-latency inference
TP also shines in serving (decoding), where batch size is small and latency—not just throughput—dominates.
Pipeline Parallelism (PP): Shard Along Depth
Each rank stores $L / W$ consecutive layers ($4 / 2 = 2$ layers per GPU here)
Communication happens only at stage boundaries using point-to-point dist.send / dist.recv
Much lower communication volume than TP—works across slower inter-node InfiniBand or RoCE links
Pipeline Parallelism (PP): Micro-Batched PyTorch
local_layers = num_layers // world_size
local_params = [get_init_params(num_dim, num_dim, rank)
for _ in range(local_layers)]
# Split batch into micro-batches to shrink pipeline bubbles
micro_bs = batch_size // num_micro_batches
if rank == 0:
micro_batches = data.to("cuda:0").chunk(num_micro_batches, dim=0)
else:
micro_batches = [torch.empty(micro_bs, num_dim, device=f"cuda:{rank}")
for _ in range(num_micro_batches)]
for x in micro_batches:
if rank - 1 >= 0:
dist.recv(tensor=x, src=rank - 1) # Receive from previous stage
for param in local_params:
x = F.gelu(x @ param) # Run local layers
if rank + 1 < world_size:
dist.send(tensor=x, dst=rank + 1) # Forward to next stage
Backward reverses the flow: each stage receives output gradients from rank + 1 and sends input gradients to rank - 1.
Pipeline Bubbles and Micro-Batching
Naive (1 batch, $P=2$ stages): half of GPU time is idle (bubble)
Stage
t1
t2
t3
t4
Rank 0 (L0–1)
Fwd
idle
idle
Bwd
Rank 1 (L2–3)
idle
Fwd
Bwd
idle
Micro-batched ($M=4$ micro-batches, $P=2$ stages): stages stay busy in steady state
Stage
t1
t2
t3
t4
t5
t6
t7
t8
t9
t10
Rank 0 (L0–1)
F0
F1
F2
F3
idle
idle
B3
B2
B1
B0
Rank 1 (L2–3)
idle
F0
F1
F2
F3
B3
B2
B1
B0
idle
With $P$ pipeline stages and $M$ micro-batches, the bubble fraction shrinks as $M$ grows: $\frac{P - 1}{M + P - 1}$
Production schedules (1F1B, interleaved / virtual stages, dual-direction schedules) further cut bubbles and peak saved activations
Part 5: Hiding Communication via CUDA Stream Overlap
Launch collectives asynchronously (work = dist.reduce_scatter_tensor(..., async_op=True)) and synchronize with CUDA events only when results are needed
FSDP prefetches layer $\ell+1$'s weight All-Gather while layer $\ell$ computes, and reduces layer $\ell$'s gradients while layer $\ell-1$ runs backward
CUDA caveat: NCCL kernels still share SMs and HBM bandwidth with compute kernels—excessive SM contention can slow down GEMMs
Current frontier models are predominantly sparse MoEs: each token activates only a few experts, multiplying total parameters without multiplying FLOPs
Expert Parallelism (EP) places distinct experts on different GPUs and uses two All-to-All collectives per MoE layer
Load balance is critical: unbalanced routing creates straggler GPUs; Blackwell NVL72 lets EP scale across 72 GPUs over NVLink 5.0
Beyond MLPs: Attention and Sequence Parallelism
Unlike MLPs, attention layers mix information across the sequence length $T$:
Attention activations and KV states grow with context length, overflowing single-GPU HBM on long documents
Sequence / Context Parallelism shards tokens along the sequence dimension ($T \to T/W$):
Elementwise ops (LayerNorm, dropout) and MLPs run locally on each rank's token slice
Attention communicates K/V blocks (ring-style exchange) or switches sharding from sequence to heads via All-to-All
Current hybrid & sparse attention architectures:
Interleaving linear/recurrent layers or sparse/sliding-window attention with full attention shrinks KV memory and cross-GPU attention traffic
Long-context training combines sequence/context parallelism with TP/EP inside NVLink domains and DP/FSDP across nodes.
Composing Multi-Dimensional Parallelism on Blackwell
Match traffic to bandwidth: put TP, EP, and context parallelism inside NVLink 5.0 / NVL72; put PP and FSDP/DP across InfiniBand
Fundamental systems trade-off: for every intermediate tensor, you can recompute it, store it in HBM, or shard & communicate it across GPUs
Frameworks: we build from explicit PyTorch/NCCL primitives to see the mechanics; compiler-driven stacks (e.g., JAX/TPUs) infer collectives from sharding annotations
Recap: Multi-GPU Parallelism
Unifying rule: compute is fast, data movement is slow—map frequent communication to fast tiers (SRAM → B200 HBM 8 TB/s → NVLink 5.0 0.9 TB/s per direction / NVL72 → InfiniBand ~0.05 TB/s)
CUDA & NCCL: collectives execute as asynchronous GPU kernels over NVLink/NVSwitch and CPU-bypassing RDMA; overlap them on separate streams and synchronize properly when timing
Collectives: Broadcast/Scatter/Gather/Reduce build up to All-Gather, Reduce-Scatter, All-Reduce ($= \text{RS} + \text{AG}$), and All-to-All (sparse MoE routing)
Parallelism axes:
Data: DDP (All-Reduce) and FSDP/ZeRO (All-Gather + Reduce-Scatter to shard state)