Pipeline Parallelism › Micro-Batching: Filling the Bubble
Language AI HandbookAll chapters Pipeline Parallelism › Micro-Batching: Filling the BubbleOne section · Sections in this chapter4 / 10 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The solution to the bubble problem is to process multiple micro-batches simultaneously. A micro-batch is a small chunk of the full mini-batch. Instead of waiting for one full mini-batch to complete its forward pass before starting the next one, we split the mini-batch into equal micro-batches and inject them into the pipeline as fast as the first stage can produce them.
A micro-batch is a subdivision of the full training mini-batch. When using pipeline parallelism, the mini-batch is split into equal parts. Each part flows through the pipeline independently, and the gradients from all micro-batches are accumulated before the optimizer step is applied. From the optimizer's perspective, the result is identical to processing the full mini-batch at once.
The pipeline schedule looks quite different with multiple micro-batches in flight. While S1 is processing micro-batch , S2 is simultaneously processing micro-batch . While S1 processes , S2 processes and S3 processes . The stages are kept busy by overlapping the processing of different micro-batches on different stages. The bubble still exists at the beginning and end of the sequence (there is no way to avoid the startup ramp for a strictly sequential pipeline), but the bubble fraction decreases as increases because the useful work time grows while the ramp time stays constant.
The key insight is that all micro-batches share the same model weights and contribute to the same gradient update. At the end of the pipeline run, all stages have produced their partial gradients, these are accumulated across micro-batches, and the optimizer takes a single parameter update step. From the optimizer's perspective, the pipeline processed one mini-batch of size . The decomposition into micro-batches is an implementation detail for managing pipeline utilization. It is transparent to the loss function and the optimizer.
One important subtlety is the choice of micro-batch size. Smaller micro-batches mean more micro-batches for the same total mini-batch size, which reduces the bubble fraction. But very small micro-batches can underutilize the GPU's tensor cores. Modern GPU tensor cores achieve peak efficiency when matrix dimensions are large multiples of 8 or 16 (and ideally 64 or 128 for the best hardware utilization on A100s and H100s). A micro-batch with too few sequences may result in matrix multiplications with tiny leading dimensions, causing the GPU to spend most of its time on memory access rather than computation. There is a sweet spot where micro-batches are large enough to keep the GPU's arithmetic units busy but small enough that is large enough to suppress the bubble. Finding this sweet spot requires profiling on the specific hardware configuration, though a rule of thumb is that the micro-batch size should be at least 8 sequences for standard transformer models.
Gradient Accumulation and Weight Updates
The relationship between micro-batches, mini-batches, and gradient accumulation is worth understanding precisely, because it affects both memory usage and training stability.
During the forward pass for micro-batch , each stage computes the activations and passes them to stage . Each stage also stores for use during the backward pass. During the backward pass for micro-batch , stage receives gradients from stage , computes gradients with respect to its own parameters, and passes to stage .
The parameter gradients are accumulated across micro-batches. After all micro-batches have completed their backward passes, stage holds the accumulated gradient:
where:
- : the accumulated gradient used for the parameter update at stage
- : the contribution to the gradient from micro-batch at stage
- : the number of micro-batches per optimizer step
This accumulated gradient is mathematically equivalent to computing the gradient over the full mini-batch simultaneously, assuming the micro-batch splits are uniform and all micro-batches use the same parameter values. The optimizer step then proceeds exactly as it would in single-device training. This equivalence is what makes synchronous pipeline parallelism a valid distributed training strategy: the model sees the same gradient signal it would see in non-pipelined training, just computed in parallel across devices.
One practical consideration is that different micro-batches could in principle encounter different parameter values if weights are updated between micro-batches. The standard synchronous pipeline parallelism approach avoids this by processing all micro-batches before taking any weight update step. This ensures gradient coherence: all micro-batches see the same model weights, so their gradients can be averaged. Asynchronous variants that update weights between micro-batches introduce a form of weight staleness, where later micro-batches in the same optimizer step observe slightly different weights than earlier ones. Asynchronous schedules can potentially achieve better device utilization, but the staleness introduces gradient inconsistency that tends to harm convergence for large models. For this reason, synchronous pipeline parallelism is the standard approach in practice.
The Micro-Batch Size and Total Batch Size Relationship
Understanding the relationship between micro-batch size, the number of micro-batches, and the total effective batch size is essential for correctly configuring pipeline parallelism training runs.
If each micro-batch contains sequences and there are micro-batches per optimizer step, the total batch size processed per step per pipeline replica is:
When this pipeline is also combined with data parallelism, where replicas of the full pipeline are run in parallel, the global effective batch size is:
Large-scale training runs often target a specific global batch size for training stability reasons (the learning rate and its schedule are typically tuned for a specific batch size). Pipeline parallelism and data parallelism together give you multiple levers to hit the target batch size: you can increase to reduce the bubble fraction, increase to add more data-parallel replicas, and adjust to satisfy hardware utilization constraints. The flexibility to tune these independently, rather than treating the batch size as a single monolithic parameter, is one of the practical benefits of the 3D parallelism approach used by modern large model training frameworks.