快速开始¶
This guide uses Qwen3-0.6B as an example to help you run your first offline inference workload or deploy an online service on a prepared Ascend host using a prebuilt vLLM Ascend container.
环境要求¶
- 操作系统:Linux
- Python:>= 3.10, < 3.13
- Docker
-
支持的硬件:
类型 常见产品 Atlas A2系列产品 Atlas 800T A2、Atlas 900 A2 PoD、Atlas 200T A2 Box16、Atlas 300T A2、Atlas 800I A2 等 Atlas A3系列产品 Atlas 800T A3、Atlas 900 A3 SuperPoD、Atlas 9000 A3 SuperPoD、Atlas 800I A3 等 Atlas 推理系列产品 Atlas 300I DUO 和 Atlas 200I Pro Ascend 950DT系列产品 950DT
vLLM Ascend 镜像中包含的软件栈
预构建镜像包含经过验证的 Python 和 Ascend 用户态软件栈,包括 CANN、NNAL、PyTorch、TorchNPU、vLLM 和 vLLM Ascend。
Atlas A2 Products (A2), Atlas A3 Products (A3), and 950DT Products images also include the matching Triton Ascend runtime. Atlas 300I DUO and Atlas 200I Pro do not use Triton Ascend.
For component roles and the exact validated versions, see Installation Guide > Hardware and software stack.
安装¶
在使用容器之前,请确保您的系统已安装 Docker。如果尚未安装 Docker,请参阅 Docker 安装指南 获取安装说明。
拉取镜像¶
如果镜像下载速度较慢
vLLM Ascend 镜像默认从 quay.io 下载。如果直接访问速度较慢,可以使用以下任一镜像仓库来加速下载。
例如,原始镜像地址为:
您可以将其替换为:
# Replace with tag you want to pull
TAG=v0.23.0
# use
docker pull m.daocloud.io/quay.io/ascend/vllm-ascend:$TAG
# or
docker pull quay.nju.edu.cn/ascend/vllm-ascend:$TAG
仅替换镜像仓库前缀,并保留完整的原始镜像标签,包括诸如 -a3、-310p、-950dt 和 -openeuler 等后缀。
启动容器¶
export DEVICE=/dev/davinci0
export MODEL_CACHE="${HOME}/.cache"
mkdir -p "$MODEL_CACHE"
docker run --rm \
--name vllm-ascend \
--shm-size=1g \
--device "$DEVICE" \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v "$MODEL_CACHE:/root/.cache" \
-p 8000:8000 \
-it "$IMAGE" bash
export DEVICE=/dev/davinci0
export MODEL_CACHE="${HOME}/.cache"
mkdir -p "$MODEL_CACHE"
docker run --rm \
--name vllm-ascend \
--shm-size=1g \
--device "$DEVICE" \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v "$MODEL_CACHE:/root/.cache" \
-p 8000:8000 \
-it "$IMAGE" bash
验证容器环境¶
在容器中运行以下命令。当输出包含 vLLM Ascend environment: OK 时,表示容器已准备就绪。
拉取镜像¶
如果镜像下载速度较慢
vLLM Ascend 镜像默认从 quay.io 下载。如果直接访问速度较慢,可以使用以下任一镜像仓库来加速下载。
例如,原始镜像地址为:
您可以将其替换为:
# Replace with tag you want to pull
TAG=v0.23.0
# use
docker pull m.daocloud.io/quay.io/ascend/vllm-ascend:$TAG
# or
docker pull quay.nju.edu.cn/ascend/vllm-ascend:$TAG
仅替换镜像仓库前缀,并保留完整的原始镜像标签,包括诸如 -a3、-310p、-950dt 和 -openeuler 等后缀。
启动容器¶
A3容器启动要求
A3采用双DIE设计,需要两个昇腾设备节点,例如 /dev/davinci0 和 /dev/davinci1。
export DEVICE0=/dev/davinci0
export DEVICE1=/dev/davinci1
export MODEL_CACHE="${HOME}/.cache"
mkdir -p "$MODEL_CACHE"
docker run --rm \
--name vllm-ascend \
--shm-size=1g \
--device "$DEVICE0" \
--device "$DEVICE1" \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v "$MODEL_CACHE:/root/.cache" \
-p 8000:8000 \
-it "$IMAGE" bash
export DEVICE0=/dev/davinci0
export DEVICE1=/dev/davinci1
export MODEL_CACHE="${HOME}/.cache"
mkdir -p "$MODEL_CACHE"
docker run --rm \
--name vllm-ascend \
--shm-size=1g \
--device "$DEVICE0" \
--device "$DEVICE1" \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v "$MODEL_CACHE:/root/.cache" \
-p 8000:8000 \
-it "$IMAGE" bash
验证容器环境¶
在容器中运行以下命令。当输出包含 vLLM Ascend environment: OK 时,表示容器已准备就绪。
拉取镜像¶
如果镜像下载速度较慢
vLLM Ascend 镜像默认从 quay.io 下载。如果直接访问速度较慢,可以使用以下任一镜像仓库来加速下载。
例如,原始镜像地址为:
您可以将其替换为:
# Replace with tag you want to pull
TAG=v0.23.0
# use
docker pull m.daocloud.io/quay.io/ascend/vllm-ascend:$TAG
# or
docker pull quay.nju.edu.cn/ascend/vllm-ascend:$TAG
仅替换镜像仓库前缀,并保留完整的原始镜像标签,包括诸如 -a3、-310p、-950dt 和 -openeuler 等后缀。
启动容器¶
export DEVICE=/dev/davinci0
export MODEL_CACHE="${HOME}/.cache"
mkdir -p "$MODEL_CACHE"
docker run --rm \
--name vllm-ascend \
--shm-size=1g \
--device "$DEVICE" \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v "$MODEL_CACHE:/root/.cache" \
-p 8000:8000 \
-it "$IMAGE" bash
export DEVICE=/dev/davinci0
export MODEL_CACHE="${HOME}/.cache"
mkdir -p "$MODEL_CACHE"
docker run --rm \
--name vllm-ascend \
--shm-size=1g \
--device "$DEVICE" \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v "$MODEL_CACHE:/root/.cache" \
-p 8000:8000 \
-it "$IMAGE" bash
验证容器环境¶
在容器中运行以下命令。当输出包含 vLLM Ascend environment: OK 时,表示容器已准备就绪。
拉取镜像¶
如果镜像下载速度较慢
vLLM Ascend 镜像默认从 quay.io 下载。如果直接访问速度较慢,可以使用以下任一镜像仓库来加速下载。
例如,原始镜像地址为:
您可以将其替换为:
# Replace with tag you want to pull
TAG=v0.23.0
# use
docker pull m.daocloud.io/quay.io/ascend/vllm-ascend:$TAG
# or
docker pull quay.nju.edu.cn/ascend/vllm-ascend:$TAG
仅替换镜像仓库前缀,并保留完整的原始镜像标签,包括诸如 -a3、-310p、-950dt 和 -openeuler 等后缀。
启动容器¶
Atlas 200I Pro 容器启动要求
Atlas 200I Pro 需要额外的设备节点、驱动库和主机配置文件。在启动容器之前,请确保以下命令挂载的所有主机路径均已存在。
export MODEL_CACHE="${HOME}/.cache"
mkdir -p "$MODEL_CACHE"
docker run --rm \
--privileged \
--name vllm-ascend \
--shm-size=10g \
--device=/dev/davinci0:/dev/davinci0 \
--device=/dev/davinci_manager \
--device=/dev/ascend_manager \
--device=/dev/user_config \
-v /etc/sys_version.conf:/etc/sys_version.conf \
-v /etc/ld.so.conf.d/mind_so.conf:/etc/ld.so.conf.d/mind_so.conf \
-v /etc/hdcBasic.cfg:/etc/hdcBasic.cfg \
-v /var/dmp_daemon:/var/dmp_daemon \
-v /usr/lib64/libmmpa.so:/usr/lib64/libmmpa.so \
-v /usr/lib64/libcrypto.so.1.1:/usr/lib64/libcrypto.so.1.1 \
-v /usr/local/sbin/npu-smi:/usr/local/sbin/npu-smi \
-v /usr/lib64/libstackcore.so:/usr/lib64/libstackcore.so \
-v /usr/lib/aarch64-linux-gnu/libyaml-0.so.2:/usr/lib64/libyaml-0.so.2 \
-v /etc/slog.conf:/etc/slog.conf \
-v /var/slogd:/var/slogd \
-v /usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64 \
-v /usr/lib64/libtensorflow.so:/usr/lib64/libtensorflow.so \
-v "$MODEL_CACHE:/root/.cache" \
-p 8000:8000 \
-it "$IMAGE" bash
export MODEL_CACHE="${HOME}/.cache"
mkdir -p "$MODEL_CACHE"
docker run --rm \
--privileged \
--name vllm-ascend \
--shm-size=10g \
--device=/dev/davinci0:/dev/davinci0 \
--device=/dev/davinci_manager \
--device=/dev/ascend_manager \
--device=/dev/user_config \
-v /etc/sys_version.conf:/etc/sys_version.conf \
-v /etc/ld.so.conf.d/mind_so.conf:/etc/ld.so.conf.d/mind_so.conf \
-v /etc/hdcBasic.cfg:/etc/hdcBasic.cfg \
-v /var/dmp_daemon:/var/dmp_daemon \
-v /usr/lib64/libsemanage.so.2:/usr/lib64/libsemanage.so.2 \
-v /usr/lib64/libmmpa.so:/usr/lib64/libmmpa.so \
-v /usr/lib64/libcrypto.so.1.1:/usr/lib64/libcrypto.so.1.1 \
-v /usr/lib64/libyaml-0.so.2.0.9:/usr/lib64/libyaml-0.so.2 \
-v /usr/local/sbin/npu-smi:/usr/local/sbin/npu-smi \
-v /usr/lib64/libstackcore.so:/usr/lib64/libstackcore.so \
-v /etc/slog.conf:/etc/slog.conf \
-v /var/slogd:/var/slogd \
-v /usr/local/Ascend/driver/lib64:/usr/local/Ascend/driver/lib64 \
-v /usr/lib64/libtensorflow.so:/usr/lib64/libtensorflow.so \
-v "$MODEL_CACHE:/root/.cache" \
-p 8000:8000 \
-it "$IMAGE" bash
验证容器环境¶
在容器中运行以下命令。当输出包含 vLLM Ascend environment: OK 时,表示容器已准备就绪。
拉取镜像¶
如果镜像下载速度较慢
vLLM Ascend 镜像默认从 quay.io 下载。如果直接访问速度较慢,可以使用以下任一镜像仓库来加速下载。
例如,原始镜像地址为:
您可以将其替换为:
# Replace with tag you want to pull
TAG=v0.23.0
# use
docker pull m.daocloud.io/quay.io/ascend/vllm-ascend:$TAG
# or
docker pull quay.nju.edu.cn/ascend/vllm-ascend:$TAG
仅替换镜像仓库前缀,并保留完整的原始镜像标签,包括诸如 -a3、-310p、-950dt 和 -openeuler 等后缀。
启动容器¶
export MODEL_CACHE="${HOME}/.cache"
mkdir -p "$MODEL_CACHE"
docker run --rm \
--name vllm-ascend \
--net=host \
--shm-size=1g \
--device /dev/davinci0 \
--device /dev/davinci_manager \
--device /dev/ummu \
--device /dev/uburma \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/Ascend/driver/tools/hccn_tool:/usr/local/Ascend/driver/tools/hccn_tool \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v "$MODEL_CACHE:/root/.cache" \
-it "$IMAGE" bash
export MODEL_CACHE="${HOME}/.cache"
mkdir -p "$MODEL_CACHE"
docker run --rm \
--name vllm-ascend \
--net=host \
--shm-size=1g \
--device /dev/davinci0 \
--device /dev/davinci_manager \
--device /dev/ummu \
--device /dev/uburma \
--device /dev/hisi_hdc \
-v /usr/local/dcmi:/usr/local/dcmi \
-v /usr/local/Ascend/driver/tools/hccn_tool:/usr/local/Ascend/driver/tools/hccn_tool \
-v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \
-v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \
-v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \
-v /etc/ascend_install.info:/etc/ascend_install.info \
-v "$MODEL_CACHE:/root/.cache" \
-it "$IMAGE" bash
验证容器环境¶
在容器中运行以下命令。当输出包含 vLLM Ascend environment: OK 时,表示容器已准备就绪。
推理¶
以下章节提供了离线推理和在线服务的示例。请根据您的需求选择相应的方法开始使用。
如果 Hugging Face 访问受限
If your environment cannot reliably access Hugging Face, model downloads may fail due to connection timeouts, DNS errors, or other network issues. You can switch to ModelScope:
如果模型已下载到本地,请将以下示例中的模型 ID 替换为本地目录。您无需设置此环境变量。
离线推理¶
以下Qwen3-0.6B示例已使用默认模型加载配置验证通过。
在容器终端中,使用以下代码创建example.py:
from vllm import LLM, SamplingParams
prompts = [
"Hello, my name is",
"The future of AI is",
]
sampling_params = SamplingParams(
temperature=0.0,
max_tokens=32,
)
llm = LLM(model="Qwen/Qwen3-0.6B")
outputs = llm.generate(prompts, sampling_params)
assert len(outputs) == len(prompts)
for output in outputs:
generated_text = output.outputs[0].text
assert generated_text.strip()
print(f"Prompt: {output.prompt!r}, Generated text: {generated_text!r}")
运行示例:
以下输出显示vLLM已成功检测到Ascend平台:
INFO 05-27 11:40:38 [__init__.py:44] Available plugins for group vllm.platform_plugins:
INFO 05-27 11:40:38 [__init__.py:46] - ascend -> vllm_ascend:register
INFO 05-27 11:40:38 [__init__.py:49] All plugins in this group will be loaded. Set `VLLM_PLUGINS` to control which plugins to load.
INFO 05-27 11:40:38 [__init__.py:238] Platform plugin ascend is activated
以下输出显示生成的结果:
Prompt: 'Hello, my name is', Generated text: ' Lucy and I am an 8 year old who loves to draw and write stories'
Prompt: 'The future of AI is', Generated text: ' a topic that is being discussed in various contexts. In the business world, AI'
以下消息显示进程在离线推理后退出,不影响推理结果:
(EngineCore pid=970) INFO 05-12 11:36:00 [core.py:1201] Shutdown initiated (timeout=0)
(EngineCore pid=970) INFO 05-12 11:36:00 [core.py:1224] Shutdown complete
ERROR 05-12 11:36:01 [core_client.py:704] Engine core proc EngineCore died unexpectedly, shutting down client.
sys:1: DeprecationWarning: builtin type swigvarlink has no __module__ attribute
以下 Qwen3-0.6B 示例已在 Atlas 300I DUO 和 Atlas 200I Pro 上验证通过。
此硬件路径的运行时要求
- 使用
float16。 - 使用
FULL_DECODE_ONLY并限制图捕获大小。 - 不支持
enable_npugraph_ex。设置--additional-config '{"ascend_compilation_config": {"enable_npugraph_ex":false}}'。
在容器终端中,使用以下代码创建 example.py:
from vllm import LLM, SamplingParams
MODEL = "Qwen/Qwen3-0.6B"
prompts = [
"Hello, my name is",
"The future of AI is",
]
llm = LLM(
model=MODEL,
dtype="float16",
max_num_seqs=8,
compilation_config={
"cudagraph_mode": "FULL_DECODE_ONLY",
"cudagraph_capture_sizes": [1, 2, 4, 8],
},
additional_config={
"ascend_compilation_config": {
"enable_npugraph_ex": False,
},
},
)
sampling_params = SamplingParams(
temperature=0.0,
max_tokens=32,
)
outputs = llm.generate(prompts, sampling_params)
assert len(outputs) == len(prompts)
for output in outputs:
generated_text = output.outputs[0].text
assert generated_text.strip()
print(f"Prompt: {output.prompt!r}, Generated text: {generated_text!r}")
运行示例:
以下输出表明 vLLM 已成功检测到 Ascend 平台:
INFO 05-27 11:40:38 [__init__.py:44] Available plugins for group vllm.platform_plugins:
INFO 05-27 11:40:38 [__init__.py:46] - ascend -> vllm_ascend:register
INFO 05-27 11:40:38 [__init__.py:49] All plugins in this group will be loaded. Set `VLLM_PLUGINS` to control which plugins to load.
INFO 05-27 11:40:38 [__init__.py:238] Platform plugin ascend is activated
以下输出显示了生成的结果:
Prompt: 'Hello, my name is', Generated text: ' Lucy and I am an 8 year old who loves to draw and write stories'
Prompt: 'The future of AI is', Generated text: ' a topic that is being discussed in various contexts. In the business world, AI'
以下消息显示离线推理后进程退出,不影响推理结果:
(EngineCore pid=970) INFO 05-12 11:36:00 [core.py:1201] Shutdown initiated (timeout=0)
(EngineCore pid=970) INFO 05-12 11:36:00 [core.py:1224] Shutdown complete
ERROR 05-12 11:36:01 [core_client.py:704] Engine core proc EngineCore died unexpectedly, shutting down client.
sys:1: DeprecationWarning: builtin type swigvarlink has no __module__ attribute
在线服务¶
以下Qwen3-0.6B示例已使用默认模型加载配置验证通过。
如果您看到以下日志:
INFO: Started server process [3594]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
恭喜!您已成功启动vLLM服务器。
您可以查询模型列表:
您还可以向模型发送提示:
curl --fail http://localhost:8000/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen3-0.6B",
"prompt": "Beijing is a",
"max_tokens": 5,
"temperature": 0
}'
确认响应中 choices[0].text 包含非空生成文本。
错误响应或空补全不能确认推理成功。
vLLM作为后台进程运行。您可以使用kill -2 $VLLM_PID优雅地停止它,这类似于在前台vLLM进程中按Ctrl+C:
停止服务前请确认进程
如果当前环境中运行着其他vllm serve进程,pgrep -f "vllm serve"也可能匹配到这些vLLM服务。
在运行kill之前,请确认VLLM_PID是本示例启动的服务,以免误停其他正在运行的vLLM进程。
输出如下:
INFO: Shutting down FastAPI HTTP server.
INFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
最后,按Ctrl+D退出容器。
以下 Qwen3-0.6B 示例已在 Atlas 300I DUO 和 Atlas 200I Pro 上验证通过。
此硬件路径的运行时要求
- 使用
float16。 - 使用
FULL_DECODE_ONLY并限制图捕获大小。 - 不支持
enable_npugraph_ex。设置--additional-config '{"ascend_compilation_config": {"enable_npugraph_ex":false}}'。
vllm serve Qwen/Qwen3-0.6B \
--dtype float16 \
--max-num-seqs 8 \
--compilation-config '{"cudagraph_mode":"FULL_DECODE_ONLY","cudagraph_capture_sizes":[1,2,4,8]}' \
--additional-config '{"ascend_compilation_config":{"enable_npugraph_ex":false}}' &
如果您看到以下日志:
INFO: Started server process [3594]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
恭喜!您已成功启动 vLLM 服务器。
您可以查询模型列表:
您还可以向模型发送提示:
curl --fail http://localhost:8000/v1/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen3-0.6B",
"prompt": "Beijing is a",
"max_tokens": 5,
"temperature": 0
}'
确认响应中 choices[0].text 包含非空的生成文本。
错误响应或空补全不能确认推理成功。
vLLM 作为后台进程运行。您可以使用 kill -2 $VLLM_PID 优雅地停止它,这类似于在前台 vLLM 进程中按 Ctrl+C:
停止服务前请确认进程
如果当前环境中运行着其他 vllm serve 进程,pgrep -f "vllm serve" 也可能匹配到那些 vLLM 服务。
在运行 kill 之前,请确认 VLLM_PID 是本示例启动的服务,以免误停其他正在运行的 vLLM 进程。
输出如下:
INFO: Shutting down FastAPI HTTP server.
INFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
最后,按 Ctrl+D 退出容器。
后续步骤¶
- See Supported Models for choosing another model.
- See Model Tutorials for deployment instructions for specific models.
- See Installation Guide > Set up the software environment for pip, CANN, and source installation methods.
- See Feature Tutorials for distributed deployment and advanced features.
- See FAQ for troubleshooting common deployment issues.