20.4.3 Parallelism and disaggregation
This part of Serving, Capacity & Load Testing: Math to Code develops the mechanisms below. Work the numerical examples or trace the code before checking the answer.
Concepts from other sections (11)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- Service Level Objective (SLO): a target for a defined measure of service behavior over a specified window. Read more: Chapter 13: Engineering Acronyms in Software Engineering
- all-reduce: every rank ends with the elementwise reduction (sum or mean) of all ranks’ arrays. Read more: 17.2 Collectives over processes: ring all-reduce
- Pipeline bubble: time a stage cannot perform useful work because the schedule has not filled or drained. Read more: 17.4 Parallelism, topology, and the global training batch
- Load balancer: a component that spreads traffic across instances of a service by round-robin, least connections, or consistent hashing, at layer 4 (TCP) or layer 7 (HTTP). Read more: Chapter 1: System Design in Systems Engineering
- Mixture of experts (MoE): a layer of many expert MLPs of which a router picks per token. Read more: 13.8 Mixture of Experts
- KV cache: the stored keys and values of all processed tokens, per layer, that let each new token attend without recomputation. Read more: Chapter 20: Inference Engines and GPU Deployment
- BF16: a 16-bit float with float32’s sign and exponent and 7 mantissa bits; the top half of a rounded float32. Read more: 6.7 Safetensors for every dtype, atomic checkpoints, and the token stream
- disaggregated serving: running prefill and decode on separate GPU pools and transferring the KV cache between them. Read more: 20.4.6 Load tests and the deployment runbook
- TPOT (time per output token): time between successive tokens of a running request, about one step. Read more: 23.4 Chunked prefill (mixed prefill + decode batches)
- TTFT (time to first token): time from a request’s arrival to its first generated token. Read more: 23.4 Chunked prefill (mixed prefill + decode batches)
- memory-bound: limited by the rate at which data can be read, not by arithmetic throughput. Read more: 22.7 Fused int4 and int8 dequantize-matmul in C
Learning objectives
- Choose a serving layout using memory needs and interconnect costs.
Parallelism: TP, PP, DP, EP, CP, and disaggregation
Section titled “Parallelism: TP, PP, DP, EP, CP, and disaggregation”When a model does not fit one GPU, or one GPU cannot meet the latency SLO, the term and the term of the step-time equation come into play. Each parallelism strategy places the model differently and pays a different communication cost.
Tensor parallelism (TP, from Megatron-LM) splits each matmul across GPUs. Weights and KV per GPU shrink by , so per-token latency drops. The cost is two all-reduces per layer of bytes each, with ring time about . TP needs NVLink: H100 NVLink 4 gives 900 GB/s per GPU, versus about 64 GB/s per direction for PCIe Gen5 x16. Keep TP inside one NVLink domain, which is 8 GPUs on HGX and 72 on GB200 NVL72.
Pipeline parallelism (PP) splits the layers into stages. It needs one point-to-point send per stage boundary per microbatch, so it tolerates PCIe and InfiniBand (NDR is 400 Gb/s, about 50 GB/s per port). It does not reduce single-request latency and it adds pipeline bubbles; use it to span nodes when a model will not fit in one NVLink domain.
Data parallelism (DP) runs independent replicas behind a load balancer. Throughput scales linearly, latency is unchanged, and there is no communication. It is the default for anything that fits on one GPU or one TP group: two TP=1 replicas of an 8B model beat one TP=2 replica on throughput per GPU.
Expert parallelism (EP) is for MoE models. It places whole experts on different GPUs and routes tokens to them with all-to-all communication, avoiding TP’s per-expert matmul slicing (small experts slice badly). It is usually combined with DP attention, in which attention runs data-parallel and the MoE layers run expert-parallel. In vLLM that is --enable-expert-parallel with --data-parallel-size; in SGLang, --ep-size with --enable-dp-attention.
Context or sequence parallelism (CP) splits one long sequence’s tokens across GPUs, ring-attention style, for prefill of prompts of 128k tokens and more, or shards its KV for decode. vLLM exposes --prefill-context-parallel-size and --decode-context-parallel-size.
The diagram shows how each strategy places the model and which collective it pays:
Disaggregated prefill and decode
Section titled “Disaggregated prefill and decode”The last strategy separates the two phases themselves. Disaggregated prefill/decode runs prefill and decode on separate GPU pools and ships the KV cache between them. The rationale, from DistServe and Splitwise, is that the phases interfere (a prefill stalls every decode in the batch) and want different parallelism and even different hardware. Mooncake, from Kimi, adds a KV-cache-centric store across DRAM and SSD so that prefixes are computed once cluster-wide.
The KV transfer cost decides whether disaggregation pays: shipping bytes must take less time than the decode interference it removes. For 8k tokens of 70B BF16 KV, that is KiB GB, about 54 ms at 50 GB/s RDMA, which is why disaggregation needs RDMA (NIXL, the Mooncake transfer engine) and not TCP. Implementations include vLLM’s --kv-transfer-config with connectors (NIXL, LMCache, Mooncake), SGLang’s --disaggregation-mode prefill|decode, and NVIDIA Dynamo, which orchestrates disaggregated vLLM, SGLang, or TensorRT-LLM workers with a KV-aware router and a planner that rebalances prefill and decode GPUs.
Disaggregated serving moves the prefill/decode split from inside one engine’s batch to two GPU pools, with the router choosing a worker in each and the KV cache crossing RDMA:
The strategies compare as follows:
| Strategy | Reduces latency | Raises throughput | Interconnect need | Use when |
|---|---|---|---|---|
| DP | No | Yes, linear | None | Model fits one GPU or one TP group |
| TP | Yes | Per replica | NVLink | Model too big for one GPU, or TPOT SLO too tight |
| PP | No | Yes, with bubbles | PCIe / IB fine | Model too big for one node |
| EP (+ DP attn) | Somewhat | Yes for MoE | NVLink / fast IB all-to-all | Large MoE (DeepSeek, Qwen-MoE, Llama-4) |
| CP | Yes for long prefill | No | NVLink | 128k+ contexts |
| P/D disaggregation | Stabilizes TPOT and TTFT | Yes at scale | RDMA | Long prompts, strict TPOT, many replicas |
Working out the TP communication cost
Section titled “Working out the TP communication cost”To see why TP needs NVLink, compute for Llama-3.1-70B decode at batch 64 in BF16 with TP=4:
per all-reduce: T × d × b = 64 × 8192 × 2 B = 1.05 MBring traffic: 2(N−1)/N × 1.05 MB = 1.5 × 1.05 MB = 1.57 MB per GPUper layer: 2 all-reduces = 3.1 MBper step: 80 layers = 252 MBtime at ~450 GB/s effective NVLink (one direction) ≈ 0.56 mstime at ~50 GB/s effective PCIe Gen5 ≈ 5 msAgainst a memory-bound step of roughly 16 ms (see capacity.py --preset llama-3.1-70b --tp 4), NVLink adds about 3% and PCIe adds about 30%, before the latency effects of 160 small collectives. This is why TP across PCIe-only cards, such as L40S boxes, is usually capped at 2, and why replicas (DP) beat TP there.
Summary
Section titled “Summary”Choose a serving layout using memory needs and interconnect costs. State the assumptions before applying the result to a different workload.
Review questions
Section titled “Review questions”-
Why can a second GPU make a small model slower?
Answer
The extra synchronization and transfers can exceed the computation saved.