Summary
A one-lecture treatment of inference, placed between the two scaling-law lectures. It argues that inference is a fundamentally different workload from training because autoregressive generation cannot parallelize over the sequence dimension, then works through the arithmetic intensity of the MLP and attention layers to show exactly where the bottleneck sits. The second half is a survey of ways to make inference faster: shrinking the KV cache through architecture changes, quantization, pruning and distillation, lossless speculative decoding, and serving-system techniques for dynamic workloads. The framing throughout is that inference is memory-bound, so almost every technique reduces to moving fewer bytes without losing accuracy.
Key Takeaways
- Training is a one-time cost but inference is a repeated one: OpenAI is estimated to produce around 8.6 trillion tokens a day, so in under four days it generates as many tokens as DeepSeek-V4 was trained on (32 trillion). With agents, most generated tokens are never read by a human, so token count is effectively compute spend and there is no point at which “fast enough” saturates.
- Three metrics that trade off: time to first token (essentially prefill time), latency (tokens per second for one query), and throughput (tokens per second across all queries). Batch size moves latency and throughput in opposite directions.
- The core asymmetry: in training the sequence is just another tensor dimension, but generation produces one token at a time, so arithmetic intensity stays low. MLP intensity is roughly B·T, which makes prefill compute-bound and generation acceptable given enough concurrent requests; attention during generation has intensity below 1, versus the roughly 295 an H100 needs to be compute-bound.
- Attention is the fundamental bottleneck because every sequence has its own KV cache, so increasing batch size does not amortize anything — unlike MLP weights, which are loaded once and shared across the batch.
- KV cache reduction is the main lever, since memory is the constraint: grouped-query attention shrinks the cache by N/K; DeepSeek’s multi-head latent attention compresses activations into a smaller latent (16k to 512 in DeepSeek-V2) and materializes K and V on demand, needing extra dimensions because it is incompatible with RoPE; cross-layer attention shares KV across layers; sliding-window attention makes the cache independent of sequence length but costs accuracy, so practical models interleave local and full-attention layers.
- Quantization-aware training simulates quantization error in the forward pass but needs expensive large-scale training, so post-training quantization is more common: GPTQ quantizes layer by layer using Hessian information and propagates the error into the not-yet-quantized weights, while activation-aware methods spend higher precision on the weights that interact with large activation channels.
- Pruning estimates unit and layer importance from activation magnitudes on a calibration set, removes parts of the model, then post-trains to heal it; an NVIDIA result took a 15B model down to 8B at modest accuracy cost and far less compute than training from scratch.
- Speculative decoding is lossless, not approximate: a cheap draft model proposes K tokens, the target model scores them in one parallel pass, and each is accepted with probability min(1, q/p), otherwise a token is drawn from the residual distribution. This is rejection sampling that always yields a sample, and the sweet spot is around three or four draft tokens — too few wastes the target model’s batching, too many get rejected.
- Serving under dynamic load: continuous batching (Orca) adds arriving requests to the batch and evicts finished ones each decode step, selective batching concatenates variable-length sequences for the MLP layers where attention cannot be shared, and PagedAttention (vLLM) stores the KV cache in non-contiguous blocks to kill internal and external fragmentation, which also allows shared system prompts and copy-on-write prefix sharing across samples.
- Closing argument: the transformer’s KV cache makes it inherently inference-unfriendly, so architectures designed for inference (state space models, linear attention, diffusion) may hold the largest remaining gains.
Extracted Notes
- None yet.