■ Change #16 · wiki.edited
Tensor, data and pipeline parallelism with compute-communication overlap: Normalize Markdown to canonical form
body
## Ways to split a model- **Data parallelism** replicates the model and splits the batch; gradients are all-reduced. ZeRO (Rajbhandari et al., 2019) shards optimiser state, gradients and then parameters over data-parallel ranks, replacing all-reduce by reduce-scatter and all-gather and cutting memory.- **Tensor parallelism** (Megatron-LM, Shoeybi et al., 2019) splits each weight matrix across GPUs; a transformer layer needs all-reduces in the forward and backward pass, on the critical path.- **Pipeline parallelism** assigns layers to stages and passes activations between them, with micro-batching to fill the pipeline.- **Sequence and context parallelism** shard the sequence; Ring Attention (Liu et al., 2023) circulates K/V blocks around a ring so each GPU attends to the whole sequence without holding it.- **Expert parallelism** places mixture-of-experts experts on different GPUs, using all-to-all.Real systems combine several, placing tensor parallelism inside a node (fast NVLink) and data or pipeline parallelism across nodes (slower network).## The overlap problem− A collective that must finish before the next operation starts is *exposed* communication. With a roofline view: if the time to move the data is comparable to the time to compute on it, exposing it can cost tens of percent of end-to-end time. Standard remedies: bucket gradients and launch their all-reduce while backward continues; run communication on a separate stream; pipeline so that stage-to-stage transfers overlap computation.+ A collective that must finish before the next operation starts is _exposed_ communication. With a roofline view: if the time to move the data is comparable to the time to compute on it, exposing it can cost tens of percent of end-to-end time. Standard remedies: bucket gradients and launch their all-reduce while backward continues; run communication on a separate stream; pipeline so that stage-to-stage transfers overlap computation.## Fusing communication into kernelsFor tensor parallelism the dependent GEMM and collective cannot be separated by streams alone, because the collective needs the GEMM's output. Approaches such as FLUX (preprint, 2024) over-decompose both operations into finer tiles and fuse them into one kernel so data is sent as soon as each output tile is ready; the authors state that up to 96% of communication can be hidden by a fused kernel and report speedups over Megatron-LM in training. Triton-distributed (preprint, 2025) extends the Triton compiler with OpenSHMEM-style primitives so such overlapping kernels can be written in Python.## Costs and risksFusion couples kernel tuning to the interconnect, tile scheduling to message sizes, and failure modes (hangs, races) to custom synchronisation. Collective results can also depend on reduction order, which affects reproducibility of training runs.
explainer.student
**What it is for.** The largest neural networks do not fit in the memory of one GPU (an H100 has 80 GB), and training them on one GPU would take far too long. So they are split across many GPUs, which must exchange data as they work. Every millisecond a GPU spends waiting for data is wasted.**Ways to split.**− - *Data parallelism.* Every GPU holds the whole model and processes different examples; gradients are summed with an all-reduce. ZeRO also splits the optimiser's stored state, the gradients and even the weights among GPUs to save memory.− - *Tensor parallelism* (Megatron-LM). Each weight matrix is split across GPUs. Splitting $W$ by columns, $W = [W_1 \; W_2]$, gives $XW = [XW_1 \; XW_2]$, so each GPU computes its own slice. Splitting by rows instead gives partial results $XW = X_1W_1 + X_2W_2$ that must be added across GPUs, in every layer, before the next layer can start.− - *Pipeline parallelism.* Groups of layers are placed on different GPUs like stations on an assembly line, and each batch is cut into micro-batches to keep the stations busy.− - *Sequence and context parallelism* split long inputs; Ring Attention passes blocks of keys and values around a ring of GPUs.− - *Expert parallelism* puts the experts of a mixture-of-experts model on different GPUs, using all-to-all exchanges.+ - _Data parallelism._ Every GPU holds the whole model and processes different examples; gradients are summed with an all-reduce. ZeRO also splits the optimiser's stored state, the gradients and even the weights among GPUs to save memory.+ - _Tensor parallelism_ (Megatron-LM). Each weight matrix is split across GPUs. Splitting $W$ by columns, $W = [W_1 \; W_2]$, gives $XW = [XW_1 \; XW_2]$, so each GPU computes its own slice. Splitting by rows instead gives partial results $XW = X_1W_1 + X_2W_2$ that must be added across GPUs, in every layer, before the next layer can start.+ - _Pipeline parallelism._ Groups of layers are placed on different GPUs like stations on an assembly line, and each batch is cut into micro-batches to keep the stations busy.+ - _Sequence and context parallelism_ split long inputs; Ring Attention passes blocks of keys and values around a ring of GPUs.+ - _Expert parallelism_ puts the experts of a mixture-of-experts model on different GPUs, using all-to-all exchanges.+Real systems combine several: tensor parallelism inside one machine over fast NVLink, data or pipeline parallelism across machines.**Exposed communication.** If the next step needs data from a communication taking $T_{comm}$ and nothing else runs meanwhile, the time is $T_{comp} + T_{comm}$. If the communication runs while useful work continues, the ideal is− $$T = \max(T_{comp},\, T_{comm}).$$+ $T = \max(T_{comp},\, T_{comm}).$Example: 10 ms of computing and 4 ms of communication take 14 ms back to back but 10 ms when overlapped, a 29% saving. Standard tricks: start summing the gradients that are already finished while later ones are still being computed, and put communication on a separate stream (an independent queue of GPU work).**Fusion.** In tensor parallelism the sum needs the output of the matrix multiply, so separate streams cannot hide it. FLUX (a 2024 preprint) breaks both the multiply and the communication into small tiles inside one kernel and sends each output tile as soon as it is ready; its authors state that up to 96% of the communication can be hidden and report speedups over Megatron-LM. Triton-distributed (a 2025 preprint) adds communication operations to the Triton compiler so such kernels can be written in Python. Analogy: a kitchen that sends each plate out the moment it is ready instead of waiting until the whole table's order is cooked. It breaks when plates are tiny and the waiter's trip time (latency) dominates.**Limits.** Fused kernels tie their tuning to one interconnect and are hard to debug (hangs, race conditions). The order of additions can change results in the last bits, which affects the reproducibility of training runs.
hash a9403579dcf1241e8eb176e9e8738693a3d43a3b7bb4016117cc7def1f009b8f
previous aeefd03b50d5bc4b3468f134687f7d0409674ac51d95c5128e904c966595dc68