TensorRT-LLM

On this page 8

TensorRT-LLM is an open-source NVIDIA library for optimizing large language model inference on NVIDIA GPUs. Among AI frameworks & tools, it sits at the serving end of the stack: it takes a trained model, typically from Hugging Face Transformers or a PyTorch checkpoint, and runs it with specialized attention kernels, quantization, batching and multi-GPU parallelism so that each GPU produces more tokens per second at a lower cost per request.

The library is published under the Apache 2.0 license and exposes a Python LLM API, a command-line server and a backend for Triton Inference Server. In the broader field of Artificial intelligence, it belongs to the group of inference engines that also includes vLLM, SGLang and Text Generation Inference, with the distinction that it is tuned specifically for NVIDIA hardware.

How TensorRT-LLM accelerates inference

TensorRT-LLM speeds up inference by replacing generic model operations with fused, hardware-specific GPU kernels and by scheduling many requests together. Early releases compiled each model into a TensorRT engine, a serialized and optimized execution plan built ahead of time for one GPU type. Since version 1.0, the PyTorch-based backend is the default, which keeps model code readable while still calling the optimized kernels underneath.

Text generation has two phases with very different behavior. The prefill phase processes the whole prompt in parallel and is limited by compute, while the decode phase generates one token at a time and is limited by memory bandwidth, because the model weights and the key-value cache must be read for every token. Most optimizations in the library target one of these two bottlenecks.

The table below lists the core runtime components and the bottleneck each one addresses.

ComponentWhat it doesMain benefit
In-flight batchingAdds and removes requests from a running batch at every stepKeeps the GPU busy, raises throughput
Paged KV cacheStores attention keys and values in fixed-size memory blocksReduces fragmentation, fits more sequences
KV cache reuseShares cached blocks for identical prompt prefixesFaster time to first token
Chunked prefillSplits long prompts into smaller piecesSmoother latency for concurrent users
Fused attention kernelsCombines attention steps into single GPU callsFewer memory round trips
Speculative decodingProposes several tokens and verifies them in one passLower latency per output token
Core runtime components of TensorRT-LLM

Quantization and precision options

Quantization is the largest single lever for TensorRT-LLM performance, because the decode phase is bound by how many bytes must be moved per token. Storing weights in 8-bit or 4-bit formats cuts memory traffic and lets a model fit on fewer GPUs. The trade-off is a possible loss of accuracy, which must be measured on the target task rather than assumed.

Supported formats depend on the GPU generation. The following table summarizes the common choices.

FormatTypical hardwareMemory saving vs FP16Accuracy risk
FP16 / BF16Most data center GPUsNone (baseline)None
FP8Hopper and Ada Lovelace or newerAbout 2xLow with calibration
INT8 SmoothQuantAmpere or newerAbout 2xLow to moderate
INT4 AWQ / GPTQAmpere or newerAbout 3-4x for weightsModerate, task dependent
NVFP4BlackwellAbout 3-4xLow to moderate with calibration
Common precision formats and their requirements

Quantized checkpoints are usually produced with the NVIDIA Model Optimizer toolkit, which runs a short calibration pass on representative data. The KV cache can be quantized separately, which matters for long contexts where the cache, not the weights, dominates memory use.

Scaling across GPUs and nodes

TensorRT-LLM distributes models that are too large for one GPU through several forms of model parallelism, using NCCL for communication between devices. The right combination depends on model size, interconnect speed and whether the model uses a mixture-of-experts architecture.

  • Tensor parallelism splits each layer’s matrices across GPUs and needs a fast interconnect such as NVLink.
  • Pipeline parallelism places consecutive layers on different GPUs and tolerates slower links but adds pipeline bubbles.
  • Expert parallelism spreads the experts of a mixture-of-experts model across devices.
  • Disaggregated serving runs prefill and decode on separate GPU pools so that each phase can be sized independently.

Disaggregated serving is often orchestrated by NVIDIA Dynamo, which routes requests and transfers KV cache between pools, while TensorRT-LLM performs the actual computation.

TensorRT-LLM is one of several engines for serving language models, and the choice usually depends on hardware, operational simplicity and model coverage rather than raw speed alone. The comparison below covers the neighbors most often evaluated alongside it.

ToolPrimary roleHardware focusRelation to TensorRT-LLM
TensorRTGeneral deep learning inference optimizerNVIDIA GPUsFoundation that TensorRT-LLM extends for language models
vLLMGeneral LLM serving engineNVIDIA, AMD and othersDirect alternative, broader hardware support
SGLangLLM serving with structured generationNVIDIA and AMDDirect alternative, strong prefix caching
Triton Inference ServerMulti-framework model serverCPU and GPUHosts TensorRT-LLM through a dedicated backend
llama.cppLightweight local inferenceCPU, consumer GPUsTargets laptops and edge, not data centers
TensorRT-LLM and neighboring tools

In practice, TensorRT-LLM often leads on peak throughput on recent NVIDIA GPUs, especially with FP8 or NVFP4, while alternatives may be faster to adopt for new model architectures. Published benchmarks vary widely with model, batch size and configuration, so teams should benchmark their own workload before committing.

Deploying TensorRT-LLM in practice

A typical deployment starts with the LLM API in Python, which loads a Hugging Face model by name or path and applies the chosen quantization and parallelism settings. For production, the trtllm-serve command exposes an OpenAI-compatible HTTP endpoint, and containers published through the NVIDIA NGC catalog provide a tested environment with matching CUDA and driver versions.

The following decision table maps common situations to a sensible starting configuration.

SituationRecommended settingReason
Chat service with many usersIn-flight batching with FP8Maximizes throughput per GPU
Strict latency targetSpeculative decoding, small batchReduces time per output token
Shared system promptEnable KV cache reuseSkips repeated prefill work
Model larger than one GPUTensor parallelism over NVLinkKeeps communication fast
Long documents as inputChunked prefill, quantized KV cacheControls memory and latency spikes
Choosing a starting configuration

Limitations and common mistakes

The main limitation of TensorRT-LLM is vendor lock-in to NVIDIA GPUs: it does not run on AMD, Intel or Apple hardware. Support for a newly released model architecture can lag behind more general engines, and version mismatches between the library, CUDA and drivers are a frequent source of build and runtime errors.

SymptomLikely causeFix
Out-of-memory errors at loadKV cache fraction set too highLower the cache memory fraction
Accuracy drop after quantizationPoor calibration dataCalibrate on task-like samples
Low throughput despite large GPUBatch size or token limit too smallRaise maximum batch and token limits
Engine fails on another GPU modelEngine built for different hardwareRebuild on the target GPU type
Frequent problems and their fixes

The idea in brief

A language model is like a huge recipe book. Every word it writes requires reading a large part of that book. TensorRT-LLM makes the reading much faster on NVIDIA graphics cards.

It does this in a few simple ways. It stores numbers in smaller, compact formats. It serves many users at the same time instead of one by one. It also splits very large models across several cards. The result is faster answers at a lower cost. The catch is that it only works on NVIDIA hardware.

A practical scenario

An insurance company runs an internal assistant that summarizes claim files for about 400 employees. The first version served an open-weight model with 70 billion parameters in BF16 precision on four GPUs, and responses slowed noticeably during morning peaks when more than 60 people sent requests at once.

The platform team moved the model to TensorRT-LLM with FP8 weights and an FP8 KV cache, enabled in-flight batching and turned on KV cache reuse for the long shared system prompt. After validating summary quality on 500 archived claims, they found no meaningful difference from the original output.

The new setup handled the same peak traffic on two GPUs instead of four, and the median time to first token dropped noticeably. The freed GPUs were reassigned to a document search project, which made lower hardware cost the main outcome of the migration.