Skip to content
Friendly disclaimer: flozi00 TechHub is a solo side-project next to a full-time job — personal learning notes, no official statements. Verify critical steps yourself.

Pipeline Parallelism: Pumping Data Upstream

Pipeline Parallelism explained: split layers vertically across GPUs, schedule with 1F1B, and keep the pipeline bubble under control.

4 min readflozi00
aigpuhardwareguidescalingdeep-learning
Skip to the full article
Watch · explore · understand

Pipeline parallelism: layers form an assembly line

Several microbatches overlap across layer stages, while a training schedule manages backward work and saved activations.

AI-assisted learning visualization · schematic article explanation

Step 1 / 4Split the depth of the model

Each stage owns a different group of layers. A microbatch travels forward by point-to-point activation transfers, so one microbatch still depends on the previous stage finishing.

SystemCurrent stepSelect a block to explain it
Split batch into microbatches
Feed independent chunks into the same staged model.
GPU 0: early layers
Begin the next microbatch once dependencies allow.
GPU 1: middle layers
Receive activations and run the next layer group.
GPU 2: final layers
Produce the output and start the reverse training pass.
  1. Split batch into microbatches GPU 0: early layers
    successive microbatches
  2. GPU 0: early layers GPU 1: middle layers
    send / receive activations
  3. GPU 1: middle layers GPU 2: final layers
    send / receive activations
What to remember

Pipeline parallelism gains utilization by overlapping different microbatches across layer groups, while scheduling determines bubbles and saved-state memory.

This diagram shows synchronous training, not an autoregressive decode schedule. Three stages are illustrative; unequal layer costs and communication prevent perfect division of memory or runtime.

Terms and the complete walkthrough
Microbatch
A smaller piece of a training batch scheduled independently through the pipeline.
Pipeline bubble
Idle time when a stage waits for dependencies or has no work left.
1F1B
A steady-state schedule alternating one forward and one backward task.
  1. Split the depth of the model

    Each stage owns a different group of layers. A microbatch travels forward by point-to-point activation transfers, so one microbatch still depends on the previous stage finishing.

  2. Overlap different microbatches

    While the middle stage processes one microbatch, the first can work on a later one. Startup and shutdown still leave idle slots, called pipeline bubbles; more stages do not automatically make a single dependent stream faster.

  3. Interleave forward and backward work

    Training sends activation gradients back through the stages in reverse order. After warmup, a 1F1B schedule alternates one forward task with one backward task, allowing saved state to be released sooner than an all-forward-then-all-backward schedule.

  4. Keep the update boundary explicit

    In the synchronous flush-based schedule shown here, all microbatches finish before the optimizer updates weights. Matching send/receive order, balanced stage times and sufficient activation memory are still required.

All connections

  • Split batch into microbatches → GPU 0: early layers: successive microbatches
  • GPU 0: early layers → GPU 1: middle layers: send / receive activations
  • GPU 1: middle layers → GPU 2: final layers: send / receive activations
  • GPU 2: final layers → Backward work in reverse order: loss gradient
  • GPU 1: middle layers → Retain and release activations: retain forward state
  • Backward work in reverse order → Retain and release activations: consume and release state
  • Backward work in reverse order → Synchronized optimizer step: all microbatches complete
Set your own pace. Pause at any time or select a step directly.

In our previous exploration of Tensor Parallelism (TP), we sliced the model horizontally, splitting individual weight matrices across GPUs. While effective, TP performs frequent collectives, so fast links are often valuable; TP can also span nodes when the interconnect and workload justify it.

To scale beyond a single node—to clusters of hundreds or thousands of GPUs—we need a technique that is less "chatty" and more tolerant of the lower bandwidth available over Ethernet or InfiniBand.

Enter Pipeline Parallelism (PP). Instead of slicing the layers themselves, PP slices the model vertically, partitioning the layers of the neural network across multiple devices. It turns your GPU cluster into an assembly line, passing activations down the chain.

This article dissects the hardware mechanics of PP, the scheduling algorithms required to keep the silicon busy, and the critical trade-offs involved.

1. The Hardware Mechanics: Vertical Slicing

TP divides operations within a layer; PP assigns different layers to different stages. Both distribute computation and parameter memory.

The Setup

Imagine a hypothetical 32-layer transformer distributed across four GPUs (stages).

  • GPU 0: Layers 0–7
  • GPU 1: Layers 8–15
  • GPU 2: Layers 16–23
  • GPU 3: Layers 24–31

The Communication Primitive: Point-to-Point (P2P)

PP commonly uses point-to-point Send/Recv between stages. TP commonly uses collectives such as All-Reduce; All-Reduce combines tensors and is not a broadcast.

  • Forward Pass: GPU 0 computes the activations for Layer 7 and Sends them to GPU 1. GPU 1 Receives them and begins computing Layer 8.
  • Backward Pass: GPU 1 computes gradients for Layer 8 and Sends the gradient-with-respect-to-input back to GPU 0.

Hardware Implication: At a simple stage boundary, each microbatch transfers an activation tensor forward and an activation-gradient tensor backward. Their sizes depend on microbatch, sequence length, hidden width and dtype. Relative to TP, the communication cost depends on the workload and topology; PP can be useful across nodes.

2. The "Bubble" Problem: Silicon Idle Time

The fundamental flaw of a naive pipeline is sequential dependency. With one microbatch and a simple sequential schedule, downstream stages wait for the forward activations; backward work proceeds in reverse. The time spent waiting is called the Pipeline Bubble.

To fight this, we inject Micro-Batches. We split the global batch into MM small chunks and pump them into the pipeline back-to-back.

Schedule A: GPipe (All-Forward-All-Backward)

This is the simplest implementation.

  1. Fill: Pump all MM micro-batches through the forward pass.
  2. Drain: Once the last micro-batch reaches the end, start the backward passes in reverse order.

The Hardware Cost: Memory. Each stage retains forward state for its microbatches until their backward passes, unless it recomputes activations. Activation memory can therefore grow with microbatch count.

Schedule B: 1F1B (One-Forward-One-Backward)

This schedule is implemented in frameworks such as PyTorch and Megatron-LM. Instead of waiting for all forward passes to finish, a GPU essentially swaps between forward and backward tasks once the pipeline is full (the "steady state").

  1. Warmup: GPUs process enough forward passes to fill the pipeline.
  2. Steady State: 1 Forward (create new activation) →\rightarrow 1 Backward (consume old activation, free memory).
  3. Cooldown: Process remaining backward passes.

The Hardware Benefit: By interleaving operations, we drastically reduce the peak memory footprint. The forward state for microbatch kk can be freed after its backward pass, rather than keeping all microbatches until the end of the training step.

3. Bare Metal Implementation: The 1F1B Logic

Implementing a pipeline requires managing a state machine on each GPU. The following pseudocode shows the ordering on an intermediate stage. It omits buffer shapes, matching peer schedules, backward bookkeeping, loss handling and synchronization. For executable code, use a supported pipeline runtime.

text
# Schematic synchronous 1F1B schedule for one intermediate stage.
# All stages must use a matching send/receive order; this is not runnable code.
for each warmup microbatch:
    activation = recv(previous_stage)
    output = local_forward(activation)
    send(output, next_stage)
    retain_backward_state(microbatch)
for each steady-state slot:
    forward_one_new_microbatch()          # receive, compute, send, retain
    gradient = recv(next_stage)           # oldest outstanding microbatch
    input_gradient = local_backward(gradient)
    send(input_gradient, previous_stage)
for each remaining outstanding microbatch:
    backward_one_microbatch()             # receive, compute, send
optimizer_step()                          # after all microbatches, all stages

The schedule is illustrative. In particular, a stage cannot simply issue blocking sends and receives without coordination with neighboring stages.

4. Pros and Cons: When to use PP?

Pros

  • Inter-Node Scaling: Because P2P communication is lightweight (only activations at the boundaries), PP can be placed across nodes when the activation transfers and pipeline bubbles fit the network and workload.
  • Memory Efficiency: By splitting the model layers, parameter, gradient and optimizer states are distributed by stage. Per-device memory depends on layer sizes, embeddings, tied weights, activations and partition balance; four stages do not automatically use one quarter of total model memory each.

Cons

  • The Bubble (Idle Compute): The biggest cost. During warmup and cooldown, GPUs sit idle. If your number of micro-batches is small, the efficiency drops drastically. For a simple balanced pipeline with equal forward and backward stage times, no communication cost and MM microbatches on NN stages, the idealized utilization is M/(M+N−1)M/(M+N-1). Imbalance and communication lower real utilization.
  • Stale Weights / Complexity: Some asynchronous schedules use multiple weight versions. A synchronous, flush-based 1F1B schedule performs the optimizer update after all microbatches of a training step; schedule details matter for equivalence to non-pipelined training.
  • Static Shapes: Variable shapes require communicating shape metadata or using fixed-size buffers/padding; runtime support varies.

Summary: The 3D Parallelism Stack

Pipeline Parallelism sits in the middle of the 3D scaling hierarchy:

  1. Tensor Parallelism: Inside the node (intra-layer). Fast links are helpful.
  2. Pipeline Parallelism: Between nodes (inter-layer). Can cross nodes depending on workload and network.
  3. Data Parallelism: Replicates the entire TP+PP cluster to scale batch size.

By combining these, we can train models with trillions of parameters on thousands of GPUs.

Sources