When do you use tensor parallelism vs. pipeline parallelism vs. data parallelism for LLM inference?
Written by the mlprep team · Updated
You need to serve a 70B parameter model (FP16 ≈ 140 GB of weights) on a cluster of 80 GB GPUs. Walk me through how you choose between Data Parallelism, Tensor Parallelism, and Pipeline Parallelism — and how each one affects latency, throughput, and interconnect requirements.
First check: memory capacity#
A 70B FP16 model needs ~140 GB just for weights, plus tens of GB for KV cache and activations. It physically cannot fit on a single 80 GB GPU — so you need at least 2 GPUs (or 4 GPUs with healthy KV cache headroom) per model replica using model parallelism (TP or PP), and then you scale out replicas with Data Parallelism (DP).
1. Data Parallelism (DP) — best for throughput#
- Replicate the entire model across independent instances; a load balancer routes different requests to different replicas.
- Communication: Zero GPU-to-GPU sync during inference.
- Effect: Linearly scales throughput (QPS) with zero overhead, but does not reduce single-request latency and cannot fit a model larger than one replica's memory.
- Rule of thumb: Always prefer DP once a model fits and meets your latency SLA.
2. Tensor Parallelism (TP) — best for reducing latency#
- Split each layer's weight matrices (attention heads and FFN columns/rows) across
NGPUs (Megatron-style column-parallel -> row-parallel). - All
NGPUs execute the same token step in parallel, reading1/Nof the weights from HBM — cutting memory-bandwidth time per decode step nearly byN×. - Communication: Requires 2
AllReducecollectives per transformer layer (one after attention, one after FFN). For an 80-layer 70B model, that's 160 synchronousAllReducebarriers per single generated token. - Interconnect requirement: Only practical over ultra-fast intra-node NVLink / NVSwitch (e.g.,
TP=2, 4, or 8inside a single 8-GPU node). Running TP across nodes over Ethernet/InfiniBand kills latency due to network round-trips on every layer.
3. Pipeline Parallelism (PP) — best for cross-node sharding / memory capacity#
- Partition layers sequentially across GPUs (e.g., layers 0–39 on Node 1, layers 40–79 on Node 2).
- Communication: Only sends a single activation tensor point-to-point between stage boundaries (
Send/Recv) — tiny bandwidth compared to TP's 160AllReducecalls. - Effect: Increases memory capacity and sustains high throughput (via micro-batching across concurrent requests), but does not reduce single-request latency (a single token still passes sequentially through every layer, plus inter-stage hop latency and pipeline bubbles under low load).
Strategy | Reduces Latency? | Scales Throughput? | Interconnect Needed
---------|------------------|--------------------|--------------------
DP | No | Best (linear) | None
TP | Yes (strong) | Good (diminishing) | NVLink (intra-node)
PP | No (slightly +) | Good (high batch) | InfiniBand / PCIe
Practical recipe for 70B FP16 on 8×80GB H100s#
- If latency SLA is tight:
TP=4, DP=2(two 4-GPU replicas inside the 8-GPU node; each replica has 320 GB HBM -> 140 GB weights + ~160 GB KV cache, fast TPOT). - If you want maximum throughput per dollar and can quantize to FP8 (~70 GB weights):
TP=2, DP=4(four 2-GPU replicas — half the AllReduce overhead, much higher aggregate throughput).
What changes when you serve a massive Mixture-of-Experts (MoE) model like DeepSeek-V3 or Mixtral? Why does Expert Parallelism enter the picture?
Why MoE changes the parallelism trade-off#
In a dense model, every token multiplies by every weight matrix. In an MoE model, each token only routes to k experts (e.g., top-2 or top-8 out of 64–256 experts).
- If you slice each small expert across 8 GPUs with Tensor Parallelism, each GPU's GEMM becomes tiny and underutilized, while you still pay full
AllReducesync costs. - With Expert Parallelism (EP), each GPU holds a distinct subset of whole experts (e.g., 32 experts per GPU). An
AllToAlldispatch sends each token to the GPU holding its chosen expert, computes full-size expert GEMMs locally, and anAllToAllcombine returns the results.
Combining DP for attention + EP for experts#
In large-scale MoE serving (e.g., DeepSeek's architecture), systems often run Data Parallelism on the attention layers (avoiding duplicating KV caches across TP ranks) and Expert Parallelism across a large GPU pool on the FFN layers — keeping batch sizes large enough to saturate compute while holding hundreds of gigabytes of expert weights across nodes.
Senior/staff considerations#
- TP efficiency drops past TP=4/8 because AllReduce latency becomes a non-trivial fraction of the ~10–20ms decode step time, and KV heads in GQA (e.g., 8 KV heads) cannot be cleanly sharded beyond
TP=8without duplicating KV caches. - Load imbalance in EP: Popular experts become stragglers during
AllToAll. Production serving monitors per-expert token counts and can replicate hot experts across GPUs (redundant experts).
Interview red flags#
- Suggesting
TP=16across two 8-GPU nodes over standard networking without mentioning inter-node AllReduce latency collapse. - Claiming Pipeline Parallelism reduces single-request latency (it increases memory capacity and throughput, never single-request latency).
- Forgetting that quantization (e.g., FP16 -> FP8) can drop required TP degree from
TP=4toTP=2, which often gives a bigger throughput boost than tuning scheduling.
The key takeaway unlocks after you reveal an expert answer.
Key Takeaway
Use the smallest Tensor Parallelism degree needed to fit weights + KV cache and hit your latency SLA (staying within NVLink intra-node), then scale out horizontally with Data Parallelism for maximum throughput. Reserve Pipeline Parallelism for cross-node models that don't fit on one node, and use Expert Parallelism for large MoE models.
Follow-up Questions to Test Yourself
Interviewers often pivot here once you cover the core concept.
- Why does GQA with 8 KV heads create a natural ceiling for Tensor Parallelism at TP=8?
- When serving a 70B model on an 8×H100 node, how would you decide between
TP=8, DP=1vs.TP=4, DP=2? - How does
AllToAllcommunication in Expert Parallelism behave at small batch sizes vs. large batch sizes?
How confident do you feel explaining this?
Track your understanding or flag it to revisit before your next loop.
Related Questions
How do you deploy speculative decoding in production — draft selection, tree attention, and batch-size trade-offs?
Why do prefill and decode have opposite hardware bottlenecks, and how does disaggregated serving help?
Explain PagedAttention and how vLLM eliminates KV cache memory fragmentation
How would you design an LLM serving system for millions of users?