Model Parallelism
Tensor, pipeline, and sequence parallelism — splitting a model that no single GPU can hold, and composing all of them into the 3D layout frontier runs actually use.
#Three ways to cut a model
Data parallelism splits the batch. When the model itself won't fit, you split the model — and there are three orthogonal axes to split along. "Orthogonal" means independent: you can use any one alone, or combine them, as later sections show.
A transformer layer's weight matrix, and the batch flowing through it:
TENSOR PARALLEL split the MATRIX across GPUs
every GPU sees every token
→ communicates within EVERY layer
PIPELINE PARALLEL split the LAYERS across GPUs
GPU0: layers 0-19, GPU1: layers 20-39
→ communicates only at stage boundaries
SEQUENCE PARALLEL split the SEQUENCE across GPUs
each GPU holds part of the token positions
→ communicates within attentionEach has a different communication frequency, and that frequency determines which tier of the bandwidth hierarchy it must live on.
#Tensor parallelism
Split the weight matrices themselves. The clever part is choosing splits so that consecutive operations need only one collective between them.
FFN BLOCK: y = GeLU(x · W₁) · W₂
Split W₁ COLUMN-wise: W₁ = [W₁ᵃ | W₁ᵇ]
GPU A computes GeLU(x · W₁ᵃ)
GPU B computes GeLU(x · W₁ᵇ)
→ no communication needed: GeLU is elementwise, and each
GPU has complete columns
Split W₂ ROW-wise: W₂ = [W₂ᵃ ]
[W₂ᵇ ]
GPU A computes GeLU(x·W₁ᵃ) · W₂ᵃ → partial sum
GPU B computes GeLU(x·W₁ᵇ) · W₂ᵇ → partial sum
→ ALL-REDUCE to sum the partials
→ ONE all-reduce for the whole FFN block, not two.
Attention splits the same way, by head:
each GPU owns whole heads, then one all-reduce after W_o
(the output matrix that recombines the heads).
Total: 2 all-reduces per transformer layer
(one after attention, one after FFN)The real limit is the NVLink domain — the group of GPUs directly joined by NVLink — not the physical server box. On rack-scale systems where 72 GPUs share one NVLink fabric, tensor and expert parallelism can stretch well beyond 8. The rule is unchanged; only the size of the fast tier moved.
The upside is unique: tensor parallelism reduces single-request latency. Every other form of parallelism buys throughput — more requests or examples per second — without making any single one faster. TP splits the work for one token across GPUs. With TP=8, each GPU reads only 1/8 of the weights from memory, and all eight read at the same time. Since decode latency is set by how long it takes to read the weights, each token comes out much sooner. This makes it the primary tool for inference latency, not just for fitting large models.
#Pipeline parallelism
Assign consecutive layers to different GPUs, like stations on an assembly line, and feed the batch through in small pieces called micro-batches so the stations can work simultaneously rather than one at a time.
The catch is the same one every assembly line has: at the start of a run the later stations sit idle waiting for work to reach them, and at the end the earlier ones have nothing left to do. That idle time is the bubble.
4 stages, naive scheduling — the bubble problem:
GPU0 F1 F2 F3 F4 ................ B4 B3 B2 B1
GPU1 .. F1 F2 F3 F4 .......... B4 B3 B2 B1 ..
GPU2 .... F1 F2 F3 F4 ...... B4 B3 B2 B1 ....
GPU3 ...... F1 F2 F3 F4 B4 B3 B2 B1 ........
↑ ↑
warm-up bubble drain bubble
bubble fraction = (stages − 1) / (micro_batches + stages − 1)
4 stages, 4 micro-batches: 3/7 = 43% idle
4 stages, 32 micro-batches: 3/35 = 8% idle
8 stages, 32 micro-batches: 7/39 = 18% idlePipeline's virtue is that it communicates only at stage boundaries — one activation tensor per micro-batch per boundary. That's tiny compared to tensor parallelism, which is why pipeline goes across nodes and tensor stays within them.
#Sequence and context parallelism
When the sequence is the problem — long-context training — split along the token dimension.
The complication: attention needs every position to see every other position, so you can't simply partition and forget.
RING ATTENTION
Sequence of 128K tokens split across 8 GPUs, 16K each.
Each GPU holds Q, K, V for its own block.
for step in 1..8:
compute attention of my Q against the K,V block I currently hold
send my K,V block to the next GPU in the ring
receive the previous GPU's K,V block
After 8 steps every GPU has attended over the whole sequence,
and each held only 1/8th of the KV at any moment.
→ Communication overlaps with computation: while computing
attention on block i, you're already sending block i+1.
Near-free when the blocks are large enough.Sequence parallelism in the Megatron sense is a lighter-weight relative. Tensor parallelism only splits the big matrix multiplies. The small operations between them — LayerNorm and dropout — run on the full tensor on every GPU, so all eight GPUs store identical copies of those activations. Megatron's fix is to split those operations along the sequence dimension instead (GPU 0 handles tokens 0–511, GPU 1 tokens 512–1,023, and so on), using an all-gather and reduce-scatter to switch between the two layouts. That removes the duplication. It's a memory optimisation that composes with tensor parallelism at almost no extra communication cost.
#Composing them: 3D (and 4D) parallelism
Real frontier runs use all of these simultaneously, arranged so each communication pattern lands on appropriate hardware.
1,024 GPUs = 128 nodes × 8 GPUs
TENSOR PARALLEL = 8 within a node, over NVLink
(communicates every layer)
PIPELINE PARALLEL = 8 across 8 nodes, over InfiniBand
(communicates per stage boundary)
DATA PARALLEL = 16 across the 16 remaining groups
(communicates once per step)
8 × 8 × 16 = 1,024 ✓
Rule that generates this layout:
TP ≤ GPUs per node (highest frequency → fastest link)
PP = enough stages to fit the model in memory
DP = whatever's left (lowest frequency → slowest link)Add expert parallelism for MoE and it becomes 4D. Experts are placed within a node where possible, because all-to-all is the most demanding collective there is.
#Choosing a layout
| Constraint | Response |
|---|---|
| Model fits on one GPU | No model parallelism. Use DDP or ZeRO |
| A single layer doesn't fit | Tensor parallelism, degree = ceil(layer size / GPU memory) |
| Model doesn't fit but layers do | Pipeline, or ZeRO-3 — try ZeRO-3 first, it's simpler |
| Sequence length is the constraint | Sequence/context parallelism |
| Inference latency matters | Tensor parallelism — the only one that reduces single-request latency |
| Inference throughput matters | Fewer TP shards, more replicas |
#Inference is a different problem
Everything above is framed around training. Inference changes the objective.
- Tensor parallelism reduces TPOT by splitting the weight read. TP=8 on a 70B model can be ~8× faster per token than TP=1 (minus collective overhead), and it's the standard way to hit aggressive latency targets.
- Pipeline parallelism does not help latency — a token still traverses every stage sequentially. It helps only when the model doesn't fit otherwise, and it adds inter-stage latency per token.
- The KV cache shards with tensor parallelism, so TP also multiplies the cache capacity available, which raises concurrency.
- Beyond TP=8, collective overhead dominates. Past that point, run more replicas (independent full copies of the model, each serving its own requests) rather than splitting one copy into more shards.
#Check yourself
Name the three ways to split a model.Show answer
How does tensor parallelism split a transformer layer?Show answer
Why does tensor parallelism stay inside the NVLink domain?Show answer
What is the pipeline bubble, and how is it reduced?Show answer
How does ring attention handle long sequences?Show answer
What rule generates every parallelism layout?Show answer
ZeRO-3 or pipeline parallelism?Show answer
Which parallelism reduces inference latency?Show answer
#What to carry forward
- Three orthogonal splits: tensor (the matrices), pipeline (the layers), sequence (the tokens).
- Tensor parallelism communicates twice per layer → must stay on NVLink, degree ≤ 8.
- Pipeline bubbles = (stages−1)/(micro-batches+stages−1). Keep micro-batches ≥ 4× stages; use 1F1B.
- Ring attention splits long sequences with communication overlapped behind compute.
- Match communication frequency to link speed — that one rule generates every layout.
- Start with ZeRO-3; add pipeline only after proving you're network-bound.
- For inference, only tensor parallelism reduces latency, and only up to about 8.