LLM Pipeline Parallelism: Train Huge Models Across GPUs

LLM Pipeline Parallelism: Train Huge Models Across GPUs

What happens when a language model is too big to fit on a single GPU? The weights alone can run to hundreds of billions of parameters, and the optimizer states and activations pile on top of that. Engineers cannot simply buy a bigger chip and call it a day. Instead, they slice the model itself into pieces and spread those pieces across many devices. That technique is pipeline parallelism, and it is one of the three pillars of large-scale LLM training, alongside data parallelism and tensor parallelism.

This article explains how pipeline parallelism works, why it produces idle “bubbles,” how modern schedules shrink those bubbles, and where the approach fits in real training and inference systems.

What pipeline parallelism actually does

The core idea is simple. A neural network is a stack of layers. Layers 1 through 10 might live on GPU 0, layers 11 through 20 on GPU 1, and so on. Each group of layers is called a stage. Data flows from stage to stage, just like an assembly line.

The problem is that a single batch moving through the line leaves most GPUs idle. While stage 0 processes the batch, stages 1 through 3 sit and wait. The fix is micro-batching: split one mini-batch into several smaller chunks and feed them through the pipeline one after another. Once the first micro-batch reaches stage 1, stage 0 can start on the second micro-batch. Now every device has work to do.

The GPipe paper from 2019 is the classic reference here, and it popularized this scheme for training very large networks, including a 557-million-parameter model spread over 8 accelerators. If you want the original description of micro-batch pipelining, the GPipe paper on pipeline-parallel training is the place to start.

Why the pipeline bubble exists

Why the pipeline bubble exists

Pipelines are never perfectly full. At the start of each iteration, the first stage must fill the pipe before the last stage receives anything. At the end, the pipe drains. During those ramp-up and ramp-down phases, some devices are idle. That idle fraction is called the pipeline bubble.

A rough formula captures the trade-off. With P pipeline stages and M micro-batches, the bubble fraction is approximately (P − 1) / (M + P − 1). The practical lesson jumps out immediately: more micro-batches shrink the bubble, and more stages enlarge it. If you have 8 stages and only 8 micro-batches, the bubble is about 47 percent. Push to 32 micro-batches and it drops to roughly 18 percent.

That formula assumes the simple schedule where all forward passes run first and all backward passes run afterward. It also explains a tension every practitioner hits: micro-batches consume memory, because activations for every in-flight micro-batch must be stored until the backward pass. You cannot just crank M to infinity.

From GPipe to 1F1B and interleaved schedules

The naive all-forward-then-all-backward schedule wastes memory and time. PipeDream, published in 2019, introduced 1F1B scheduling, short for one-forward-one-backward. Instead of batching all forward passes, each device alternates between a forward pass for a new micro-batch and a backward pass for an older one, keeping the pipeline steadily full. The PipeDream paper on 1F1B scheduling also tackles a subtle correctness issue: with asynchronous updates, different stages may be using different weight versions, so PipeDream adds weight stashing to keep gradients consistent.

A second leap came in 2021 with Megatron-LM’s interleaved 1F1B schedule. Instead of giving each device one contiguous block of layers, the system hands each device several non-contiguous chunks. A device might own layers 1–4, 13–16, and 25–28. This virtualizes the pipeline, effectively multiplying the number of stages without adding devices, which shrinks the bubble for the same micro-batch count. The Megatron-LM paper on interleaved pipeline schedules reports training models up to a trillion parameters using this approach.

Here is how the main schedules compare:

Schedule How it orders work Main strength Main cost
GPipe (all-forward, all-backward) All forwards, then all backwards Simple to implement Large bubble, high activation memory
1F1B (PipeDream) Alternates forward and backward Smaller memory footprint Still has fill and drain phases
Interleaved 1F1B (Megatron-LM) Multiple layer chunks per device Smaller bubble at same device count More cross-device communication

Newer research has pushed further, with zero-bubble schedules that split the backward pass into separate input-gradient and weight-gradient steps so idle time can be filled more aggressively. The principle stays the same: rearrange work to keep devices busy.

Pipeline parallelism versus tensor and data parallelism

Pipeline parallelism is one of three ways to spread an LLM across hardware, and choosing among them matters more than any single implementation detail.

Data parallelism replicates the full model on every device and splits the batch. It scales beautifully until the model no longer fits on one device. Tensor parallelism splits individual layers, for example by dividing weight matrices column-wise across GPUs. It needs very fast interconnects because every layer requires an all-reduce, and it scales poorly beyond a single server node. Pipeline parallelism splits by depth, sending only activations between stages, so it tolerates slower links between nodes.

That last property is why pipeline parallelism shines on multi-node clusters. Communication happens only at stage boundaries, not inside every layer. The trade-off is the bubble and the complexity of scheduling.

The Megatron-LM work analyzes how all three dimensions interact and offers guidance on picking degrees of each for a given cluster size. A common pattern is tensor parallelism within a node, pipeline parallelism across nodes, and data parallelism over the remaining replicas. Getting the combination right can matter more than any individual optimization. Teams tracking how these systems evolve often follow infrastructure coverage such as the cloud news section on 9481.org to keep up with new hardware and cluster designs.

Memory: the hidden constraint

Pipeline parallelism reduces per-device model-state memory dramatically. Weights, gradients, and optimizer states are partitioned by stage, so an 8-stage pipeline cuts that footprint by roughly 8×. But activations for every micro-batch in flight must still be held in memory.

That is why pipeline parallelism is almost always combined with activation checkpointing, which discards most activations during the forward pass and recomputes them during the backward pass. The combination lets teams trade extra compute for memory and fit larger models per device.

A practical mistake beginners make is increasing micro-batch count to shrink the bubble without watching memory. The bubble shrinks, then the job crashes with an out-of-memory error. The working approach is to tune micro-batch size and count together, then add activation checkpointing if memory remains tight. Deep dives on these memory techniques appear regularly in technical write-ups like the engineering blog on 9481.org.

Pipeline parallelism for inference

Training is not the only use. When a model is too large for one GPU, serving it requires splitting it too. Pipeline parallelism is a standard deployment strategy for inference, and vLLM documents a `–pipeline-parallel-size` flag alongside its tensor-parallel options in its distributed serving documentation for pipeline-parallel inference. (Parallel computing)

Inference pipelines differ from training pipelines in one key way: there is no backward pass, so the bubble math changes. Latency also matters more than throughput for interactive applications. A request that must traverse four stages pays four sequential hops, which raises time-to-first-token. For batch-heavy offline workloads, pipeline parallelism is often a clear win; for chat applications with tight latency budgets, teams frequently prefer tensor parallelism within a node or a hybrid of both.

Framework support and practical setup

PyTorch now ships `torch.distributed.pipelining`, a library with scheduling utilities for pipeline-parallel training and inference. Its PyTorch distributed pipelining documentation covers the available schedules and the API for splitting a model into stages. The feature has moved through beta status, so check the current docs before committing to it in production.

A sensible rollout looks like this:

  • Start with data parallelism alone and confirm the model fits on one device.

  • Add tensor parallelism within a node if the model still does not fit.

  • Introduce pipeline parallelism across nodes when tensor parallelism runs out of fast interconnect.

  • Tune micro-batch count and activation checkpointing together until the bubble and memory both land in an acceptable range.

  • Benchmark end-to-end throughput rather than trusting any single paper’s speedup number.

That last point deserves emphasis. Reported speedups vary wildly by model size, interconnect, and micro-batch count, and papers benchmark different hardware. GPipe’s reported speedup over a single-device baseline does not transfer to your cluster. Measure your own setup.

Common mistakes and what actually works

Several pitfalls show up again and again in real deployments.

Ignoring the interconnect. Pipeline stages communicate only at boundaries, but those transfers still cross the network. Slow links between nodes turn a theoretically small bubble into a real bottleneck.

Over-partitioning. More stages mean a bigger bubble for a fixed micro-batch count. Teams sometimes split into 16 stages when 8 would deliver better throughput.

Forgetting the optimizer. Optimizer states can dwarf weights for Adam-style training. Partitioning them across stages is a major memory benefit that is easy to overlook when planning.

Skipping profiling. The bubble formula is a guide, not a measurement. Real pipelines have uneven stage durations if layers are not balanced, and the slowest stage sets the pace. Balancing layers per stage is often worth more than a fancier schedule.

For teams evaluating infrastructure choices around these workloads, broader cloud architecture resources, including the cloud category on 9481.org, can help frame the cost and scaling picture.

Conclusion

Pipeline parallelism solves a specific problem: models too large for one device, spread across machines connected by links too slow for tensor parallelism. Its central challenge, the pipeline bubble, has been whittled down over years of research, from GPipe’s micro-batches to PipeDream’s 1F1B scheduling to Megatron-LM’s interleaved chunks and beyond. The technique works best as part of a combined strategy, layered with tensor and data parallelism and paired with activation checkpointing. Get the balance right, measure your own throughput, and pipeline parallelism becomes one of the most reliable tools for training and serving LLMs at scale.

What is LLM pipeline parallelism in simple terms?

It is a way to split a large language model’s layers across several GPUs, like an assembly line. Each GPU handles one group of layers, called a stage, and small chunks of data called micro-batches flow from stage to stage so multiple GPUs work at the same time.

Why is it called a pipeline bubble?

At the start and end of each iteration, some stages have no work because data has not reached them yet or has already passed through. That idle period is the bubble. With P stages and M micro-batches, the idle fraction is roughly (P − 1) / (M + P − 1), so more micro-batches shrink it.

How does pipeline parallelism differ from tensor parallelism?

Tensor parallelism splits individual layers, so every layer needs communication between GPUs, which demands very fast links. Pipeline parallelism splits by depth, so communication happens only at stage boundaries. That makes pipeline parallelism far more suitable for spreading a model across multiple servers.

Can pipeline parallelism be used for inference as well as training?

Yes. Serving frameworks support it for models too large for a single GPU. Inference pipelines have no backward pass, so the bubble math differs, and latency-sensitive applications must weigh the extra sequential hops against the memory savings.

What is interleaved 1F1B scheduling?

It is a Megatron-LM technique that gives each device several non-contiguous chunks of layers instead of one contiguous block. This effectively multiplies the number of virtual pipeline stages without adding hardware, shrinking the bubble for the same number of micro-batches.

Does pipeline parallelism reduce memory per GPU?

It reduces model-state memory, because weights, gradients, and optimizer states are split by stage. It does not eliminate activation memory, since activations for every in-flight micro-batch must be stored. That is why it is usually combined with activation checkpointing.

Latest articles

Scroll to Top