vLLM is the de-facto standard for serving open-weight LLMs in production. It implements PagedAttention — a memory management technique that increases GPU utilisation by 2–4x compared to naive inference — and continuous batching, which processes requests as they arrive rather than waiting to fill a batch. The result is 3–10x higher throughput than llama.cpp server at the same hardware cost. This guide covers installing vLLM, serving Llama 3 and Mistral models, configuring tensor parallelism for multi-GPU setups, and deploying behind a reverse proxy.
Why vLLM over llama.cpp for production
llama.cpp is excellent for local inference and single-user workloads. vLLM is built for concurrent multi-user serving. The key difference is how they handle memory and batching. llama.cpp allocates a fixed KV cache per request — if you have 10 concurrent users, you need 10x the VRAM. vLLM's PagedAttention allocates KV cache in pages shared across requests, dramatically reducing memory waste.
Continuous batching means vLLM starts processing new requests the moment a slot frees up, rather than waiting for a full batch to complete. At 10 concurrent requests, vLLM typically achieves 3–5x higher throughput than llama.cpp server on the same GPU. At 50+ concurrent requests, the gap widens to 8–10x.
vLLM also supports tensor parallelism (splitting a model across multiple GPUs), quantisation (AWQ, GPTQ, FP8), speculative decoding, and LoRA adapter hot-swapping. For any production deployment serving more than a handful of users, vLLM is the right choice.
Installation
vLLM requires Python 3.9+ and CUDA 12.1+. Install with pip: `pip install vllm`. For a clean environment, use a virtual env or conda: `conda create -n vllm python=3.11 && conda activate vllm && pip install vllm`.
Verify the installation: `python -c "import vllm; print(vllm.__version__)"`. If you see a version number, you're ready. If you get CUDA errors, check your driver version with `nvidia-smi` — you need driver 525+ for CUDA 12.1.
For Docker deployment (recommended for production), use the official image: `docker pull vllm/vllm-openai:latest`. This image includes all CUDA dependencies and is the most reliable way to deploy vLLM in a containerised environment. See the Docker + GPU Setup Guide for container configuration details.
Serving your first model
Start an OpenAI-compatible server with Llama 3.1 8B Instruct: `python -m vllm.entrypoints.openai.api_server --model meta-llama/Meta-Llama-3.1-8B-Instruct --port 8000`. vLLM downloads the model from Hugging Face on first run (~16 GB for fp16). Set `HUGGING_FACE_HUB_TOKEN` in your environment for gated models.
For quantised inference (half the VRAM, ~5% quality loss): `python -m vllm.entrypoints.openai.api_server --model meta-llama/Meta-Llama-3.1-8B-Instruct --quantization awq --dtype auto`. AWQ quantisation runs the 8B model in ~5 GB VRAM vs ~16 GB for fp16.
Test the server: `curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{"model": "meta-llama/Meta-Llama-3.1-8B-Instruct", "messages": [{"role": "user", "content": "Hello"}]}'`. The response format is identical to OpenAI's API.
Key startup flags: `--max-model-len` caps the context window (reduces VRAM), `--gpu-memory-utilization` controls how much VRAM vLLM reserves (default 0.9), `--max-num-seqs` sets maximum concurrent sequences (default 256).
Multi-GPU tensor parallelism
For models that don't fit on a single GPU (70B+ at fp16), vLLM supports tensor parallelism — splitting the model's weight matrices across multiple GPUs. Each GPU holds a shard of every layer and they communicate via NVLink or PCIe during inference.
Enable tensor parallelism with `--tensor-parallel-size N` where N is the number of GPUs: `python -m vllm.entrypoints.openai.api_server --model meta-llama/Meta-Llama-3.1-70B-Instruct --tensor-parallel-size 4 --port 8000`. This splits the 70B model across 4 GPUs (~20 GB per GPU at fp16).
NVLink-connected GPUs (A100, H100 SXM, RTX 3090/4090 with NVLink bridge) achieve near-linear scaling — 4x GPUs gives ~3.5x throughput. PCIe-connected GPUs have higher communication overhead — expect ~2.5–3x throughput from 4 GPUs. Check live GPU cloud prices for multi-GPU instance costs.
For pipeline parallelism (splitting layers across GPUs rather than within layers), use `--pipeline-parallel-size`. This is useful when GPUs are connected via PCIe and you want to minimise inter-GPU communication bandwidth.
Production deployment with nginx
Never expose vLLM directly to the internet. Put it behind nginx for TLS termination, rate limiting, and authentication. A minimal nginx config: set `proxy_pass http://127.0.0.1:8000;`, add `proxy_read_timeout 300s;` for long generations, and configure `limit_req_zone` to rate-limit by IP.
For API key authentication, vLLM supports `--api-key YOUR_SECRET_KEY` at startup. All requests must include `Authorization: Bearer YOUR_SECRET_KEY`. For more sophisticated auth (per-user keys, usage tracking), put a lightweight proxy like LiteLLM in front of vLLM.
Health check endpoint: `GET /health` returns 200 when the server is ready. Use this for load balancer health checks and Kubernetes readiness probes. The `/metrics` endpoint exposes Prometheus metrics including request latency, throughput, and queue depth.
For high availability, run multiple vLLM instances behind a load balancer. Each instance is stateless — requests can be routed to any instance. Use sticky sessions only if you need KV cache reuse across requests from the same user (prefix caching feature).
Cost and throughput benchmarks
On an H100 80GB SXM, vLLM serves Llama 3.1 70B at ~800–1,200 tokens/second throughput (across all concurrent requests) with continuous batching. At $2.50/hr (spot), that's $0.0006–0.0009 per 1,000 output tokens — cheaper than any managed API for this model tier.
On an A100 80GB, expect 400–600 tokens/second for the 70B model at ~$1.50–2.00/hr spot. For the 8B model on an RTX 4090 ($0.40–0.60/hr spot), throughput reaches 2,000–3,000 tokens/second — under $0.00006 per 1,000 tokens at full utilisation.
The self-hosted break-even vs managed APIs depends on utilisation. At 50% GPU utilisation, double these per-token costs. Use the LLM ROI Calculator to model your specific token volume and find the exact break-even point against managed API pricing.