LLM + RoboticsModule 12 · Video 02

5D parallelism: data, tensor, context, pipeline and expert

When data parallelism and ZeRO run out, there are four more ways to cut a training job across GPUs. Each one splits a different axis of the work and pays with a different kind of network traffic. This guide names the axis, the traffic and the original paper for each, and ends with how the pieces are stacked on a real cluster.

Video length40:27
Published22 October 2026
LevelIntermediate to advanced: watch Video 01 first
Builds onVideo 01 · ZeRO & FSDP, Module 08 · Distributed training, 30u30 Day 24 · GPipe

Video by Jia-Bin Huang · Watch on YouTube

Start here (no maths needed)

Training a giant AI is too much work for one computer chip, so thousands of chips share it. There are five different ways to share the work, and real systems use several at once, like a big kitchen splitting a banquet.

Think of it like this

A school kitchen has to make 1,000 sandwiches, each with five layers. You could give each cook their own pile of orders (that's splitting the data). You could have two cooks build every sandwich together, one doing the left half and one the right (splitting the maths inside a step). You could line the cooks up so the first does bread, the next does filling, and so on (a pipeline of layers). For a giant sandwich, you could cut it into slices along its length (splitting a long sequence). And you could have specialist cooks, one for salad and one for cheese, and send each order to whoever is needed (experts). Every choice means the cooks pass different things to each other, and passing things across the room is slower than passing them to the cook next to you.

How it works

  1. Data: every chip runs the whole model on different examples, then they agree on one update.
  2. Tensor: each big multiplication is split across chips that sit very close together.
  3. Context: one very long text is cut into pieces, and chips swap notes so every word can still look at every earlier word.
  4. Pipeline: the model's layers are split into stages, and examples flow through them like a factory line.
  5. Expert: in a mixture-of-experts model, different chips hold different experts, and each word is sent to the right one.

Why robots care

Robot foundation models are trained on huge piles of video and sensor data, and some long-horizon tasks need long sequences of camera frames. The same five tricks decide how fast those models can be trained and how long a history they can learn from.

Try it

Words to know

Parallelism
Doing parts of a job at the same time on different chips.
All-reduce
Every chip adds up a shared list of numbers and ends with the same total.
All-to-all
Every chip sends a different piece of data to every other chip.
Pipeline bubble
Time when a chip in a pipeline is idle, waiting for work from its neighbour.
Mixture of experts
A model with many specialist sub-networks, where each word uses only a few of them.

Going deeper: everything below is the full version, with some maths. On a first read, skim the headings and the "Why it matters for robotics" box, and come back for the rest later.

1. Watch

Chapter guide

Timestamps come from the video's description. The right-hand column is this course's reading guide, written from the chapter titles; it doesn't describe what the video shows frame by frame.

TimeChapterWhat to look for
0:005D parallelism: Five ways to cut the workloadThe five names. Try to say, for each, what gets split.
0:33Recap: data parallelism and ZeROA summary of Video 01. Skip if it's fresh.
4:49The work cube: tokens × sequences × layersThe mental model for the whole video: each method slices one axis. The demo below draws it.
6:00Three limits of data parallelismWhat data parallelism (even with ZeRO) can't fix: think activation memory, per-GPU batch size and communication.
8:44Tensor parallelism: column-linear and row-linearSplitting a weight matrix by columns needs no communication on the way in; splitting by rows needs a sum on the way out.
10:24The MLP and attention: one all-reduce eachThe Megatron-LM trick of pairing a column split with a row split so each block needs a single all-reduce.
14:10Sequence parallelismThe parts tensor parallelism leaves replicated (LayerNorm, dropout) and how splitting them along the sequence saves activation memory.
16:16Context parallelism: long sequences across serversWhy attention is the hard part when a single sequence is split across GPUs.
17:24Ring attention, online softmax and zig-zagKeys and values travel around a ring; online softmax lets each GPU merge partial results; zig-zag balances the causal mask.
20:51Pipeline parallelism 1: the naive schedule and GPipeWhere the bubble comes from and how micro-batches shrink it.
23:03Pipeline parallelism 2: 1F1B and interleaved stages1F1B caps how many micro-batches' activations are alive at once; interleaving gives each GPU several smaller stages.
25:30Pipeline parallelism 3: Zero-bubble and DualPipeSplitting the backward pass into input-gradient and weight-gradient parts, and using the weight part to fill the gaps.
27:23Expert parallelism: mixture of experts and all-to-allTokens are dispatched to the GPU that holds their expert and sent back. Note the two all-to-alls per MoE layer.
30:08Pipeline vs ZeRO-3Both split the model's layers, but one moves activations and the other moves weights.
31:58Communication cost and the network hierarchyFast links inside a server, slower links between servers. Which traffic goes where.
32:58Llama 3's 16,384-GPU layoutA real production layout. Check that the degrees multiply to the GPU count.
34:15The cheatsheet: three steps to your own layoutThe decision order. Compare it with the rules of thumb at the end of section 2.
39:21RecapTest yourself with the self-check below.

2. The ideas, explained

The work cube

One training step processes a batch of sequences, each made of tokens, through a stack of layers. Picture that as a cube with three axes: sequences × tokens × layers. Each parallelism slices a different part of it:

data parallelism     splits sequences        traffic: gradients, once per step
context parallelism  splits tokens           traffic: keys/values, every attention layer
pipeline parallelism splits layers           traffic: activations, at stage boundaries
tensor parallelism   splits inside a layer   traffic: activations, twice per layer
expert parallelism   splits the MoE experts  traffic: tokens, all-to-all per MoE layer

total GPUs = DP × TP × CP × PP   (EP usually reuses GPUs from the DP/CP groups)

Recap: data parallelism and its limits

Data parallelism and ZeRO are explained in Video 01 and Module 08 · Distributed training. The limits that push you to the other four methods: ZeRO shards model states but not activations, which grow with sequence length; the global batch is at least DP × (one sequence), and very large batches stop helping optimisation; and gradient synchronisation over thousands of GPUs eventually costs more than it saves.

Tensor parallelism (Megatron-LM)

Shoeybi et al. (2019) split each transformer block's matrices across GPUs. For the MLP Z = GeLU(X·A)·B:

column-linear:  A = [A1 | A2]       GPU i computes Y_i = GeLU(X·A_i)
                (GeLU is elementwise, so no communication is needed here)
row-linear:     B = [B1 ; B2]       GPU i computes Z_i = Y_i·B_i
                Z = Z1 + Z2         ← one all-reduce

attention: split the heads (Q, K, V projections column-wise),
           output projection row-wise  ← one all-reduce
per layer: 2 all-reduces in the forward pass, 2 in the backward pass

Every layer waits on these all-reduces, so tensor parallelism is kept inside one server, where GPUs share fast NVLink-class links. The communication volume scales with batch × sequence × hidden size, so it grows with the activations, not the weights.

Sequence parallelism

Korthikanti et al. (2022) noticed that tensor parallelism leaves LayerNorm and dropout replicated on every GPU, with full-size activations. They split those regions along the sequence dimension instead, and replace each all-reduce with a reduce-scatter (into the sequence-split region) and an all-gather (back into the tensor-split region). That's the same total communication as the all-reduce, and much less activation memory. The same paper introduced selective activation recomputation.

Context parallelism and ring attention

Context parallelism splits every layer's tokens across GPUs, so one long sequence spreads over several servers. Everything except attention is per-token and needs no communication. Attention needs each query to see every earlier key and value. Ring attention (Liu, Zaharia and Abbeel, 2023) arranges the GPUs in a ring: each holds a block of queries, and key/value blocks are passed around the ring while each GPU computes attention against the block it currently holds, overlapping the transfer with compute.

That only works because softmax can be computed in pieces. Online softmax (Milakov and Gimelshein, 2018) keeps a running maximum and a running sum, and rescales when a new block raises the maximum:

for each incoming K,V block:
    s     = q·Kᵀ / √d
    m_new = max(m, max(s))
    l     = l·exp(m − m_new) + Σ exp(s − m_new)
    o     = o·exp(m − m_new) + exp(s − m_new)·V
    m     = m_new
output = o / l          (exactly equal to softmax over all blocks)

With a causal mask, a GPU holding early tokens has little work and a GPU holding late tokens has a lot. The zig-zag fix cuts the sequence into 2N chunks and gives GPU i chunks i and 2N−1−i, so every GPU gets one early and one late chunk. Ring attention is covered in more depth in Module 08 · Beyond transformers.

Pipeline parallelism: GPipe, 1F1B, interleaving

Pipeline parallelism gives consecutive layers to different GPUs (stages) and sends activations between neighbours. A naive schedule leaves all but one stage idle. GPipe (Huang et al., 2018) splits the batch into m micro-batches so stages overlap; with p stages the idle fraction is

bubble ≈ (p − 1) / (m + p − 1)       p = 8, m = 32  →  7/39 ≈ 18%
interleaved (v chunks per GPU):  bubble time shrinks by about v

GPipe runs all forwards, then all backwards, so it stores activations for all m micro-batches. The 1F1B schedule, from PipeDream (Harlap, Narayanan et al., 2018), alternates one forward and one backward once the pipeline is full, so at most about p micro-batches are in flight. Narayanan et al. (2021) added the synchronous 1F1B schedule with interleaved stages to Megatron-LM: each GPU holds several non-adjacent chunks of layers, which shrinks the bubble at the cost of more point-to-point messages. The GPipe schedule and its bubble are animated in 30u30 Day 24 · GPipe.

Zero-bubble pipelines and DualPipe

Qi et al. (2023, "Zero Bubble Pipeline Parallelism") split the backward pass into two parts: B, the gradient with respect to the layer's input (which the previous stage is waiting for), and W, the gradient with respect to the weights (which nobody is waiting for). Doing B first and slotting W into the gaps removes the bubble. The paper reports the first zero-bubble schedules under synchronous training and up to 23% higher throughput than 1F1B at a similar memory limit. DeepSeek-V3 (2024) describes DualPipe, a bidirectional schedule that feeds micro-batches from both ends of the pipeline and overlaps forward and backward computation with the expert-parallel communication of another micro-batch.

Expert parallelism

In a mixture-of-experts layer, a router sends each token to its top-k experts. Expert parallelism places different experts on different GPUs (GShard, Lepikhin et al., 2020; Switch Transformer, Fedus et al., 2021). Each MoE layer then needs two all-to-alls: dispatch tokens to their experts, then combine the outputs back. Experts' weights aren't duplicated, so it scales parameters cheaply, but the all-to-all is sensitive to load imbalance and network topology. Routing, load balancing and capacity are covered in Module 08 · Beyond transformers (with a load-balancing demo) and Module 05 · Trillion-scale architecture.

Pipeline vs ZeRO-3

Both spread the layers' weights so no GPU holds the whole model. ZeRO-3 shards every layer across all GPUs and moves weights: each layer is all-gathered before use. Pipeline parallelism gives whole layers to one stage and moves activations, point-to-point, at stage boundaries. ZeRO-3 has no bubble and no scheduling to tune, but its weight traffic only hides behind compute if each GPU has enough tokens per step. Pipeline traffic is small, but you must feed enough micro-batches to hide the bubble, and the stages must be balanced.

Network hierarchy and a real layout

A GPU server typically has 8 GPUs joined by very fast links; servers are joined by a slower network. So the chattiest traffic goes innermost:

innermost (inside a server):  TP      all-reduce every layer
                              CP, EP  per attention / MoE layer
                              PP      point-to-point at stage edges
outermost (across the cluster): DP    one gradient sync per step

The Llama 3 paper (Grattafiori, Dubey et al., 2024) trained the 405B model with this four-dimensional layout, ordered TP, CP, PP, DP from innermost to outermost. Its scaling table lists, for 16,384 GPUs at 8K context, TP 8 × PP 16 × DP 128 = 16,384; for the 128K-context stage it adds CP 16 and reduces DP to 8. Read the paper's parallelism section for the exact batch sizes and utilisation figures.

Rules of thumb

The video ends with its own three-step cheatsheet; watch it for the author's version. The common rules in the literature (for instance Hugging Face's Ultra-Scale Playbook) are: first make the model fit (TP inside a server, then PP or ZeRO-3 across servers, CP if long sequences blow up activations, EP for MoE); then use DP for the remaining GPUs to reach the target global batch; then tune micro-batch size, recomputation and overlap for throughput.

Interactive: slicing the work cube

The cube is one training step: sequences (left to right), tokens (bottom to top) and layers (front to back). Each coloured block is the share of work owned by one group of GPUs. Lines across a block mean its maths is split further by tensor parallelism. Servers are assumed to hold 8 GPUs.

GPUs
–
Servers (8 GPUs)
–
Blocks of work
–
TP inside one server?
–

Try this: start at Data 4, Pipeline 2, Tensor 4 (32 GPUs, 4 servers). Push Tensor to 16 and the TP group spills across two servers, so its per-layer all-reduces would cross the slow network. Set Context to 4 for long sequences and watch the cube split along the tokens axis instead.

3. Where the course goes deeper

TopicCourse page
Data parallelism, ZeRO, FSDP, 3D parallelism, NCCL collectivesModule 08 · Distributed training, Video 01
Pipeline schedule and bubble, with an animation30u30 Day 24 · GPipe
Ring attention and MoE routingModule 08 · Beyond transformers (ring), (MoE)
MoE at trillion scale, expert parallelism in Kimi K3Module 05 · Trillion-scale architecture
Parallelism for serving: TP vs PP vs EP at inference timeModule 09 · Scale & cost capstone
Online softmax inside attention kernelsModule 09 · KV cache & attention

4. Why it matters for robotics

Self-check

Which axis of the work cube does each method split?

Data: sequences. Context: tokens within a sequence. Pipeline: layers. Tensor: the matrices inside each layer. Expert: the experts of MoE layers.

Why does a Megatron MLP block need only one all-reduce in the forward pass?

The first matrix is split by columns, so each GPU can apply GeLU to its own slice without talking to the others. The second matrix is split by rows, so each GPU produces a partial sum of the output, and one all-reduce adds them up.

Why is tensor parallelism kept inside one server?

It needs all-reduces in every layer, forward and backward, sized by the activations. That traffic is only cheap on the fast links inside a server.

What makes ring attention exact rather than approximate?

Online softmax. Each GPU keeps a running maximum and normaliser and rescales its partial output when a new key/value block arrives, so the final result equals softmax over the whole sequence.

With 4 pipeline stages and 12 micro-batches, roughly what fraction of time is bubble in a GPipe schedule?

(p − 1)/(m + p − 1) = 3/15 = 20%.

How does a zero-bubble schedule fill the gaps?

It splits the backward pass into the input gradient (needed by the previous stage right away) and the weight gradient (needed only at the optimiser step), and schedules the weight-gradient work into slots that would otherwise be idle.

References

The video's description lists no references. Primary papers cited in this guide: