Splitting a Model Across Devices
Data, tensor and pipeline parallelism compared by the one quantity that decides between them — bytes communicated per FLOP of useful work.
Counting rules
Throughout, let be the parameter count, the model width, the layer count, the achievable FLOP rate per device, the achievable interconnect bandwidth per device, and the bytes per element communicated. For a decoder-only transformer we use the standard counts established in Inference Arithmetic and the Roofline:
- parameters per layer (attention , MLP ), so ;
- training cost FLOPs per token (forward , backward ).
Data parallelism
Every device holds a full replica and processes a different slice of the batch. After the backward pass the gradients must be summed across replicas — one all-reduce of elements per step.
Let each device process tokens per optimiser step. Using a ring all-reduce, whose per-device volume is at most bytes,
The parameter count cancels. The ratio depends only on the hardware ratio , the gradient precision , and the tokens per device per step.
Assumptions
- The all-reduce is bandwidth-bound, so its latency term is negligible. For a multi-gigabyte gradient this holds; for small models it does not, and the latency term restores a dependence on .
- Communication is not overlapped with computation. Overlapping changes the conclusion from "this is the cost" to "this is the amount that must be hidden", which is the same number.
Key idea
Data parallelism is amortised by tokens per device per step. Doubling the per-device microbatch halves the relative cost of gradient synchronisation. This is why data-parallel training degrades at small per-device batch — and why gradient accumulation, which raises without raising memory for activations proportionally, is the standard fix.
Tensor parallelism
Each weight matrix is sharded across devices, so a single layer's matmuls are computed jointly. The Megatron decomposition requires one all-reduce of the activation tensor after the attention block and one after the MLP block, in the forward pass, and the same in the backward pass.
With tokens in flight, a hidden size , and all-reduces per layer per step (two forward, two backward) each of elements,
Both and cancel. The ratio falls like : wider models tolerate tensor parallelism better.
Pipeline parallelism
The layer stack is cut into contiguous stages, one per device. A batch is split into microbatches which flow through the stages; only activations at stage boundaries are communicated, which is a small point-to-point transfer rather than a collective. The cost is not bandwidth but idleness: at the start, stages downstream have nothing to do, and at the end, upstream stages are finished.
With stages, microbatches, and equal per-stage time per microbatch, the schedule completes in against an ideal . The fraction of wall-clock time lost to idle stages is
and the overhead relative to the ideal is .
With and the bubble is ; raising to brings it to .
Key idea
Pipeline parallelism is amortised by microbatch count. But cannot grow freely: every in-flight microbatch holds its activations for the backward pass, so memory grows with . The bubble and the activation memory pull in opposite directions, and that trade is what interleaved and 1F1B schedules exist to improve.
Why all three
The three overheads are amortised by three different quantities:
Since is fixed by the model and and are bounded by memory, no single axis can be pushed to absorb an arbitrary device count; minimising total overhead subject to a fixed device budget therefore has an interior optimum in general.
What this does not say
This page counts bytes and FLOPs. It says nothing about convergence: a configuration that minimises time per step can still be worse per unit of progress, because the global batch size it implies may sit past the point where larger batches stop helping. Step time and steps-to-target are separate quantities, and a parallelism plan that optimises only the first is incomplete.
References
- PaperM. Shoeybi, M. Patwary, R. Puri, P. LeGresley, J. Casper, B. Catanzaro (2019). Megatron-LM: Training Multi-Billion Parameter Language Models Using Model ParallelismSource of the tensor-parallel decomposition whose communication is counted here.
- PaperY. Huang et al. (2019). GPipe: Efficient Training of Giant Neural Networks using Pipeline ParallelismThe microbatched pipeline schedule whose bubble fraction is derived here.
- PaperD. Narayanan et al. (2021). Efficient Large-Scale Language Model Training on GPU Clusters Using Megatron-LMCombines the three strategies and reports the interaction effects discussed at the end.
- PaperS. Rajbhandari, J. Rasley, O. Ruwase, Y. He (2020). ZeRO: Memory Optimizations Toward Training Trillion Parameter ModelsShards optimiser state, gradients and parameters across data-parallel ranks.
These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.
Results stated on this page
- PropositionData-parallel communication does not depend on model sizeproof includedThe ratio of gradient-synchronisation time to compute time is independent of the parameter count and falls inversely with tokens processed per device per step.
- PropositionTensor-parallel communication does not depend on batch sizeproof includedThe ratio of activation-exchange time to compute time is independent of layer count and sequence length, and falls inversely with model width.
- PropositionThe pipeline bubble fractionproof includedWith p stages and m microbatches, the fraction of wall-clock time in which some stage is idle is (p−1)/(m+p−1).
- CorollaryWhy the three are combined rather than chosen betweenproof includedEach strategy is amortised by a different quantity, so the cheapest configuration mixes them rather than maximising any one.