TensorRT-LLM
NVIDIA's open-source library for optimizing LLM inference with state-of-the-art 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)
docker pull nvidia/tensorrt_llm:latest
# pip install
pip install tensorrt_llm==1.2.0rc3
# Requires CUDA 13.0.0, TensorRT 10.13.2, 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
Execution Workflow
- Load target context and configurations.
- Execute structured capabilities deterministically.
- Validate output artifacts against criteria.
1---2name: tensorrt-llm-gpu-kernel-acceleration-23description: Optimizes LLM inference with NVIDIA TensorRT for maximum throughput and lowest latency. Use for production deployment on NVIDIA GPUs (A100/H100), when you need 10-100x faster inference than PyTorch, or for serving models with quantization (FP8/INT4), in-flight batching, and multi-GPU scaling.4version: 1.0.05author: Orchestra Research6license: MIT7tags: [Inference Serving, TensorRT-LLM, NVIDIA, Inference Optimization, High Throughput, Low Latency, Production, FP8, INT4, In-Flight Batching, Multi-GPU]8dependencies: [tensorrt-llm, torch]9metadata:10 source: https://skillmd.com/skills/robertoatila/tensorrt-llm-gpu-kernel-acceleration-211---1213# TensorRT-LLM1415NVIDIA's open-source library for optimizing LLM inference with state-of-the-art performance on NVIDIA GPUs.1617## When to use TensorRT-LLM1819**Use TensorRT-LLM when:**20- Deploying on NVIDIA GPUs (A100, H100, GB200)21- Need maximum throughput (24,000+ tokens/sec on Llama 3)22- Require low latency for real-time applications23- Working with quantized models (FP8, INT4, FP4)24- Scaling across multiple GPUs or nodes2526**Use vLLM instead when:**27- Need simpler setup and Python-first API28- Want PagedAttention without TensorRT compilation29- Working with AMD GPUs or non-NVIDIA hardware3031**Use llama.cpp instead when:**32- Deploying on CPU or Apple Silicon33- Need edge deployment without NVIDIA GPUs34- Want simpler GGUF quantization format3536## Quick start3738### Installation3940```bash41# Docker (recommended)42docker pull nvidia/tensorrt_llm:latest4344# pip install45pip install tensorrt_llm==1.2.0rc34647# Requires CUDA 13.0.0, TensorRT 10.13.2, Python 3.10-3.1248```4950### Basic inference5152```python53from tensorrt_llm import LLM, SamplingParams5455# Initialize model56llm = LLM(model="meta-llama/Meta-Llama-3-8B")5758# Configure sampling59sampling_params = SamplingParams(60 max_tokens=100,61 temperature=0.7,62 top_p=0.963)6465# Generate66prompts = ["Explain quantum computing"]67outputs = llm.generate(prompts, sampling_params)6869for output in outputs:70 print(output.text)71```7273### Serving with trtllm-serve7475```bash76# Start server (automatic model download and compilation)77trtllm-serve meta-llama/Meta-Llama-3-8B \78 --tp_size 4 \ # Tensor parallelism (4 GPUs)79 --max_batch_size 256 \80 --max_num_tokens 40968182# Client request83curl -X POST http://localhost:8000/v1/chat/completions \84 -H "Content-Type: application/json" \85 -d '{86 "model": "meta-llama/Meta-Llama-3-8B",87 "messages": [{"role": "user", "content": "Hello!"}],88 "temperature": 0.7,89 "max_tokens": 10090 }'91```9293## Key features9495### Performance optimizations96- **In-flight batching**: Dynamic batching during generation97- **Paged KV cache**: Efficient memory management98- **Flash Attention**: Optimized attention kernels99- **Quantization**: FP8, INT4, FP4 for 2-4× faster inference100- **CUDA graphs**: Reduced kernel launch overhead101102### Parallelism103- **Tensor parallelism (TP)**: Split model across GPUs104- **Pipeline parallelism (PP)**: Layer-wise distribution105- **Expert parallelism**: For Mixture-of-Experts models106- **Multi-node**: Scale beyond single machine107108### Advanced features109- **Speculative decoding**: Faster generation with draft models110- **LoRA serving**: Efficient multi-adapter deployment111- **Disaggregated serving**: Separate prefill and generation112113## Common patterns114115### Quantized model (FP8)116117```python118from tensorrt_llm import LLM119120# Load FP8 quantized model (2× faster, 50% memory)121llm = LLM(122 model="meta-llama/Meta-Llama-3-70B",123 dtype="fp8",124 max_num_tokens=8192125)126127# Inference same as before128outputs = llm.generate(["Summarize this article..."])129```130131### Multi-GPU deployment132133```python134# Tensor parallelism across 8 GPUs135llm = LLM(136 model="meta-llama/Meta-Llama-3-405B",137 tensor_parallel_size=8,138 dtype="fp8"139)140```141142### Batch inference143144```python145# Process 100 prompts efficiently146prompts = [f"Question {i}: ..." for i in range(100)]147148outputs = llm.generate(149 prompts,150 sampling_params=SamplingParams(max_tokens=200)151)152153# Automatic in-flight batching for maximum throughput154```155156## Performance benchmarks157158**Meta Llama 3-8B** (H100 GPU):159- Throughput: 24,000 tokens/sec160- Latency: ~10ms per token161- vs PyTorch: **100× faster**162163**Llama 3-70B** (8× A100 80GB):164- FP8 quantization: 2× faster than FP16165- Memory: 50% reduction with FP8166167## Supported models168169- **LLaMA family**: Llama 2, Llama 3, CodeLlama170- **GPT family**: GPT-2, GPT-J, GPT-NeoX171- **Qwen**: Qwen, Qwen2, QwQ172- **DeepSeek**: DeepSeek-V2, DeepSeek-V3173- **Mixtral**: Mixtral-8x7B, Mixtral-8x22B174- **Vision**: LLaVA, Phi-3-vision175- **100+ models** on HuggingFace176177## References178179- **[Optimization Guide](references/optimization.md)** - Quantization, batching, KV cache tuning180- **[Multi-GPU Setup](references/multi-gpu.md)** - Tensor/pipeline parallelism, multi-node181- **[Serving Guide](references/serving.md)** - Production deployment, monitoring, autoscaling182183## Resources184185- **Docs**: https://nvidia.github.io/TensorRT-LLM/186- **GitHub**: https://github.com/NVIDIA/TensorRT-LLM187- **Models**: https://huggingface.co/models?library=tensorrt_llm188189190191192## Execution Workflow1931941. Load target context and configurations.1952. Execute structured capabilities deterministically.1963. Validate output artifacts against criteria.