Convert Figma logo to code with AI

NVIDIA logoTensorRT-LLM

TensorRT-LLM provides users with an easy-to-use Python API to define Large Language Models (LLMs) and build TensorRT engines that contain state-of-the-art optimizations to perform inference efficiently on NVIDIA GPUs. TensorRT-LLM also contains components to create Python and C++ runtimes that execute those TensorRT engines.

9,235
1,083
9,235
443

Top Related Projects

37,573

DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.

Transformer related optimization, including BERT, GPT

2,820

🚀 Accelerate inference and training of 🤗 Transformers, Diffusers, TIMM and Sentence Transformers with easy to use hardware optimization tools

18,282

Open standard for machine learning interoperability

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator

Reference implementations of MLPerf™ inference benchmarks

Quick Overview

TensorRT-LLM is an open-source library developed by NVIDIA for optimizing and deploying large language models (LLMs) using NVIDIA GPUs. It leverages TensorRT, NVIDIA's high-performance deep learning inference SDK, to accelerate LLM inference and reduce latency for various applications.

Pros

  • Significantly improves inference speed and reduces latency for LLMs
  • Supports popular LLM architectures like GPT, BERT, and T5
  • Provides optimizations for both single-GPU and multi-GPU/multi-node deployments
  • Offers integration with popular frameworks like PyTorch and Hugging Face Transformers

Cons

  • Limited to NVIDIA GPUs, not usable on other hardware platforms
  • Requires expertise in NVIDIA's ecosystem and tools for optimal use
  • May have a steeper learning curve compared to more general-purpose libraries
  • Documentation and community support might be less extensive than more established frameworks

Code Examples

  1. Building and running a GPT model:
import tensorrt_llm
from tensorrt_llm.models import GPTLMHeadModel

# Initialize the model
model = GPTLMHeadModel.from_pretrained("gpt2")

# Compile the model for TensorRT
engine = tensorrt_llm.build_engine(model)

# Run inference
output = engine.infer("Hello, world!")
  1. Quantizing a model for improved performance:
from tensorrt_llm.quantization import QuantMode

# Initialize the model with INT8 quantization
model = GPTLMHeadModel.from_pretrained("gpt2", quant_mode=QuantMode.INT8)

# Build the engine with quantization
engine = tensorrt_llm.build_engine(model, precision="int8")
  1. Multi-GPU inference:
import tensorrt_llm
from tensorrt_llm.models import GPTLMHeadModel

# Initialize the model for multi-GPU
model = GPTLMHeadModel.from_pretrained("gpt2", device_map="auto")

# Build engines for multiple GPUs
engines = tensorrt_llm.build_engines(model, num_gpus=4)

# Run inference across multiple GPUs
output = tensorrt_llm.infer_multi_gpu(engines, "Hello, world!")

Getting Started

To get started with TensorRT-LLM:

  1. Install TensorRT and CUDA:
pip install nvidia-tensorrt
  1. Install TensorRT-LLM:
git clone https://github.com/NVIDIA/TensorRT-LLM.git
cd TensorRT-LLM
pip install -e .
  1. Use TensorRT-LLM in your Python code:
import tensorrt_llm
from tensorrt_llm.models import GPTLMHeadModel

model = GPTLMHeadModel.from_pretrained("gpt2")
engine = tensorrt_llm.build_engine(model)
output = engine.infer("Hello, TensorRT-LLM!")
print(output)

Competitor Comparisons

37,573

DeepSpeed is a deep learning optimization library that makes distributed training and inference easy, efficient, and effective.

Pros of DeepSpeed

  • More flexible and framework-agnostic, supporting PyTorch, TensorFlow, and other deep learning frameworks
  • Offers a wider range of optimization techniques beyond inference, including training optimizations
  • Provides more extensive documentation and community support

Cons of DeepSpeed

  • May have slightly lower performance for specific NVIDIA hardware compared to TensorRT-LLM
  • Requires more manual configuration and tuning to achieve optimal performance
  • Less specialized for LLM inference, which can result in more complex setup for certain use cases

Code Comparison

DeepSpeed:

import deepspeed
model = deepspeed.init_inference(model, mp_size=2, dtype=torch.float16)
output = model(input_ids)

TensorRT-LLM:

import tensorrt_llm
engine = tensorrt_llm.runtime.Engine("path/to/engine")
output = engine.infer(input_ids)

Both libraries aim to optimize large language model inference, but DeepSpeed offers a more general-purpose solution with broader framework support, while TensorRT-LLM focuses on maximizing performance specifically for NVIDIA GPUs. The code snippets demonstrate that DeepSpeed integrates more closely with existing model objects, while TensorRT-LLM uses a separate engine for inference.

Transformer related optimization, including BERT, GPT

Pros of FasterTransformer

  • More mature and established project with a longer history
  • Supports a wider range of model architectures and use cases
  • Offers more flexibility in terms of customization and fine-tuning

Cons of FasterTransformer

  • Less optimized for specific LLM inference tasks
  • May require more manual configuration and setup
  • Potentially slower inference speed for certain LLM models

Code Comparison

FasterTransformer:

fastertransformer::Allocator<AllocatorType::CUDA> allocator(0);
fastertransformer::GptJ<half> gpt(
    max_batch_size, max_seq_len, head_num, size_per_head,
    inter_size, num_layer, vocab_size, start_id, end_id,
    &allocator, false, stream, cublas_wrapper, false);

TensorRT-LLM:

builder = Builder()
network = builder.create_network()
config = builder.create_builder_config()
model = GPTJForCausalLM(config)
engine = builder.build_engine(network, config)

The code snippets demonstrate the initialization process for each library. FasterTransformer uses C++ and requires more detailed configuration, while TensorRT-LLM offers a more high-level Python API for model creation and engine building.

2,820

🚀 Accelerate inference and training of 🤗 Transformers, Diffusers, TIMM and Sentence Transformers with easy to use hardware optimization tools

Pros of Optimum

  • Broader model support across various frameworks (PyTorch, TensorFlow, JAX)
  • Easier integration with Hugging Face ecosystem and model hub
  • More extensive documentation and community support

Cons of Optimum

  • Less specialized for NVIDIA hardware optimization
  • May not achieve the same level of performance as TensorRT-LLM for NVIDIA GPUs
  • Potentially more complex setup for specific NVIDIA optimizations

Code Comparison

Optimum:

from optimum.onnxruntime import ORTModelForSequenceClassification
model = ORTModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english", export=True)

TensorRT-LLM:

import tensorrt_llm
engine = tensorrt_llm.runtime.Engine("path/to/engine.plan")
model = tensorrt_llm.runtime.GenerationSession(engine)

Both repositories aim to optimize and accelerate machine learning models, but they have different focuses. Optimum provides a more general-purpose optimization toolkit for various frameworks, while TensorRT-LLM specializes in optimizing large language models for NVIDIA hardware. The choice between them depends on specific hardware requirements, model types, and integration needs within existing workflows.

18,282

Open standard for machine learning interoperability

Pros of ONNX

  • Broader ecosystem support and compatibility across various frameworks and hardware
  • More extensive model coverage, supporting a wide range of AI and ML models
  • Active community and contributions from multiple major tech companies

Cons of ONNX

  • Less optimized for NVIDIA GPUs compared to TensorRT-LLM
  • May require additional steps or tools for deployment on specific hardware
  • Potentially slower inference performance for certain models on NVIDIA hardware

Code Comparison

TensorRT-LLM:

import tensorrt_llm
model = tensorrt_llm.Builder().create_network()
# ... model definition ...
engine = tensorrt_llm.Builder().build_engine(model)

ONNX:

import onnx
model = onnx.ModelProto()
# ... model definition ...
onnx.save(model, "model.onnx")

Summary

While ONNX offers broader compatibility and ecosystem support, TensorRT-LLM provides more optimized performance for NVIDIA GPUs, especially for large language models. ONNX is more versatile across different frameworks and hardware, but may require additional optimization steps for specific deployments. TensorRT-LLM focuses on high-performance inference for LLMs on NVIDIA GPUs, offering potentially faster execution for these specific use cases.

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator

Pros of ONNX Runtime

  • Broader hardware support, including CPUs and various accelerators
  • More extensive ecosystem and integration with other ML frameworks
  • Easier deployment across different platforms and devices

Cons of ONNX Runtime

  • May have lower performance for specific NVIDIA GPU optimizations
  • Less specialized for large language models compared to TensorRT-LLM
  • Potentially more complex setup for high-performance LLM inference

Code Comparison

TensorRT-LLM:

import tensorrt_llm
model = tensorrt_llm.models.LLaMAForCausalLM.from_pretrained("path/to/model")
output = model.generate("Hello, how are you?")

ONNX Runtime:

import onnxruntime as ort
session = ort.InferenceSession("path/to/model.onnx")
input_name = session.get_inputs()[0].name
output = session.run(None, {input_name: "Hello, how are you?"})

Both repositories aim to optimize inference for machine learning models, but TensorRT-LLM focuses specifically on large language models and NVIDIA GPUs, while ONNX Runtime provides a more general-purpose solution for various hardware platforms.

Reference implementations of MLPerf™ inference benchmarks

Pros of MLCommons Inference

  • Broader scope: Covers a wide range of ML tasks and models, not limited to LLMs
  • Vendor-neutral: Supports multiple hardware platforms and frameworks
  • Established benchmarking standard: Widely recognized in the industry

Cons of MLCommons Inference

  • Less specialized: May not offer optimizations specific to LLMs
  • Higher complexity: Requires more setup and configuration for specific use cases
  • Slower development cycle: Updates may be less frequent due to broader focus

Code Comparison

TensorRT-LLM example:

import tensorrt_llm
from tensorrt_llm.models import GPTLMHeadModel

model = GPTLMHeadModel.from_pretrained("gpt2")
engine = model.to_engine()

MLCommons Inference example:

from mlperf_inference_src.loadgen import *

settings = TestSettings()
settings.scenario = Scenario.SingleStream
settings.mode = TestMode.PerformanceOnly
lg = ConstructLoadGenerator(settings)

Summary

TensorRT-LLM focuses on optimizing LLMs for NVIDIA hardware, offering specialized tools and potentially better performance for specific use cases. MLCommons Inference provides a more comprehensive benchmarking framework across various ML tasks and hardware platforms, but may lack the specialized optimizations for LLMs that TensorRT-LLM offers.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

TensorRT-LLM

A TensorRT Toolbox for Optimized Large Language Model Inference

Documentation python python cuda trt version license

Architecture   |   Performance   |   Examples   |   Documentation   |   Roadmap


Latest News

  • [03/22] TensorRT-LLM is now fully open-source, with developments moved to GitHub!

  • [03/18] 🚀🚀 NVIDIA Blackwell Delivers World-Record DeepSeek-R1 Inference Performance with TensorRT-LLM ➡️ Link

  • [02/28] 🌟 NAVER Place Optimizes SLM-Based Vertical Services with TensorRT-LLM ➡️ Link

  • [02/25] 🌟 DeepSeek-R1 performance now optimized for Blackwell ➡️ Link

  • [02/20] Explore the complete guide to achieve great accuracy, high throughput, and low latency at the lowest cost for your business here.

  • [02/18] Unlock #LLM inference with auto-scaling on @AWS EKS ✨ ➡️ link

  • [02/12] 🦸⚡ Automating GPU Kernel Generation with DeepSeek-R1 and Inference Time Scaling ➡️ link

  • [02/12] 🌟 How Scaling Laws Drive Smarter, More Powerful AI ➡️ link

  • [01/25] Nvidia moves AI focus to inference cost, efficiency ➡️ link

  • [01/24] 🏎️ Optimize AI Inference Performance with NVIDIA Full-Stack Solutions ➡️ link

  • [01/23] 🚀 Fast, Low-Cost Inference Offers Key to Profitable AI ➡️ link

  • [01/16] Introducing New KV Cache Reuse Optimizations in TensorRT-LLM ➡️ link

  • [01/14] 📣 Bing's Transition to LLM/SLM Models: Optimizing Search with TensorRT-LLM ➡️ link

  • [01/04] ⚡Boost Llama 3.3 70B Inference Throughput 3x with TensorRT-LLM Speculative Decoding ➡️ link

Previous News
  • [2024/12/10] ⚡ Llama 3.3 70B from AI at Meta is accelerated by TensorRT-LLM. 🌟 State-of-the-art model on par with Llama 3.1 405B for reasoning, math, instruction following and tool use. Explore the preview ➡️ link

  • [2024/12/03] 🌟 Boost your AI inference throughput by up to 3.6x. We now support speculative decoding and tripling token throughput with our NVIDIA TensorRT-LLM. Perfect for your generative AI apps. ⚡Learn how in this technical deep dive ➡️ link

  • [2024/12/02] Working on deploying ONNX models for performance-critical applications? Try our NVIDIA Nsight Deep Learning Designer ⚡ A user-friendly GUI and tight integration with NVIDIA TensorRT that offers: ✅ Intuitive visualization of ONNX model graphs ✅ Quick tweaking of model architecture and parameters ✅ Detailed performance profiling with either ORT or TensorRT ✅ Easy building of TensorRT engines ➡️ link

  • [2024/11/26] 📣 Introducing TensorRT-LLM for Jetson AGX Orin, making it even easier to deploy on Jetson AGX Orin with initial support in JetPack 6.1 via the v0.12.0-jetson branch of the TensorRT-LLM repo. ✅ Pre-compiled TensorRT-LLM wheels & containers for easy integration ✅ Comprehensive guides & docs to get you started ➡️ link

  • [2024/11/21] NVIDIA TensorRT-LLM Multiblock Attention Boosts Throughput by More Than 3x for Long Sequence Lengths on NVIDIA HGX H200 ➡️ link

  • [2024/11/19] Llama 3.2 Full-Stack Optimizations Unlock High Performance on NVIDIA GPUs ➡️ link

  • [2024/11/09] 🚀🚀🚀 3x Faster AllReduce with NVSwitch and TensorRT-LLM MultiShot ➡️ link

  • [2024/11/09] ✨ NVIDIA advances the AI ecosystem with the AI model of LG AI Research 🙌 ➡️ link

  • [2024/11/02] 🌟🌟🌟 NVIDIA and LlamaIndex Developer Contest 🙌 Enter for a chance to win prizes including an NVIDIA® GeForce RTX™ 4080 SUPER GPU, DLI credits, and more🙌 ➡️ link

  • [2024/10/28] 🏎️🏎️🏎️ NVIDIA GH200 Superchip Accelerates Inference by 2x in Multiturn Interactions with Llama Models ➡️ link

  • [2024/10/22] New 📝 Step-by-step instructions on how to ✅ Optimize LLMs with NVIDIA TensorRT-LLM, ✅ Deploy the optimized models with Triton Inference Server, ✅ Autoscale LLMs deployment in a Kubernetes environment. 🙌 Technical Deep Dive: ➡️ link

  • [2024/10/07] 🚀🚀🚀Optimizing Microsoft Bing Visual Search with NVIDIA Accelerated Libraries ➡️ link

  • [2024/09/29] 🌟 AI at Meta PyTorch + TensorRT v2.4 🌟 ⚡TensorRT 10.1 ⚡PyTorch 2.4 ⚡CUDA 12.4 ⚡Python 3.12 ➡️ link

  • [2024/09/17] ✨ NVIDIA TensorRT-LLM Meetup ➡️ link

  • [2024/09/17] ✨ Accelerating LLM Inference at Databricks with TensorRT-LLM ➡️ link

  • [2024/09/17] ✨ TensorRT-LLM @ Baseten ➡️ link

  • [2024/09/04] 🏎️🏎️🏎️ Best Practices for Tuning TensorRT-LLM for Optimal Serving with BentoML ➡️ link

  • [2024/08/20] 🏎️SDXL with #TensorRT Model Optimizer ⏱️⚡ 🏁 cache diffusion 🏁 quantization aware training 🏁 QLoRA 🏁 #Python 3.12 ➡️ link

  • [2024/08/13] 🐍 DIY Code Completion with #Mamba ⚡ #TensorRT #LLM for speed 🤖 NIM for ease ☁️ deploy anywhere ➡️ link

  • [2024/08/06] 🗫 Multilingual Challenge Accepted 🗫 🤖 #TensorRT #LLM boosts low-resource languages like Hebrew, Indonesian and Vietnamese ⚡➡️ link

  • [2024/07/30] Introducing🍊 @SliceXAI ELM Turbo 🤖 train ELM once ⚡ #TensorRT #LLM optimize ☁️ deploy anywhere ➡️ link

  • [2024/07/23] 👀 @AIatMeta Llama 3.1 405B trained on 16K NVIDIA H100s - inference is #TensorRT #LLM optimized ⚡ 🦙 400 tok/s - per node 🦙 37 tok/s - per user 🦙 1 node inference ➡️ link

  • [2024/07/09] Checklist to maximize multi-language performance of @meta #Llama3 with #TensorRT #LLM inference: ✅ MultiLingual ✅ NIM ✅ LoRA tuned adaptors➡️ Tech blog

  • [2024/07/02] Let the @MistralAI MoE tokens fly 📈 🚀 #Mixtral 8x7B with NVIDIA #TensorRT #LLM on #H100. ➡️ Tech blog

  • [2024/06/24] Enhanced with NVIDIA #TensorRT #LLM, @upstage.ai’s solar-10.7B-instruct is ready to power your developer projects through our API catalog 🏎️. ✨➡️ link

  • [2024/06/18] CYMI: 🤩 Stable Diffusion 3 dropped last week 🎊 🏎️ Speed up your SD3 with #TensorRT INT8 Quantization➡️ link

  • [2024/06/18] 🧰Deploying ComfyUI with TensorRT? Here’s your setup guide ➡️ link

  • [2024/06/11] ✨#TensorRT Weight-Stripped Engines ✨ Technical Deep Dive for serious coders ✅+99% compression ✅1 set of weights → ** GPUs ✅0 performance loss ✅** models…LLM, CNN, etc.➡️ link

  • [2024/06/04] ✨ #TensorRT and GeForce #RTX unlock ComfyUI SD superhero powers 🦸⚡ 🎥 Demo: ➡️ link 📗 DIY notebook: ➡️ link

  • [2024/05/28] ✨#TensorRT weight stripping for ResNet-50 ✨ ✅+99% compression ✅1 set of weights → ** GPUs\ ✅0 performance loss ✅** models…LLM, CNN, etc 👀 📚 DIY ➡️ link

  • [2024/05/21] ✨@modal_labs has the codes for serverless @AIatMeta Llama 3 on #TensorRT #LLM ✨👀 📚 Marvelous Modal Manual: Serverless TensorRT-LLM (LLaMA 3 8B) | Modal Docs ➡️ link

  • [2024/05/08] NVIDIA TensorRT Model Optimizer -- the newest member of the #TensorRT ecosystem is a library of post-training and training-in-the-loop model optimization techniques ✅quantization ✅sparsity ✅QAT ➡️ blog

  • [2024/05/07] 🦙🦙🦙 24,000 tokens per second 🛫Meta Llama 3 takes off with #TensorRT #LLM 📚➡️ link

  • [2024/02/06] 🚀 Speed up inference with SOTA quantization techniques in TRT-LLM

  • [2024/01/30] New XQA-kernel provides 2.4x more Llama-70B throughput within the same latency budget

  • [2023/12/04] Falcon-180B on a single H200 GPU with INT4 AWQ, and 6.7x faster Llama-70B over A100

  • [2023/11/27] SageMaker LMI now supports TensorRT-LLM - improves throughput by 60%, compared to previous version

  • [2023/11/13] H200 achieves nearly 12,000 tok/sec on Llama2-13B

  • [2023/10/22] 🚀 RAG on Windows using TensorRT-LLM and LlamaIndex 🦙

  • [2023/10/19] Getting Started Guide - Optimizing Inference on Large Language Models with NVIDIA TensorRT-LLM, Now Publicly Available

  • [2023/10/17] Large Language Models up to 4x Faster on RTX With TensorRT-LLM for Windows

TensorRT-LLM Overview

TensorRT-LLM is an open-sourced library for optimizing Large Language Model (LLM) inference. It provides state-of-the-art optimizations, including custom attention kernels, inflight batching, paged KV caching, quantization (FP8, FP4, INT4 AWQ, INT8 SmoothQuant, ...), speculative decoding, and much more, to perform inference efficiently on NVIDIA GPUs.

Recently re-architected with a PyTorch backend, TensorRT-LLM now combines peak performance with a more flexible and developer-friendly workflow. The original TensorRT-based backend remains supported and continues to provide an ahead-of-time compilation path for building highly optimized "Engines" for deployment. The PyTorch backend complements this by enabling faster development iteration and rapid experimentation.

TensorRT-LLM provides a flexible LLM API to simplify model setup and inference across both PyTorch and TensorRT backends. It supports a wide range of inference use cases from a single GPU to multiple nodes with multiple GPUs using Tensor Parallelism and/or Pipeline Parallelism. It also includes a backend for integration with the NVIDIA Triton Inference Server.

Several popular models are pre-defined and can be easily customized or extended using native PyTorch code (for the PyTorch backend) or a PyTorch-style Python API (for the TensorRT backend).

Getting Started

To get started with TensorRT-LLM, visit our documentation:

Useful Links

  • Quantized models on Hugging Face: A growing collection of quantized (e.g., FP8, FP4) and optimized LLMs, including DeepSeek FP4, ready for fast inference with TensorRT-LLM.
  • NVIDIA Dynamo: A datacenter scale distributed inference serving framework that works seamlessly with TensorRT-LLM.
  • AutoDeploy: An experimental backend for TensorRT-LLM to simplify and accelerate the deployment of PyTorch models.