Why LLM serving is slow / how vLLM fixes it
HF vLLM
01 · The race

Same GPU, same model, same prompts.

HuggingFace naive

model.generate() behind a lock · one request at a time

–tokens / s
–avg first token
–total time

vLLM

continuous batching · PagedAttention · same weights

–tokens / s
–avg first token
–total time
–× faster

Pick a number of concurrent users and start the race.

Aggregate throughput vs. concurrent users

02 · Where memory goes

Every user rents GPU memory: the KV cache.

Prefillwhole prompt, one parallel passcompute-bound
Decodeone token per pass, per usermemory-bandwidth-bound
KV cache one K and one V vector per token, per layer
 
  • Without the cache, token t would recompute attention over all t−1 previous tokens: O(n²) per sequence. The cache stores their keys and values once.
  • Decode barely computes. Each step emits one token but must stream all the weights and the growing cache through the GPU, so speed is set by GB/s of memory bandwidth, not FLOPs.
  • That weight read is shared. Decode 32 users in one pass and the weights are read once for all of them. This is why batching is nearly free, and why memory for 32 caches is the real limit.

KV cache calculator

–per token
–per user at this context
–all users
GPU memory · RTX 5090, 32 GB
weights KV cache
03 · The memory fix

PagedAttention: virtual memory for the KV cache.

Contiguous reservation

each request reserves max_len up front, in one piece

0running
0queued
0served
holding tokens 0%reserved, empty 0%

PagedAttention

16-token blocks, allocated on demand, anywhere

0running
0queued
0served
holding tokens 0%last-block slack 0%
Hover a request to see its block table

Same GPU memory, same request stream on both sides. A block table maps each sequence's logical blocks to physical ones, exactly like an OS page table, so memory is claimed only when a token actually exists. Waste is bounded by one partial block per sequence, and identical prefixes can share blocks copy-on-write.

04 · The scheduling fix

Continuous batching: never wait for the slowest request.

Static batching

batch is fixed at admission; everyone waits for the longest sequence

–decode steps
–slot utilization
–requests finished

Continuous batching

the batch is re-formed every decode step; a finished slot is refilled immediately

–decode steps
–slot utilization
–requests finished
request generatingslot idle: padding or waiting for the batch to end

Each row is one slot of the GPU batch, time runs left to right in decode steps. The naive HuggingFace server in the race is the limiting case: one slot. Paging is what makes this cheap: admitting a request mid-flight only needs a few free blocks, not a contiguous slab.

05 · In production

Three flags decide how many users fit.


      
  • --gpu-memory-utilization sizes the pool. vLLM grabs it all at start-up and carves it into blocks, so there is no allocation on the hot path and no OOM mid-request.
  • --max-model-len does not change the pool. It bounds the worst case one request can take.
  • --max-num-seqs caps the batch. Bigger batch: more throughput, slower per-token latency for everyone.
GPU memory · 32 GB
weights activations + CUDA graphs KV block pool HF copy (this demo)
–tokens of KV cache
–16-token blocks
–full-length requests, guaranteed
–typical ~400-token requests
06 · Live

Fill the KV cache on a real server.

Requests

one cell per user · fills as tokens stream back

waitingstreamingdone
–tokens / s
–tokens generated
–first token p50 / p95
–request latency p50 / p95
KV cache usage
Requests running waiting
Throughput
1Decode is memory-bound, so the scarce resource is the KV cache, not compute.
2Paging turns reserved-but-empty memory into more concurrent users.
3Continuous batching shares one weight read across all of them, every step.