Chapter 41
Pipeline Parallelism and Hybrid Plans
On this page
- Pipeline fundamentals
- GPipe-style schedule
- One-forward-one-backward
- A two-stage 1F1B schedule with an activation ledger
- Virtual stages and their additional boundaries
- Compute a schedule from readiness recurrences
- Stage partitioning
- Activation communication
- Hybrid parallel coordinates
- A 64-GPU design example
- Selecting the global batch and microbatches
- Plan evaluation
- Design Exercises
- Worked Solutions
Pipeline parallelism partitions model depth and turns a batch into a schedule of activation and gradient messages. Throughput depends on filling stages, balancing their service times, and controlling the number of in-flight microbatches.
A hybrid plan partitions batch, hidden dimensions, sequence, layers, and experts. Each axis creates a different process group and communication boundary.
Pipeline fundamentals¶
Partition a model into s ordered stages. A microbatch executes forward through the stages and backward in reverse, with activations and activation gradients sent between neighbors.
For a forward-only pipeline with m equal-time microbatches and balanced stages, a simple bubble fraction is:
Four microbatches traverse four stages in seven equal-duration slots. Each stage works for four slots and is idle for three. This forward-only example explains the bubble formula; a training schedule must also account for backward work, communication, and saved activations.
Equivalently, useful stage slots are m out of m+s-1. For training schedules, exact utilization depends on forward/backward times, memory policy, and schedule. The approximation still shows why more microbatches amortize fill and drain.
More microbatches are not free. They change local matrix shapes, increase scheduler operations and in-flight activation state, and may force a smaller per-microbatch batch size. The global-batch and optimizer semantics must remain deliberate.
GPipe-style schedule¶
A flush schedule runs forward for all microbatches, then backward for all. It is simple and has one model-weight version per batch, but retains activations for many microbatches and has a fill/drain bubble.
Activation checkpointing can reduce memory by storing stage inputs and recomputing internal activations. The recompute cost and communication schedule must be included in stage balance.
Flush boundaries simplify checkpointing and failure recovery because no microbatches from the next weight version are in flight.
One-forward-one-backward¶
After warmup, a 1F1B schedule alternates forward and backward work. It reduces peak live activations because backward frees a microbatch's saved state earlier. It still has warmup and cooldown bubbles.
The number of in-flight forward microbatches differs by stage. Earlier stages may hold more activation state during warmup. Memory planning needs a per-stage schedule simulation rather than multiplying one activation estimate by the same count everywhere.
Schedulers must define send/receive ordering. Blocking operations issued inconsistently across adjacent stages can deadlock. Use explicit tags or sequence IDs, bounded buffers, and a schedule generated identically on every rank.
A two-stage 1F1B schedule with an activation ledger¶
Take two stages and four microbatches. Each forward or backward operation takes one time slot; transfers are assumed instantaneous at slot boundaries. Fj and Bj refer to microbatch j. An operation may consume only results completed in an earlier slot. This is a schedule calculation, not a measured GPU trace.
| Slot | Stage 0 | Stage 1 | Live saved microbatches on stage 0 after slot | On stage 1 |
|---|---|---|---|---|
| 1 | F0 | Idle | 1 | 0 |
| 2 | F1 | F0 | 2 | 1 |
| 3 | Idle | B0 | 2 | 0 |
| 4 | B0 | F1 | 1 | 1 |
| 5 | F2 | B1 | 2 | 0 |
| 6 | B1 | F2 | 1 | 1 |
| 7 | F3 | B2 | 2 | 0 |
| 8 | B2 | F3 | 1 | 1 |
| 9 | Idle | B3 | 1 | 0 |
| 10 | B3 | Idle | 0 | 0 |
Each stage executes eight operations in ten slots. Under the equal-duration assumptions, utilization is 80%; the two idle slots are not eliminated by keeping more activations. Stage 0 needs at most two saved microbatch activation sets and stage 1 at most one. If their per-microbatch saved activations occupy 0.8 and 1.2 GiB, the corresponding peaks are 1.6 and 1.2 GiB, before communication buffers and operator scratch. A flush schedule that completes all forwards before any backward retains four sets per stage, or 3.2 and 4.8 GiB.
The table holds weights fixed until all four backwards complete; it does not imply asynchronous parameter updates. If stage 1's backward takes two slots, the table is no longer legal without shifting dependent operations. If a send is asynchronous, freeing a buffer after backward is also unsafe until its final consumer completes. Activation checkpointing changes what each live set contains and adds recomputation work; simply multiplying the old peak by a compression factor leaves the schedule analysis unfinished.
Virtual stages and their additional boundaries¶
A device can own multiple nonadjacent model chunks. Interleaving gives it useful work while another chunk waits, reducing bubble and improving balance. It also increases the frequency of activation transfers, complicates ordering, and can enlarge live state.
Virtual-stage count should follow measured imbalance and communication. Too many chunks turn large efficient stage work into small launches and more messages. The right goal is critical-path reduction, not the maximum number of virtual stages.
Compute a schedule from readiness recurrences¶
Index stages i=0..p-1 and microbatches j=0..m-1. In a forward-only pipeline with one compute resource per stage, fixed service time f_i, and transfer delay c_(i-1), completion obeys F_i,j=max(F_i,j-1, F_(i-1),j+c_(i-1))+f_i. Omit the upstream term at stage zero and initialize previous-microbatch availability to zero. The maximum expresses both resource availability and data readiness; adding stage times without it loses pipeline overlap.
For training, backward task B_i,j additionally depends on its local saved forward state and on B_(i+1),j. Its placement must avoid overlap with any forward or backward task using the same stage resource. The choice of which ready task to run defines GPipe, 1F1B, or another schedule; dependencies alone do not select the policy.
Maintain a live-activation ledger: allocate saved state when F_i,j produces it and release it after the last local backward consumer. Peak saved bytes are the maximum sum of these live intervals, not the number of forwards times a constant unless all forwards coexist. Recompute alters both the interval sizes and the service times. Include transfer-buffer ownership separately when send completion occurs after local compute completion.
Stage partitioning¶
Equal layer count rarely means equal time. Embeddings, output heads, long-context attention, MoE layers, and checkpointed segments have different compute and memory. Partition using:
- measured forward, backward, and recompute time;
- parameter and optimizer bytes;
- peak activation state under the chosen schedule;
- activation-transfer bytes between candidate cuts;
- topology and colocated communicator traffic.
The slowest stage sets steady-state cadence. A 10 percent imbalance can waste roughly that fraction even after bubbles are small. Dynamic sequence length may change which stage is slow, so evaluate workload buckets rather than one synthetic shape.
Activation communication¶
Boundary activation bytes scale with microbatch, sequence, hidden dimension, and dtype. Tensor parallelism changes ownership: pipeline sends may be per-TP rank, gathered, or scattered depending on adjacent layouts. Preserve consistent rank pairing between stages so traffic uses intended links.
Compression can reduce bytes but adds conversion and numerical risk. It is attractive only when boundary transfer is exposed and the compressed representation is part of the training-quality contract.
Hybrid parallel coordinates¶
Represent each rank by coordinates such as:
(data, pipeline, tensor, context, expert)
Not every axis is always independent; expert groups may fold with data or tensor dimensions. Write the exact group construction. A common dense-model relation is:
For each coordinate, list:
- tensors owned persistently;
- activations and parameters temporarily materialized;
- communicators and their physical paths;
- microbatch schedule and random-number mapping;
- checkpoint shard identity.
A 64-GPU design example¶
Suppose eight nodes contain eight tightly connected GPUs each. A model needs more memory than one node but has large hidden layers and moderate sequence length. One candidate is:
- TP=8 within each node;
- PP=2 across pairs of nodes;
- DP=4 across four pipeline replicas;
- CP=1 for the initial sequence target.
TP traffic stays local. Pipeline boundaries cross nodes once per microbatch in each direction. Data-parallel reductions connect corresponding TP/PP coordinates across replicas and should be mapped across network rails.
This is a hypothesis, not a default. Compare with TP=4, PP=4, DP=4 or a sharded-data plan. The first may have better local TP bandwidth but larger pipeline stages; the second changes pipeline bubbles and per-rank GEMM shapes. Measure peak memory and step time under the same global batch.
Selecting the global batch and microbatches¶
For local microbatch size b, accumulation microbatches m, and data degree d:
Increasing m reduces pipeline bubble but raises global batch unless b or d falls. b may already be one sequence, leaving optimization changes or sequence packing as the remaining levers. Do not silently change training hyperparameters to make a systems schedule look efficient.
Plan evaluation¶
For every candidate plan, calculate and then measure:
- persistent and peak memory per rank and stage;
- local matrix dimensions and achieved compute;
- bytes, steps, and exposed time for every communicator;
- pipeline bubble, imbalance, and recomputation;
- data input and checkpoint bandwidth;
- failure blast radius and spare-capacity requirement.
Reject plans that fit only with zero allocator reserve or depend on perfect overlap. Include shape changes across curriculum, sequence-length ramp, or expert routing.
Design Exercises¶
- Derive pipeline bubble and explain why more microbatches can still hurt throughput.
- Compare flush and 1F1B schedules by memory, semantics, and recovery.
- How would you partition heterogeneous transformer layers into stages?
- Design rank coordinates and process groups for a 3D or 4D plan.
- Evaluate the 64-GPU example against an alternative plan.
- Why is the fastest isolated parallel plan sometimes wrong for the full training run?
Worked Solutions¶
1. Bubble and microbatches¶
With s equal forward-only stages and m microbatches, useful slots are m across m+s-1, so bubble fraction is (s-1)/(m+s-1). Training schedules add backward and schedule-specific terms. Raising m lowers fill/drain fraction but may shrink local batch below efficient GEMM shapes, increase messages and scheduler overhead, increase live activations, or alter global batch. Sweep complete step time and memory, not the formula alone.
2. Flush versus 1F1B¶
Flush runs all forwards then all backwards, retains more activations, and has clear weight-version and checkpoint boundaries. 1F1B alternates after warmup, releases activations earlier, and reduces peak memory, but has stage-dependent live state and more intricate ordering. Both can preserve synchronous update semantics when weights do not update until the batch completes. Recovery is simpler at flush points; mid-schedule restart needs microbatch commit state or a full-step replay.
3. Stage partitioning¶
Profile forward, backward, recompute, parameter bytes, and boundary activations by layer and workload bucket. Solve for balanced maximum stage time subject to per-stage peak memory and legal cut points. Account for embeddings, loss, MoE, and long-context attention separately, then map adjacent stages to links and simulate the actual schedule. Validate with per-stage idle time because equal estimated FLOPs may hide memory or communication differences.
4. Rank coordinates¶
Assign deterministic (dp, pp, tp, cp) coordinates whose product equals world size for the dense case. TP groups vary tp while other coordinates are fixed; PP groups vary pp; CP groups vary cp; DP groups vary dp. Also define the optimizer-synchronization group explicitly: with parameters replicated over CP, it commonly varies both dp and cp at fixed pp and tp, or uses the sharded equivalent. Map TP to local fabric, PP to low-contention neighbor paths, and replica synchronization across rails. Print memberships and include expert folding explicitly rather than assuming another independent product dimension.
5. Sixty-four GPUs¶
For TP8-PP2-DP4, verify that TP8 local GEMMs remain efficient, two-node stage memory fits, pipeline activation traffic is acceptable, and DP groups use independent rails. Compare TP4-PP4-DP4: it may improve local GEMM size and lower TP communication but doubles pipeline depth and boundary count. Measure bubble at the same global batch, stage imbalance, peak bytes, collective exposure, and failure recovery. The winner follows the actual model and topology.
6. Full-run objective¶
An isolated steady-state step excludes startup, data stalls, checkpoint pauses, sequence curriculum, evaluation, failures, and scheduler fragmentation. A plan may require a changed global batch, have fragile zero-reserve memory, or make checkpoints and resharded restore expensive. Choose time-to-valid-model and recovery-adjusted cost under the full run, while preserving optimization semantics and quality.