vLLM Deployment Guide: 10x Faster Model Inference
Native transformers inference serves one user per GPU and queues the rest. vLLM fixes throughput with PagedAttention and continuous batching, provided the deployment flags are right. Here is a production-ready setup.
📜 Table of Contents
📖 Keep reading
Deploying vLLM: Turning an Open Model into a Concurrent API
A plain transformers script answers one request quickly and stalls at ten concurrent users: KV cache is preallocated, batch size is fixed, and every new request waits for a slot. vLLM allocates KV cache in fixed blocks on demand (PagedAttention) and lets requests join or leave the batch continuously (continuous batching).
1. Size the GPU first
VRAM ≈ weights + KV cache + activations and framework overhead. FP16 costs about 2GB per billion parameters; INT4/AWQ about 0.6GB.
| Model | FP16 | 4-bit | Suggested GPU |
|---|---|---|---|
| 7B-8B | ~16GB | ~5GB | 24GB comfortable |
| 14B | ~28GB | ~9GB | 40GB or dual |
| 32B | ~64GB | ~20GB | 80GB or four cards |
| 70B | ~140GB | ~40GB | Tensor parallel |
KV cache scales with layers, heads, sequence length and precision; at long context it can exceed the weights.
2. Install and serve
pip install vllm
vllm serve Qwen/Qwen2.5-7B-Instruct \
--served-model-name qwen7b \
--port 8000 \
--gpu-memory-utilization 0.90 \
--max-model-len 8192 \
--max-num-seqs 64
The startup log prints available KV blocks and theoretical concurrency. Those numbers matter more than any marketing figure.
3. Flags that actually matter
| Flag | Effect | Guidance |
|---|---|---|
| --tensor-parallel-size | Shards the model | Equals GPU count, must divide attention heads |
| --gpu-memory-utilization | VRAM budget | Drop to 0.7-0.8 when sharing a GPU |
| --max-model-len | Context ceiling | Set to what you need; oversized wastes KV cache |
| --max-num-seqs | Concurrent sequences | Lower when VRAM is tight |
| --quantization | Quantization mode | Must match the checkpoint |
| --enable-prefix-caching | Reuses shared prefixes | Turn on when the system prompt is fixed |
Prefix caching is especially effective for agents and RAG, where every request starts with the same system prompt.
4. Call it
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
resp = client.chat.completions.create(
model="qwen7b",
messages=[{"role": "user", "content": "Summarize this in one sentence"}],
temperature=0.3, max_tokens=256,
)
print(resp.choices[0].message.content)
5. Load test before launch
vllm bench serve --backend openai-chat \
--base-url http://localhost:8000 --model qwen7b \
--num-prompts 200 --request-rate 8 --max-concurrency 32
Watch time-to-first-token, per-request output speed, and aggregate tokens per second. Raise concurrency until throughput flattens and latency spikes; that knee is your safe operating point. Size fleet as peak concurrency × average output tokens ÷ measured throughput, plus 30% headroom.
6. Production notes
- Gate traffic on
/health; model loading takes minutes. - Scrape
/metricsfor KV cache usage, queued requests and TTFT. - Isolate long-context requests in a separate pool; they slow short requests in the same batch.
- Drain connections before rolling restarts, or users see truncated responses.
FAQ
OOM at startup? Lower --gpu-memory-utilization, then --max-model-len, then quantize. The log states required and available memory.
vLLM vs Ollama? Ollama for single-user local use, vLLM for multi-user serving; throughput differs by an order of magnitude.
Multi-GPU? Yes, via tensor and pipeline parallelism; cross-node needs the Ray backend.
Hot model swap? Not supported in place; restart behind a blue-green deployment.
Related
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.