
Running a model on your laptop is very different from serving it to hundreds of users concurrently. Production inference needs high throughput, efficient GPU memory usage, an API your applications can call, and monitoring. vLLM has become the most widely used open-source engine for this job. In this vllm tutorial, you will deploy llm with vllm on a cloud GPU step by step, size your GPUs correctly, expose an OpenAI-compatible API, tune performance and prepare to self host llm in production.
Start with why vLLM is the standard for serving.
Why vLLM
vLLM is an inference server designed for throughput. Its key innovations include:
PagedAttention, which manages the key-value cache in small blocks, reducing memory waste and allowing more concurrent requests.
Continuous batching, which adds new requests to running batches instead of waiting for a batch to finish, keeping GPUs busy.
Broad model support for popular open-weight architectures, quantization formats and multi-GPU parallelism.
An OpenAI-compatible API server, so applications can switch from hosted APIs with minimal changes.
The vllm vs ollama comparison comes down to purpose. Ollama is ideal for local development and single users. vLLM is designed for serving many concurrent users efficiently in production.
Step 1: Choose a Model
Pick an open-weight model suited to your task and license requirements, such as a Qwen, Llama, Mistral, Gemma or gpt-oss model. Note its parameter count, context length and available quantized versions. For this tutorial, imagine deploying a model in the 30 billion parameter range.
Step 2: Size Your GPUs
Gpu sizing for llm serving depends on two memory components:
Model weights: roughly 2 bytes per parameter at 16-bit precision, 1 byte at 8-bit and about half a byte at 4-bit. A 30 billion parameter model needs around 60GB at 16-bit, 30GB at 8-bit or about 15 to 18GB at 4-bit.
KV cache: memory for active requests, which grows with context length and the number of concurrent users. This often needs as much memory as the weights, or more, for high concurrency.
Practical guidance:
- A single 24GB GPU suits small models or quantized mid-size models with limited concurrency.
- A single 80GB GPU, such as the H100 or A100 80GB class, comfortably serves mid-size models with good concurrency.
- Multiple GPUs with tensor parallelism serve large models or very high traffic.
Mixture-of-experts models need memory for all parameters but compute only for active experts, so they can deliver strong throughput relative to their size.
Step 3: Provision a Cloud GPU
Choose a provider such as AWS, Google Cloud, Azure, or GPU-focused clouds like Lambda, RunPod or CoreWeave. Launch an instance with your chosen GPU, an image with recent NVIDIA drivers and CUDA, and enough disk for model weights.
Visual description: your provider's console shows the instance running, with a public IP address and the GPU type listed. Connect with SSH and run nvidia-smi to confirm the GPU is visible.
Step 4: Install vLLM
The simplest method is Docker. vLLM publishes an official image with the OpenAI-compatible server. Alternatively, install it with pip in a Python environment.
If the model is gated on Hugging Face, accept its license on the website and set your Hugging Face token as an environment variable on the server.
Step 5: Start the Server
Run the vLLM server with the model name. With Docker, you run the official image with GPU access, map port 8000, mount a cache directory for downloaded weights and pass the model identifier. With pip, you run vllm serve followed by the model identifier.
Useful options include:
- max model len to cap context length, which controls KV cache size.
- gpu memory utilization to set what fraction of GPU memory vLLM uses.
- tensor parallel size to split the model across multiple GPUs.
- quantization options for compatible quantized models.
- api key to require a key for requests.
The first start downloads weights, which may take several minutes. Visual description: the logs show the model loading, memory allocated for the KV cache and finally a message that the server is running on port 8000.
Step 6: Test the API
From the server, send a request to the chat completions endpoint at localhost port 8000 under the v1 path, using curl or the OpenAI Python library with the base URL set to your server. You should receive a response from the model.
Because the llm inference server is OpenAI-compatible, your existing application code works by changing the base URL, API key and model name.
Step 7: Secure the Deployment
Never expose a raw inference server to the internet. Instead:
- Require an API key or place the server behind an authenticated gateway.
- Use HTTPS through a reverse proxy or load balancer.
- Restrict network access with firewall rules or private networking.
- Apply rate limits per client.
- Log requests for auditing, masking sensitive content where required.
Step 8: Tune Performance
Measure throughput and latency with realistic traffic using benchmarking tools. Common tuning levers:
- Lower max model len if you do not need long contexts, freeing memory for more concurrent requests.
- Use quantization to fit larger models or increase concurrency.
- Enable prefix caching to reuse computation for shared system prompts.
- Use tensor parallelism for larger models across GPUs.
- Consider speculative decoding to reduce latency for some workloads.
Track time to first token, tokens per second per request and total throughput.
Step 9: Monitor and Scale
vLLM exposes metrics in a Prometheus-compatible format, including queue length, running requests, KV cache usage and token throughput. Visualize them in Grafana and alert on high queue times or errors.
To scale, run multiple replicas behind a load balancer, or use orchestration such as Kubernetes with GPU node pools. Production stacks built around vLLM add routing, autoscaling and caching across replicas.
Troubleshooting Common Issues
Out of memory at startup: reduce max model len, lower gpu memory utilization, use quantization or add GPUs.
Model architecture not supported: upgrade vLLM to a recent version, as new architectures are added frequently.
Slow responses under load: check KV cache usage and queue metrics; add replicas or reduce context length.
Gated model download fails: confirm license acceptance and the Hugging Face token.
Wrong chat formatting: ensure the model's chat template is used; specify a template if the model lacks one.
Frequently Asked Questions
Is self-hosting cheaper than APIs? At high, steady utilization it often is. At low or bursty traffic, APIs are usually cheaper.
Can vLLM serve multiple models? Typically one model per server instance; run multiple instances or use a router for several models.
Conclusion
In this tutorial you learned to deploy llm with vllm: choosing a model, sizing GPUs for weights and KV cache, provisioning a cloud GPU, running the OpenAI-compatible server, securing it, tuning performance and monitoring for scale.
Key takeaways: size for both weights and KV cache, cap context length deliberately, never expose the server without authentication, use prefix caching and quantization, and monitor queue and cache metrics. Next, benchmark your deployment with realistic traffic and compare cost per million tokens with your current API provider.