On this page
The moment a model doesn't fit on one GPU, or one GPU can't serve your traffic, you have to choose how to split the work. There are four basic options, and they trade memory, latency, throughput and communication very differently. Picking the wrong one is one of the most common ways to waste a multi-GPU node.
#Data parallelism: copies of the model
Run a complete copy of the model on each GPU (or group of GPUs) and spread requests across them with a load balancer.
- Communication: none between copies.
- Helps: throughput, linearly with the number of copies.
- Doesn't help: latency for a single request, or models that don't fit on one GPU.
If the model fits comfortably on one GPU with room for KV cache, data parallelism is usually the most efficient choice. It's also the easiest to operate: each replica is independent, so one failing doesn't take the others down, and you can scale replicas up and down with traffic.
#Tensor parallelism: split every layer
Split each layer's weight matrices across GPUs. Each GPU holds of every layer and computes its share of every matrix multiply. After the attention block and after the MLP, the GPUs combine their partial results with an all-reduce.
x
W1
W2
GPU 0
idle
GPU 1
idle
One MLP block on one GPU
x (batch × hidden) times W1 (hidden × 4·hidden), activation, then times W2 back to hidden.
Blue = GPU 0's share, violet = GPU 1's share.
#How a layer is split
The standard recipe (from Megatron-LM) needs only one all-reduce per block:
- The first matrix is split by columns. In the MLP, each GPU holds a slice of the up and gate projections and computes a slice of the hidden activations. In attention, each GPU holds a subset of the heads. No communication is needed: every GPU already has the full input.
- The second matrix is split by rows. Each GPU multiplies its slice of activations by its slice of the down (or output) projection, producing a partial sum of the full output.
- An all-reduce adds the partial sums, so every GPU ends up with the full output, ready for the next block.
One all-reduce after attention and one after the MLP: two per layer.
- Memory: weights per GPU fall by , and so does the KV cache per GPU (heads are split too). More room for cache means bigger batches.
- Latency: each GPU reads only of the weights per decode step, so per-token latency can drop substantially.
- Communication: two all-reduces per layer, every step. That's a lot of small messages, which is why tensor parallelism needs a fast interconnect like NVLink and is usually kept inside one node.
How much does that communication cost? For each all-reduce, every GPU sends and receives about times the size of the activation. At decode with batch , hidden size and 2-byte values, the activation is bytes. For a 70B model (hidden size 8,192, 80 layers) at batch 64 with :
Times 160 all-reduces per step, that's about 290 MB per GPU per step. Over NVLink at several hundred GB/s it's under a millisecond; over PCIe it would dominate. And at small batch the messages are tiny, so latency per all-reduce (a few microseconds to a few tens of microseconds each, times 160) matters more than bandwidth. The ring all-reduce lesson shows where these numbers come from.
Link between the GPUs
Model
Tensor-parallel degree
Message
16 KB
Comm per step
0.92 ms
Weight read
5.22 ms
Comm share
15%
Without overlap, this time adds straight onto every output token.
Same model as the lesson's code: BF16 activations, two all-reduces per layer, 4 µs launch per collective, the fastest of three algorithms. The weight read assumes H100 HBM (B200 for NVLink 5).
#Worked example: diminishing returns
A 70B model in FP8 (about 70 GB of weights) on H100s at batch 1, assuming 70% of peak bandwidth (2.35 TB/s) and about 10 µs per small all-reduce:
| TP size | Weights read per GPU | Weight-read time | All-reduce time (160 × 10 µs) | Time per token |
|---|---|---|---|---|
| 2 | 35 GB | about 15 ms | about 1.6 ms | about 16.6 ms |
| 4 | 17.6 GB | about 7.5 ms | about 1.6 ms | about 9.1 ms |
| 8 | 8.8 GB | about 3.8 ms | about 1.6 ms | about 5.4 ms |
Doubling from TP=4 to TP=8 doubles the GPUs but cuts time per token by only about 1.7 times, because the communication cost doesn't shrink. These are estimates; real all-reduce latency depends on the library, message size and topology. But the shape is real, and it's why TP=8 is chosen for tight latency targets, not by default.
#Pipeline parallelism: split by layers
Give each GPU a contiguous range of layers: GPU 0 runs layers 1 to 20, GPU 1 runs 21 to 40, and so on. Activations flow from one stage to the next.
- Memory: weights per GPU fall by the number of stages.
- Communication: one activation transfer between neighbouring stages per step: small, and tolerant of slower links, so it works across nodes.
- Latency: doesn't improve. A token still passes through every layer in sequence, plus transfer hops.
- Throughput: good only if the pipeline is kept full with several micro-batches in flight; otherwise stages sit idle (the "bubble").
GPU utilisation
57%
Bubble
43%
In decode, continuous batching keeps many micro-batches in flight, so the bubble mostly hurts latency for a single stream, not throughput.
Rows = 4 GPUs, each holding a quarter of the layers. Columns = time slots. Grey = bubble (idle). More micro-batches in flight shrink the bubble.
With stages and micro-batches, the fraction of time lost to the bubble is about:
With 4 stages and only 1 micro-batch, three-quarters of the time is idle. With 16 micro-batches, the bubble falls to about 16%. Serving engines keep the pipeline full by having different batches at different stages at once.
In serving, pipeline parallelism is mostly used to fit very large models across nodes, combined with tensor parallelism inside each node.
#Expert parallelism: split the experts
For mixture-of-experts models, place different experts on different GPUs. Each token is routed to its chosen experts, wherever they live, using all-to-all communication.
- Memory: spreads the large total weight of all experts.
- Communication: two all-to-alls per MoE layer (dispatch and combine), with traffic depending on routing.
- Challenges: load balance (popular experts become hot spots) and all-to-all latency.
Large MoE deployments typically combine expert parallelism for the MoE layers with tensor or data parallelism for attention (MoE inference explained). Models with MLA attention often use data-parallel attention: each GPU runs attention for its own requests, avoiding duplicated KV cache, while the experts are shared across all GPUs.
#Context parallelism: split the sequence
A fifth option matters for very long prompts. Context parallelism splits one long sequence across GPUs: each GPU holds a slice of the tokens and their KV cache, and attention is computed by passing key and value blocks around a ring of GPUs (ring attention). It cuts prefill time for 100K-plus-token prompts and spreads one request's huge KV cache, at the cost of more communication. It's usually combined with tensor parallelism, and supported in some engines for long-context serving (long-context serving).
#How to choose
| Situation | Usually best |
|---|---|
| Model fits on one GPU with plenty of KV room | Data parallel replicas |
| Model fits on one GPU but you need lower latency | Tensor parallel 2 (or more), if you have NVLink |
| Model needs 2 to 8 GPUs, all in one NVLink node | Tensor parallel within the node |
| Model needs more than one node | Tensor parallel inside nodes, pipeline parallel across them |
| Large MoE model | Expert parallel for experts, plus tensor or data parallel for attention |
| Very long prompts (100K tokens and more) | Add context parallelism for prefill |
| Lots of traffic, latency target is relaxed | Fewer GPUs per replica, more replicas |
A useful rule: use the smallest tensor-parallel size that fits the model with enough KV cache and meets your latency target, then add replicas. Two replicas at TP=4 often serve more total traffic than one replica at TP=8, because each GPU does less communication and you get two independent schedulers. TP=8 wins when latency per token matters more than total throughput (how many GPUs do you need shows a case where the latency target forces TP=8).
#Setting it up
In vLLM, the main switches are (names may vary by version):
# TP=4 inside a node
vllm serve MODEL --tensor-parallel-size 4
# TP=8 inside each node, 2 pipeline stages across 2 nodes
vllm serve MODEL --tensor-parallel-size 8 --pipeline-parallel-size 2
# MoE: expert parallelism across the GPUs
vllm serve MODEL --tensor-parallel-size 8 --enable-expert-parallelSGLang has equivalents (--tp, --dp and options for data-parallel attention and expert parallelism). Before choosing a TP size, check how your GPUs are connected:
nvidia-smi topo -mNV entries mean NVLink between those GPUs; PIX, PHB or SYS mean PCIe paths, which are much slower for tensor parallelism.
#Common mistakes
- Tensor parallelism over PCIe without NVLink. Communication eats the gain.
- Tensor parallelism across nodes. Hundreds of all-reduces per step over the network is painfully slow; use pipeline parallelism across nodes instead.
- Maxing out TP by default. More GPUs per replica isn't free; measure TP=2, 4 and 8 for your workload.
- TP larger than the number of KV heads, which replicates KV heads and stops saving cache memory (GQA vs MQA vs MLA).
- Pipeline parallelism with small batches, leaving stages idle.
#FAQ
Does tensor parallelism change the model's outputs? Only at the level of floating-point rounding, because sums happen in a different order.
Can I mix GPU types in one tensor-parallel group? Not sensibly: the group runs at the speed of its slowest member. Keep groups uniform.
Is data parallelism always more efficient? Per GPU, usually, when the model fits on one GPU. It can't help when the model doesn't fit or when a single request needs lower latency than one GPU can give.
#Go deeper
Model parallelism covers all four strategies with the communication maths, and the tensor versus data parallel lab has you measure both on real GPUs. For a full sizing example, see how many GPUs do you need to serve an LLM.
parallelismmulti-gputensor-parallelservinginference-engineering
Found this useful?
Send it to someone who is learning the same thing.
Preparing for an interview?
Next: learn it step by step, free
Capacity planning and cost
Turn traffic and latency targets into a GPU count and a monthly bill. A free lesson with step-through diagrams and a quiz.