TensorRT-LLM
NVIDIA's open-source library for optimizing LLM inference with high performance on NVIDIA GPUs.
When to use TensorRT-LLM
Use TensorRT-LLM when:
- Deploying on NVIDIA GPUs (A100, H100, GB200)
- Need maximum throughput (24,000+ tokens/sec on Llama 3)
- Require low latency for real-time applications
- Working with quantized models (FP8, INT4, FP4)
- Scaling across multiple GPUs or nodes
Use vLLM instead when:
- Need simpler setup and Python-first API
- Want PagedAttention without TensorRT compilation
- Working with AMD GPUs or non-NVIDIA hardware
Use llama.cpp instead when:
- Deploying on CPU or Apple Silicon
- Need edge deployment without NVIDIA GPUs
- Want simpler GGUF quantization format
Quick start
Installation
# Docker (recommended) — images are on NGC (nvcr.io), not Docker Hub.
# Replace x.y.z with the desired version (e.g. 1.2.1). Browse tags on NGC:
# https://catalog.ngc.nvidia.com/orgs/nvidia/teams/tensorrt-llm/containers/release/tags
docker pull nvcr.io/nvidia/tensorrt-llm/release:x.y.z
# pip install (current stable GA)
pip install tensorrt_llm
# Requires CUDA 13.2.1, TensorRT 10.x, Python 3.10-3.12
Basic inference
from tensorrt_llm import LLM, SamplingParams
# Initialize model
llm = LLM(model="meta-llama/Meta-Llama-3-8B")
# Configure sampling
sampling_params = SamplingParams(
max_tokens=100,
temperature=0.7,
top_p=0.9
)
# Generate
prompts = ["Explain quantum computing"]
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
print(output.text)
Serving with trtllm-serve
# Start server (automatic model download and compilation)
trtllm-serve meta-llama/Meta-Llama-3-8B \
--tp_size 4 \ # Tensor parallelism (4 GPUs)
--max_batch_size 256 \
--max_num_tokens 4096
# Client request
curl -X POST http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "meta-llama/Meta-Llama-3-8B",
"messages": [{"role": "user", "content": "Hello!"}],
"temperature": 0.7,
"max_tokens": 100
}'
Key features
Performance optimizations
- In-flight batching: Dynamic batching during generation
- Paged KV cache: Efficient memory management
- Flash Attention: Optimized attention kernels
- Quantization: FP8, INT4, FP4 for 2-4× faster inference
- CUDA graphs: Reduced kernel launch overhead
Parallelism
- Tensor parallelism (TP): Split model across GPUs
- Pipeline parallelism (PP): Layer-wise distribution
- Expert parallelism: For Mixture-of-Experts models
- Multi-node: Scale beyond single machine
Advanced features
- Speculative decoding: Faster generation with draft models
- LoRA serving: Efficient multi-adapter deployment
- Disaggregated serving: Separate prefill and generation
Common patterns
Quantized model (FP8)
from tensorrt_llm import LLM
# Load FP8 quantized model (2× faster, 50% memory)
llm = LLM(
model="meta-llama/Meta-Llama-3-70B",
dtype="fp8",
max_num_tokens=8192
)
# Inference same as before
outputs = llm.generate(["Summarize this article..."])
Multi-GPU deployment
# Tensor parallelism across 8 GPUs
llm = LLM(
model="meta-llama/Meta-Llama-3-405B",
tensor_parallel_size=8,
dtype="fp8"
)
Batch inference
# Process 100 prompts efficiently
prompts = [f"Question {i}: ..." for i in range(100)]
outputs = llm.generate(
prompts,
sampling_params=SamplingParams(max_tokens=200)
)
# Automatic in-flight batching for maximum throughput
Performance benchmarks
Meta Llama 3-8B (H100 GPU):
- Throughput: 24,000 tokens/sec
- Latency: ~10ms per token
- vs PyTorch: 100× faster
Llama 3-70B (8× A100 80GB):
- FP8 quantization: 2× faster than FP16
- Memory: 50% reduction with FP8
Supported models
- LLaMA family: Llama 2, Llama 3, CodeLlama
- GPT family: GPT-2, GPT-J, GPT-NeoX
- Qwen: Qwen, Qwen2, QwQ
- DeepSeek: DeepSeek-V2, DeepSeek-V3
- Mixtral: Mixtral-8x7B, Mixtral-8x22B
- Vision: LLaVA, Phi-3-vision
- 100+ models on HuggingFace
References
- Optimization Guide - Quantization, batching, KV cache tuning
- Multi-GPU Setup - Tensor/pipeline parallelism, multi-node
- Serving Guide - Production deployment, monitoring, autoscaling
Resources
1---2name: tensorrt-llm3description: High-throughput LLM inference on NVIDIA GPUs.4version: 1.0.15author: Orchestra Research6license: MIT7dependencies: [tensorrt-llm, torch]8platforms: [linux, macos]9metadata:10 loki:11 tags: [Inference Serving, TensorRT-LLM, NVIDIA, Inference Optimization, High Throughput, Low Latency, Production, FP8, INT4, In-Flight Batching, Multi-GPU]1213---1415# TensorRT-LLM1617NVIDIA's open-source library for optimizing LLM inference with high performance on NVIDIA GPUs.1819## When to use TensorRT-LLM2021**Use TensorRT-LLM when:**22- Deploying on NVIDIA GPUs (A100, H100, GB200)23- Need maximum throughput (24,000+ tokens/sec on Llama 3)24- Require low latency for real-time applications25- Working with quantized models (FP8, INT4, FP4)26- Scaling across multiple GPUs or nodes2728**Use vLLM instead when:**29- Need simpler setup and Python-first API30- Want PagedAttention without TensorRT compilation31- Working with AMD GPUs or non-NVIDIA hardware3233**Use llama.cpp instead when:**34- Deploying on CPU or Apple Silicon35- Need edge deployment without NVIDIA GPUs36- Want simpler GGUF quantization format3738## Quick start3940### Installation4142```bash43# Docker (recommended) — images are on NGC (nvcr.io), not Docker Hub.44# Replace x.y.z with the desired version (e.g. 1.2.1). Browse tags on NGC:45# https://catalog.ngc.nvidia.com/orgs/nvidia/teams/tensorrt-llm/containers/release/tags46docker pull nvcr.io/nvidia/tensorrt-llm/release:x.y.z4748# pip install (current stable GA)49pip install tensorrt_llm5051# Requires CUDA 13.2.1, TensorRT 10.x, Python 3.10-3.1252```5354### Basic inference5556```python57from tensorrt_llm import LLM, SamplingParams5859# Initialize model60llm = LLM(model="meta-llama/Meta-Llama-3-8B")6162# Configure sampling63sampling_params = SamplingParams(64 max_tokens=100,65 temperature=0.7,66 top_p=0.967)6869# Generate70prompts = ["Explain quantum computing"]71outputs = llm.generate(prompts, sampling_params)7273for output in outputs:74 print(output.text)75```7677### Serving with trtllm-serve7879```bash80# Start server (automatic model download and compilation)81trtllm-serve meta-llama/Meta-Llama-3-8B \82 --tp_size 4 \ # Tensor parallelism (4 GPUs)83 --max_batch_size 256 \84 --max_num_tokens 40968586# Client request87curl -X POST http://localhost:8000/v1/chat/completions \88 -H "Content-Type: application/json" \89 -d '{90 "model": "meta-llama/Meta-Llama-3-8B",91 "messages": [{"role": "user", "content": "Hello!"}],92 "temperature": 0.7,93 "max_tokens": 10094 }'95```9697## Key features9899### Performance optimizations100- **In-flight batching**: Dynamic batching during generation101- **Paged KV cache**: Efficient memory management102- **Flash Attention**: Optimized attention kernels103- **Quantization**: FP8, INT4, FP4 for 2-4× faster inference104- **CUDA graphs**: Reduced kernel launch overhead105106### Parallelism107- **Tensor parallelism (TP)**: Split model across GPUs108- **Pipeline parallelism (PP)**: Layer-wise distribution109- **Expert parallelism**: For Mixture-of-Experts models110- **Multi-node**: Scale beyond single machine111112### Advanced features113- **Speculative decoding**: Faster generation with draft models114- **LoRA serving**: Efficient multi-adapter deployment115- **Disaggregated serving**: Separate prefill and generation116117## Common patterns118119### Quantized model (FP8)120121```python122from tensorrt_llm import LLM123124# Load FP8 quantized model (2× faster, 50% memory)125llm = LLM(126 model="meta-llama/Meta-Llama-3-70B",127 dtype="fp8",128 max_num_tokens=8192129)130131# Inference same as before132outputs = llm.generate(["Summarize this article..."])133```134135### Multi-GPU deployment136137```python138# Tensor parallelism across 8 GPUs139llm = LLM(140 model="meta-llama/Meta-Llama-3-405B",141 tensor_parallel_size=8,142 dtype="fp8"143)144```145146### Batch inference147148```python149# Process 100 prompts efficiently150prompts = [f"Question {i}: ..." for i in range(100)]151152outputs = llm.generate(153 prompts,154 sampling_params=SamplingParams(max_tokens=200)155)156157# Automatic in-flight batching for maximum throughput158```159160## Performance benchmarks161162**Meta Llama 3-8B** (H100 GPU):163- Throughput: 24,000 tokens/sec164- Latency: ~10ms per token165- vs PyTorch: **100× faster**166167**Llama 3-70B** (8× A100 80GB):168- FP8 quantization: 2× faster than FP16169- Memory: 50% reduction with FP8170171## Supported models172173- **LLaMA family**: Llama 2, Llama 3, CodeLlama174- **GPT family**: GPT-2, GPT-J, GPT-NeoX175- **Qwen**: Qwen, Qwen2, QwQ176- **DeepSeek**: DeepSeek-V2, DeepSeek-V3177- **Mixtral**: Mixtral-8x7B, Mixtral-8x22B178- **Vision**: LLaVA, Phi-3-vision179- **100+ models** on HuggingFace180181## References182183- **[Optimization Guide](references/optimization.md)** - Quantization, batching, KV cache tuning184- **[Multi-GPU Setup](references/multi-gpu.md)** - Tensor/pipeline parallelism, multi-node185- **[Serving Guide](references/serving.md)** - Production deployment, monitoring, autoscaling186187## Resources188189- **Docs**: https://nvidia.github.io/TensorRT-LLM/190- **GitHub**: https://github.com/NVIDIA/TensorRT-LLM191- **Models**: https://huggingface.co/models?library=tensorrt_llm192193