“The model is slow” is not specific enough. The input may be long, caches may fill memory, or requests may wait for one another. Locate the delay before choosing an optimization.

Follow one request

In one linePrefill handles the given context; decode extends it from the cache. Sampling picks the token; caching decides which state is kept.

input text → token IDs → prefill → first token
                                      ↓
                   update KV cache ← decode → sample next token
                                      ↓
                              stop and release state

This simplified autoregressive path does not prescribe a scheduler. Prefill processes the existing context; decode uses cached state to continue generation. Sampling decides which token to select, while caching decides which state to retain and read. They solve different problems.

Similar names, different interventions

In one lineEach method changes one thing, such as token choice, KV layout, positions or data movement. Saving memory does not mean end-to-end speedup.

Method Main intervention What does not follow
Temperature / top-p Token selection from the output distribution More randomness does not imply greater capability
KV cache Reuse of prefix keys / values Caching does not remove subsequent reads of history
MQA / GQA Number and sharing of KV heads Memory reduction is not end-to-end speedup
RoPE / YaRN Position representation and long-context handling Accepting a long input is not using its evidence well
NoPE and sequence order No added explicit position encoding; order information has to come from elsewhere It does not remove order information, and it is not training-free context extension
FlashAttention Attention-related memory traffic Dense attention pairs do not disappear
PagedAttention Physical allocation and sharing of KV state It does not make attention sparse
MLA Representation stored for each position Compressing state differs from reading fewer positions
Sparse attention Query–key pairs included in computation Omitted pairs are not necessarily unimportant

Start with generation and caching below, then move to long context and efficient attention. If you already understand decoders, find the particular mechanism you need to distinguish.

Chapter contents

In one lineFollow one request through a service, learn where prefill and decode each get stuck, then size one GPU. Read DFlash-style speedups last.

For the engines that serve a model, read vLLM and SGLang: separate the application, engine, and kernels, then examine batching, prefix reuse, HiCache, and benchmarking. Mechanisms live here; product integration and ownership belong in an ML system in production.

To follow a request through an actual service, read a request through the system. It connects input preparation, queues, caching, model execution, and output, then uses a chunking example to explain first-token versus streaming latency. If you already deploy models, jump to the KV memory budget or cache eviction.

For why prefill is limited by compute and decode by memory bandwidth, read Prefill & decode; if that is shaky, walk the hardware track first. To put it together and work out how many requests one GPU can take when the first token has a deadline, read capacity.

Once decode and caching are clear, DFlash and MTP examines reducing target-model rounds: follow drafting and verification, then rejection, cache rollback, and costs. Beginners do not need every acceleration method first.

01

Generation, context & inference

18 notes

Separate token selection, cached state, memory traffic, and the number of attention pairs.

A small performance diagnosis

In one lineThe first token arrives after 800 ms; later tokens arrive 20 ms apart. These timings alone don't separate queueing, compute and delivery.

Suppose a request waits 800 ms for its first token, then receives a token every 20 ms. These intervals measure different parts of the experience. The first can include queuing, prefill, and the first generation step; the second reflects ongoing decode. The decode roofline example explains why decode at small batch sizes is mostly limited by memory bandwidth. Reporting only average tokens/s hides the distinction.

If inputs grow longer, inspect prefill and cache reads. If concurrency delays the first token, inspect queuing, scheduling, and resource contention. This example illustrates measurement decomposition, not proof of a particular bottleneck.

Hold fixed when comparing Report alongside it
Model, weights, tokenizer, precision Output quality and numerical tolerance
Input/output length distributions, concurrency Time to first token, inter-token intervals, end-to-end latency
Hardware, batch, cache state Useful throughput, peak memory, tail latency

Training-side memory belongs in pretraining and training mechanics, rather than an inference-cache checklist. Version-specific claims still need the model report and implementation.