Notes

Compute for Inference

Training a model happens once. Answering with it happens forever. Compute for inference is the arithmetic spent every time the model produces text, and across a deployed model's life it is usually the larger bill.

Two phases, two bottlenecks

A request splits in half. Prefill reads the whole prompt in parallel and is compute-bound — roughly 2 × N FLOPs per token for an N-parameter dense model — so it saturates the accelerator's arithmetic units. Decode then emits one token at a time, and each step must stream the entire set of weights out of memory to produce that single token, which makes it memory-bandwidth-bound. This is why a model can be quick at reading and slow at writing. Meanwhile the KV cache grows with every token in play, so long contexts and many simultaneous users compete for memory rather than for FLOPs.

What is done about it
  • Quantization to 8- or 4-bit weights, which cuts both the memory footprint and the bytes moved per token.
  • Continuous batching and paged attention, so one weight read does useful work for many requests at once — the core of what vLLM provides.
  • Speculative decoding, where a small model drafts tokens that the large one verifies in parallel.
  • Grouped-query attention and prompt caching, which shrink the KV cache and skip prefill that has already been paid for.

Get this wrong and the symptoms are immediately visible to the user: a long wait for the first token, a thin trickle of tokens-per-second, requests queued behind a few enormous contexts, and a serving bill that makes the product uneconomic at the price you charge for it.

Compute for inference is the arithmetic spent each time a model generates text — roughly 2 × parameters FLOPs per token for a dense model, split between a compute-bound prefill of the prompt and a memory-bandwidth-bound decode of one token at a time. Because a model is served far more often than it is trained, this dominates lifetime cost, and it sets latency, throughput and how many concurrent users one accelerator can hold.

Teaching the model is a one-off expense. Using it is the expense that never stops. Compute for inference is the computing power burned every single time the assistant answers a question — and since millions of people are asking at once, all day, this is where the money actually goes.

It also explains two things you can feel while you wait. The pause before the first word appears is the system reading your question. The steady trickle of words after that is it writing one word at a time, consulting its entire memory again for each one. Making that trickle faster and cheaper, without making the answers worse, is an engineering speciality all of its own.