在 AutoDL 上部署 TensorRT-LLM 实践
#TensorRTLLM 1.0 实战#
在 AutoDL 上升级 CUDA 版本到 13.0
NVIDIA 官方文档中说 TensorRT-LLM 只支持 pytorch 2.7.1 和 CUDA 12.9 到 13.0 <https://nvidia.github.io/TensorRT-LLM/latest/installation/linux.html#linux>.
但是目前 AutoDL 官方镜像最高只提供到 CUDA 12.8,可以在 AutoDL 的文档查到 AutoDL 当前所有默认支持的 CUDA 版本 <https://autodl.com/docs/base_config/>。所以我们需要升级一下 CUDA 版本。
我们选择官方的 pytorch 2.8.0 + CUDA 12.8 版本的镜像启动 AutoDL,然后开始升级 CUDA 到 13.0 版本。
首先,AutoDL 系统盘只有 30G,很容易爆盘。咱们先把. cache 目录给移动到数据盘上去。
mkdir -p /root/autodl-tmp/cache
rm -rf ~/.cache
ln -s /root/autodl-tmp/cache ~/.cache
mv /root/miniconda3 /root/autodl-tmp
ln -s /root/autodl-tmp/miniconda3/ /root/miniconda3
AutoDL 查看剩余容量的方法比较特殊,使用如下命令查看。
source ~/.bashrc
在 AutoDL 上查看 ubuntu 版本
cat /proc/version
在 NIVIDA 官网 <https://developer.nvidia.com/cuda-toolkit-archive> 下载安装新的 CUDA 安装包。
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/13.0.2/local_installers/cuda-repo-ubuntu2204-13-0-local_13.0.2-580.95.05-1_amd64.deb
dpkg -i cuda-repo-ubuntu2204-13-0-local_13.0.2-580.95.05-1_amd64.deb
cp /var/cuda-repo-ubuntu2204-13-0-local/cuda-*-keyring.gpg /usr/share/keyrings/
apt-get update
apt-get -y install cuda-toolkit-13-0
在 AutoDL 上查看 CUDA 版本的方法也比较特殊。
ldconfig -p | grep nvrtc
ldconfig -p | grep cudnn
在 AutoDL 上安装 TensorRT-LLM
接下来我们稍微更新一下系统,安装两个TensorRT-LLM的依赖。
apt update
apt upgrade
apt-get -y install libopenmpi-dev
apt-get -y install libzmq3-dev
然后,我们使用 pip 安装 。
pip install tensorrt_llm
这个过程耗时会比较长,我们多等待一会儿。
安装 TensorRT-LLM 的依赖库
像上面那样安装结束之后,trtllm-serve 命令会卡在 orted 命令的执行过不去。还是缺少某些依赖。
找了一会儿没定位到具体缺什么依赖。我们放一个解决依赖问题的大招 —— 安装 anaconda 整合包。我们去 anaconda 的官网 <https://www.anaconda.com/download> <https://www.anaconda.com/download/success>下载一个 linux 的整合包安装上。
当然,由于主磁盘的容量限制,在 AutoDL 上安装 anaconda 也有些特殊。我们用下面的命令安装。其中 -u 参数是允许目录在安装之前就存在。
wget https://repo.anaconda.com/archive/Anaconda3-2025.06-0-Linux-x86_64.sh
mkdir -p /root/autodl-tmp/anaconda3
ln -s /root/autodl-tmp/anaconda3/ /root/anaconda3
bash Anaconda3-2025.06-0-Linux-x86_64.sh -u
然后我们再执行 trtllm-serve 命令,就会出现如下的成功画面了。
(base) root@autodl-container-ed0440a042-7c88f889:~# trtllm-serve
<frozen importlib._bootstrap_external>:1297: FutureWarning: The cuda.cuda module is deprecated and will be removed in a future release, please switch to use the cuda.bindings.driver module instead.
<frozen importlib._bootstrap_external>:1297: FutureWarning: The cuda.cudart module is deprecated and will be removed in a future release, please switch to use the cuda.bindings.runtime module instead.
[2025-11-08 11:40:09] INFO config.py:54: PyTorch version 2.7.1 available.
2025-11-08 11:40:12,502 - INFO - flashinfer.jit: Prebuilt kernels not found, using JIT backend
[TensorRT-LLM] TensorRT LLM version: 1.0.0
/root/miniconda3/lib/python3.12/site-packages/tensorrt_llm/serve/openai_protocol.py:84: UserWarning: Field name "schema" in "ResponseFormat" shadows an attribute in parent "OpenAIBaseModel"
class ResponseFormat(OpenAIBaseModel):
Usage: trtllm-serve [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
disaggregated Running server in disaggregated mode
disaggregated_mpi_worker Launching disaggregated MPI worker
serve Running an OpenAI API compatible server
至此,我们就成功安装好了 TensorRT-LLM,后面我们来试试使用它来做推理工作。
使用 ModelScope 下载模型
TensorRT-LLM 支持自动下载大模型文件并进行推理的模式,但有些自定义模型需要我们从本地载入。所以本次我们采取先使用 ModelScope 客户端下载大模型到磁盘,然后 TensorRT-LLM 读取本地离线文件推理的方式启动推理服务。
我们先安装 modelscope。
pip install modelscope
然后我们下载一个 qwen3 的 0.6b 让 trtllm-serve 试试看。
mkdir -p /root/autodl-tmp/qwen3-0.6b
modelscope download --model Qwen/Qwen3-0.6B --local_dir /root/autodl-tmp/qwen3-0.6b/
使用 TensorRT-LLM 调用本地模型进行推理
trtllm-serve Qwen3-0.6B/
需要注意的是这里使用的是相对路径,不成功的话,看看自己的当前路径。
测试推理
接下来我们可以用 curl 命令验证是否可以成功推理。
curl http://localhost:8000/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen3-0.6B/",
"prompt": "中国最长的河是?",
"max_tokens": 128,
"temperature": 0
}'
得到答复即为部署成功。
总结
搞了好几个小时的调试,有点超出本来的预想时间,但是最终还是成功在AutoDL上部署了TensorRT-LLM 1.0。
AutoDL 是基于 Docker 提供的服务,需要特殊处理的地方还是挺多的。好在 TensorRT-LLM 的文档和社区支持还是比较完善,基本能找到清晰的安装指引。
虽然安装的麻烦超出预期,好在推理速度也远超预期,响应时间很短。未来可能会考虑找个项目,实际尝试一下。希望在更复杂的环境中也能工作良好。
更多推荐


所有评论(0)