Pipeline Parallelism
Pipeline parallelism is a model-parallel training and inference strategy that partitions a neural network's layers across multiple accelerators and processes micro-batches in a staged, assembly-line fashion to maximize device utilization. It is essential for training models whose parameter counts exceed single-device memory capacity—the dominant constraint for frontier LLMs such as GPT-4, PaLM-2, and Megatron—and enables near-linear scaling of throughput with device count when tuned correctly. A counterintuitive fact: naïve pipeline parallelism can achieve lower hardware utilization than a single GPU due to pipeline bubbles, yet with careful micro-batch scheduling the bubble fraction approaches zero asymptotically as the number of micro-batches grows.
The fundamental insight is that a deep neural network is a sequential computation graph that can be cut into contiguous layer-slabs, each assigned to a different device, so that while device processes the forward pass of micro-batch , device can simultaneously process micro-batch —turning serial latency into parallel throughput. The "aha moment" is recognizing that temporal overlap between stages is only possible because micro-batches are independent of one another, so the only synchronization required is the activation tensor passed between adjacent stages. The cost of this independence is a pipeline bubble—idle time at startup and drain—whose relative overhead shrinks as the number of micro-batches per batch increases. Minimizing bubble fraction and activation memory simultaneously is the central engineering tension in all modern pipeline-parallel systems.
How It Works
Formal Setup
Let a neural network be partitioned into stages, where stage consists of consecutive layers assigned to device . A global mini-batch of size is split into micro-batches each of size .
Throughput model. Define the per-stage compute time as (assumed uniform for analysis). The ideal pipeline throughput for micro-batches across stages is:
Explanation: In a perfectly filled pipeline, total useful compute scales linearly with the number of micro-batches, independent of stage count.
Bubble time. Pipeline startup requires filling stages; drain requires another steps. Total wall-clock time is:
Explanation: The actual wall time equals the ideal time plus the bubble steps that are unavoidable at the beginning and end of every batch.
Bubble fraction. The fraction of time all devices are idle (the pipeline bubble ratio) is:
Explanation: As the bubble fraction vanishes, but large inflates peak activation memory, creating the fundamental micro-batch count trade-off. Here is the number of pipeline stages, the number of micro-batches, and the per-micro-batch per-stage latency.
1F1B Schedule
The one-forward-one-backward (1F1B) schedule (Narayanan et al., 2019) interleaves forward and backward passes to cap the number of in-flight activations at rather than . In 1F1B, once the pipeline is full, each device alternates executing one forward pass and one backward pass per clock cycle. Activation memory per device is bounded:
Explanation: Only micro-batches have outstanding (unreleased) activations at any moment, so memory scales with stage count rather than total micro-batch count. Here is the activation tensor size for one micro-batch at stage .
Interleaved Stages (Virtual Stages)
Narayanan et al. (2021) introduced interleaved pipeline parallelism, assigning each device non-contiguous virtual stage chunks. This reduces bubble fraction by factor :
Explanation: By interleaving virtual stages per device, each device stays active more of the time, shrinking the relative bubble overhead at the cost of more point-to-point communications per micro-batch. The trade-off: inter-device communication volume scales as where is the hidden dimension, so cannot be made arbitrarily large without saturating interconnect bandwidth.
Deepak Narayanan, a PhD student and later researcher at Stanford and Microsoft Research, was the primary architect of the Megatron-LM pipeline parallelism infrastructure, introducing both the 1F1B schedule and interleaved virtual-stage scheduling that became the de facto standard for training hundred-billion parameter models. His 2019 PipeDream paper and 2021 Megatron-LM v2 paper together resolved the memory-bubble tension that had made earlier systems like GPipe impractical for very deep models. Remarkably, the interleaved schedule paper was developed concurrently with the Megatron-Turing NLG 530B training run, meaning the scheduling theory was being finalized while the largest model of its time was being trained on it.
Gradient Staleness and Weight Update Semantics
A subtle correctness issue: in the 1F1B schedule, the backward pass for micro-batch is computed with the same weight snapshot used for its forward pass (weight version at step ), but in async variants (PipeDream, 2019) later micro-batches may begin their forward pass with a more recent weight snapshot. The weight staleness for micro-batch in the async case is:
Explanation: Each micro-batch in the asynchronous regime uses weights that are optimizer steps newer than the batch-start weights, introducing a weight-version mismatch between forward and backward passes that can bias gradient estimates. This motivates the weight stashing technique (PipeDream-Flush, Narayanan et al., 2021): devices cache the weight version used during each micro-batch's forward pass and use the identical version during backprop, eliminating gradient staleness at the cost of weight copies per device.
Yanping Huang, a research scientist at Google Brain, led the GPipe project (Huang et al., NeurIPS 2019) which was the first large-scale demonstration that pipeline parallelism combined with re-materialization (gradient checkpointing) could train otherwise-infeasible models—specifically AmoebaNet-D with 557M parameters on image classification. GPipe's key contribution was trading compute for memory by discarding intermediate activations during the forward pass and recomputing them during backprop, bounding activation memory at rather than for layers. Interestingly, GPipe's name was chosen before the project scope was defined—the team named it after Pipe and only later decided it should stand for "Giant Pipeline."