Module 7 · AI infrastructureLesson 88 of 887 minAdvanced
How vLLM works
vLLM is a popular LLM serving engine. Its PagedAttention manages KV cache memory like an OS manages RAM, so far more requests fit per GPU.
Watch "Reserve max length" leave most memory reserved but empty, with few requests running. Switch to "Paged (vLLM)" and compare.
vLLM, started at UC Berkeley, became one of the most widely used engines for serving LLMs. It brings together ideas from this module, plus one important new one.
The problem: KV cache memory
Every running request needs KV cache memory that grows with each generated token. Before vLLM, servers typically reserved a contiguous block for the maximum possible length when a request started, because they didn't know how long the answer would be.
Most answers are much shorter than the maximum, so most reserved memory sat empty. Memory, not compute, limited how many requests could run, and much of it was wasted.
PagedAttention
vLLM borrows the idea of virtual memory paging from operating systems:
- KV cache is split into small, fixed-size blocks (for example, 16 tokens each).
- A request gets a new block only when it needs one, from anywhere in memory.
- A block table maps each request's logical blocks to physical ones, and the attention kernel reads through it.
Waste drops to at most one partly filled block per request. Several times more requests fit in the same memory, which means bigger batches and much higher throughput.
Other things vLLM does
- Continuous batching: scheduling at every step.
- Prefix sharing (copy-on-write): requests with the same system prompt share its KV blocks.
- Chunked prefill to mix long prompts with ongoing generation smoothly.
- Quantization, speculative decoding, tensor and pipeline parallelism.
- An OpenAI-compatible API, so apps can switch to it easily.
The bigger lesson
vLLM is a good example of system design thinking: the bottleneck wasn't the maths but memory management, and an old, well-understood idea from operating systems solved it.