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 core insight

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 kk processes the forward pass of micro-batch mm, device k−1k-1 can simultaneously process micro-batch m+1m+1—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 f=fS∘fS−1∘⋯∘f1f = f_S \circ f_{S-1} \circ \cdots \circ f_1 be partitioned into SS stages, where stage ss consists of consecutive layers {las,…,lbs}\{l_{a_s}, \ldots, l_{b_s}\} assigned to device dsd_s. A global mini-batch B\mathcal{B} of size BB is split into MM micro-batches {μ1,…,μM}\{\mu_1, \ldots, \mu_M\} each of size B/MB/M.

Throughput model. Define the per-stage compute time as tst_s (assumed uniform ts=tt_s = t for analysis). The ideal pipeline throughput for MM micro-batches across SS stages is:

1
Tideal=M⋅t\quad T_{\text{ideal}} = M \cdot t

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 S−1S-1 stages; drain requires another S−1S-1 steps. Total wall-clock time is:

2
Twall=(M+S−1)⋅t\quad T_{\text{wall}} = (M + S - 1)\cdot t

Explanation: The actual wall time equals the ideal time plus the (S−1)(S-1) 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:

3
ϕ=Twall−TidealTwall=S−1M+S−1\quad \phi = \frac{T_{\text{wall}} - T_{\text{ideal}}}{T_{\text{wall}}} = \frac{S - 1}{M + S - 1}

Explanation: As M→∞M \to \infty the bubble fraction vanishes, but large MM inflates peak activation memory, creating the fundamental micro-batch count trade-off. Here SS is the number of pipeline stages, MM the number of micro-batches, and tt 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 SS rather than MM. 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:

4
M1F1B=S⋅BM⋅As\quad \mathcal{M}_{\text{1F1B}} = S \cdot \frac{B}{M} \cdot A_s

Explanation: Only SS micro-batches have outstanding (unreleased) activations at any moment, so memory scales with stage count rather than total micro-batch count. Here AsA_s is the activation tensor size for one micro-batch at stage ss.

Interleaved Stages (Virtual Stages)

Narayanan et al. (2021) introduced interleaved pipeline parallelism, assigning each device VV non-contiguous virtual stage chunks. This reduces bubble fraction by factor VV:

5
ϕinterleaved=1V⋅S−1M+S−1\quad \phi_{\text{interleaved}} = \frac{1}{V}\cdot\frac{S-1}{M+S-1}

Explanation: By interleaving VV virtual stages per device, each device stays active more of the time, shrinking the relative bubble overhead at the cost of V×V\times more point-to-point communications per micro-batch. The trade-off: inter-device communication volume scales as O(V⋅S⋅B/M⋅dmodel)\mathcal{O}(V \cdot S \cdot B/M \cdot d_{\text{model}}) where dmodeld_{\text{model}} is the hidden dimension, so VV cannot be made arbitrarily large without saturating interconnect bandwidth.

researcher · Deepak Narayanan | b. 1993 | GPipe and Megatron-LM Pipeline Scheduling

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.

Figure
Pipeline Parallelism: 1F1B Schedule
1F1B Pipeline Schedule (4 Stages, 6 Micro-batches) Stage 1 Stage 2 Stage 3 Stage 4 F1 F2 F3 F4 F5 F6 B6 B5 B4 B3 B2 F1 F2 F3 F4 F5 F6 B6 B5 B4 B3 F1 F2 F3 F4 F5 F6 B6 B5 B4 F1 F2 F3 F4 B4 B3 B2 B1 idle bubble Forward (Fm) Backward (Bm) Idle (bubble)

Gradient Staleness and Weight Update Semantics

A subtle correctness issue: in the 1F1B schedule, the backward pass for micro-batch μm\mu_m is computed with the same weight snapshot used for its forward pass (weight version at step tt), 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 mm in the async case is:

6
δm=θt+⌊m/S⌋vs.θt (synchronous)\quad \delta_m = \theta_{t + \lfloor m/S \rfloor} \quad \text{vs.} \quad \theta_t \text{ (synchronous)}

Explanation: Each micro-batch in the asynchronous regime uses weights that are ⌊m/S⌋\lfloor m/S \rfloor 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 SS weight copies per device.

researcher · Yanping Huang | b. 1985 | GPipe: Gradient Checkpointing for Pipeline Parallelism

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 O(SL/S)\mathcal{O}(S \sqrt{L/S}) rather than O(L)\mathcal{O}(L) for LL 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."

Figure
3D Parallelism: Pipeline + Tensor + Data

3D Parallelism Decomposition Data Parallel Replica Pipeline → Stage 1 Layers 1-8 Stage 2 Layers 9-16 Stage 3 Layers 17-24 Stage 4 Layers 25-32 TP:0 TP:1 all-reduce ← Tensor Parallel →