Key LLM Publications Series — Presentation 04

Efficient Inference & Serving

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.

FlashAttention Mixture of Experts GPTQ PagedAttention/vLLM Speculative Decoding KV Cache
KV Cache → IO-aware Attention → Sparse MoE → Quantisation → Paged Serving → Speculative Decode
00

The Five Papers

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.

01

FlashAttention — Fast and Memory-Efficient Exact Attention with IO-Awareness

Dao, Fu, Ermon, Rudra & Ré (Stanford), 2022 2022 · arXiv:2205.14135

The problem

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.

The contribution

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).

GPU memory hierarchy — keep the working set in SRAM SRAM (on-chip) ~20 MB · ~19 TB/s Q/K/V tiles load tiles write output HBM (off-chip) 40–80 GB · ~2 TB/s Q, K, V, O stored here N×N matrix NEVER materialised Online softmax: running max m and running sum ℓ are rescaled as each K/V block streams in, so the exact softmax-weighted output is built incrementally without the quadratic buffer.
N×N matrix in HBM
→
Tile Q,K,V into SRAM
→
Online softmax per block
→
Stream output to HBM

Why it matters to a practising engineer

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.

The lesson

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.

02

Switch Transformers — Scaling to Trillion Parameter Models with Simple and Efficient Sparsity

Fedus, Zoph & Shazeer (Google), 2021 2021 · arXiv:2101.03961

The problem

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.

The contribution

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.

Token
→
Router
softmax gate
→
Expert 1
Expert 2 ✓
Expert 3
… Expert E
→
Output

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.

PropertyDense FFNSparse MoE (top-1)
Parameters1×~E× (E = expert count)
FLOPs per token1×~1× (one expert active)
BottleneckComputeMemory / VRAM to hold all experts
Routing riskNoneLoad imbalance, token dropping at capacity

Why it matters to a practising engineer

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.

The lesson

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.

03

GPTQ — Accurate Post-Training Quantization for Generative Pre-trained Transformers

Frantar, Ashkboos, Hoefler & Alistarh, 2022 2022 · arXiv:2210.17323

The problem

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.

The contribution

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.

PrecisionBits/weight7B model70B model175B model
FP16 (baseline)16~14 GB~140 GB~350 GB
INT88~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.

Why it matters to a practising engineer

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.

The lesson

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.

04

PagedAttention & vLLM — Efficient Memory Management for LLM Serving

Kwon, Li, Zhuang, Sheng, Zheng, Yu, Gonzalez, Zhang & Stoica (UC Berkeley), 2023 2023 · arXiv:2309.06180

The problem

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.

The contribution

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.

Before — contiguous allocation

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.

After — paged blocks

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.

Block table maps logical tokens to non-contiguous physical KV blocks Request A logical: b0 b1 b2 Request B logical: b0 b1 Physical VRAM pool: · scattered, no contiguity needed

Why it matters to a practising engineer

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 lesson

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.

05

Speculative Decoding — Fast Inference from Transformers

Leviathan, Kalman & Matias (Google), 2022/2023 2023 · arXiv:2211.17192

The problem

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.

The contribution

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.

Draft model
proposes k tokens
→
Target model
1 parallel pass scores all k
→
Accept longest correct prefix
→
Reject & resample first mismatch
AspectStandard decodingSpeculative decoding
Target passes per token1 (sequential)< 1 amortised (k verified at once)
Output distributionTargetIdentical to target (provably)
Extra costNoneCheap draft model + rejected tokens
Best case—High when draft agrees with target often

Why it matters to a practising engineer

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.

The lesson

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.

06

What to Take Away

Where to next

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.