Contents
Follow one microbatch across four GPUs
Pipeline parallelism (PP) makes a model fit across multiple GPUs by assigning pieces of the model to different devices. That creates a scheduling problem. A stage can start its forward pass only after the previous stage produces activations, and it can start its backward pass only after the next stage returns an input gradient. An idle interval created by these dependencies is a pipeline bubble.
Consider a 32-layer model split across four GPUs. GPU 0 holds layers 1–8, GPU 1 holds layers 9–16, GPU 2 holds layers 17–24, and GPU 3 holds layers 25–32. Each block of layers is a stage. An input travels from GPU 0 to GPU 3, where the loss is computed. Backward computation then travels in the opposite direction.
Forward GPU 0 -> GPU 1 -> GPU 2 -> GPU 3 -> loss
Backward GPU 0 <- GPU 1 <- GPU 2 <- GPU 3 <- loss gradient
During a synchronized optimizer step, all microbatches use the same parameter values. Each GPU saves the activations its stage needs for backpropagation. A stage sends its input gradient to the previous stage and accumulates its parameter gradients locally for the optimizer. The four GPUs store one model collectively, and the optimizer updates it once the step's gradients are ready.
If the GPUs process one microbatch from start to finish before admitting the next, most devices spend most of their time waiting. A pipeline lets GPU 0 start the next microbatch as soon as it hands off the previous one. Different GPUs can then work on different microbatches at the same time.
For the schedules below, one optimizer step processes 16 samples in eight microbatches of two samples each. A forward pass on an eight-layer stage takes one time unit (\(F=1\)), and a full backward pass takes two (\(B=2\)). Each GPU executes one operation at a time. Communication, loss, recomputation, and the optimizer update take zero time in this example. The numbers describe the schedule under these assumptions.
GPipe fills and drains the pipeline
GPipe completes the forward pass for every microbatch before the last stage starts backpropagation. A GPU can begin its own backward phase once the downstream gradient arrives. The example processes microbatches in order from 1 through 8 in both phases.
| GPU | Forward wave, F1 through F8 | Backward wave, B1 through B8 |
|---|---|---|
| GPU 0 | 0–8 | 17–33 |
| GPU 1 | 1–9 | 15–31 |
| GPU 2 | 2–10 | 13–29 |
| GPU 3 | 3–11 | 11–27 |
During warmup, GPU 3 waits until microbatch 1 finishes on the first three stages. During drain, GPU 3 finishes at time 27 while the remaining stages are still passing gradients upstream. GPU 0 holds activations for all eight microbatches by time 8 because all eight forward passes precede its first backward pass. The full step takes 33 time units.
1F1B frees activations earlier
Once its warmup is over, each stage of a one-forward, one-backward (1F1B) schedule alternates forward and backward work during steady state. The two operations in a pair generally belong to different microbatches. On GPU 0, F1 through F4 run first. GPU 0 then waits for the first return gradient, runs B1, starts F5, and follows it with B2.
The timeline uses one cell per time unit. F means forward, B means backward, and the number identifies the microbatch. A repeated B occupies both time units of a single backward pass. A dot is an idle slot.
Each row runs from t=0 to t=18.
GPU 0 F1 F2 F3 F4 . . . . . . B1 B1 F5 B2 B2 F6 B3 B3
GPU 1 . F1 F2 F3 . . . . B1 B1 F4 B2 B2 F5 B3 B3 F6 B4
GPU 2 . . F1 F2 . . B1 B1 F3 B2 B2 F4 B3 B3 F5 B4 B4 F6
GPU 3 . . . F1 B1 B1 F2 B2 B2 F3 B3 B3 F4 B4 B4 F5 B5 B5
These rows continue from t=18 to t=33.
GPU 0 F7 B4 B4 F8 B5 B5 . B6 B6 . B7 B7 . B8 B8
GPU 1 B4 F7 B5 B5 F8 B6 B6 . B7 B7 . B8 B8 . .
GPU 2 B5 B5 F7 B6 B6 F8 B7 B7 . B8 B8 . . . .
GPU 3 F6 B6 B6 F7 B7 B7 F8 B8 B8 . . . . . .
GPU 3 starts B1 at time 4, immediately after its own F1. The gradient reaches GPU 2 at time 6, GPU 1 at time 8, and GPU 0 at time 10.
| GPU | Forward for microbatch 1 | Backward for microbatch 1 |
|---|---|---|
| GPU 0 | 0–1 | 10–12 |
| GPU 1 | 1–2 | 8–10 |
| GPU 2 | 2–3 | 6–8 |
| GPU 3 | 3–4 | 4–6 |
By time 8, GPU 0 has four sets of saved activations in 1F1B, compared with eight in GPipe. At time 12, GPU 0 finishes B1, releases microbatch 1's activations, and starts F5. Its resident set changes from {1, 2, 3, 4} to {2, 3, 4, 5}. GPU 3 finishes B3 at that same time and starts F4. Its B1 finished six time units earlier.
GPU 0 peaks at four sets of activations in this 1F1B schedule and eight in GPipe. The model counts one set per stage and microbatch, from forward allocation through completion of that stage's backward pass. A framework can release some tensors layer by layer during backward. References elsewhere can also extend tensor lifetimes. Parameter storage, accumulated gradients, optimizer state, communication buffers, and allocator overhead require a separate memory budget.
Both schedules finish at time 33. For sufficiently many microbatches, the peak number of activation sets under non-interleaved 1F1B is bounded by the pipeline depth. The freed memory can make more microbatches or less activation recomputation practical. The resulting throughput depends on the workload. Megatron-LM's schedule analysis
Calculate the bubble fraction
Each GPU performs eight forwards and eight backwards, or \(8(1+2)=24\) useful time units. The 33-unit step therefore has nine units of equivalent bubble overhead. Across all four GPUs this is 36 idle GPU-time units out of \(4\times33=132\). In this balanced example the two views produce the same fraction, \(9/33 = 36/132 \approx 27.3\%\).
Let \(p\) be the number of balanced stages and \(m\) the number of microbatches. For the schedules above, filling and draining add the equivalent of \(p-1\) forward-plus-backward pairs to the ideal compute time.
Dividing the equivalent bubble by the whole step gives the idle fraction.
An overhead reported relative to useful compute time uses \((p-1)/m\), or \(9/24=37.5\%\) here. Check the denominator before comparing percentages from different papers or dashboards.
At \(p=4\), doubling \(m\) from 8 to 16 lowers the whole-step idle fraction from 27.3% to 15.8%. If per-microbatch compute stays fixed, the nine absolute bubble units stay fixed too. If the global batch stays fixed, increasing \(m\) normally means shrinking each microbatch. Smaller matrix multiplications can be less efficient, so the new step time still needs to be measured.
Interleaved 1F1B uses shorter model chunks
An eight-layer stage can instead become two four-layer chunks. Number the chunks C0 through C7 in model order and place them round-robin across the GPUs. Each physical rank still holds eight layers.
| GPU | Non-interleaved placement | Interleaved placement |
|---|---|---|
| GPU 0 | Layers 1–8 | C0 (1–4), C4 (17–20) |
| GPU 1 | Layers 9–16 | C1 (5–8), C5 (21–24) |
| GPU 2 | Layers 17–24 | C2 (9–12), C6 (25–28) |
| GPU 3 | Layers 25–32 | C3 (13–16), C7 (29–32) |
The forward path visits GPUs 0, 1, 2, 3, then 0, 1, 2, 3 again. Each GPU switches between its two chunks while scheduling the forward and backward work for several microbatches. With balanced chunks and a compatible schedule, the shorter operations reduce the time needed to fill and drain the pipeline.
For \(v\) chunks per physical rank, assume each chunk costs \(F/v\) to run forward and \(B/v\) backward. Useful compute per GPU stays at \(m(F+B)\). Writing the ideal interleaved bubble as \(\Delta_{\mathrm{I}}\) gives the following idle fraction.
In the four-GPU example, \(v=2\) gives a forward time of 0.5 and a backward time of 1 for each chunk. One interleaved schedule groups microbatches in fours and finishes in 28.5 time units. The table shows just microbatch 1 on that timeline. Other microbatches can use the gaps between its operations.
| Chunk | GPU | Forward for microbatch 1 | Backward for microbatch 1 |
|---|---|---|---|
| C0 | GPU 0 | 0–0.5 | 13.5–14.5 |
| C1 | GPU 1 | 0.5–1 | 12–13 |
| C2 | GPU 2 | 1–1.5 | 11–12 |
| C3 | GPU 3 | 1.5–2 | 10–11 |
| C4 | GPU 0 | 2–2.5 | 7–8 |
| C5 | GPU 1 | 2.5–3 | 6–7 |
| C6 | GPU 2 | 3–3.5 | 5–6 |
| C7 | GPU 3 | 3.5–4 | 4–5 |
| Schedule | Useful time per GPU | Equivalent bubble | Step time | Idle fraction |
|---|---|---|---|---|
| GPipe | 24 | 9 | 33 | 27.3% |
| 1F1B | 24 | 9 | 33 | 27.3% |
| Interleaved 1F1B, \(v=2\) | 24 | 4.5 | 28.5 | 15.8% |
With eight GPUs and 32 microbatches, the corresponding ideal idle fractions are 17.9% for plain 1F1B, 9.9% for two chunks per rank, and 5.2% for four. A twofold reduction in bubble time applies to the idle term. The total step contains the same useful work, plus the cost of crossing more chunk boundaries. The Megatron analysis estimates a roughly \(v\)-fold increase in point-to-point pipeline communication, with activation residency and scheduler overhead also affected by the execution order. Interleaved 1F1B construction and trade-offs
V-shaped placement pairs early and late chunks
The same eight chunks can be assigned so that the forward path goes out and then returns along the GPU ranks. GPU 0 holds both the model's first and last chunks, and GPU 3 holds the two adjacent middle chunks.
| GPU | Round-robin interleaved | V-shaped |
|---|---|---|
| GPU 0 | C0, C4 | C0, C7 |
| GPU 1 | C1, C5 | C1, C6 |
| GPU 2 | C2, C6 | C2, C5 |
| GPU 3 | C3, C7 | C3, C4 |
Chunk: C0 -> C1 -> C2 -> C3 -> C4 -> C5 -> C6 -> C7
GPU: 0 1 2 3 3 2 1 0
An activation's lifetime runs from its forward allocation until backward finishes consuming it. Early chunks generally hold activations longer because their gradients have farther to travel. A V-shaped placement gives each GPU both a longer-lived and a shorter-lived chunk. The actual peak still depends on how their lifetimes overlap. With V-shaped placement and intact backward operations, the 1F1B-V schedule in Pipeline Parallelism with Controllable Memory has a smaller bubble and asymptotic peak activation memory of about two-thirds that of plain 1F1B under the paper's model. A zero-bubble schedule also needs to arrange the backward work and handle the optimizer boundary. 1F1B-V and other schedules
Zero Bubble splits the backward pass
Take a linear layer with forward operation \(Y=XW\). Given the gradient \(dY\) returned by the next layer, backpropagation computes the gradient of the input and the gradient of the weight.
Call the input-gradient operation I and the weight-gradient operation Wgrad. The preceding stage needs \(dX\) before it can run its own backward pass. The optimizer needs \(dW\) by the update boundary. Zero Bubble uses those two deadlines to send \(dX\) early and move Wgrad into a later slot. In papers that split backward, B sometimes refers only to input-gradient work. Here B means the full backward pass.
dY arrives -> I -> send dX to the previous stage
-> Wgrad -> accumulate dW before the update
A stage with one ready I operation and no ready forward work can run I now, pass the gradient upstream, and use one of its own later idle slots for Wgrad. This can unblock a whole chain of input-gradient operations on other devices. The reordered schedule must keep the saved inputs and any needed gradient tensors alive until Wgrad executes. The gain depends on how well available slots match the work and on the memory cost of retaining those tensors. Zero Bubble's backward split
Memory and idle-time trade-offs
Let \(M\) be peak activation memory in the plain 1F1B baseline. The activation budget includes dynamic tensors retained for delayed Wgrad. Parameters, gradient accumulation buffers, and optimizer state sit outside that budget.
| Schedule | Scheduling change | Peak activation memory | Bubble time relative to 1F1B |
|---|---|---|---|
| ZB-H1 | Prioritize I and use deferred Wgrad to fill gaps | About \(M\) | About 1/3 |
| ZB-H2 | Admit more in-flight forwards and reorder more Wgrad work | Approaches \(2M\) | Can reach zero |
| ZB-V | Combine V-shaped placement with split backward | About \(M\) | Can reach zero |
| V-Half | Use a V-shaped schedule with shorter overlapping lifetimes | Approaches \(M/2\) | About 1/2 |
| V-Min | Reduce activation residency further | Approaches \(M/3\) | About 2/3 in the equal-duration model |
| V-ZB | Use the controllable-memory paper's V-shaped zero-bubble construction | About \(M\) | Can reach zero |
These ratios come from the papers' simplified balanced models, with equal times for F, I, and Wgrad, enough microbatches, and small constants omitted. ZB-V and V-ZB are named in separate papers. In a real model, the operations take different amounts of time. Some schedules leave gaps, and the gaps in V-Min can repeat with every scheduling block and accumulate as the microbatch count grows. Zero Bubble schemes · Controllable-memory schemes
The optimizer boundary
Global gradient clipping needs the full gradient norm. Mixed-precision training may also need a distributed check for non-finite gradients. These global decisions can introduce a synchronization stall between steps. The Zero Bubble paper uses optimizer post-validation to proceed under the expected outcome and then validate along the pipeline. If validation shows that the update must be skipped or changed, the implementation rolls back and retries as required to preserve synchronized training semantics. It must keep parameters, optimizer state, and the work that consumes them consistent. An empty pipeline at cold start still has to propagate the first microbatch through its stages. Optimizer synchronization and post-validation
Bidirectional pipelines and communication overlap
Chimera runs two model pipelines in opposite directions. One feeds microbatches from GPU 0 toward GPU 3, and the other feeds different microbatches from GPU 3 toward GPU 0. A stage can use the gaps in one direction for work from the other direction. The original construction roughly halves the bubble at the cost of an extra model copy and gradient synchronization between copies. Chimera paper
DualPipe also interleaves work inside forward and backward passes. In a mixture-of-experts (MoE) layer, token dispatch and combine can involve expensive expert-parallel (EP) all-to-all communication. The DualPipe schedule arranges attention, MLP computation, and the MoE transfers so that ready computation for one microbatch can cover exposed communication for another. Pipeline scheduling reduces idle slots with no ready compute, while communication overlap targets time spent waiting for transfers. Both effects matter when reading a profiler trace. DeepSeek-V3 Technical Report, §3.2.1
DualPipeV folds the two directions into a V-shaped placement and removes the replicated model. For the same model and physical GPU count, the authors' comparison puts DualPipe at roughly twice ordinary parameter storage, and DualPipeV back at one model's parameter storage, with roughly twice the ordinary point-to-point pipeline traffic. Authors' DualPipeV analysis · Official DualPipe implementation
Sequence-level scheduling for long inputs
Seq1F1B creates smaller work units by cutting a microbatch along the sequence dimension. A downstream stage can start on a subsequence as soon as the required upstream outputs are ready. The schedule exploits the direction of causal attention. A token reads keys and values from its own position and earlier ones. Forward therefore follows the prefix toward later subsequences, and backward carries dependencies in reverse.
The scheduler tracks dependencies across stages, microbatches, and subsequences. Equal token counts can yield different compute costs because a later subsequence attends over a longer prefix. The paper partitions according to work and describes combinations with interleaving and split backward. Bidirectional full attention, as used by some diffusion transformers, introduces dependencies on later tokens and calls for a different design. Seq1F1B methodology
Asynchronous systems such as PipeDream and PipeDream-2BW keep work moving across weight updates and reduce the need to drain at every step. That changes the optimization semantics. Comparisons should account for which weight version each microbatch sees and how delayed gradients affect convergence.
Configure the corresponding schedules in Megatron-LM
The implementation details below refer to NVIDIA Megatron-LM commit 3d3323fbd. The schedule selector uses ordinary 1F1B for pipeline parallelism without virtual stages and interleaved 1F1B when virtual stages are configured. Megatron calls the latter virtual pipeline parallelism (VPP). The V in VPP stands for virtual. V-shaped placement describes how chunks are mapped to devices.
The ordinary training selector in that revision exposes the non-pipelined, non-interleaved, and interleaved paths. GPipe, 1F1B-V, the Zero Bubble and controllable-memory schedules, Chimera, DualPipe, and Seq1F1B are research schedules readers may encounter in separate implementations or forks. The MoE Combined 1F1B path overlaps communication within the supported Megatron schedules, including a path for MoE training without PP. Pinned schedule selector · Megatron Core scheduling API
Set physical ranks and virtual stages
For 32 evenly split Transformer layers and four physical PP ranks, each rank handles eight layers. Setting two virtual stages per rank makes eight logical stages, each with four layers. This count assumes the embedding, output layer, and multi-token prediction (MTP) stages are outside the simplified layer split. These flags belong in the existing training command.
--num-layers 32 \
--pipeline-model-parallel-size 4 \
--num-virtual-stages-per-pipeline-rank 2
The last flag can be expressed as --num-layers-per-virtual-pipeline-stage 4. Use at most one of those two flags or the explicit --pipeline-model-parallel-layout option. Pinned argument validation
For a fixed global batch of \(G\) equal-length samples, \(D\) data-parallel replicas, and microbatch size \(b\), each pipeline replica handles \(m=G/(Db)\) microbatches per optimizer step. Setting \(G=64\), \(D=2\), and \(b=4\) gives \(m=8\). Switching from one to two chunks per physical rank changes which layers each microbatch visits on a given rank. The same eight microbatches still pass through each pipeline replica.
Enable supported expert-parallel overlap
A compatible MoE configuration can combine these options.
--overlap-moe-expert-parallel-comm \
--delay-wgrad-compute
Combined 1F1B interleaves forward and backward operations from different microbatches to hide expert all-to-all and can defer some weight-gradient work. In the pinned revision, expert-parallel overlap requires EP greater than one. With PP greater than one it also requires VPP. The overlap path has additional restrictions on the dispatcher, precision, and recomputation. Delayed weight-gradient compute requires expert-parallel overlap. Pinned overlap checks · Pinned wgrad validation
The defer_embedding_wgrad_compute option defers the embedding weight-gradient GEMM to the pipeline flush. Its scope is the embedding gradient. Pinned embedding configuration
Read a real training timeline
Start with a trace that shows each stage's forward and backward operations, point-to-point transfers, and the optimizer boundary. Repeated waiting at the two ends of a step points to filling and draining. A stage with consistently longer kernels can leave other ranks idle even in steady state. A gap aligned with a point-to-point receive or expert collective calls for checking whether the transfer is on the critical path and whether useful compute is ready to overlap it. Recomputed activations increase the amount of work the schedule must accommodate.
Hold the model, global batch and token count, device count, and numerical precision fixed across alternatives. Record step time, useful tokens per second, and peak GPU memory. Track microbatch size because it can change kernel efficiency, and inspect the per-stage timings because an uneven split can dominate the result. A smaller ideal bubble may come with more communication, while shorter activation lifetimes can make it possible to remove expensive recomputation. The end-to-end measurements capture those effects together.
References
- GPipe: Efficient Training of Giant Neural Networks using Pipeline Parallelism
- Efficient Large-Scale Language Model Training on GPU Clusters Using Megatron-LM
- Zero Bubble Pipeline Parallelism
- Pipeline Parallelism with Controllable Memory
- Chimera: Efficiently Training Large-Scale Neural Networks with Bidirectional Pipelines
- DeepSeek-V3 Technical Report
- DualPipe could be better without the Dual
- Seq1F1B: Efficient Sequence-Level Pipeline Parallelism for Large Language Model Training
- Megatron Core pipeline scheduling API