The five papers that turned the transformer from a research curiosity into something you can serve at scale: IO-aware attention, sparse experts, post-training quantisation, paged KV-cache memory, and speculative decoding.
Training a large model is one problem; serving it cheaply, with low latency, at high throughput, is an entirely different one. These five publications define the modern inference and serving stack — each attacks a distinct bottleneck: memory bandwidth, FLOPs-per-token, model footprint, KV-cache fragmentation, and sequential decoding latency.
Dao, Fu, Ermon, Rudra & Ré (Stanford), 2022 2022 · arXiv:2205.14135
Standard attention computes the full N×N score matrix, writes it to high-bandwidth memory (HBM), reads it back to apply softmax, writes again, reads again for the value matmul. On modern GPUs the arithmetic is cheap but the memory traffic dominates: attention is bandwidth-bound, not compute-bound. Materialising the quadratic matrix also makes memory scale as O(N²), capping context length.
FlashAttention reorders the computation to be IO-aware. It tiles the query, key and value matrices into blocks small enough to fit in the GPU's fast on-chip SRAM, and uses an online softmax (running max and running sum, rescaled as new blocks arrive) so the full attention matrix is never written to HBM. The result is exact attention — not an approximation — that is several times faster and whose memory footprint drops from O(N²) to O(N).
FlashAttention is the reason long-context models are economically viable. It is now the default attention kernel in PyTorch (scaled_dot_product_attention), vLLM, and every serious training stack. FlashAttention-2 (2023) improved work partitioning across warps for ~2× further speedup; FlashAttention-3 (2024) exploits Hopper-specific features (async TMA, FP8) to reach ~75% of an H100's theoretical FLOPs. You rarely call it directly — but if your attention is slow, the first question is whether the kernel is being dispatched at all.
On modern accelerators, the bottleneck is usually data movement, not arithmetic. The biggest wins come from algorithms that respect the memory hierarchy — reducing HBM reads/writes — rather than from reducing FLOPs. FlashAttention changes nothing mathematically; it changes where the bytes live.
Fedus, Zoph & Shazeer (Google), 2021 2021 · arXiv:2101.03961
In a dense transformer, every parameter is activated for every token, so raising capacity raises the per-token compute (FLOPs) in lockstep. That makes scaling to trillions of parameters prohibitively expensive both to train and to serve.
Switch Transformers replace the dense feed-forward block with a sparse Mixture-of-Experts (MoE) layer: a learned router inspects each token and sends it to a single expert FFN (top-1 routing — the “switch”). With E experts the model holds roughly E× the parameters of a dense block, but each token still passes through only one expert, so per-token FLOPs stay flat. The paper simplifies prior MoE work (top-1 instead of top-2), adds a load-balancing auxiliary loss to keep experts evenly used, and uses selective-precision and capacity-factor tricks for stable training — reaching 1.6 trillion parameters.
Top-1 routing: the router picks exactly one expert per token. Total parameters scale with E; active parameters (and therefore FLOPs) per token do not.
| Property | Dense FFN | Sparse MoE (top-1) |
|---|---|---|
| Parameters | 1× | ~E× (E = expert count) |
| FLOPs per token | 1× | ~1× (one expert active) |
| Bottleneck | Compute | Memory / VRAM to hold all experts |
| Routing risk | None | Load imbalance, token dropping at capacity |
MoE is now mainstream: Mixtral 8x7B (Mistral, 2023) uses 8 experts with top-2 routing — ~47 B total parameters but only ~13 B active per token, giving the quality of a much larger model at the inference cost of a small one. The serving catch is memory: you must hold all experts in VRAM even though most are idle each step, and throughput depends on routing being well-balanced across the batch. When you see “A active of B total parameters”, you are looking at this paper's idea.
Decouple capacity from compute. Sparsity lets you grow what the model knows without growing what it costs to run per token — trading cheap-but-abundant VRAM for expensive-and-scarce FLOPs.
Frantar, Ashkboos, Hoefler & Alistarh, 2022 2022 · arXiv:2210.17323
A 175 B-parameter model in FP16 needs ~350 GB of memory just to hold its weights — far beyond a single GPU. Naive rounding to low precision (round-to-nearest) destroys accuracy on large models, and quantisation-aware training is far too expensive to redo on a foundation model.
GPTQ is a one-shot, layer-wise post-training quantisation method. For each layer it minimises the reconstruction error of the layer's output using approximate second-order (Hessian) information — quantising weights one column at a time and updating the remaining full-precision weights to compensate for the error just introduced. It quantises down to 3–4 bits with negligible accuracy loss, and can process a 175 B model in a few GPU-hours using only a small calibration set.
| Precision | Bits/weight | 7B model | 70B model | 175B model |
|---|---|---|---|---|
| FP16 (baseline) | 16 | ~14 GB | ~140 GB | ~350 GB |
| INT8 | 8 | ~7 GB | ~70 GB | ~175 GB |
| GPTQ INT4 | ~4 | ~3.5 GB | ~35 GB | ~88 GB |
| GPTQ INT3 | ~3 | ~2.7 GB | ~27 GB | ~66 GB |
Weight memory only; excludes activations and KV cache. INT4 turns a 70B model from a multi-GPU deployment into a single-A100 deployment.
GPTQ (and the GPTQ file format) is one of the dominant ways quantised open-weights models are distributed and run — you have almost certainly downloaded a -GPTQ checkpoint. The complementary method to know is AWQ (Activation-aware Weight Quantization, Lin et al. 2023, arXiv:2306.00978): instead of Hessians it identifies the small fraction of salient weight channels — spotted via activation magnitudes — and protects them, which is often faster to apply and very competitive in accuracy. In practice you pick GPTQ or AWQ based on which has a clean kernel for your serving stack and your target hardware.
You can recover most of full-precision quality at ~4 bits by being clever about which error you minimise — not the per-weight rounding error, but the layer's output error, compensated across remaining weights. Quantisation is the cheapest lever for fitting a big model onto small hardware.
Kwon, Li, Zhuang, Sheng, Zheng, Yu, Gonzalez, Zhang & Stoica (UC Berkeley), 2023 2023 · arXiv:2309.06180
During generation, every request accumulates a KV cache — the keys and values of all previous tokens. Classic serving systems allocate one large contiguous buffer per request, sized for the maximum possible length. This wastes enormous memory to internal and external fragmentation and reserved-but-unused slots, so GPU memory — not compute — becomes the limit on how many requests you can batch.
PagedAttention applies the operating-system idea of virtual memory and paging to the KV cache. The cache is split into fixed-size blocks (pages) that need not be contiguous in physical GPU memory; a per-request block table maps logical positions to physical blocks. Blocks are allocated on demand (near-zero waste) and can be shared across requests — e.g. a common prompt prefix, or the parallel samples of one beam — via copy-on-write. Combined with continuous batching (admitting new requests as soon as slots free up), this multiplies serving throughput. It is the foundation of vLLM.
Each request reserves one big slab sized for max_len. Unused tail = wasted VRAM. Two requests of different lengths cannot share, and fragmentation strands free memory you cannot use.
KV cache is chopped into uniform blocks scattered across VRAM. A block table indirects logical → physical. Allocate per-token-block on demand; share identical prefix blocks across requests via copy-on-write.
vLLM is now one of the most widely deployed open-source inference servers. The paper reports up to 2–4× higher throughput than prior systems (FasterTransformer, Orca) at the same latency, by wasting under ~4% of KV memory instead of 60–80%. When you tune gpu_memory_utilization, block_size, or enable prefix caching, you are tuning the machinery from this paper.
The serving bottleneck is often memory management, not the model. Borrowing a 50-year-old OS abstraction — paging — for the KV cache turned LLM serving from memory-starved into throughput-bound. Sometimes the best ML systems idea is a classic systems idea.
Leviathan, Kalman & Matias (Google), 2022/2023 2023 · arXiv:2211.17192
Autoregressive decoding is inherently sequential: each token needs the previous one. Generation latency is therefore dominated by the number of forward passes through the big model, and each pass is memory-bandwidth-bound (you reload all the weights to produce a single token), so the expensive GPU sits massively underutilised.
Speculative decoding uses a small, cheap draft model to propose several future tokens, then runs the large target model once to score all of them in parallel. A clever acceptance/rejection test accepts the longest correct prefix and corrects the first wrong token from the target's own distribution. Crucially, the output distribution is provably identical to sampling from the target model alone — it is a pure latency optimisation, not an approximation — typically delivering a 2–3× speedup.
| Aspect | Standard decoding | Speculative decoding |
|---|---|---|
| Target passes per token | 1 (sequential) | < 1 amortised (k verified at once) |
| Output distribution | Target | Identical to target (provably) |
| Extra cost | None | Cheap draft model + rejected tokens |
| Best case | — | High when draft agrees with target often |
Speculative decoding is now standard in production servers (vLLM, TensorRT-LLM, TGI). Speedup depends on the acceptance rate — how often the draft agrees with the target — so a well-matched draft model (or a self-drafting variant like Medusa heads, or n-gram / prompt-lookup drafting) matters. It pairs naturally with the previous papers: it reduces latency, while PagedAttention and quantisation reduce memory, and FlashAttention speeds each pass.
Turn a sequential bottleneck into a parallel verification one. Because verifying k guesses in one batched pass costs almost the same as generating one token, a cheap draft model can buy a large speedup — with zero change to the output distribution.
O(N) memory. It is the default kernel everywhere; FlashAttention-2/3 push it further on newer GPUs.Presentation 05 — Context, Position & Retrieval — turns from how fast to how far: positional encodings (RoPE, ALiBi), context-length extension, long-context attention, and retrieval-augmented generation. The efficiency techniques in this deck are exactly what make those long contexts affordable to serve.