AI/ML Distributed Training DualPipe Pipeline Parallelism Systems ML

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.

Pipeline Bubble Time Comparison ($p$ PP Stages, $T_F, T_B, T_W$ Chunk Durations)
$$T_{\text{bubble}}^{\text{1F1B}} = (p - 1)(T_F + T_B + T_W), \qquad T_{\text{bubble}}^{\text{DualPipe}} = \left(\frac{p}{2} - 1\right)(T_{F\&B} + T_B - 3T_W)$$

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:

Compute SMs (112 SMs) Attn (F) MLP / MoE (B) MLP / MoE (F) Attn (B) + W_grad Comm SMs (20 SMs) All-to-All Combine (B) All-to-All Dispatch (F) All-to-All Dispatch (B) All-to-All Combine (F) 100% of cross-node InfiniBand EP communication hides behind opposite-direction GEMM compute.
Inside a single DualPipe F&B block, dedicated communication SMs stream MoE All-to-All packets while compute SMs run the opposite direction's Attention and MLP kernels.
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
DualPipe Memory Tradeoff: Because each pipeline rank holds two symmetric stage chunks (one for each direction), DualPipe stores $2\times$ model parameters per rank compared to 1F1B. At 671B MoE scale with 64-way Expert Parallelism, the per-GPU parameter shard is already small enough that $2\times$ weights is trivial compared to eliminating cross-node All-to-All stalls.
SchedulePipeline BubblePeak Activation MemoryHides 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)