Inference

Wiki chapters and blog posts about Inference.

Wiki

Production evaluation for LLMs: replay, canaries, and rollback

Production evaluation connects model quality, system reliability, and user outcomes. Compare versions on paired requests, set release gates for critical slices, and use shadow traffic, canaries, and randomized experiments to answer different release questions.

Intermediate 8 min read

Efficient Attention: MQA, GQA, MLA and FlashAttention

Attention has two bottlenecks: the KV cache that decoding rereads at every step, and the N×N score matrix of training and prefill. MQA, GQA and MLA shrink the KV cache; FlashAttention cuts memory traffic with tiling and online softmax, and its output is identical to standard attention.

Intermediate 27 min read

Test-Time Compute: Spending Compute on Inference

Test-time compute is extra computation spent while answering each question: voting over samples, verifier selection, revision, search and RL-trained long chains of thought. A reproducible simulation shows what caps the gain, what a fooled verifier does and why wall-clock time differs.

Advanced 28 min read

Decoding and Sampling: Temperature, Top-k, Top-p and Beam Search

Decoding turns the model's output distribution into tokens: greedy picks the most likely one, temperature sharpens or flattens the distribution, top-k and top-p cut off the unlikely tail, and beam search keeps several candidates. Together they set how deterministic and diverse the output is.

Beginner 14 min read

KV Cache and Inference Performance

Understand how the KV cache removes repeated computation from autoregressive decoding, and master the trade-offs between latency, throughput, memory and request scheduling.

Intermediate 18 min read

Prefix Caching and PD Disaggregation: Pay for Repeated Compute Once

Prefix caching reuses the KV cache of system prompts, shared documents, and chat history across requests (RadixAttention, CacheBlend, LMCache). PD disaggregation places compute-bound prefill and bandwidth-bound decoding on different hardware; DistServe, Splitwise, and Mooncake show when it pays off.

Intermediate 12 min read

Model Quantization: INT8, INT4, GPTQ and AWQ Explained and Measured

Quantization stores weights, activations or the KV cache in fewer bits. This page starts from the memory budget, builds up from scales and groups, measures INT8 and INT4 on Qwen2.5-0.5B, implements SmoothQuant, AWQ-style scaling, GPTQ and KV-cache quantization, and ends with a selection guide.

Intermediate 55 min read

Speculative Decoding: Draft with a Small Model, Verify with a Large One

Speculative decoding lets a small, fast draft model guess the next few tokens and the large model verify them in one parallel forward pass, with an accept-and-correct rule that keeps the output distribution unchanged. This page derives the expected speedup and lets you tune it interactively.

Intermediate 15 min read

LLM Cheat Sheet: Estimating Parameters, Compute, Memory and Decoding Speed

One page for the estimates you reuse most: counting parameters, training compute (about 6ND), memory for weights, training state and the KV cache, the bandwidth bound on decoding speed, and the LoRA and pass@k formulas, each with a standard-library script checked against published numbers.

Intermediate 24 min read

GPUs and the Roofline Model: Why Big Models Are Bound by Memory Bandwidth

A GPU is limited by two walls: how many operations it can do per second (compute) and how many bytes it can move per second (memory bandwidth). The roofline model uses arithmetic intensity to tell which wall an operator hits first. This page derives it and measures it on a CPU.

Intermediate 41 min read

GPU kernels: from tiled matrix multiplication to fusion

GPU kernel tuning combines thread-level memory access, on-chip reuse, and output stores. Derive the logical traffic of tiled matrix multiplication with edge masks, check it with a CPU experiment, and trace practical limits from staging buffers to register spills.

Intermediate 9 min read

Blog posts

vLLM and PagedAttention: Managing the KV Cache Like Paged Memory

The vLLM paper (SOSP 2023) brings operating-system paging to the KV cache: fixed-size blocks, on-demand allocation, a block table, copy-on-write sharing. This post checks the paper's numbers and shows the real range behind the headline 2-4x, what it was compared with, and where it stops applying.

Paper notes SOSP 2023

Fast Inference from Transformers via Speculative Decoding

In speculative decoding a small draft model guesses several tokens, the large model verifies them in one parallel pass, and a sampling rule keeps the output distribution unchanged. This post reads the paper's formulas, recomputes its Tables 1 and 4, and explains the 1.4x to 3.4x measured on T5-XXL.

Paper notes ICML 2023

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

FlashAttention computes exact attention block by block in the GPU's on-chip SRAM, so the N×N score matrix never goes to GPU memory. HBM accesses fall from Θ(Nd+N²) to Θ(N²d²/M); BERT trains about 15% faster, GPT-2 3.0 to 3.5 times faster than HuggingFace. A breakdown of the paper.

Paper notes NeurIPS 2022

Topics