Zero-Bubble Pipeline Parallelism & DualPipe: Overlapping All-to-All with Compute at 671B Scale
In Sparse Mixture-of-Experts (MoE), we saw that routing tokens across 64 Expert-Parallel (EP) GPUs incurs massive cross-node InfiniBand All-to-All dispatch and combine traffic. Meanwhile, standard 1F1B Pipeline Parallelism (PP) leaves GPUs idle in pipeline "bubbles" at the start and end of every batch. Two breakthroughs – Zero-Bubble Pipeline Parallelism (Qi et al., ICLR 2024, arXiv:2401.10241) and DeepSeek-V3's DualPipe (DeepSeek-AI, 2024, arXiv:2412.19437) – crush both bottlenecks simultaneously.
1. Splitting Backward into $B$ (Input) and $W$ (Weight)
A standard linear layer $Y = X W^\top$ has two independent backward GEMMs: the activation gradient $B = \nabla_X \mathcal{L} = (\nabla_Y \mathcal{L}) W$ and the weight gradient $W_{\text{grad}} = \nabla_W \mathcal{L} = (\nabla_Y \mathcal{L})^\top X$. Only $B$ lies on the critical path required by the upstream pipeline stage! $W_{\text{grad}}$ has zero downstream dependency until the optimizer step – meaning the scheduler can stash $W_{\text{grad}}$ thunks in a queue and execute them inside otherwise-idle bubble slots.
2. DualPipe: Bidirectional Micro-Batches & Overlapping All-to-All
DeepSeek-V3 feeds micro-batches from both ends of the pipeline simultaneously (Stage $0 \to p-1$ and Stage $p-1 \to 0$). Inside each steady-state step, every GPU pairs one forward chunk $F$ (from direction A) with one backward chunk $B$ (from direction B) into a single overlapped unit F&B:
PyTorch Implementation: Zero-Bubble SplitBackwardLinear (B/W Decoupling)PyTorch
import torch
class SplitBackwardLinear(torch.autograd.Function):
"""Demonstrates Zero-Bubble B/W decoupling: computes dX immediately, defers dW to a queue."""
@staticmethod
def forward(ctx, x: torch.Tensor, weight: torch.Tensor, dw_queue: list):
ctx.save_for_backward(x, weight)
ctx.dw_queue = dw_queue
return x @ weight.T
@staticmethod
def backward(ctx, grad_out: torch.Tensor):
x, weight = ctx.saved_tensors
# 1. Critical-path activation gradient (B): unblock upstream pipeline stage immediately!
grad_x = grad_out @ weight
# 2. Defer weight gradient (W) to fill future pipeline bubble slots
ctx.dw_queue.append(lambda: grad_out.reshape(-1, grad_out.shape[-1]).T @ x.reshape(-1, x.shape[-1]))
return grad_x, None, None
| Schedule | Pipeline Bubble | Peak Activation Memory | Hides MoE All-to-All? |
|---|---|---|---|
| GPipe | $(p-1)(F+B+W)$ | $M \times$ (all micro-batches) | No |
| 1F1B | $(p-1)(F+B+W)$ | $p \times$ | No |
| Zero-Bubble (ZB1P) | $(p-1)(F+B-2W)$ | $p \times$ | Partial |
| DualPipe (DeepSeek-V3) | $(p/2-1)(F\&B+B-3W)$ | $(p+1) \times$ | Yes (near-zero overhead) |