For 1M-token context decode, which parallelism axis actually relieves KV pressure?
Only sequence / context parallelism splits along the dimension that grows with context length, so at 1M tokens it is the parallelism axis that actually shrinks the per-GPU KV cache. TP, PP, and EP shard other dimensions.
Think about which way you slice a giant pizza. The cached conversation history at 1M words is a pizza that is enormous along one specific direction: how many words long it is. Splitting the math across GPUs by columns is like slicing the pizza into thinner and thinner radial wedges; that helps with width but not length. Splitting by stacking layers across GPUs is like piling pizzas in a tower (one per layer); it does not split any single pizza at all. The right move is to cut the pizza crosswise along its length, so each diner gets a shorter section of the long pizza. Splitting a long input across helpers is the only cut that reduces how much of the long axis any one diner has to hold.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Long-context inference is fundamentally a memory problem. The KV cache grows linearly with sequence length, and at 1M tokens for any modern model the cache is hundreds of gigabytes, far more than one GPU can hold. The question 'which parallelism solves this' is testing whether you can map the memory dimension that needs to shrink onto the parallelism axis that shards that dimension.
The right answer is sequence parallelism (also called context parallelism), and the reason is dimensional. KV is shaped along five axes: batch, sequence, layers, K-heads, and head-dim. Each parallelism strategy splits a different one of these axes. Sequence parallelism is the only one that splits the sequence axis.
The wrong options test the most common confusions: tensor parallelism sounds like it should shard 'attention' so people assume it shrinks KV per GPU at long context (it does, but only by a constant factor); pipeline parallelism splits the model so people assume it distributes 'everything' (it splits layers, not sequences); expert parallelism deals with MoE routing (irrelevant to attention KV). This deep-dive walks the dimensional analysis end to end so the right answer becomes obvious.
The KV cache as a five-dimensional tensor
Every transformer's KV cache has the same shape:
where the factor of 2 is K and V. At 1M context for Llama-3-70B (B=1, L=1e6, N_layers=80, H_kv=8, d_head=128, FP16):
That is the headline number. No single GPU has 327 GB of HBM; the cache must be split across GPUs.
The question is which axis to split along. Each parallelism strategy makes a specific choice:
- Tensor parallel (TP) shards H_kv (and the head dimension of attention). Per-GPU KV shrinks by TP degree along H_kv.
- Pipeline parallel (PP) shards N_layers. Per-GPU KV shrinks by PP degree along N_layers.
- Sequence / context parallel (SP / CP) shards L. Per-GPU KV shrinks by SP degree along L.
- Expert parallel (EP) shards MoE experts in the FFN. Per-GPU KV is unchanged because EP does not touch attention.
- Data parallel (DP) holds an independent copy per replica. Per-GPU KV is unchanged because B is replicated, not sharded.
The question's binding constraint is L (it just grew to 1M). The only strategy that splits L is SP / CP.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
| Parallelism axis | What it shards | KV-cache effect at long context | When it helps |
|---|---|---|---|
| Tensor (TP) | Heads, hidden dim, projection matrices | Constant-factor shrink (by TP degree); does not scale with L | Model too large for one GPU; modest context |
| Pipeline (PP) | Layers (depth) | No help; each layer's KV still full sequence on its GPU | Very deep models; weight budget bottleneck |
| Expert (EP) | MoE FFN experts | Zero effect on attention KV | MoE FFN distribution only |
| Sequence / Context (SP / CP) | Token sequence dimension (L) | Linear shrink in L; scales with context length | Long context (the canonical answer) |
| Data (DP) | Independent samples across replicas | Zero effect on per-sample KV | Throughput scaling, not memory |
Real products, models, and research that use this idea.
- Llama-3.1's 128k context support was enabled by training with context parallelism in Megatron-LM, not by tensor parallelism alone.
- Ring Attention (Liu, Yan, Abbeel 2023) demonstrated 1M+ context training on Llama-class models by ring-rotating KV blocks across GPUs.
What an interviewer would ask next. Try answering before peeking at the approach.
QIf a 70B-class model has KV cache of ~327 KB/token, what topology serves it at 1M context with reasonable headroom?
Total KV at 1M context, FP16: 1e6 * 327 KB = 327 GB. With TP-8 (KV per rank = 327 / 8 = 41 GB) and SP-4 across nodes (per-rank slice = 41 / 4 = ~10 GB), each GPU holds ~10 GB of KV plus its weight shard. Fits on H100 80 GB comfortably. Without SP, no single-node TP topology fits.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Believing tensor parallelism solves long-context memory. TP shards heads and projection weights, not the sequence dimension. At long context the KV per TP rank still scales linearly with context length and runs out.
60 second bullets to scan on the way to the call.
Primary sources. Browse if you want the original framing.
- Liu, Yan, Abbeel 2023, Ring Attention with Blockwise Transformers for Near-Infinite Context
- DeepSpeed-Ulysses: System Optimizations for Enabling Training of Extreme Long Sequence Transformer Models
- Megatron-LM long-context training documentation
- Llama-3 technical report (training topology for long context)
Same topic, related formats. Practice these next.