GPipe: Easy Scaling with Micro-Batch Pipeline Parallelism

Training giant neural networks by pipelining micro-batches across devices

Updated

Contents
  1. Why Students Should Care
  2. The Problem
  3. The GPipe Solution
  4. Pipeline Schedule
  5. Interactive Demo
  6. Efficiency Analysis
  7. Memory Optimization
  8. Synchronous Training
  9. Results
  10. Comparison with Data Parallelism
  11. Common Confusion
  12. Where To Go Next
  13. Key Paper

GPipe is a technique for training giant neural networks that don’t fit on a single accelerator. It splits the model into consecutive stages across devices, then keeps every device busy by streaming small “micro-batches” through the pipeline like an assembly line.

This page assumes you know the basic training loop (forward pass, backward pass, weight update). If not, read Backpropagation first.

Why Students Should Care

  • Every large language model today is trained across many devices; pipeline parallelism is one of the core strategies, and GPipe is its classic formulation.
  • The efficiency analysis here (pipeline “bubbles”) is a clean, worked example of the kind of systems reasoning that dominates large-scale ML.
  • The memory trick GPipe popularized — activation recomputation — shows up everywhere in modern training.

The Problem

Some models are simply too large for one accelerator’s memory. The obvious fix is to put different layers on different devices — layers 1-10 on device 1, layers 11-20 on device 2, and so on. But think about what happens with a single batch: device 2 cannot start until device 1 finishes, and device 1 then sits idle while everyone else works. At any moment, only one device is busy:

Utilization=1K\text{Utilization} = \frac{1}{K}

where KK is the number of devices. With 8 devices, you pay for 8 accelerators and effectively use 1.

The GPipe Solution

GPipe fixes this like a factory assembly line: instead of pushing one big batch through, push many small pieces so every station works at once.

  1. Partition the model into KK consecutive stages across KK devices
  2. Split each mini-batch into MM micro-batches
  3. Pipeline micro-batches through the stages

While device 2 processes micro-batch 1, device 1 is already processing micro-batch 2.

Pipeline Schedule

Forward passes flow left-to-right, backward passes right-to-left:

Time=(K1)+M+(K1)\text{Time} = (K - 1) + M + (K - 1)

The (K1)(K-1) terms are “pipeline bubbles” — the ramp-up at the start (later stages waiting for their first micro-batch) and the drain at the end (earlier stages having nothing left to do).

Interactive Demo

Watch micro-batches flow through a 4-device pipeline:

GPipe Pipeline Parallelism

Device
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
GPU 0
0
0
GPU 1
GPU 2
GPU 3
Forward
Backward
Bubble (idle)
Micro-batch Splitting
Split batch into M micro-batches. Pipeline them across devices to hide latency.
Bubble Overhead
Bubbles = (K-1)/M of total time. More micro-batches → less overhead.

Efficiency Analysis

How much time is wasted in bubbles? The bubble fraction is:

Bubble=2(K1)2(K1)+2M=K1K1+M\text{Bubble} = \frac{2(K-1)}{2(K-1) + 2M} = \frac{K-1}{K-1+M}

You do not need to memorize the formula. The important idea is: the more micro-batches you push through relative to the number of stages, the smaller the fraction of time lost to ramp-up and drain. With MKM \gg K, bubbles become negligible. GPipe recommends M4KM \geq 4K.

Memory Optimization

More micro-batches in flight would normally mean storing more activations for the backward pass. GPipe avoids this with activation recomputation (also called gradient checkpointing):

  • Forward: Only store activations at partition boundaries
  • Backward: Recompute intermediate activations as needed

This trades extra compute for less memory, enabling larger models.

Synchronous Training

A worry you might have: does all this pipelining change what the model learns? No. Despite pipelining, GPipe maintains synchronous SGD semantics:

θt+1=θtη1Mm=1MθLm\theta_{t+1} = \theta_t - \eta \cdot \frac{1}{M}\sum_{m=1}^{M} \nabla_\theta \mathcal{L}_m

Gradients are accumulated across micro-batches before the update — mathematically the same update you would get from the full mini-batch on one giant device.

Results

TaskModel SizeDevicesSpeedup
ImageNet557M params8 TPUs6.3×
Translation6B params2048 TPUsNear-linear

GPipe achieved 84.4% ImageNet accuracy with a 557M parameter AmoebaNet.

Comparison with Data Parallelism

Pipeline parallelism is not the only way to use many devices. Data parallelism copies the full model to every device and splits the data instead:

AspectData ParallelGPipe
Memory per deviceFull model1/K model
CommunicationGradient syncActivation transfer
Batch sizeScales with KIndependent of K

GPipe is complementary — real large-scale training systems combine both approaches.

Common Confusion

  • Micro-batch vs. mini-batch: the mini-batch is the unit of one weight update; micro-batches are the smaller slices it is cut into purely for pipelining. Weights update once per mini-batch, not per micro-batch.
  • Pipeline parallelism vs. data parallelism: pipeline parallelism splits the model across devices; data parallelism splits the data and replicates the model.
  • Pipelining does not change the math. GPipe computes exactly the same gradients as ordinary synchronous training — it only changes the schedule.
  • Activation recomputation is not an approximation either; it recomputes exact values, spending compute to save memory.

Where To Go Next

  • Read Backpropagation to understand the forward/backward structure the pipeline schedules.
  • Read Scaling Laws for why anyone wants models too big for one device in the first place.
  • Read Transformer for the architecture that dominates large-scale distributed training.
  • Read Adam for the optimizer side of large-model training.

Key Paper

Found an error or want to contribute? Edit this page on GitHub

↑↓ to navigate ↵ to open esc to close