The waste that vLLM was built to remove
A naive serving loop allocates a contiguous block of memory for each request's KV cache, sized for the maximum sequence length the model allows. A request that might reach 8,000 tokens reserves room for 8,000 tokens even if it stops at 200. Because requests arrive at different times and finish at different lengths, the allocator ends up with holes it cannot reuse, and measurements from the original vLLM paper found that existing systems wasted 60 to 80 percent of KV cache memory in typical workloads. That waste is not an abstract inefficiency: it directly caps how many requests a GPU can hold, and the GPU is the expensive part.
Static batching compounds the problem. A conventional batch waits for every sequence to finish before accepting new work, so a short request that completes in 50 tokens sits idle behind a long one that runs for 2,000. The GPU alternates between fully utilised and nearly idle, and latency for the short request is dictated by the longest sequence in its batch. vLLM, published by the Sky Computing Lab at UC Berkeley in 2023, attacked both problems at once, and the ideas have since been adopted across the industry.
PagedAttention, in plain terms
PagedAttention borrows the operating system's approach to virtual memory. Instead of one contiguous buffer per sequence, the KV cache is divided into fixed-size blocks, 16 tokens by default. A block table maps each sequence's logical blocks to physical blocks anywhere in GPU memory, so blocks do not need to be adjacent and a sequence grows by allocating another block when it needs one. Internal fragmentation is limited to the partially filled last block of each sequence, which is under four percent in practice, and there is no external fragmentation at all because every free block is interchangeable.
The block table also enables sharing. When several sequences branch from the same prompt, as in parallel sampling, beam search, or a batch of requests that share a long system prompt, their identical prompt blocks are stored once and referenced by multiple block tables. A block is copied only when one sequence needs to write to it, the same copy-on-write rule an operating system uses for forked processes. Prefix caching extends this across requests: the server hashes token prefixes into blocks and reuses them when a later request arrives with the same opening, which is exactly what happens in agent loops and RAG pipelines where every call carries the same instructions and tool definitions.
Continuous batching keeps the GPU fed
Continuous batching, also called iteration-level scheduling, makes the scheduling decision at every decode step rather than at the granularity of a whole request. When a sequence emits its end token, it leaves the batch immediately and a queued request takes its slot in the next iteration. The batch composition changes dozens of times per second, and the GPU stays close to saturated with useful tokens instead of waiting for the longest sequence in a fixed batch.
The combination is what produces the headline numbers. PagedAttention raises the number of sequences that fit in memory, and continuous batching keeps those sequences progressing. The paper reported two to four times the throughput of prior serving systems at similar latency, with the largest gains on workloads that mix prompt lengths and output lengths. In practice the gain over a hand-rolled Hugging Face loop is larger still, because the naive baseline also recomputes the prompt and has no batching at all.
Three more optimisations worth knowing
Chunked prefill splits a long prompt into pieces and interleaves those pieces with decode steps from other requests. Without it, a 30K-token prompt stalls every other request for the duration of its prefill, producing a latency spike that users notice even though average throughput looks fine. With it, time between output tokens stays stable and the scheduler can balance prefill and decode work within a token budget per step.
Speculative decoding accelerates the latency-sensitive case. A small draft model, an n-gram cache, or a trained head proposes several tokens, and the large model verifies them in a single forward pass, accepting the ones that match its own distribution. When acceptance rates are high, this yields 1.5 to 2.5 times lower inter-token latency at low concurrency, at the cost of extra memory for the draft model and wasted compute when acceptance is poor. It is a latency tool, not a throughput tool: at high batch size the GPU is already busy and speculation adds overhead.
Disaggregated prefill and decode, where separate pools of GPUs handle prompt processing and token generation, is the newest direction. Prefill is compute-bound and decode is bandwidth-bound, so splitting them lets each pool be sized and scaled independently, and KV cache is transferred between them over fast interconnect. It adds operational complexity and is worth considering only when you are large enough that a single pool is visibly inefficient.
What ships in the box
- An OpenAI-compatible HTTP server with chat completions, completions, embeddings and a models endpoint, plus tokenize and health endpoints.
- Tensor parallelism within a node, pipeline parallelism across nodes, and data-parallel deployment for replicas, including expert parallelism for mixture-of-experts models.
- Quantization support for FP8, INT8, AWQ, GPTQ, NVFP4 and MXFP4, with Marlin kernels for four-bit weight formats on Ampere and newer GPUs.
- Multi-LoRA serving: one base model in memory with many adapters loaded and selected per request by name.
- Guided decoding through grammars and JSON schemas, plus tool-call parsers for common chat templates.
- Prometheus metrics for throughput, time to first token, cache utilisation and preemption counts.
- A Python API for offline batch inference that uses the same scheduler without the HTTP layer.
Flags that actually change behaviour
The defaults are reasonable, but four settings decide most of your fate. gpu_memory_utilization, at 0.9 by default, tells the engine how much of the card it may claim for weights and cache; on a shared machine it must come down or the process will be killed by the driver. max_model_len caps the context the scheduler will admit, and leaving it at the model's architectural maximum makes vLLM reserve cache for sequences no user will send. max_num_seqs limits concurrent sequences, and setting it high without enough cache causes preemption, where sequences are swapped out and recomputed, which looks like a throughput collapse rather than an error.
The fourth is the KV cache dtype. Setting it to FP8 halves cache memory and lets you fit roughly twice the context or concurrency, with a quality cost that is usually small but should be tested on long-context retrieval. Two other flags deserve mention: enforce_eager disables CUDA graphs, which is useful for debugging but typically costs 20 to 40 percent of throughput, and enable_prefix_caching is close to free and a large win for workloads with shared system prompts. Recent releases default to the V1 engine, which reduced CPU scheduling overhead substantially; older flags and behaviours may not carry over, so check the version's documentation rather than a blog post from a previous release.
Throughput and what it costs per million tokens
On a single A100 80 GB, an 8B model in FP16 typically sustains roughly 2,000 to 3,000 output tokens per second at high concurrency, which is 7 to 11 million tokens per hour. At $2 per hour that is about $0.20 to $0.30 per million output tokens, but only if the GPU is actually busy. At 30 percent average utilisation the effective cost triples to roughly $0.70 to $0.90, and that is the number that should be compared with an API price, not the fully loaded figure. An L40S at about $1.20 per hour and 1,200 to 1,800 tokens per second lands in a similar range, and a four-GPU A100 node serving a 70B model at 500 to 900 tokens per second costs around $3 per million tokens at full utilisation.
Latency has two components and they scale differently. Time to first token is dominated by prefill and queueing, so it improves with more GPUs and shorter prompts. Time per output token is dominated by memory bandwidth and batch size, so it improves with quantization and worsens as concurrency rises. A benchmark that reports only tokens per second hides which of the two you have optimised. Measure both at the concurrency your product actually sees, and separately for prompts at the 50th and 95th percentile of length.
Where vLLM is the wrong tool
vLLM is a serving engine for a GPU you control, not a product. It does not manage customers, issue API keys, enforce per-tenant quotas, bill usage, or route between providers. Those belong to a gateway in front of it. It also serves one base model per process, so a platform offering five models needs five deployments, each with its own weights resident; multi-LoRA helps only when the models share a base. There is no autoscaling, no semantic cache and no prompt firewall, and its cold start of one to three minutes for a large model is a poor fit for scale-to-zero serverless pricing.
For a single user on a laptop, Ollama or llama.cpp is simpler and lighter, with better CPU and Apple silicon support and no CUDA dependency. For maximum throughput on NVIDIA hardware with a fixed model and an engineering team to tune it, TensorRT-LLM can beat vLLM by 10 to 30 percent after a difficult build process. SGLang is often faster on prefix-heavy and structured-generation workloads because of its radix-tree cache. The honest summary is that vLLM is the default because it is good at everything and easy to start, not because it is the fastest at every specific thing.
Operating it without surprises
Model weights should live on a fast local disk or a pre-warmed volume, because downloading 15 GB at startup turns a deploy into a three-minute outage. Readiness should depend on a real health endpoint, not on the process existing, since weight loading and CUDA graph capture happen after the port opens. Pin the version and the model revision: a minor upgrade can change default flags, kernel selection and therefore throughput, and a silent model update changes outputs. Keep an eye on cache utilisation and preemption counts; rising preemption is the earliest signal that concurrency has outgrown the card.
If you run several replicas behind a load balancer, prefix caching only helps when requests with the same prefix reach the same replica, so either use sticky routing by conversation or accept a lower hit rate. Long generations need generous idle timeouts and no buffering proxy in front, because server-sent events will otherwise arrive in bursts. And log the finish reason: a rising count of length-truncated responses is a product bug that looks like a model quality problem.
A minimal deployment, end to end
Start the server with an explicit context, an explicit concurrency cap and prefix caching enabled: vllm serve the model path with max-model-len set to the product's real limit, max-num-seqs set to a number the cache can hold, gpu-memory-utilization at 0.85 on a shared card, and enable-prefix-caching on. Point the OpenAI SDK at the base URL, set the API key to any placeholder unless you have enabled authentication, and send one request to confirm the chat template is being applied. Then run a load test with prompts at your p95 length and the concurrency you expect at peak, and record time to first token, time per output token and cache utilisation together.
Container images should pin the CUDA and driver compatibility explicitly, because a host driver older than the image expects fails at startup with an error that reads like a model problem. Mount the weights from a persistent volume rather than baking them into the image, and give the process a generous termination grace period so in-flight generations can finish during a rolling deploy. None of this is specific to vLLM, but it is where most first deployments lose an afternoon.
Common mistakes
- Benchmarking at concurrency one, seeing 50 tokens per second, and concluding that vLLM is slow; its advantage appears under load.
- Leaving max_model_len at 128K on a 24 GB card, which makes the scheduler reserve cache it can never fill.
- Setting max_num_seqs to 256 on hardware that supports 30, then treating the resulting preemption storm as a bug.
- Running with enforce_eager in production after using it to debug an unrelated issue.
- Putting a buffering reverse proxy in front of the streaming endpoint and breaking token-by-token delivery.
- Assuming the OpenAI-compatible layer supports every OpenAI feature, including logprobs, seeds and strict tool schemas.
- Upgrading the engine without re-running the load test, because kernel selection and defaults change between releases.
- Forgetting that the tokenizer and chat template ship with the model, so a mismatched template produces worse answers at unchanged speed.