Serving one request
Running a model in production means serving it. An inference server waits for requests. Your app sends a prompt over HTTP, "Write a haiku about the sea", and the server queues it until the GPU, the chip that runs the model, is free.
Before any request, the server loads the weights, the model's learned numbers, into GPU memory. Our example: 13 billion weights at 2 bytes each (16-bit numbers) is 26 GB, about two thirds of a 40 GB GPU.
First comes prefill. All the prompt's tokens go through the model in one pass, side by side. Every layer saves each token's key and value vectors, what attention looks up later, in the KV cache. Out comes the first new token.
Then decode: one new token per step. The newest token goes in, its key and value join the cache, and attention reads all the cached ones instead of recomputing them. The cache grows by one token every step.
Memory and speed
Each token stores a key and a value in each of 40 layers, 5,120 numbers each, 2 bytes per number: 819,200 bytes, about 0.8 MB. A full 2,048-token request needs about 1.7 GB of cache.
Each decode step reads all 26 GB of weights from memory. This GPU reads 1,555 GB per second, so a step takes at least 17 ms: at most about 60 tokens a second for one request. Memory, not arithmetic, is the limit.
Serving many users
So servers batch: many requests run through the same step, and one read of the weights serves them all. With continuous batching, a new request joins at the very next step instead of waiting for the whole batch to finish.
Older servers reserved cache for the longest possible answer up front, and only 20 to 38% of it held real tokens. vLLM's PagedAttention hands out small blocks only when needed, anywhere in memory, and raises throughput 2 to 4 times.
Quantization stores each weight in fewer bits. At 4 bits our 26 GB of weights shrinks to 6.5 GB, leaving far more room for cache, and so for bigger batches. Methods such as GPTQ keep the accuracy loss small; always measure it.
Each new token is sent to your app the moment it is made, so text appears while the model is still writing. Time to first token is the queue plus prefill; after that, each token takes one decode step.
What happens
;; step 1/10 · request POST /v1/completions (HTTP request) prompt "Write a haiku about the sea" max_tokens 64 the server queues it until the GPU can take it
The numbers are the worked example from the vLLM paper: a 13-billion-weight model (OPT-13B) on one NVIDIA A100 with 40 GB. The paper writes the KV cache as 800 KB per token and 1.6 GB per request, counting in binary units (1 KB = 1,024 bytes); here 1 GB = 10^9 bytes. The cache blocks in the figure hold 4 tokens so they stay readable; vLLM uses 16 tokens per block by default. Real KV caches also live in every layer at once, not in one row.