Skip to content

vLLM vs SGLang vs TensorRT-LLM: choosing an inference engine

vLLM vs SGLang vs TensorRT-LLM: how each inference engine batches, caches, and schedules, where each one wins, and why you benchmark on your own traffic.

Published
Updated
Reading time
13 min read

In short

  • vLLM vs SGLang is a choice between two open-source inference engines built on the same ideas: paged KV cache memory, continuous batching, and reuse of shared prompt prefixes. They differ in scheduling, defaults, and what each one optimizes first.
  • SGLang keeps the KV cache of earlier requests in a radix tree and reuses any shared prefix, which suits multi-turn chat, agents, and structured output. vLLM has the broadest hardware and model support and is the safest default.
  • TensorRT-LLM now runs on PyTorch by default, with no engine-build step, and targets NVIDIA GPUs only. Test it when you serve on recent NVIDIA hardware and want NVIDIA's own kernels.
  • Published benchmarks disagree because the projects release often. Benchmark current versions on your model, your GPUs, and a replay of your own prompts before you commit.

vLLM vs SGLang is the choice most teams face when they move from hosted model APIs to serving open-weight models on their own GPUs. Both are open-source inference engines: servers that load a model onto GPUs, accept requests over an OpenAI-compatible API, and decide how to batch and cache work so the hardware stays busy. TensorRT-LLM, NVIDIA's engine, is the usual third candidate.

The short answer: start with vLLM if you want the broadest hardware and model support, try SGLang first if your traffic reuses long shared prefixes (multi-turn chat, agents, few-shot prompts), and benchmark TensorRT-LLM if you serve only on recent NVIDIA GPUs. Then test all of them on your own traffic, because the published numbers will not tell you which one wins for you.

What an inference engine does

An inference engine is the program between your model weights and your GPUs. It schedules incoming requests, groups them into batches, manages the memory that holds each request's attention state, runs optimized kernels, and splits large models across devices. Throughput and latency come from those five jobs far more than from the model file.

Every request runs in two phases. Prefill reads the whole prompt in one pass and decides time to first token. Decode then produces output one token at a time. During both, the engine keeps a key-value tensor for every token the model has seen, the KV cache, so it never recomputes attention over earlier tokens.

The jobs an engine does on every step:

  • Scheduling: which waiting requests join the next batch, and which running ones pause when memory is short.
  • Batching: running many requests through the GPU together. Continuous batching adds and removes requests at every decode step instead of waiting for a whole batch to finish.
  • KV cache memory: allocating, sharing, and evicting attention state. This is usually the limit on how many requests fit at once.
  • Kernels: the attention, matrix multiply, and quantized-math code that runs on the accelerator.
  • Parallelism: splitting one model across GPUs (tensor, pipeline, or expert parallelism) when it does not fit on one.
REQUESTSGatewayONE API · KEYSMORE REPLICASInference engineVLLM · SGLANG · TRT-LLMSchedulerContinuous batchingPaged KV cachePrefix reuseKernelsGPU 0WEIGHTS · KV CACHEGPU 1TENSOR PARALLELONE MODEL, TWO GPUS
An inference engine sits behind your gateway. Its scheduler decides what joins each batch, and the KV cache it manages decides how many requests fit on the GPUs at once.

All three engines below do all five jobs. They differ in how they manage the KV cache, how aggressively they reuse it across requests, and which hardware they treat as first class.

vLLM vs SGLang vs TensorRT-LLM at a glance

The three engines converge on the same core techniques and diverge on defaults and hardware. vLLM covers the most accelerators and model architectures. SGLang reuses cached prefixes more aggressively and leads on structured programs. TensorRT-LLM is NVIDIA's own engine, tuned for NVIDIA GPUs and nothing else.

vLLMSGLangTensorRT-LLM
OriginSky Computing Lab, UC BerkeleyIntroduced on the LMSYS blog in 2024NVIDIA
LicenseApache-2.0Apache-2.0Apache-2.0
KV cache memoryPagedAttention: fixed-size blocksPaged, one token per pagePaged KV cache with block reuse
Prefix reuseHash of full blocks, on by default since V1Radix tree of all cached tokensBlock reuse across requests
Structured outputxgrammar or guidance backendsCompressed state machines, XGrammar by defaultGuided decoding with xgrammar or llguidance
HardwareNVIDIA, AMD, Intel, CPUs, and plugins for TPU, Gaudi, Ascend, and moreNVIDIA, AMD, Intel, TPU, Ascend, Moore Threads, Apple SiliconNVIDIA GPUs only
Servervllm serve, OpenAI and Anthropic APIssglang.launch_server, OpenAI APItrtllm-serve, OpenAI API

All three expose an OpenAI-compatible HTTP server, which matters more than it looks. Your application, your gateway, and your load tests can treat the engine as a swappable backend.

terminal
# vLLM: OpenAI-compatible server on localhost:8000
vllm serve Qwen/Qwen2.5-1.5B-Instruct
 
# SGLang: OpenAI-compatible server, port 30000 by default
python -m sglang.launch_server --model-path meta-llama/Meta-Llama-3.1-8B-Instruct --host 0.0.0.0
 
# TensorRT-LLM: loads the Hugging Face checkpoint directly
trtllm-serve TinyLlama/TinyLlama-1.1B-Chat-v1.0

vLLM: PagedAttention and the broadest support

vLLM's core idea is PagedAttention: store each request's KV cache in fixed-size blocks, the way an operating system stores memory in pages, instead of reserving one contiguous region sized for the longest possible output. Memory is allocated as tokens arrive, so far more requests fit on the same GPU.

The PagedAttention paper frames the problem plainly: managed inefficiently, KV cache memory is wasted through fragmentation and duplication, which caps batch size. The authors report near-zero waste and 2 to 4 times the throughput of FasterTransformer and Orca at the same latency, with larger gains on longer sequences and bigger models. That result is from 2023, and every serious engine now pages its KV cache, so read it as the reason the design won, not as today's margin.

On top of paging, vLLM batches continuously, splits long prefills into chunks, and caches prefixes. Its prefix caching hashes each full KV block together with all the tokens before it, reuses blocks when a new request starts with the same tokens, and evicts the least recently used blocks first. The V1 engine turned prefix caching on by default because its overhead dropped to near zero.

vLLM's strength is breadth:

  • Hardware: NVIDIA GPUs with compute capability 7.5 or higher, AMD GPUs on ROCm, Intel GPUs, x86, ARM, and PowerPC CPUs, plus plugins for Google TPUs, Intel Gaudi, Huawei Ascend, and others. Linux is the only natively supported operating system.
  • Quantization: FP8, NVFP4, INT8, INT4, GPTQ, AWQ, GGUF, and more.
  • Speculative decoding: n-gram, suffix, and EAGLE methods, among others.
  • Parallelism: tensor, pipeline, data, expert, and context parallelism, with Ray for multi-node serving.
  • APIs: OpenAI-compatible, plus an Anthropic Messages API and gRPC.

The cost of breadth is focus. vLLM is not tuned for one accelerator the way TensorRT-LLM is tuned for NVIDIA, and its prefix cache only reuses whole blocks. What you get in return is the engine most likely to run your model on your hardware on the first try, which is why it is a common default.

SGLang: RadixAttention and structured programs

SGLang treats the KV cache as a cache of everything it has already computed. It keeps the attention state of finished prompts and generated outputs in a radix tree keyed by token sequences, so any new request that shares a prefix with any earlier one reuses that work, not only a fixed system prompt.

The LMSYS post that introduced it describes the mechanics: the tree holds KV tensors for prompts and generation results, stored on the GPU in pages of one token, and an LRU policy evicts leaf nodes when memory runs short. A cache-aware scheduler works with the tree to raise the hit rate. In current releases, --schedule-policy accepts lpm (longest prefix match) among other options; the default is first come, first served. RadixAttention is on unless you pass --disable-radix-cache.

This design pays off when prefixes branch. A multi-turn chat extends the previous turn. An agent sends the same tool definitions and history with a new observation on each step. A few-shot prompt shares its examples across thousands of requests. In each case SGLang finds the longest cached match without you marking anything.

SGLang also started as a way to run structured language model programs. The SGLang paper pairs RadixAttention with compressed finite state machines that speed up constrained decoding such as JSON output, and reports up to 6.4 times the throughput of the systems it compared on agent control, reasoning, few-shot, JSON decoding, RAG, and multi-turn chat. Today the server uses XGrammar by default for JSON schema, regex, and EBNF constraints, with one constraint type per request.

Hardware support is wide too: NVIDIA, AMD, Intel Xeon, Google TPU, Ascend NPU, and Moore Threads accelerators, with Apple Silicon listed in the project README. The cost is configuration surface. The server takes a long list of flags, and several of them, such as the scheduling policy, change behavior under load. Pin versions and read release notes before you upgrade.

TensorRT-LLM: NVIDIA's engine, now on PyTorch

TensorRT-LLM is NVIDIA's open-source library for LLM inference on NVIDIA GPUs. It used to require compiling a TensorRT engine for each model and GPU configuration. Since version 1.0, PyTorch is the default backend, and Hugging Face checkpoints load directly with no build step.

The engine backend is on its way out. The 1.3 release candidates removed it, starting with 1.3.0rc21, and PyTorch is the only backend there and on the main branch. The latest stable release, 1.2.1, still ships the engine backend as a legacy option.

The migration guide lists what the removal takes away, including the trtllm-build command. Many tutorials and comparisons online still describe the engine-build workflow, so check the date on anything you read about TensorRT-LLM. If it tells you to run trtllm-build, it predates the current design.

What remains is a feature set aimed at getting the most out of current NVIDIA hardware:

  • In-flight batching, NVIDIA's name for continuous batching.
  • A paged KV cache with block reuse across requests.
  • FP8 on Hopper GPUs such as the H100 and native FP4 kernels on Blackwell GPUs such as the B200.
  • Speculative decoding with EAGLE, MTP, and n-gram methods.
  • Disaggregated serving that puts prefill and decode on different GPUs, labeled beta.

trtllm-serve starts an OpenAI-compatible server with /v1/models, /v1/completions, and /v1/chat/completions endpoints, plus a Responses API. The cost is the obvious one: it runs on NVIDIA GPUs and nothing else. If your fleet is all recent NVIDIA hardware, that is not a constraint. If you want the option to move to other accelerators, it is.

Which engine wins for which workload

The right engine depends on the shape of your traffic and the hardware you have. Prefix-heavy, multi-turn, and structured workloads favor SGLang. Mixed hardware and a long tail of model architectures favor vLLM. An all-NVIDIA fleet chasing peak throughput per GPU should benchmark TensorRT-LLM against both.

Your situationTry firstWhy
Chat or agents that resend long, growing historiesSGLangRadix tree reuses any shared prefix
Many requests with heavy JSON or grammar constraintsSGLangBuilt around constrained decoding
A new or unusual model architecturevLLMA long supported-models list; check each engine's list for your model
AMD, TPU, Gaudi, or CPU servingvLLMMost hardware backends and plugins
Only recent NVIDIA GPUs, FP8 or FP4 weightsTensorRT-LLMNVIDIA's kernels and quantization paths
One default for a platform teamvLLMBroadest hardware support

The "try first" column is a starting point, not a verdict. vLLM also caches prefixes and supports structured outputs, and SGLang runs many models on many accelerators. The gap between them on any one workload is often smaller than the gap between a tuned and an untuned deployment of either.

Why vLLM vs SGLang benchmarks disagree

Published vLLM vs SGLang benchmarks contradict each other because each one is a snapshot: two specific versions, one model, one GPU type, one prompt mix, and one concurrency level. Both projects ship often and adopt similar techniques, so the leader changes from release to release and from workload to workload.

Look at what a benchmark held constant before you trust it. A test on short, unrelated prompts measures raw decode speed and gives prefix caching nothing to do. A test on multi-turn chat rewards prefix reuse. A test at a concurrency of 1 says nothing about a service with 200 users. And a test that compares a year-old release of one engine with the latest release of the other measures the calendar.

Run your own comparison instead. It answers the only question that matters: which engine is faster for your traffic.

Hold constantWhy it matters
Model weights and quantizationFP8 vs FP16 changes speed more than the engine does
Maximum context lengthIt sets how much memory each request may claim
GPU type and countKernels are tuned per architecture
Prompt setReplay real traffic, with its real prefix overlap
Concurrency levelsSweep from 1 to above your peak

Then record the numbers users feel: p95 time to first token, inter-token latency, output tokens per second at your target concurrency, the error rate, and the prefix cache hit rate. Pick the engine that meets your latency target at the lowest GPU count, not the one with the highest peak throughput on a chart.

Above the engine: routers, orchestrators, and gateways

One engine process serves one model on its own GPUs. Production serving adds layers above it: a router that sends each request to the replica most likely to have its prefix cached, an orchestrator that can split prefill and decode across GPU pools, and a gateway that handles keys, budgets, and failover.

Two open-source projects cover the middle layer. NVIDIA Dynamo runs on top of SGLang, TensorRT-LLM, or vLLM and adds disaggregated prefill and decode, KV-aware routing, and offloading of KV cache to CPU memory and storage. llm-d, a CNCF Sandbox project, is a Kubernetes-native stack above vLLM and SGLang with prefix-cache-aware and load-aware routing. Neither replaces the engine; both make many engine replicas behave like one service.

The top layer is the same LLM gateway you would put in front of hosted providers. It gives applications one API whether a request lands on your own vLLM cluster or a hosted model, applies per-team keys and budgets, and fails over to a hosted provider when your GPUs are saturated. Bifrost, an open-source AI gateway by Maxim AI, lists self-hosted vLLM and SGLang among its supported providers, so a self-hosted engine and a hosted API sit behind the same routing and failover rules.

That separation is the main reason to keep the engine choice reversible. If every application talks to a gateway, swapping vLLM for SGLang on one model is a change to a single provider entry, and you can canary it on a slice of traffic before you commit.

Frequently asked questions

Is SGLang faster than vLLM?

Sometimes. SGLang is built to lead on workloads with heavy prefix reuse, such as multi-turn chat and agents, because its radix tree reuses any shared prefix. On short, unrelated prompts there is little to reuse, so the gap narrows or reverses. Both projects release often, so results flip between versions. Benchmark current releases on your own model, hardware, and prompts.

What is the difference between vLLM and SGLang?

Both are open-source inference engines with paged KV cache memory, continuous batching, and OpenAI-compatible servers. vLLM caches prefixes by hashing fixed-size blocks and supports the most hardware and model types. SGLang keeps a radix tree of all cached tokens, reuses any shared prefix, and grew out of work on structured language model programs and fast constrained decoding.

Is TensorRT-LLM faster than vLLM?

It depends on the model, the GPU, and the release. TensorRT-LLM aims to lead on recent NVIDIA GPUs, with NVIDIA's own kernels and FP8 and FP4 quantization paths, but it runs only on NVIDIA hardware. vLLM runs on far more accelerators. Test both with the same weights, context length, and concurrency on your own GPUs before you decide.

Do you still need to build an engine for TensorRT-LLM?

No. PyTorch has been the default backend since version 1.0, and Hugging Face checkpoints load directly. The 1.3 release candidates go further and remove the engine backend and the trtllm-build command; the latest stable release, 1.2.1, still has them as a legacy option. Guides that describe compiling an engine per model and GPU configuration describe the older workflow.

Can you switch from vLLM to SGLang without changing your application?

Usually, yes. Both serve an OpenAI-compatible API, so an application that calls /v1/chat/completions works against either. Check the edges: model names, sampling parameters, structured-output options, and streaming behavior can differ. A gateway in front of both lets you move one model at a time and compare them on live traffic.

What is an LLM inference engine?

An LLM inference engine is the server software that runs a model on accelerators and answers requests. It schedules and batches requests, manages the KV cache that holds attention state, runs optimized kernels, and splits large models across GPUs. vLLM, SGLang, and TensorRT-LLM are inference engines; Ollama and llama.cpp target local and single-machine use.

Sources

  1. 01Efficient Memory Management for Large Language Model Serving with PagedAttentionarXiv:2309.06180
  2. 02SGLang: Efficient Execution of Structured Language Model ProgramsarXiv:2312.07104
  3. 03vLLM documentationvLLM docs
  4. 04vLLM V1: A Major Upgrade to vLLM's Core ArchitecturevLLM blog
  5. 05Automatic prefix caching designvLLM docs
  6. 06GPU installationvLLM docs
  7. 07Structured outputsvLLM docs
  8. 08Fast and Expressive LLM Inference with RadixAttention and SGLangLMSYS blog
  9. 09Server argumentsSGLang docs
  10. 10Structured outputsSGLang docs
  11. 11TensorRT LLM overviewNVIDIA docs
  12. 12Migration Guide: TensorRT Backend RemovedNVIDIA docs
  13. 13Guided decodingNVIDIA docs
  14. 14trtllm-serveNVIDIA docs
  15. 15NVIDIA DynamoGitHub
  16. 16llm-dGitHub
  17. 17Supported providersBifrost docs