跳转至

Ray 分布式(Qwen3-235B-A22B)

多节点推理适用于模型无法在单机上部署的场景。在这种情况下,可以使用张量并行或流水线并行对模型进行分布式部署。具体的并行策略将在以下章节中介绍。要成功部署多节点推理,需要完成以下三个步骤:

  • 验证多节点通信环境
  • 设置并启动 Ray 集群
  • 在多节点上启动在线推理服务

验证多节点通信环境

物理层要求

  • 物理机器必须位于同一局域网内,并且网络连通。
  • 所有 NPU 均通过光模块连接,且连接状态必须正常。

验证流程

依次在每个节点上执行以下命令。结果必须全部为 success,状态必须为 UP:

 # Check the remote switch ports
 for i in {0..7}; do hccn_tool -i $i -lldp -g | grep Ifname; done
 # Get the link status of the Ethernet ports (UP or DOWN)
 for i in {0..7}; do hccn_tool -i $i -link -g ; done
 # Check the network health status
 for i in {0..7}; do hccn_tool -i $i -net_health -g ; done
 # View the network detected IP configuration
 for i in {0..7}; do hccn_tool -i $i -netdetect -g ; done
 # View gateway configuration
 for i in {0..7}; do hccn_tool -i $i -gateway -g ; done
 # View NPU network configuration
 cat /etc/hccn.conf

NPU 互连验证

1. 获取 NPU IP 地址

for i in {0..7}; do hccn_tool -i $i -ip -g | grep ipaddr; done

2. 跨节点 PING 测试

# Execute on the target node (replace with actual IP)
hccn_tool -i 0 -ping -g address 10.20.0.20

设置并启动 Ray 集群

设置基础容器

为确保所有节点上具有一致的运行环境,包括模型路径和 Python 环境,建议使用 Docker 镜像。

对于使用 Ray 搭建多节点推理集群,容器化部署是推荐方式。应在头节点和工作节点上都启动容器,并使用 --net=host 选项以启用正确的网络连通性。

以下是示例容器设置命令,应在所有节点上执行:

# Update the vllm-ascend image
export IMAGE=quay.nju.edu.cn/ascend/vllm-ascend:v0.23.0
export NAME=vllm-ascend

# Run the container using the defined variables
# Note if you are running bridge network with docker, please expose available ports for multiple nodes communication in advance.
# IMPORTANT: The cache directory mounted at /root/.cache must be a shared directory accessible by all nodes.
docker run --rm \
--name $NAME \
--net=host \
--shm-size=1g \
--device /dev/davinci0 \
--device /dev/davinci1 \
--device /dev/davinci2 \
--device /dev/davinci3 \
--device /dev/davinci4 \
--device /dev/davinci5 \
--device /dev/davinci6 \
--device /dev/davinci7 \
--device /dev/davinci_manager \
--device /dev/devmm_svm \
--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 /path/to/shared/cache:/root/.cache \
-it $IMAGE bash

启动 Ray 集群

Note

为多节点推理启动 Ray 集群时,必须在启动 Ray 集群之前设置每个节点上的环境变量,才能使其生效。 更新环境变量需要重启 Ray 集群。

在设置好容器并在每个节点上安装 vllm-ascend 后,按照以下步骤启动 Ray 集群并执行推理任务。

选择一台机器作为头节点,其余机器作为工作节点。在继续之前,使用 ip addr 检查你的 nic_name(网络接口名称)。

设置 ASCEND_RT_VISIBLE_DEVICES 环境变量以指定要使用的 NPU 设备。对于 2.1 以上的 Ray 版本,还需设置 RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES 变量,以避免设备识别问题。

以下是头节点和工作节点的命令:

头节点:

# Head node
export HCCL_IF_IP={local_ip}
export GLOO_SOCKET_IFNAME={nic_name}
export TP_SOCKET_IFNAME={nic_name}
export RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES=1
export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
ray start --head

工作节点:

# Worker node
export HCCL_IF_IP={local_ip}
export GLOO_SOCKET_IFNAME={nic_name}
export TP_SOCKET_IFNAME={nic_name}
export RAY_EXPERIMENTAL_NOSET_ASCEND_RT_VISIBLE_DEVICES=1
export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
ray start --address='{head_node_ip}:6379' --node-ip-address={local_ip}

在多个节点上启动集群后,执行 ray status 和 ray list nodes 以验证 Ray 集群的状态。你应该能看到正确数量的节点和 NPU 列表。

Ray 成功启动后,将出现以下内容:\ 本地 Ray 实例已成功启动。\ Dashboard URL:Ray Dashboard 的访问地址(默认:http://localhost:8265);节点状态(CPU/内存资源、健康节点数量);集群连接地址(用于添加多个节点)。

在多节点场景下启动在线推理服务

在容器中,你可以像所有 NPU 都在单个节点上一样使用 vLLM。vLLM 将利用 Ray 集群中所有节点上的 NPU 资源。

你只需要在一个节点上运行 vllm 命令。

要设置并行,常见做法是将 tensor-parallel-size 设置为每个节点的 NPU 数量,将 pipeline-parallel-size 设置为节点数量。

例如,在 2 个节点上共有 16 个 NPU(每个节点 8 个 NPU)时,将张量并行大小设置为 8,流水线并行大小设置为 2:

vllm serve Qwen/Qwen3-235B-A22B \
  --distributed-executor-backend ray \
  --pipeline-parallel-size 2 \
  --tensor-parallel-size 8 \
  --enable-expert-parallel \
  --seed 1024 \
  --max-model-len 8192  \
  --max-num-seqs 25 \
  --served-model-name qwen \
  --trust-remote-code \
  --gpu-memory-utilization 0.9

或者,如果只想使用张量并行,请将张量并行大小设置为集群中 NPU 的总数。例如,在 2 个节点上共有 16 个 NPU 时,将张量并行大小设置为 16:

vllm serve Qwen/Qwen3-235B-A22B \
  --distributed-executor-backend ray \
  --tensor-parallel-size 16 \
  --enable-expert-parallel \
  --seed 1024 \
  --max-model-len 8192  \
  --max-num-seqs 25 \
  --served-model-name qwen \
  --trust-remote-code \
  --gpu-memory-utilization 0.9

服务器启动后,你可以使用输入提示查询模型:

curl http://localhost:8000/v1/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "qwen",
        "prompt": "tell me how to sleep well",
        "max_completion_tokens": 100,
        "temperature": 0
    }'

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 vl/vllm-ascend