Chapter 08 · Parallelism
Tensor, pipeline and expert parallelism
Splitting one model across GPUs: slicing every layer's matrices, cutting the layers into pipeline stages, or spreading a mixture of experts, and what each costs in communication, memory and idle time. Below, the mechanism as the simulator ran it, step by step; then what it measured, why it behaves that way, and the papers.
Check yourself ↓ three questions and what to remember, at the end
Loading the all-reduce animation…
Loading the pipeline animation…
Its row of the matrix
Loading the matrix…
Three ways to split one model
Tensor parallelism (Megatron-LM) splits every layer's matrices across GPUs, so each GPU reads a slice of the weights and the partial results are summed by an all-reduce, twice per layer: the first animation, a ring all-reduce (Patarasuk and Yuan). Pipeline parallelism (GPipe) gives each group of GPUs a run of whole layers and passes activations along: the second, with its bubble. Expert parallelism (GShard) puts whole experts of a mixture-of-experts model on different GPUs and sends each token to its experts and back (an all-to-all).
Why more GPUs per instance can be slower
Splitting a decode step over more GPUs divides its bytes, but every all-reduce costs at least its link latency, twice per layer, and that cost does not shrink with the batch. In the simulator's first-order model (link latency per hop, not overlapped with compute) a batch-1 decode step on eight H100s spends 61.5% of its time in all-reduces, and is no faster than on four (18.2 ms against 18.3 ms). That model is pessimistic for small batches on NVSwitch systems, so read the TP8 cells with the matrix's caveat.
| Layout | Prefill step | Decode step | GPipe bubble (p-1)/(m+p-1) |
|---|---|---|---|
| TP4 | 1,236 ms | 22.8 ms | 0.0% |
| TP2 x PP2, 1 micro-batch | 2,273 ms | 36.4 ms | 50.0% |
| TP2 x PP2, 2 micro-batches | 1,706 ms | 48.1 ms | 33.3% |
| TP2 x PP2, 4 micro-batches | 1,424 ms | 74.6 ms | 20.0% |
| PP4, 4 micro-batches | 1,904 ms | 98.3 ms | 42.9% |
Pipeline parallelism shows only its cost here, because the simulator does not keep several batches in flight across stages (as serving engines do), so a step waits for its own pipeline to drain. Expert parallelism trades the all-reduce for an all-to-all and is as fast as tensor parallelism when the experts are balanced; an imbalance stretches the busiest GPU (a prefill step goes from 211.5 ms to 296.4 ms when one GPU carries half as much again as the mean).
What the sweep measured
With the eight GPUs as one TP8 instance instead of two of TP4, TTFT p99 falls (chat -30%: each prefill has twice the FLOPs) but TPOT p99 rises (+19%), and with one instance instead of two the capacity falls on most workloads (goodput chat -24%, voice -36%), except the coding agent (+6%), whose long shared prompts need the prefill FLOPs. Four TP2 instances leave almost no room for KV once two GPUs hold the whole model, and lose most of their capacity (chat -87%).
What the sweep measured, lever by lever
1 x TP8
Change from the baseline on H100, at capacity for goodput, cost and energy, at the reference load for latency. Run it live
| Workload | goodput | $/M tok | J/tok | TTFT p99 | TPOT p99 | ITL p99 |
|---|---|---|---|---|---|---|
| Chat | -24% T | +32% T$ | +2% T | -30% T | +19% T | -4% T |
| Coding agent | +6% T | -6% T$ | -12% T | -45% T | -2% T | -1% T |
| Offline batch | -15% T | +18% T$ | +1% T | +35% T | -28% T | +101% T |
| Long-context RAG | -15% T | +18% T$ | -1% T | -32% T | +10% T | +1325% T |
| Real-time voice | -36% T | +55% T$ | +17% T | -28% T | +5% T | +402% T |
4 x TP2
Change from the baseline on H100, at capacity for goodput, cost and energy, at the reference load for latency. Run it live
| Workload | goodput | $/M tok | J/tok | TTFT p99 | TPOT p99 | ITL p99 |
|---|---|---|---|---|---|---|
| Chat | -87% T | +659% T$ | +370% T | +75867% T | +4% T | -53% T |
| Coding agent | -100% T | – T$ | – T | +526% T | -21% T | +48% T |
| Offline batch | -100% T | – T$ | – T | +675% T | -87% T | -84% T |
| Long-context RAG | -100% T | – T$ | – T | +1011% T | -26% T | +40% T |
| Real-time voice | -100% T | – T$ | – T | +91% T | +40% T | +53% T |
2 x (TP2, PP2), 2 micro-batches
Change from the baseline on H100, at capacity for goodput, cost and energy, at the reference load for latency. Run it live
| Workload | goodput | $/M tok | J/tok | TTFT p99 | TPOT p99 | ITL p99 |
|---|---|---|---|---|---|---|
| Chat | -85% PT | +568% PT$ | +273% PT | +69% PT | +152% PT | +136% PT |
| Coding agent | -93% PT | +1364% PT$ | +472% PT | +45% PT | +116% PT | +128% PT |
| Offline batch | -38% PT | +61% PT$ | +19% PT | +41% PT | +44% PT | +45% PT |
| Long-context RAG | -83% PT | +500% PT$ | +189% PT | +58% PT | +131% PT | +2828% PT |
| Real-time voice | -100% PT | – PT$ | – PT | +58% PT | +106% PT | +864% PT |
2 x (TP2, PP2), no micro-batching
Change from the baseline on H100, at capacity for goodput, cost and energy, at the reference load for latency. Run it live
| Workload | goodput | $/M tok | J/tok | TTFT p99 | TPOT p99 | ITL p99 |
|---|---|---|---|---|---|---|
| Chat | -64% PT | +183% PT$ | +63% PT | +162% PT | +138% PT | +209% PT |
| Coding agent | -100% PT | – PT$ | – PT | +121% PT | +122% PT | +59% PT |
| Offline batch | -43% PT | +74% PT$ | +15% PT | +82% PT | +81% PT | +77% PT |
| Long-context RAG | -72% PT | +257% PT$ | +93% PT | +132% PT | +129% PT | +70% PT |
| Real-time voice | -100% PT | – PT$ | – PT | +136% PT | +74% PT | +933% PT |
Caveats on these numbers
- PPipeline parallelism is not overlapped. The simulator does not keep several batches in flight across pipeline stages, so PP shows only its cost (bubbles, weight re-reads, an activation hop per stage) and every PP configuration in the sweep loses. Real engines overlap micro-batches across steps.
- TTP all-reduce cost is pessimistic at small batch. Tensor-parallel all-reduces use a first-order α–β ring model whose latency term (5 µs a hop, illustrative) dominates at small batch; NVSwitch hardware with in-switch reduction does better. It has not been calibrated against nccl-tests, and communication does not overlap with compute.
- $Prices per GPU-hour are illustrative. Cost per million tokens uses round illustrative prices (H100 $3.00, H200 $3.50, B200 $5.00 per GPU-hour), not quotes. Cost scales linearly with them, so the ranking of levers on one device does not depend on them; comparisons across devices do.
✓ better than the baseline, ✗ worse, by more than ±2%. Every lever on every metric and device: the matrix; on any two metrics: the explorer.
Check yourself
Commit to an answer before you reveal it: a wrong guess you can explain teaches more than a right one you skimmed. Every number in the answers comes from the same tested model as the chapter’s.
Reveal the answer
Answer: 61.5% (counted right within 10%)
Commit to a number, then reveal.
Reveal the answer
Answer: TTFT falls and TPOT rises, and capacity falls
Pick one, then reveal.
Reveal the answer
Answer: Two GPUs hold the whole model, leaving almost no room for KV
Pick one, then reveal.
Papers and sources
- Shoeybi, Patwary, Puri et al., Megatron-LM: Training Multi-Billion Parameter Language Models Using Model Parallelism (arXiv:1909.08053): tensor parallelism with two all-reduces per layer
- Huang, Cheng, Bapna et al., GPipe: Efficient Training of Giant Neural Networks using Pipeline Parallelism (arXiv:1811.06965): micro-batches through pipeline stages, and the bubble
- Lepikhin, Lee, Xu et al., GShard: Scaling Giant Models with Conditional Computation and Automatic Sharding (arXiv:2006.16668): experts across devices, with all-to-all dispatch and combine
- Patarasuk, Yuan, Bandwidth optimal all-reduce algorithms for clusters of workstations (Journal of Parallel and Distributed Computing, 2009): the ring all-reduce