You will rarely write an inference engine, but you will choose, deploy, tune and operate one. Three open-source engines dominate datacenter LLM serving: vLLM, SGLang and NVIDIA TensorRT-LLM. All three expose an OpenAI-compatible API and share the same core ideas, but they differ in where they shine. This lesson gets each one running locally, explains what each optimises, and gives you a way to choose that is grounded in your own benchmarks rather than someone else's chart.
- Launch vLLM, SGLang and TensorRT-LLM as OpenAI-compatible servers
- Explain the features all modern engines share and where they differ
- Choose an engine based on hardware, workload shape and operational needs
- Run the same client against any engine by changing only the base URL
- Place lighter local runtimes such as llama.cpp correctly for development
What every modern engine does
The engines have converged on the same toolkit, so learn it once. Continuous batching adds and removes requests at every step. Paged KV-cache management allocates cache in blocks. Prefix caching reuses cache for shared prompt prefixes. Chunked prefill keeps long prompts from stalling decode. CUDA graphs and fused kernels cut launch overhead. Quantization (FP8 and 4-bit formats), tensor and pipeline parallelism, speculative decoding, LoRA adapters, structured output and tool-call parsing are standard features.
Because all three speak the OpenAI API, your application, gateway and benchmark client do not change when you switch engines; only the base URL and model name do. That makes trying several engines on your own workload cheap, and it is the right way to decide.
The differences that remain are in defaults, kernels and focus: which models and GPUs get optimised first, how aggressively each engine schedules prefill against decode, how its prefix cache is indexed, how it exposes metrics, and how often it releases. Those differences can swing results by large margins on one workload and vanish on another, which is why the comparison below ends with a benchmark rather than a verdict.
vLLM
vLLM is the broad, community default: the widest model and hardware support (NVIDIA, AMD, Intel, TPUs and more through plugins), PagedAttention, a large feature set and a big ecosystem that includes KServe runtimes, a production-stack Helm chart and integration in distributed frameworks such as Dynamo and llm-d. Pick it when you want the safest general choice. The open-source track's vLLM lesson covers its flags and metrics in depth.
export MODEL_ID=YOUR_ORG/YOUR_MODEL
uv pip install vllm
vllm serve "$MODEL_ID" --port 8000 --max-model-len 8192SGLang
SGLang is a high-performance engine whose signature is RadixAttention: the KV cache is kept in a radix tree keyed by token prefixes, so any request that shares a prefix with earlier work, a multi-turn conversation, an agent re-sending its scratchpad, few-shot templates, reuses it automatically. It is strong for agentic and multi-turn workloads, structured generation, and large mixture-of-experts models, and it is widely used for reinforcement-learning rollouts.
uv pip install --prerelease=allow sglang
sglang serve "$MODEL_ID" --host 0.0.0.0 --port 30000TensorRT-LLM
TensorRT-LLM is NVIDIA's engine, with kernels tuned for each NVIDIA GPU generation, early support for new hardware features and low-precision formats, and in-flight batching. Older versions required compiling a per-model engine ahead of time; current releases default to a PyTorch-based backend that loads checkpoints directly. trtllm-serve gives an OpenAI-compatible server, trtllm-bench benchmarks, and it also runs behind Triton or Dynamo. Pick it when you are all-in on NVIDIA and want the most from the newest GPUs.
trtllm-serve "$MODEL_ID" --tp_size 2 --host 0.0.0.0 --port 8000For laptops and CPUs, llama.cpp and tools built on it run quantized GGUF models without a datacenter GPU. They are excellent for development and edge devices, not a substitute for a batching datacenter engine under heavy concurrent load.
Choosing, and the same client for all
| If you need | Start with |
|---|---|
| Broadest model and hardware support, biggest ecosystem | vLLM |
| Heavy prefix reuse: multi-turn chat, agents, structured generation | SGLang |
| Maximum performance on the newest NVIDIA GPUs and formats | TensorRT-LLM |
| Laptop, CPU or edge device | llama.cpp-based runtimes |
Treat the table as a starting hypothesis. Performance rankings change with every release, model and GPU. Run your real prompt and output length distribution through each candidate at your target latency, compare goodput per GPU, and weigh operational factors: container images, metrics, upgrade cadence, model support for what you will serve next year.
from openai import OpenAI
for base in ["http://localhost:8000/v1", "http://localhost:30000/v1"]:
client = OpenAI(base_url=base, api_key="not-needed-locally")
reply = client.chat.completions.create(
model=client.models.list().data[0].id,
messages=[{"role": "user", "content": "One sentence on KV caches."}],
max_tokens=60,
)
print(base, reply.choices[0].message.content)