Transformers documentation

TensorRT-LLM

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

TensorRT-LLM

TensorRT-LLM 可优化 NVIDIA GPU 上的 LLM 推理。它将模型编译为 TensorRT 引擎,支持 in-flight batching、paged KV caching 和 tensor parallelism。AutoDeploy 可直接接受 Transformers 模型,无需任何修改。它会自动将模型转换为优化后的运行时。

将来自 Hub 的模型 ID 传递给 build_and_run_ad.py,以运行 Transformers 模型。

cd examples/auto_deploy
python build_and_run_ad.py --model meta-llama/Llama-3.2-1B

Under the hood, AutoDeploy creates an LLM class. It loads the model configuration with AutoConfig.from_pretrained() and extracts any parallelism metadata stored in tp_plan. AutoModelForCausalLM.from_pretrained() loads the model with the config and enables Transformers’ built-in tensor parallelism.

from tensorrt_llm._torch.auto_deploy import LLM

llm = LLM(model="meta-llama/Llama-3.2-1B")

TensorRT-LLM 使用 torch.export 提取模型图并应用优化。它将 Transformers 的注意力机制替换为 TensorRT-LLM 的 注意力内核,并将模型编译为优化后的执行后端。

资源

Update on GitHub