TensorRT LLM NVIDIA 推出的一款全面开源库,用于在 NVIDIA GPU 上提升和优化最新大语言模型(LLM)的推理性能。
TensorRT LLM 提供高级 Python LLM API,支持从单 GPU 到多 GPU 或多节点部署等多种推理配置,内置对各类并行策略和高级功能的支持。该 LLM API 可与更广泛的推理生态系统无缝集成,包括 NVIDIA Dynamo 和 Triton 推理服务器。
TensorRT LLM 采用模块化设计,易于修改。其原生 PyTorch 架构让开发者能够对运行时进行实验或扩展功能,同时还预定义了多个热门模型,开发者可通过原生 PyTorch 代码对模型进行自定义,轻松实现系统的个性化适配。
在最新的 NVIDIA GPU 上,TensorRT LLM 可实现突破性性能:
TensorRT LLM 支持最新且最热门的 LLM 架构:
TensorRT LLM 致力于在模型发布当天(Day 0)就实现对热门模型的支持。
TensorRT LLM 支持全系列 NVIDIA GPU 架构:
无论你是在构建下一代 AI 应用、优化现有 LLM 部署,还是探索大语言模型技术的前沿领域,TensorRT LLM 都能提供所需的工具、性能与灵活性,助力开发者在生成式 AI 时代取得成功。如需开始使用,请参考《快速入门指南》。
本指南是试用 TensorRT LLM 的起点,将帮助你快速完成环境搭建,并使用 TensorRT LLM 发送 HTTP 请求。
(参考链接:https://nvidia.github.io/TensorRT-LLM/latest/quick-start-guide.html )
你可以通过 trtllm-serve 命令启动一个兼容 OpenAI 的服务器,以实现与模型的交互。在 Docker 容器内,可通过以下示例命令启动服务器:
(示例命令参考:trtllm-serve "TinyLlama/TinyLlama-1.1B-Chat-v1.0",参考链接:https://nvidia.github.io/TensorRT-LLM/latest/quick-start-guide.html )
若在 Docker 容器内运行 trtllm-server,有两种发送 API 请求的方式:
docker exec -it <container_id> bash,参考链接:服务器启动后,你可以访问常见的 OpenAI 端点(如 v1/chat/completions)。在另一个终端中,可通过类似以下示例的方式执行推理:
curl -X POST http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"model": "TinyLlama/TinyLlama-1.1B-Chat-v1.0",
"messages": [{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Where is New York? Tell me in a single sentence."}],
"max_tokens": 32,
"temperature": 0
}'
(参考链接:https://nvidia.github.io/TensorRT-LLM/latest/quick-start-guide.html )
{
"id": "chatcmp1-ef648e7489c040679d87ed12db5d3214",
"object": "chat.completion",
"created": 1741966075,
"model": "TinyLlama/TinyLlama-1.1B-Chat-v1.0",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "New York is a city in the northeastern United States, located on the east coast."
},
"logprobs": null,
"finish_reason": "stop",
"stop_reason": null
}
],
"usage": {
"prompt_tokens": 43,
"total_tokens": 69,
"completion_tokens": 26
}
}
(参考链接:https://nvidia.github.io/TensorRT-LLM/latest/quick-start-guide.html )
如需详细示例和命令语法,请参考 trtllm-serve 相关章节。
LLM API 是一款 Python API,旨在帮助用户在 Python 环境中直接完成 TensorRT-LLM 的设置与推理。只需指定 HuggingFace 仓库名称或模型检查点,即可实现模型优化。该 API 会统一管理模型加载、优化和推理流程,全程仅需一个 LLM 实例即可完成。
以下是使用 LLM API 调用 TinyLlama 模型的简单示例:
from tensorrt_llm import LLM, SamplingParams
def main():
# 模型支持的输入格式:HF 模型名称、本地 HF 模型路径、TensorRT 模型优化器量化后的检查点(如 nvidia/Llama-3.1-8B-Instruct)
llm = LLM(model="TinyLlama/TinyLlama-1.1B-Chat-v1.0")
# 示例提示词
prompts = [
"Hello, my name is",
"The capital of France is",
"The future of AI is"
]
# 创建采样参数
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
# 生成输出并打印
for output in llm.generate(prompts, sampling_params):
print(f"Prompt: {output.prompt!r}, Generated text: {output.outputs[0].text!r}")
# 预期输出示例:
# Prompt: 'Hello, my name is', Generated text: '\n\nJane Smith. I am a student pursuing a degree in computer science.'
# Prompt: 'The capital of France is', Generated text: 'Paris.'
# Prompt: 'The future of AI is', Generated text: 'an exciting time for us. We are continuing to see rapid advancements in various fields.'
if __name__ == '__main__':
main()
(参考链接:https://nvidia.github.io/TensorRT-LLM/latest/quick-start-guide.html )
你也可以在 LLM 构造函数中直接加载 HuggingFace 上已量化的预量化模型。如需了解更多关于 LLM API 的信息,请查看《LLM API 介绍》和《LLM 示例》。
在本《快速入门指南》中,你已完成以下操作:
若需进一步学习 TensorRT LLM,可参考以下资源:
提供不同平台的详细安装说明。
TensorRT LLM 提供多种安装和运行方式,对大多数用户而言,以下方式按操作复杂度从低到高排序,且所有方式支持的功能一致。
注意:本项目会下载并安装额外的第三方开源软件项目,请在使用前查阅这些开源项目的许可条款。
提供在各类场景下部署 LLM 推理的综合示例。
查看支持的模型列表及新增模型的方法。
以下是 PyTorch 后端支持的模型表格:
| 架构(Architecture) | 模型(Model) | HuggingFace 示例 |
|---|---|---|
| BertForSequenceClassification | 基于 BERT 的模型 | textattack/bert-base-uncased-yelp-polarity |
| DeciLMForCausalLM | Nemotron | nvidia/Llama-3_1-Nemotron-51B-Instruct |
| DeepseekV3ForCausalLM | DeepSeek-V3 | deepseek-ai/DeepSeek-V3 |
| Exaone4ForCausalLM | EXAONE 4.0 | LGAI-EXAONE/EXAONE-4.0-32B |
| Gemma3ForCausalLM | Gemma 3 | google/gemma-3-1b-it |
| LlamaForCausalLM | Llama 3.1、Llama 3、Llama 2、LLaMA | meta-llama/Meta-Llama-3.1-70B |
| Llama4ForConditionalGeneration | Llama 4 | meta-llama/Llama-4-Scout-17B-16E-Instruct |
| MistralForCausalLM | Mistral | mistralai/Mistral-7B-v0.1 |
| MixtralForCausalLM | Mixtral | mistralai/Mixtral-8x7B-v0.1 |
| MllamaForConditionalGeneration | Llama 3.2 | meta-llama/Llama-3.2-11B-Vision |
| NemotronForCausalLM | Nemotron-3、Nemotron-4、Minitron | nvidia/Minitron-8B-Base |
| NemotronNASForCausalLM | NemotronNAS | nvidia/Llama-3_3-Nemotron-Super-49B-v1 |
| Qwen2ForCausalLM | QwQ、Qwen2 | Qwen/Qwen2-7B-Instruct |
| Phi3ForCausalLM | Phi-4 | microsoft/Phi-4 |
| Qwen2ForProcessRewardModel | 基于 Qwen2 的模型 | Qwen/Qwen2.5-Math-PRM-7B |
| Qwen2ForRewardModel | 基于 Qwen2 的模型 | Qwen/Qwen2.5-Math-RM-72B |
| Qwen3ForCausalLM | Qwen3 | Qwen/Qwen3-8B |
| Qwen3MoeForCausalLM | Qwen3MoE | Qwen/Qwen3-30B-A3B |
注意:其他模型的功能支持情况可能有所不同,标记为“N/A”的功能表示不适用于该模型架构。
| 模型架构/功能 | 重叠调度器(Overlap Scheduler) | CUDA 图(CUDA Graph) | 注意力数据并行(Attention Data Parallelism) | 解耦服务(Disaggregated Serving) | 分块预填充(Chunked Prefill) | MTP | EAGLE-3(单模型引擎) |
|---|---|---|---|---|---|---|---|
| DeepseekV3ForCausalLM | 是 | 是 | 是 | 是 | 是 [1] | 是 | 否 |
| Qwen3MoeForCausalLM | 是 | 是 | 是 | 是 | 是 | 否 | 是 |
| Llama4ForConditionalGeneration | 是 | 是 | 是 | 是 | 是 | 否 | 是 |
| GPT-OSS | 是 | 是 | 是 | 是 | 否 | 否 | 是 |
| 模型架构/功能 | EAGLE-3(双模型引擎) | Torch 采样器(Torch Sampler) | TLLM C++ 采样器(TLLM C++ Sampler) | KV 缓存复用(KV Cache Reuse) | 滑动窗口注意力(Sliding Window Attention) | Logits 后处理器(Logits Post Processor) | 引导解码(Guided Decoding) |
|---|---|---|---|---|---|---|---|
| DeepseekV3ForCausalLM | 否 | 是 | 是 | 是 [2] | N/A | 是 | 是 |
| Qwen3MoeForCausalLM | 是 | 是 | 是 | 是 | N/A | 是 | 是 |
| Llama4ForConditionalGeneration | 是 | 是 | 是 | 未测试 | N/A | 是 | 是 |
| GPT-OSS | 否 | 是 | 是 | 否 | N/A | 是 | 是 |
| 模型架构/功能 | 重叠调度器(Overlap Scheduler) | CUDA 图(CUDA Graph) | 分块预填充(Chunked Prefill) | Torch 采样器(Torch Sampler) | TLLM C++ 采样器(TLLM C++ Sampler) | KV 缓存复用(KV Cache Reuse) | Logits 后处理器(Logits Post Processor) | EPD 解耦服务(EPD Disaggregated Serving) | 模态(Modality) |
|---|---|---|---|---|---|---|---|---|---|
| Gemma3ForConditionalGeneration | 是 | 是 | N/A | 是 | 是 | N/A | 是 | 否 | L + I |
| HCXVisionForCausalLM | 是 | 是 | 否 | 是 | 是 | 否 | 是 | 否 | L + I |
| LlavaLlamaModel(VILA) | 是 | 是 | 否 | 是 | 是 | 否 | 是 | 否 | L + I + V |
| LlavaNextForConditionalGeneration | 是 | 是 | 否 | 是 | 是 | 否 | 是 | 否 | L + I |
| Llama4ForConditionalGeneration | 是 | 是 | 否 | 是 | 是 | 否 | 是 | 否 | L + I |
| Mistral3ForConditionalGeneration | 是 | 是 | 是 | 是 | 是 | 是 | 是 | 否 | L + I |
| NemotronH_Nano_VL_V2 | 是 | 是 | 是 | 是 | 是 | 否 | 是 | 否 | L + I + V |
| Phi4MMForCausalLM | 是 | 是 | 是 | 是 | 是 | 是 | 是 | 否 | L + I + A |
| Qwen2VLForConditionalGeneration | 是 | 是 | 否 | 是 | 是 | 是 | 是 | 否 | L + I + V |
| Qwen2_5_VLForConditionalGeneration | 是 | 是 | 否 | 是 | 是 | 是 | 是 | 否 | L + I + V |
注:L(Language,语言)、I(Image,图像)、V(Video,视频)、A(Audio,音频)
[1] 多语言适配器(MLA)的分块预填充功能仅支持在 SM100 架构上启用
[2] 多语言适配器(MLA)的 KV 缓存复用功能仅支持在 SM90/SM100 架构及 BF16/FP8 KV 缓存数据类型下启用
探索 TensorRT LLM 命令行工具:
TensorRT LLM 1.0 现已在 GitHub 正式发布,欢迎下载体验:
**https://github.com/NVIDIA/TensorRT-LLM
TensorRT LLM 快速入门指南源连接:
**https://nvidia.github.io/TensorRT-LLM/1.2.0rc0/overview.html
更多NVIDIA AI软件相关内容请关注 NVIDIA AI 技术专区
NVIDIA企业开发者社区:
