图模式指南#

备注

此功能目前为实验性功能。在未来的版本中,配置、覆盖率和性能改进等方面的行为可能会有变化。

备注

在上下文并行场景下(即 prefill_context_parallel_size * decode_context_parallel_size > 1),目前尚不支持将 "cudagraph_mode" 充分设置为 "FULL"。

本指南提供了在 vLLM Ascend 中使用昇腾图模式的操作说明。请注意,图模式仅在 V1 引擎上可用,并且从 0.9.0rc1 版本起,仅对 Qwen、DeepSeek 系列模型进行了充分测试。我们将在下一个版本中使其更加稳定和通用。

快速入门#

从 v0.9.1rc1 版本起,在使用 V1 引擎时,vLLM Ascend 默认将在图模式下运行模型,以保持与 vLLM 一致的行为。如果遇到任何问题,欢迎在 GitHub 上提交 issue,并可在初始化模型时通过设置 enforce_eager=True 临时切换回 eager 模式。

vLLM Ascend 支持两种图模式:

  • ACLGraph:这是 vLLM Ascend 支持的默认图模式。在 v0.9.1rc1 版本中,Qwen 和 DeepSeek 系列模型经过了充分测试。

  • XliteGraph:这是 OpenEuler Xlite 图模式。在 v0.11.0 版本中,仅支持 Llama、Qwen 稠密系列模型、Qwen MoE 系列模型以及 Qwen3-VL。

使用 ACLGraph#

ACLGraph 默认启用。以 Qwen 系列模型为例,只需设置为使用 V1 引擎即可。

离线示例:

import os

from vllm import LLM

model = LLM(model="path/to/Qwen2-7B-Instruct")
outputs = model.generate("Hello, how are you?")

在线示例:

vllm serve Qwen/Qwen2-7B-Instruct

使用 XliteGraph#

如果你想使用 Xlite 图模式运行 Llama、Qwen 稠密系列模型、Qwen MoE 系列模型或 Qwen3-VL,请安装 xlite 并设置 xlite_graph_config。

pip install xlite

离线示例:

import os
from vllm import LLM

# xlite supports the decode-only mode by default, and the full mode can be enabled by setting: "full_mode": True
model = LLM(model="path/to/Qwen3-32B", tensor_parallel_size=8, additional_config={"xlite_graph_config": {"enabled": True, "full_mode": True}})
outputs = model.generate("Hello, how are you?")

在线示例:

vllm serve path/to/Qwen3-32B --tensor-parallel-size 8 --additional-config='{"xlite_graph_config": {"enabled": true, "full_mode": true}}'

你可以在 Xlite 找到更多详细信息。

回退到 Eager 模式#

如果 ACLGraphXliteGraph 都无法运行,你应该退回到 eager 模式。

离线示例:

import os
from vllm import LLM

model = LLM(model="someother_model_weight", enforce_eager=True)
outputs = model.generate("Hello, how are you?")

在线示例:

vllm serve someother_model_weight --enforce-eager

常见限制与注意事项#

  • 不支持 NPU 软分区 + CUDAGraphMode.PIECEWISE 组合。在使用软分区的虚拟 NPU 实例时,2048 个设备流在容器间共享和拆分(参见virtual instance with vCANN RT 描述),但 vLLM Ascend 在 update_aclgraph_sizesvllm_ascend/utils.py)中仍然从固定的全设备流预算中推导 ACL 图捕获限制,而未使用每个容器的流配额,因此该组合不兼容。