Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Prefill | Processing all the input tokens of a request in one parallel pass. The paper is one of the first to use this word (12.c). |
| Decode | Generating output tokens one step at a time after prefill. |
| MFU | Model FLOPs utilisation: useful model FLOPs actually achieved ÷ the hardware’s peak. 50% MFU means half the chip’s maths is doing real work. |
| Memory time / compute time | The time to stream weights and KV cache from HBM once, versus the time to do the step’s FLOPs at peak. The larger of the two is a lower bound on the step (30.a). |
| Partitioning layout | Which tensor dimension is split across which group of chips. |
| Weight-stationary | Each chip keeps its slice of the weights forever and the activations move between chips. |
| Weight-gathered | Activations stay put and the weights are all-gathered to the chips that need them, just in time. Worth it only when the batch is huge. |
| All-gather / reduce-scatter | Collectives that respectively assemble pieces from all chips, or sum and split results across chips (9.f). |
| 3D torus | TPU v4’s network: each chip links to neighbours in X, Y and Z, wrapping around at the edges. |
1. The paper#
- Title: “Efficiently Scaling Transformer Inference”
- Authors: Reiner Pope, Sholto Douglas, Aakanksha Chowdhery, Jacob Devlin, James Bradbury, Anselm Levskaya, Jonathan Heek, Kefan Xiao, Shivani Agrawal, Jeff Dean (Google)
- Venue: MLSys 2023 (arXiv November 2022).
- Link: arXiv:2211.05102
Where most papers in this module propose one trick, this one is a method for thinking: model memory time, compute time and communication time for every way of splitting a model, and pick the best split for each phase and batch size.
2. The problem#
Serving PaLM 540B, a dense 540-billion-parameter model, on TPU v4 chips with 32 GiB of HBM each:
- The weights alone (about 1 TB in bfloat16) need dozens of chips.
- The KV cache can be larger than the weights. For PaLM-sized multi-head attention at batch 512 and 2048 tokens of context, the paper computes about 3 TB, three times the parameters.
- Decode reads all of that for every token while the maths units sit mostly idle.
- Splitting across more chips cuts memory time per chip but adds communication, which eventually dominates. Megatron-style tensor parallelism (30.c) stopped scaling well past 16–32 GPUs.
Different applications want different things: a chatbot wants low latency per token at small batch; offline scoring wants maximum throughput per chip at any latency. No single layout serves both.
3. The idea#
Treat inference as an optimisation over partitioning layouts, with a simple analytical cost model:
step time ≳ max( memory time, compute time ) + communication timeThen:
- Separate prefill from decode. Prefill has many tokens per batch and is compute-bound; decode has few and is memory-bound. They get different layouts, chip counts and even weight formats.
- Pick the feed-forward layout by tokens per batch.
- 1D weight-stationary (Megatron-like): communication does not shrink as chips are added.
- 2D weight-stationary: split both d_model and d_ff across two torus axes, so communication per chip falls as √(number of chips). Best for small and medium batches — that is, decode.
- Weight-gathered (X, XY or XYZ): when the batch has hundreds of thousands of tokens (big prefill), moving the weights is cheaper than moving the activations.
- Shard multi-query attention by batch, not by head. MQA (30.d) has one KV head, so splitting by head would replicate the KV cache on every chip and throw away MQA’s savings. Splitting the batch across chips gives each chip only its own sequences’ KV cache.
- Low-level work: the “parallel” Transformer block (attention and FFN computed from the same input, as PaLM does), int8 weight quantization for low-latency decode, and overlapping communication with computation by looping over chunks of the matmul.
flowchart TD
W["Workload: phase, batch, latency target"] --> P{"Tokens per batch"}
P -- "few (decode)" --> WS["2D weight-stationary FFN, batch-sharded MQA, int8 weights"]
P -- "very many (big prefill)" --> WG["Weight-gathered FFN, bfloat16"]
WS --> CM["Check: memory, compute, communication time"]
WG --> CM
CM --> CH["Choose chip count on the latency-cost frontier"]
class W io
class P neutral
class WS,WG compute
class CM,CH queue4. How it works#
Cost model. A decoder-only model with N parameters does about 2N FLOPs per token. Memory time is (weight bytes + KV bytes) ÷ total HBM bandwidth. At small batch the weights dominate; at large batch and long context the KV cache does. Communication time comes from counting the bytes each collective moves and dividing by the torus link bandwidth.
Why 2D beats 1D. In 1D weight-stationary, each chip all-gathers the full activation of size batch × d_model each layer, regardless of how many chips there are, so adding chips stops helping. 2D splits the activation along a second axis and its communication falls with √chips. The paper shows 2D scaling to 64-way model parallelism on TPU v4 at 44% MFU, while FasterTransformer’s GPU benchmarks topped out at 33% MFU with 32-way tensor parallelism (46% at 16-way).
Why MQA needs a different layout. With multi-head attention, splitting heads across chips also splits the KV cache. With one KV head, head-splitting copies the whole cache everywhere. Splitting by batch keeps one copy, and the paper shows this allows 32× longer context in the same memory than multi-head attention with head sharding.
Choosing per scenario. The output is a Pareto frontier of latency against cost (chip-seconds per token), one point per (chip count, batch, layout) combination.
5. Results#
PaLM 540B on TPU v4, 2048-token context (Table 2):
| Scenario | Chips | Batch | FFN layout | Attention sharding | Weights | MFU | Latency |
|---|---|---|---|---|---|---|---|
| Low-latency prefill (2048 tokens) | 16 | 1 | 2D weight-stationary | head | int8 | 36% | 0.16 s |
| Low-latency decode (64 tokens) | 16 | 32 | 2D weight-stationary | batch | int8 | 8% | 0.73 s |
| High-throughput prefill | 32 | 512 | weight-gathered XYZ | batch | bfloat16 | 73% | 20.2 s |
| High-throughput decode | 8 | 512 | 2D weight-stationary | batch | bfloat16 | 37% | 5.1 s |
Headline numbers from the abstract and introduction:
- 29 ms per token at small batch during generation, with int8 weights, on 64 chips.
- 76% MFU during large-batch prefill.
- A chatbot turn on 64 chips — 64 new input tokens, 1920 tokens of cached history, 64 output tokens — in 1.9 s total.
- Offline: 1984 input + 64 output tokens per example at 73% overall FLOPs efficiency.
Note the 8% MFU for low-latency decode. That is not a failure; it is the roofline (30.a) at small batch, and the paper says so plainly.
6. What held up and what did not#
Held up
- Prefill and decode as separate problems with separate configurations. It is the seed of chunked prefill (30.t) and of disaggregated serving, which literally gives them separate machines (30.q, 30.w).
- Analytical cost models before benchmarks. Memory time, compute time and communication time is how capacity planning is done in 2026 (12.q, 23.b). The paper’s vocabulary — prefill, decode, MFU for inference — is now everyone’s.
- Layout by phase and batch size. Modern engines pick different parallelism for prefill and decode workers (for example wide expert parallelism for decode in DeepSeek’s serving, 30.v).
- Shard KV by batch (data parallel attention) when KV heads are few. vLLM and SGLang’s “DP attention” for MLA models is the same insight (14.h, 19.a).
Did not, or changed
- The specific 2D/weight-gathered layouts are tied to TPU’s 3D torus. GPU servers have an all-to-all NVLink domain of 8, now 72 GPUs (7.d), so GPU engines mostly use plain TP within the domain plus data, pipeline or expert parallelism across it.
- Dense 540B models gave way to MoE models, which add expert parallelism and all-to-all traffic the paper does not cover (30.e).
- It assumes static batches per scenario. Continuous batching (30.g) and paged memory (30.o) changed how batch size behaves in a real server.
7. Where it lives in 2026#
- Taught in depth: prefill versus decode in 12.c, capacity math in 12.q, tensor parallelism in 14.c, communication cost in 9.g, TPU in 7.i.
- Google’s JAX serving stack and the public “How to Scale Your Model” book (Austin et al., 2025) extend the same analysis to newer TPUs and GPUs.
- The first author, Reiner Pope, later co-founded MatX, a startup designing chips for LLMs.
Checked on 13 November 2026.
8. Questions#
- Write the paper’s step-time bound. When does memory time dominate, and which memory?
- Why does 1D weight-stationary partitioning stop scaling, and how does 2D fix it?
- When is it cheaper to move weights than activations?
- Why must multi-query attention be sharded by batch rather than by head?
- The low-latency decode configuration ran at 8% MFU. Is that bad? Explain with the roofline.
- Why does the paper use int8 weights for low-latency decode but bfloat16 for high-throughput?
- How would you adapt this analysis to a 72-GPU NVLink domain serving an MoE model?
9. Further reading#
- arXiv:2211.05102 — sections 2 and 3 are the method.
- Austin et al., “How to Scale Your Model” (Google DeepMind, 2025) — the same reasoning, taught as a book.
- 12.c, 12.q and 9.g in this material.
- Next: SmoothQuant (30.k).