在 Linux 上安装#
安装 TensorRT-LLM(在 Ubuntu 24.04 上测试)。
sudo apt-get -y install libopenmpi-dev && pip3 install --upgrade pip setuptools && pip3 install tensorrt_llm
通过在 Python 中运行以下代码来检查安装是否正确(在 Python 3.12 上测试)
1from tensorrt_llm import LLM, SamplingParams 2 3 4def main(): 5 6 prompts = [ 7 "Hello, my name is", 8 "The president of the United States is", 9 "The capital of France is", 10 "The future of AI is", 11 ] 12 sampling_params = SamplingParams(temperature=0.8, top_p=0.95) 13 14 llm = LLM(model="TinyLlama/TinyLlama-1.1B-Chat-v1.0") 15 16 outputs = llm.generate(prompts, sampling_params) 17 18 # Print the outputs. 19 for output in outputs: 20 prompt = output.prompt 21 generated_text = output.outputs[0].text 22 print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") 23 24 25# The entry point of the program need to be protected for spawning processes. 26if __name__ == '__main__': 27 main()
已知限制
当您使用 pip 安装预构建的 TensorRT-LLM wheel 包时,存在一些已知的限制。
C++11 ABI
预构建的 TensorRT-LLM wheel 链接到了 pypi 上托管的公共 pytorch,该 pytorch 关闭了 C++11 ABI。而 NGC 容器 nvcr.io/nvidia/pytorch:xx.xx-py3 中的 NVIDIA 优化 pytorch 开启了 C++11 ABI,请参阅NGC pytorch 容器页面 。因此,我们建议用户在使用 NGC pytorch 容器时从源代码构建。从源代码构建的指南可以在在 Linux 上从源代码构建中找到
Slurm 环境中的 MPI
如果在 Slurm 管理的集群中运行 TensorRT-LLM 时遇到错误,您需要重新配置 MPI 安装以与 Slurm 配合使用。设置方法取决于您的 slurm 配置,请咨询您的管理员。这不是 TensorRT-LLM 特定的问题,而是一个通用的 mpi+slurm 问题。
The application appears to have been direct launched using "srun", but OMPI was not built with SLURM support. This usually happens when OMPI was not configured --with-slurm and we weren't able to discover a SLURM installation in the usual places.
CUDA 工具包
pip install tensorrt-llm
不会在您的系统中安装 CUDA 工具包,如果您只想部署 TensorRT-LLM 引擎,则不需要 CUDA 工具包。TensorRT-LLM 使用 ModelOpt 量化模型,而 ModelOpt 需要 CUDA 工具包来即时编译某些 pytorch 中不包含的内核,以有效地进行量化。当您在运行 ModelOpt 量化时看到以下消息时,请安装 CUDA 工具包。/usr/local/lib/python3.10/dist-packages/modelopt/torch/utils/cpp_extension.py:65: UserWarning: CUDA_HOME environment variable is not set. Please set it to your CUDA install root. Unable to load extension modelopt_cuda_ext and falling back to CPU version.
CUDA 工具包的安装可以在 CUDA 工具包文档中找到