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.
Detailed answer & concept explanation~8 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
30 sec: KV cache shape and which axis is too big at 1M (it is L). 1 min: each parallelism splits a different axis (TP heads, PP layers, EP experts, SP sequence). 1 min: only SP / CP attacks L. 1 min: explain ring attention or all to all communication during the attention op. 30 sec: production stack is TP + SP.
| 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.
- DeepSpeed-Ulysses provides an all to all sequence-parallel attention implementation used in long-context training pipelines.
- Gemini 1.5 / 2 with 1M to 2M context is widely believed to use ring-style attention across many TPU pods.
- Anthropic's Claude long-context handling at 200k+ context likely uses some form of sequence partitioning in serving; the exact mechanism is undisclosed.
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?
QWhy is ring attention bandwidth-efficient compared to all to all sequence parallel?
QDoes sequence parallelism help with prefill too, or only decode?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes 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.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim 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.