vLLM serving means running an open-weight model behind an HTTP server where the engine, not your application code, decides how concurrent requests share one GPU. You send OpenAI-style calls; vLLM schedules tokens, manages memory in pages, and streams the result back. If you have ever watched a hand-rolled Hugging Face generate() loop collapse at eight concurrent users, that scheduler is the thing you are buying.
This guide is for application engineers who have been handed a GPU and an SLO and need a launch they can defend in review. It covers the minimum command, the five flags that decide capacity, a sizing calculation you can redo on a napkin, the service-level objectives worth paging on, and the failure modes that show up in the first week. It assumes you already understand why serving cost matters; if not, start with the LLMOps production guide.
What vLLM does that a plain model server does not
Two ideas carry most of the value. The first is paged KV memory: instead of reserving one contiguous slab per request sized for the worst-case sequence length, the engine allocates the key/value cache in small blocks and maps them on demand. The PagedAttention paper reports that this cuts waste enough to raise throughput roughly 2–4× over earlier serving systems at similar latency. The second is continuous batching: a finished sequence leaves the batch immediately and a waiting one takes its slot on the next decode step, so short answers never wait behind long ones.
What you give up is some predictability. A request’s latency now depends on who else is on the GPU. That is the trade behind every number in this post, and it is why the companion piece on LLM batching and latency is worth reading before you promise anyone a p99.
A launch command you can explain line by line
The server entry point is vllm serve, which exposes the OpenAI-compatible server. Pin the version in your container image; flag names and defaults have moved between releases, and an unpinned latest tag is a quiet source of Monday-morning regressions.
vllm serve meta-llama/Llama-3.1-8B-Instruct \
--max-model-len 16384 \
--gpu-memory-utilization 0.90 \
--max-num-seqs 96 \
--max-num-batched-tokens 8192 \
--enable-prefix-caching \
--served-model-name support-8b \
--api-key "$VLLM_API_KEY"
Two details are easy to miss. --served-model-name decouples the name clients use from the weights path, so you can swap the underlying checkpoint without touching callers. And an API key on an internal service is not paranoia: a GPU endpoint with no auth is a free compute pool for whoever finds the port.
The five flags that set your capacity
| Flag | What it controls | Typical move | Risk if wrong |
|---|---|---|---|
--max-model-len | Longest prompt + completion the server accepts | Lower it to your real p99 plus 20% | Too high wastes KV budget; too low truncates users |
--gpu-memory-utilization | Fraction of GPU memory vLLM may claim | 0.88–0.92 on a dedicated card | Above 0.95 invites OOM during activation spikes |
--max-num-seqs | Concurrent sequences in the running batch | Start near 64–128, tune with load tests | Too high inflates inter-token latency |
--max-num-batched-tokens | Token budget per scheduler step | 4k–16k; larger favors throughput | Too high makes first-token latency spiky |
--tensor-parallel-size | GPUs a single replica spans | Smallest value that fits weights + KV | Cross-GPU traffic costs latency; over-sharding wastes cards |
The official optimization and tuning page documents preemption, chunked prefill, and how the scheduler budgets tokens. Read it once with your own numbers beside it; the guidance changes depending on whether your traffic is short chat turns or 12k-token document prompts.
Sizing by arithmetic before you rent anything
You can estimate concurrency from memory alone. Take an 8B-class model with grouped-query attention: 32 layers, 8 KV heads, head dimension 128, FP16 cache. Each token stores 2 (K and V) × 32 × 8 × 128 × 2 bytes = 131,072 bytes, or 128 KiB. That figure is illustrative for this architecture, so read your model’s config file for the real values.
Now budget an 80 GB card. At 0.90 utilization vLLM may use 72 GB. Subtract roughly 16 GB for FP16 weights and about 4 GB for activations and CUDA overhead, and about 52 GB remains for KV cache. Divided by 128 KiB per token, that is on the order of 400,000 cached tokens. If your average live request holds 4,000 tokens (prompt plus what it has generated so far), the card sustains about 100 concurrent sequences before it must preempt.
- Prompt-heavy RAG traffic (6k tokens average): about 65 concurrent sequences. Set
--max-num-seqsnear 64 and expect the KV pool, not the flag, to be the limit. - Short chat (1k tokens average): the memory allows 400 sequences, but compute becomes the ceiling. Latency, not memory, decides your real batch size.
- Long-context summarization (24k tokens): about 16 sequences. This is where quantizing the cache or sharding across two GPUs starts to pay for itself.
If those numbers surprise you, the mechanism is explained in KV cache explained for builders, and the memory-saving options are in quantization for LLM inference.
SLOs worth putting on a vLLM endpoint
Generic uptime is a poor objective for a GPU service. A server can answer /health while every user waits ten seconds for the first token. Define objectives around the user’s experience of a streamed response, then map each to a metric you can scrape.
| Objective | Example target | Where it comes from |
|---|---|---|
| Time to first token (TTFT), interactive chat | p95 ≤ 800 ms, p99 ≤ 2 s | Client-side timer; server histogram as cross-check |
| Inter-token latency (ITL) | p95 ≤ 60 ms (about 16 tokens/s per user) | Server histogram of time per output token |
| Queue wait before scheduling | p95 ≤ 200 ms | Waiting-request gauge and request timestamps |
| Availability of successful completions | 99.5% over 30 days | Non-5xx and non-timeout ratio at the gateway |
| Preemption rate | < 1% of requests | Engine preemption counter |
The server exposes a Prometheus /metrics endpoint with running and waiting request gauges, KV cache usage, and latency histograms (metric names have shifted across versions, so check yours). Pair those with the gateway-level objectives in agent SLAs so one dashboard tells the same story as the contract.
Load test with your own traffic shape
Synthetic benchmarks with uniform 128-token prompts will flatter your server. Record a day of real request lengths (input and output token counts, not text) and replay that distribution at stepped concurrency.
- Export input and output token counts from production logs, or from your tracing store if you already have one.
- Replay at 25%, 50%, 100%, and 150% of expected peak concurrency, holding each step for at least five minutes.
- Record TTFT, ITL, queue wait, and KV usage at each step; stop raising load once p95 TTFT crosses your objective.
- Set
--max-num-seqsto the highest value that kept every objective green with 20% headroom. - Repeat after any change to model, quantization,
--max-model-len, or prompt template length.
What goes wrong in the first week
Startup OOM with a seemingly roomy GPU
Usually the sum of weights, a high --max-model-len, and a utilization setting that leaves no slack for the profiling pass. Lower the context cap first; it is almost always the cheapest fix.
A preemption storm under bursty load
When the KV pool fills, vLLM evicts running sequences and recomputes them later. A few are normal; sustained preemption means you admitted more concurrency than memory supports. Cap --max-num-seqs, shorten --max-model-len, or add a replica.
One long prompt wrecks everyone’s TTFT
A 30k-token prefill monopolizes a scheduler step. Enable chunked prefill if your version does not already, lower the token budget, and give long-context traffic its own replica or route.
Cold starts that outlast your autoscaler
Pulling tens of gigabytes of weights takes minutes. Bake weights into the image or a node-local cache, and scale on queue depth early enough that a new replica is ready before the queue is painful.
When self-hosting does not pay
Break-even is a utilization question. Suppose a dedicated 80 GB GPU costs about $2.00 per hour, roughly $1,460 per month (placeholder price; use your quote). If a hosted API charges $0.60 per million output tokens for a comparable model (also a placeholder), the card breaks even at about 2.4 billion tokens per month, which is roughly 940 tokens per second sustained around the clock. A service that peaks at 300 tokens per second and idles overnight will usually lose to the API.
Self-hosting still wins when data cannot leave your network, when you need a fine-tuned adapter (see the LoRA fine-tuning guide), or when latency control matters more than unit price. If you are weighing vendors rather than hardware, Hugging Face vs OpenAI frames the trade from the API side, and Ray Serve for agents shows one way to scale replicas behind a router.
A short pre-launch checklist
- Container pinned to a specific vLLM version and model revision hash.
- API key enforced; port reachable only from the gateway.
- Metrics scraped, with alerts on TTFT p95, waiting requests, and KV usage above 90%.
- Load test report stored next to the config that produced it.
- A tested fallback route to a hosted model for when the GPU pool is saturated or down.
FAQ
What is vLLM used for?
vLLM is an inference engine for serving large language models with high throughput. Teams use it to host open-weight models behind an OpenAI-compatible API, relying on paged KV cache memory and continuous batching to serve many concurrent users per GPU.
Is vLLM faster than Hugging Face Transformers for serving?
For multi-user serving, usually yes, because it batches requests continuously and manages cache memory in blocks. For a single request on an idle GPU the gap is small. Measure with your own prompt lengths rather than trusting published headline multiples.
How much GPU memory do I need to serve an 8B model with vLLM?
Weights in FP16 take about 16 GB, and you need extra room for the KV cache and activations. A 24 GB card runs an 8B model with limited concurrency; an 80 GB card leaves tens of gigabytes for cache and supports far more simultaneous sessions.
Does vLLM support the OpenAI API format?
Yes. vllm serve starts a server compatible with the chat completions and completions endpoints, so most OpenAI client libraries work by changing the base URL and key. Check the docs for which parameters and features your version supports.
Should I enable prefix caching in vLLM?
Enable it when many requests share a long common prefix, such as a system prompt, tool definitions, or retrieved boilerplate. It skips recomputing that prefill. It does nothing for generation speed, so it helps TTFT and throughput on prompt-heavy traffic.
What should I monitor on a vLLM server?
Track time to first token, inter-token latency, running and waiting request counts, KV cache usage, preemptions, and error rates. Alert on queue growth and cache saturation before users report slow responses.
AI Generated Apps AI Code Learning Technology
