Suryanand/ Bootcamp
suryanand.com ↗Let's talk
← Inference and servingAI guideIntermediate#inference#vllm#sglang#tensorrt-llm
Frame · ai-engineering / inference-serving / 02-serving-engines-compared.mdGuide 061 / 103

Serving engines compared, vLLM, SGLang, TensorRT-LLM, TGI and llama.cpp

If you are self-hosting open-weight models, the serving engine is the most important piece of software you will pick. It owns the scheduler, the KV cache, the kernels and the HTTP API. The good news is that by late 2026 the field has consolidated around a few mature options that all speak an OpenAI-compatible API, so switching is cheaper than it used to be. This doc is my map of that field and how I choose.

Why it matters

The engine decides how many concurrent users one GPU can carry, how fast the first token arrives, and which models, quantization formats and hardware you can use at all. Picking badly usually does not fail loudly. It shows up as paying for twice the GPUs you need, or as an upgrade path that dead-ends when the project stops getting features.

That last point is not theoretical. Hugging Face's Text Generation Inference (TGI) was a default choice for years. It has since moved into maintenance mode: the project notice says it accepts only minor bug fixes, documentation and lightweight maintenance, and points users to vLLM, SGLang, llama.cpp and MLX instead. Existing TGI deployments keep working, but I would not start anything new on it.

How it works

Every modern engine is built from the same parts: an OpenAI-compatible front end, a scheduler doing continuous batching, a paged KV cache manager, a model executor with fused attention kernels, and optional extras such as prefix caching, speculative decoding and multi-GPU parallelism. They differ in which of those parts they optimise hardest.

Rendering diagram…

vLLM. The project that introduced PagedAttention and the de facto default for open-model serving. The V1 engine rewrite (alpha in early 2025, now the default) focused on low CPU overhead and turning optimisations like prefix caching and chunked prefill on by default. Its strengths are breadth: a huge model catalogue, many hardware backends (NVIDIA, AMD, TPU, Intel and more through plugins), many quantization formats, speculative decoding including EAGLE-3, and a large production ecosystem. If I do not have a specific reason to pick something else, I pick vLLM.

SGLang. Started from the "structured generation" research at LMSYS and is best known for RadixAttention: it keeps KV cache for previously seen prefixes in a radix tree and reuses it across requests automatically. For multi-turn chat, RAG with shared instructions, and agent loops that re-send long histories, that reuse removes a lot of redundant prefill. It also has strong support for constrained decoding (JSON schemas, regex) and for large mixture-of-experts deployments. Its sweet spot is workloads with lots of prefix overlap.

TensorRT-LLM. NVIDIA's engine, tuned for NVIDIA GPUs with hand-optimised kernels and early support for new hardware features such as FP8 and FP4. Historically it required compiling a per-model "engine" ahead of time, which made iteration slow. That has changed: the PyTorch backend became the default, and NVIDIA's migration guide for the 1.3 line says the TensorRT engine backend has been removed, leaving PyTorch as the sole execution backend. You now serve a Hugging Face checkpoint directly with trtllm-serve. Pick it when you are all-in on NVIDIA and willing to tune for the last slice of efficiency.

llama.cpp. A C/C++ engine built around the GGUF format with aggressive quantization and CPU, Metal, CUDA, Vulkan and other backends. It is the engine underneath many local tools and its llama-server exposes an OpenAI-compatible API. It shines on single-user and small-team setups and edge devices. It is not designed for high-concurrency datacenter serving. See running models locally.

TGI. In maintenance mode as described above. Fine to keep, not where new features land.

Reference architecture

At small scale you run one engine per GPU node behind a load balancer. At larger scale, two orchestration layers have emerged on top of the engines rather than replacing them: NVIDIA Dynamo (works with vLLM, SGLang and TensorRT-LLM) and the Kubernetes-native llm-d project (built on vLLM and the Kubernetes Inference Gateway). Both add KV-cache-aware routing and disaggregated prefill and decode, moving KV cache between GPU pools with NVIDIA's NIXL transfer library.

Rendering diagram…

Disaggregation helps most for large models with long inputs, where prefill and decode fight each other on shared GPUs. For small models it often does not pay for the extra network hop, and Dynamo's own tooling will tell you when aggregated serving is the better choice.

Code

All three datacenter engines launch the same way and expose /v1/chat/completions, so client code does not care which one you picked.

# vLLM
vllm serve Qwen/Qwen2.5-7B-Instruct --port 8000 --max-model-len 32768

# SGLang
python -m sglang.launch_server --model-path Qwen/Qwen2.5-7B-Instruct --port 8000

# TensorRT-LLM (PyTorch backend, no engine build)
trtllm-serve Qwen/Qwen2.5-7B-Instruct --port 8000

# llama.cpp with a local GGUF
llama-server -m qwen2.5-7b-instruct-q4_k_m.gguf --port 8000 -ngl 99
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")
resp = client.chat.completions.create(
    model="Qwen/Qwen2.5-7B-Instruct",
    messages=[{"role": "user", "content": "Summarise PagedAttention in two lines."}],
    stream=True,
)
for chunk in resp:
    print(chunk.choices[0].delta.content or "", end="", flush=True)

Flags drift between versions, so always confirm with --help on the exact build you deploy.

Trade-offs and pitfalls

  • Benchmarks are workload-specific. Published comparisons swing heavily with prompt length, prefix overlap, batch size and quantization. A chart showing SGLang far ahead on prefix-heavy RAG says little about your short-prompt classification API. Run your own traffic replay.
  • "OpenAI compatible" is not identical. Tool calling formats, response_format support, logprobs and usage fields differ in the details. Test the features you depend on.
  • Hardware lock-in. TensorRT-LLM is NVIDIA only. vLLM and SGLang support more vendors, but kernel quality varies by backend, so test on the hardware you will actually buy.
  • Release cadence is fast. These projects ship often and change defaults. Pin versions, read release notes, and re-benchmark on upgrades.
  • Do not add orchestration too early. Dynamo or llm-d add real operational weight. One engine per node with a decent load balancer gets most teams very far.

Checklist

  • My engine is under active development (not in maintenance mode) for new projects.
  • I benchmarked at least two engines on a replay of my real traffic.
  • I verified the OpenAI-compatible features I use (tools, JSON mode, streaming usage).
  • I pinned the engine version and have a re-benchmark step for upgrades.
  • I know whether my workload has enough prefix overlap to favour prefix caching.
  • I only adopt disaggregated serving once single-pool serving is the measured bottleneck.

Further reading

Why this exists README

I learn best by explaining things, so I record the explanations. Everything here is free, with no sign-up. If a lesson helps you ship something, I'd love to hear about it.