New to inference? Start with these three notes.

  1. How is the next token picked? The model returns a score for each token. Why might the same prompt end differently if you change the temperature?
  2. What can the model keep from the last step? The KV cache holds keys and values, not ready-made answers.
  3. Follow one request from prompt to final token. With four inputs and three outputs, you can trace exactly where prefill ends and what decode still has to compute.

To see what changes when requests share a GPU, follow a long prompt arriving mid-stream. For the separate question of how many requests fit, see serving capacity.

12 core notes, about 2.5 h. 4 deep dives fold under the notes they extend.

One generation4

How the next token is sampled, what the KV cache saves, and why prefill and decode differ

  1. Inference: from the next token to a complete requestFollow one request to find where the time goes, then read sampling, caching, engines4 min
  2. Decoding strategies: temperature, top-k, top-pThe model gives a distribution; top-k fixes the count, top-p the probability mass14 min
  3. KV cache: what do we stop computing, and start storing?Keep old K/V instead of recomputing: with 7B weights, 24 GiB fits six 8K caches8 min
  4. One generation: from prefill and decode to engine schedulingFour tokens in, three out: one prefill, two decodes, and why the bottlenecks differ11 min

Serving and engines2 core · 2 deep

Many requests at once: queueing, batching, prefix reuse, and how much one GPU can take

  1. What happens between an LLM request and the answer on screen?Queue, schedule, output: batching four finishes all sooner, but the first one later9 min
  2. How many requests can one GPU take when the first token has a deadline?Qwen3-4B on a 4090 at a 1 s P99: two slots reach 60–71% of full load, eight 82–93%9 min
  3. vLLM and SGLang: what a generation engine actually doesLong prompts, quick asks, cancellations: how engines batch, reuse prefixes and scale27 min
  4. Prefix caching in hybrid models: why did 8 samples each compute the prompt?State not cached yet, or evicted by LRU; hold it and cap groups: 19–27% faster10 min

Making it faster2

Same output, faster: kernels that move less data, and drafting tokens then verifying them

  1. FlashAttention and PagedAttention: what does each save?Flash avoids writing the full probability matrix; Paged stores KV in blocks12 min
  2. DFlash: drafting, verification, and speedThe target verifies a drafted block; after a rejected X, even a correct D is dropped9 min

Quantization4 core · 2 deep

What fewer bits buy: where error comes from, weight-only, FP8 and KV, and measuring the loss

  1. Quantization: what fewer bits buy, and what they cost70B needs 140 GB in BF16; in order: formats, weight-only, FP8 and KV, quality checks10 min
  2. Quantization: FP8 inference and KV-cache quantizationAt 128K one sequence's KV is 16 GiB; in FP8 an 80 GB H100 holds six, not three14 min
  3. Quantization: how to measure what was lostMMLU drops 0.45 points yet 4.26% of answers flip: check KL, pairs and weak slices11 min
  4. Quantization: where the error comes from when numbers are squeezed onto a gridThe largest value sets the step: turn 1.40 into 14.0 and the other seven round to 017 min
  5. Quantization: weight-only compression and post-training quantizationW4A16 cuts the batch-1 step bound from 4.77 to 1.45 ms; GPTQ and AWQ limit the error16 min
  6. Quantization: review questionsReview: what W4A16, W8A8 and FP8 KV each buy, and how the bottleneck decides10 min