Pipeline parallelism (PP) is one of the three main kinds of parallelism in training and serving large models, alongside tensor and data parallelism. It spreads parts of the model across different GPUs and nodes when the model does not fit on a single device, and puts almost no load on the network between nodes.
How the pipeline works
The model is cut by layers into stages: for example, a 64-layer model is placed on 8 GPUs with 8 layers on each. Each batch is divided into microbatches, and the stages work like an assembly line: while the first computes the forward pass of the next microbatch, the second is already processing the previous one.
| Element | What it is |
|---|---|
| Stage | several consecutive layers of the model on one GPU or node |
| Microbatch | a chunk of a batch that goes through the pipeline independently of the others |
| Bubble | idle time of the stages while the pipeline fills and drains |
Bubbles and microbatches
At the start of a step the pipeline fills, at the end it drains — some stages are idle during this time. In Megatron-LM the idle fraction is estimated as (p − 1)/m, where p is the number of stages and m the number of microbatches: with 8 stages and 32 microbatches the idle time is 7/32 ≈ 22% of the time. There are many times more microbatches than stages; in the GPipe schedule, where all forward passes run before the backward ones, activations are kept for all microbatches at once, and memory grows with their number. The interleaved schedule splits the model into v chunks per GPU and reduces the idle time by a factor of v — at the cost of v-fold more communication; in the Megatron-LM paper this added up to 10% throughput at comparable memory.
Where it is used
When training large models, the pipeline is placed between nodes: tensor parallelism is kept within a node with NVLink links, pipeline parallelism between nodes, and data parallelism is added on top. The Megatron-LM authors’ rule: the total model parallelism TP × PP is kept at the minimum at which the model fits in memory, and the rest is made up with data parallelism. In inference the pipeline is enabled with the pipeline_parallel_size parameter: in vLLM it is given the number of nodes, and on GPUs without NVLink pipeline parallelism is preferred over tensor because of less communication. For neural networks the technique was described in the 2018 GPipe paper.
Sources
the term is written from these pages- Efficient Large-Scale Language Model Training on GPU Clusters Using Megatron-LM (SC 2021)arxiv.org/abs/2104.04473(opens in a new tab)
- GPipe: Efficient Training of Giant Neural Networks using Pipeline Parallelismarxiv.org/abs/1811.06965(opens in a new tab)
- Parallelism Scaling — vLLM documentationdocs.vllm.ai/en/latest/serving/parallelism_scaling.html(opens in a new tab)
Verified 9 Nov