How to Serve an Open-Source LLM With vLLM on Your Own GPU
The official vLLM quickstart installs the engine on Linux with Python 3.11 through 3.14, then either runs offline batches in Python or starts an OpenAI-compatible server at localhost port 8000.
vLLM is an open-source engine for running large language models on your own hardware. Its official quickstart covers two jobs that teams actually need: offline batched inference in Python, and an HTTP server that speaks the OpenAI API so existing clients can point at a local URL instead of a hosted endpoint.
This guide follows the project's current documentation for Linux, with Python 3.11 through 3.14. It uses the commands and defaults published in the quickstart and the security guide. It does not invent memory requirements, token speeds, or a "best" GPU. Those depend on the model and the card in front of you.
Key facts at a glance
- The documented prerequisites are Linux and Python 3.11 through 3.14. A separate Metal-based path exists for Apple Silicon.
- The recommended NVIDIA install uses the
uvenvironment manager,uv pip install vllm --torch-backend=auto, and thenvllm download-kernels. - Offline inference is built around the
LLMandSamplingParamsclasses. The quickstart example loadsfacebook/opt-125m. - Online serving starts with
vllm serve Qwen/Qwen2.5-1.5B-Instructand, by default, listens athttp://localhost:8000. - By default, both the engine and the server apply
generation_config.jsonfrom the Hugging Face model repository when that file exists. - The
--api-keyflag, or theVLLM_API_KEYenvironment variable, authenticates only some HTTP path prefixes. The security guide says not to rely on that flag alone.
Who this is for
This is for developers and platform engineers who want to serve or batch an open-source model on a machine they control: a workstation GPU, a small internal server, or a first proof that an app can talk to a local OpenAI-compatible endpoint. It is not a managed-cloud tutorial, and it is not a guide to training or fine-tuning.
If you are on AMD ROCm, Intel GPUs, Google TPUs, Ascend NPUs, or an Apple Silicon Mac, the same documentation points to different packages and images. Those paths are summarized later so you do not copy the NVIDIA commands onto the wrong accelerator.
Install vLLM on an NVIDIA GPU
The project recommends uv to create the environment. After uv itself is installed, the documented CUDA flow is:
uv venv --python 3.14 --seed
source .venv/bin/activate
uv pip install vllm --torch-backend=auto
vllm download-kernels
--torch-backend=auto inspects the installed CUDA driver and picks a PyTorch index at runtime. You can pin a backend such as cu126 with --torch-backend=cu126 or UV_TORCH_BACKEND=cu126.
vllm download-kernels installs precompiled kernels that vLLM would otherwise download and compile at startup. The docs note that this compilation can add several minutes on Hopper and newer GPUs, which is why the extra command exists.
If you do not want a permanent environment, the same docs show:
uv run --with vllm vllm --help
Conda is also documented: create an environment with Python 3.14, install or upgrade uv inside it, then run the same uv pip install vllm --torch-backend=auto command.
Run a batch of prompts offline
Offline inference is for a list of prompts you already have, not for an interactive chat service. Import LLM and SamplingParams, define the prompts and sampling settings, construct the engine, then call generate.
The official example sets temperature to 0.8 and nucleus sampling (top_p) to 0.95, and loads a small OPT model:
from vllm import LLM, SamplingParams
prompts = [
"Hello, my name is",
"The president of the United States is",
"The capital of France is",
"The future of AI is",
]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
llm = LLM(model="facebook/opt-125m")
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
Two defaults matter more than they first appear. If you omit SamplingParams, vLLM applies the model creator's recommended sampling values from generation_config.json when that file is in the Hugging Face repository. The documentation says this usually gives better results. If you want vLLM's own defaults instead, create the engine with generation_config="vllm".
By default, models are downloaded from Hugging Face. To use ModelScope instead, set VLLM_USE_MODELSCOPE=True before you initialize the engine.
llm.generate does not apply a chat template for you. For an Instruct or Chat model, apply the tokenizer's chat template first, or use llm.chat and pass a list of messages in the same role-and-content shape used by OpenAI's chat completions client.
Start an OpenAI-compatible server
The server hosts one model at a time and implements endpoints such as list models, create chat completion, and create completion. Start it with the documented 1.5 billion parameter Qwen instruct model:
vllm serve Qwen/Qwen2.5-1.5B-Instruct
The default address is http://localhost:8000. Change that with --host and --port. As with offline inference, the server applies generation_config.json from the model repository when present. Pass --generation-config vllm if you want to turn that off.
List the models, then send a completion and a chat request using the exact paths in the docs:
curl http://localhost:8000/v1/models
curl http://localhost:8000/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen2.5-1.5B-Instruct",
"prompt": "San Francisco is a",
"max_tokens": 7,
"temperature": 0
}'
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen2.5-1.5B-Instruct",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"}
]
}'
The same server can be used through the official openai Python package by pointing base_url at http://localhost:8000/v1. The quickstart examples set the API key to the placeholder string EMPTY when no key is configured.
To require a key, pass --api-key or set VLLM_API_KEY. You can pass more than one key after --api-key; the server accepts any of them, which the docs describe as useful for rotation.
If you need to pick an attention implementation instead of the automatic choice, the CLI flag is --attention-backend. On NVIDIA CUDA the documented options include FLASH_ATTN and FLASHINFER. FlashInfer ships with vLLM, but its precompiled kernels do not; run vllm download-kernels after install or upgrade so those kernels are not compiled at first start.
Lock the server down before you leave the laptop
The project's security guide is blunt: several internal channels are insecure by default, and even a single-host install can open more than the chat port.
Internode traffic — PyTorch distributed, KV-cache transfer, and tensor, pipeline, or data-parallel communication — is unencrypted and has no authorization protocol. The guide says those nodes belong on an isolated network. Even when you run vLLM on one machine, PyTorch's TCPStore may listen on all network interfaces unless you add protections. From PyTorch's perspective, any use of torch.distributed should be considered insecure by default.
The firewall advice is specific: block all incoming connections except the TCP port the API server uses, and keep internal ports (distributed communication and KV-cache transfer, whose documented defaults include 127.0.0.1:14579 for KV transfer) away from the public internet.
API keys have a documented gap. --api-key or VLLM_API_KEY enforces Bearer authentication only for endpoints under the /v1, /v2, /inference, and /cohere prefixes. Other endpoints on the same HTTP server are not covered. The official wording is that you should not rely exclusively on --api-key for production, and that a reverse proxy plus a minimal exposed surface is part of a real deployment.
If the server accepts remote media URLs, set --allowed-media-domains so the process cannot be pointed at internal addresses or cloud metadata services. The docs also suggest VLLM_MEDIA_URL_ALLOW_REDIRECTS=0 so a redirect cannot bypass the allowlist. Default download caps include a 256 MB limit on a single remote media response, controlled by VLLM_MAX_MEDIA_DOWNLOAD_SIZE_MB. Setting those limits to 0 disables them, which the project does not recommend on a server exposed to untrusted users.
Other accelerators, and what to do when a start fails
The same quickstart documents non-CUDA installs so you do not mix packages:
- AMD ROCm: create a Python 3.14 environment with
uv, thenuv pip install vllm --extra-index-url https://wheels.vllm.ai/rocm/. The notes currently list Python 3.14, ROCm 7.0, andglibc >= 2.35. - Intel GPUs (XPU): official Docker images are in the vLLM release starting with v0.26.0, with a nightly
vllm/vllm-openai-xpu:nightlyimage. - Google TPUs: install the
vllm-tpupackage withuv pip install vllm-tpu. - Ascend NPUs: use the community vLLM Ascend plugin and its own quick start; the setup depends on the NPU and CANN version.
- Apple Silicon: use vLLM-Metal, which relies on MLX rather than PyTorch and expects MLX-optimized models.
If the NVIDIA install finishes but the first vllm serve start takes many minutes, check whether you skipped vllm download-kernels. If a chat model answers poorly, confirm you used the chat completions endpoint or applied the chat template, rather than sending raw prompts to llm.generate. If clients can reach ports other than the API port, treat that as a firewall problem, not an API-key typo. If an expected device never appears, you are on the wrong install tab.
What it means for you
Serving an open model locally is useful for teams in the US, UK, Canada, and Australia that cannot send prompts to a third-party API, or that want a drop-in OpenAI-compatible URL for development. The operational cost is on you: driver and Python versions, kernel downloads, and network exposure. A default server bound to localhost is a reasonable laptop test. It is not a production posture. The project's own security guide is the counterweight to the quickstart's two-line vllm serve command.
Takeaways
- Install on NVIDIA with
uv,--torch-backend=auto, andvllm download-kernelsso startup does not compile kernels on a Hopper-class GPU. - Use
LLM.generatefor batches, andllm.chator the chat completions API when the model expects a chat template. - Expect
generation_config.jsonto override sampling defaults unless you passgeneration_config="vllm"or--generation-config vllm. - Start the server with
vllm serveand test/v1/models,/v1/completions, and/v1/chat/completionsonlocalhost:8000. - Turn on
--api-key, but do not treat it as the only control: many paths are unauthenticated, and PyTorch distributed may listen more widely than the API port. - Put a firewall in front, restrict media domains if you accept URLs, and use the matching install path for ROCm, Intel XPU, TPU, Ascend, or Apple Silicon.