在Linux上安装
安装 TensorRT-LLM(已在 Ubuntu 22.04 上测试)。
sudo apt-get -y install libopenmpi-dev && pip3 install tensorrt_llm
通过在Python中运行以下内容来检查安装是否正常(已在Python 3.10上测试):
from tensorrt_llm import LLM, SamplingParams def main(): prompts = [ "Hello, my name is", "The president of the United States is", "The capital of France is", "The future of AI is", ] sampling_params = SamplingParams(temperature=0.8, top_p=0.95) llm = LLM(model="TinyLlama/TinyLlama-1.1B-Chat-v1.0") outputs = llm.generate(prompts, sampling_params) # Print the outputs. for output in outputs: prompt = output.prompt generated_text = output.outputs[0].text print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") # The entry point of the program need to be protected for spawning processes. if __name__ == '__main__': main()
已知限制
当你使用 pip 安装预构建的 TensorRT-LLM 轮包时,存在一些已知的限制。
C++11 ABI
预构建的TensorRT-LLM轮子已经链接到pypi上托管的公共pytorch,该pytorch关闭了C++11 ABI。 而NVIDIA在NGC容器nvcr.io/nvidia/pytorch:xx.xx-py3中优化的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 Toolkit Documentation中找到