Hy4-preview (实验性)¶
1 简介¶
Hy4 Preview 是腾讯 Hy 团队开发的下一代旗舰级混合专家(MoE)模型。模型总参数量为 770B,每个 token 约激活 49B 参数。
模型主干包含 78 层:第一层采用标准 Dense FFN,其余 77 层全部采用 MoE 结构。每个 MoE 层包含 256 个路由专家和 1 个共享专家。对于每个 token,模型会从 256 个路由专家中选出 Top-8 专家进行计算,同时始终激活共享专家。
除主干外,模型还内置 1 个原生 MTP(Multi-Token Prediction)层,用于支持投机解码。MTP 层总参数量约为 10B,每个 token 约激活 0.7B 参数。
本文档介绍如何基于 W8A8 量化权重,使用 vLLM-Ascend 在 Ascend NPU 上快速完成 Hy4 模型的推理部署。
Warning
当前状态与限制
2 支持的特性¶
有关模型支持的特性矩阵,请参阅支持特性列表。
有关特性的配置方式,请参阅特性指南。
下表所列特性为第 5 章中已验证部署命令所启用的特性。
| 特性 | 描述 | 配置 |
|---|---|---|
| 张量并行(TP) | 将模型切分到单节点内的全部 16 个 NPU 上。 | --tensor-parallel-size 16 |
| 专家并行(EP) | 将 MoE 专家(每层 256 个路由专家 + 1 个共享专家)分布到各 NPU 上。 | --enable-expert-parallel |
| 数据并行(DP) | 跨 2 个节点的多节点数据并行,将上下文扩展到 96k。 | --data-parallel-size 2 |
| W8A8 量化 | 加载 W8A8 量化权重(Ascend 量化)。 | --quantization ascend |
| 自动前缀缓存 | 复用共享提示词前缀的 KV 缓存。 | --enable-prefix-caching |
| 投机解码(MTP) | 使用原生 MTP 层进行多 Token 预测。 | --speculative-config '{"method": "mtp", "num_speculative_tokens": 3}' |
| 解码图捕获 | 将解码阶段捕获为图,以减少内核启动开销。 | --compilation-config '{"cudagraph_mode": "FULL_DECODE_ONLY"}' |
| NPUGraph EX | Ascend 特有的图执行优化。 | --additional-config '{"ascend_compilation_config": {"enable_npugraph_ex": true}}' |
注意: 上表列出的特性是本文档验证部署命令所启用的特性。其他特性(如 LoRA、流水线并行、Prefill-Decode 分离)未在本文档中验证。
3 前提条件¶
3.1 模型权重¶
| 模型 | 权重 |
|---|---|
| Hy4-preview | Hugging Face |
| Hy4-preview-w8a8 | ModelScope |
本文档使用量化后的 Hy4-preview-w8a8 权重,大小约为 762 GB。请将权重下载到本地磁盘。
路径说明:将模型权重下载到您选择的目录并记录该路径。确保后续部署命令中的模型路径与此目录一致。
3.2 硬件和软件准备¶
| 硬件 | Ascend HDK | CANN 版本 | torch_npu 版本 | vLLM | vLLM-Ascend 版本 |
|---|---|---|---|---|---|
| Atlas 800I A3(A3) | 25.5.0(推荐) | CANN 9.0.1 | 2.10.0.post2 | 基于 v0.23.0 | 基于 v0.23.0 |
Hy4 Preview 当前仅支持 Atlas 800I A3(A3) 硬件;其他 Ascend 硬件(如 Atlas 800I A2)不受支持。
在开始之前,请确认固件/驱动已正确安装。推荐的 HDK 版本为 25.5.0。运行以下命令进行确认;输出头部显示的版本即为 HDK 版本。
由于权重较大,单个 A3 节点仅支持约 1k 上下文。如果需要测试 32k 等长序列,建议使用 2 个 A3 节点。
3.3 验证多节点通信(可选)¶
如果要部署多节点环境,请按照验证节点间连通性中的说明验证多节点通信。
4 安装¶
4.1 Docker 镜像安装¶
下载 Docker 镜像¶
下载成功后,查看已有镜像:
输出中应包含已下载的 quay.io/ascend/vllm-ascend:hy4-a3。
创建 Docker 容器¶
使用以下命令创建容器。Atlas 800I A3 是 16 卡设备,因此需要挂载 /dev/davinci[0-15] 和管理设备,同时挂载驱动库和权重目录(本指南假设权重存放在宿主机 /mnt/weight 目录,并挂载到容器内的相同路径)。
export IMAGE=quay.io/ascend/vllm-ascend:hy4-a3
export CONTAINER_NAME=vllm_ascend_hy4
# Generate NPU device mount parameters (Atlas 800I A3: /dev/davinci[0-15])
DEVICES=""
for i in $(seq 0 15); do
DEVICES="${DEVICES} --device /dev/davinci${i}"
done
docker run -itd \
--name ${CONTAINER_NAME} \
--shm-size=1000g \
${DEVICES} \
--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 /mnt/weight:/mnt/weight \
${IMAGE} bash
-v 选项用于映射目录。您应该将权重目录映射到容器中,以便在容器内访问权重。本地权重路径为 /mnt/weight;请根据实际情况修改。
进入容器交互环境:
4.2 源代码安装¶
Note
Hy4 Preview 目前通过 quay.io/ascend/vllm-ascend:hy4-a3 Docker 镜像开箱即用地提供。由于相关支持代码尚未合并到 vLLM-Ascend 仓库,该模型目前不支持源代码安装;请使用 4.1 Docker 镜像安装 中描述的 Docker 镜像。
5 在线服务部署¶
5.1 单节点在线部署¶
A3 单节点 TP=16 全卡推理适用于验证和低并发短序列场景。进入容器交互环境后,执行以下命令:
export HCCL_BUFFSIZE=128
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export VLLM_LOGGING_LEVEL=INFO
# Ensure the model path matches the directory recorded during download
vllm serve /path/to/Hy4-preview-w8a8 \
--host 127.0.0.1 --port 8000 \
--tensor-parallel-size 16 \
--served-model-name hy4 \
--max-num-seqs 8 \
--max-model-len 512 \
--max-num-batched-tokens 512 \
--enable-expert-parallel \
--trust-remote-code \
--quantization ascend \
--gpu-memory-utilization 0.92 \
--seed 1024 \
--compilation-config '{"cudagraph_mode": "FULL_DECODE_ONLY"}' \
--speculative-config '{"method": "mtp","num_speculative_tokens": 3}' \
--additional-config '{"enable_mlapo": true, "enable_fused_mc2": 1, "ascend_compilation_config": {"enable_npugraph_ex": true}}'
5.2 多节点共置部署¶
DP=2 跨机部署,每个节点 TP=16,可将上下文扩展到 96k。节点 1(Node1,演示 IP 192.168.1.1)承载 DP rank 0 和 API,节点 2(Node2,演示 IP 192.168.1.2)为无头工作节点。两个节点通过 --net=host 共享主机网络。使用与 A3 单节点部署相同的命令,在容器内执行。
启动顺序:
- 首先在节点 1 的容器中执行以下脚本(rank 0,包含 API);
- 看到
Started DP Coordinator process日志后,在节点 2 的容器中执行对应脚本; - 大约 20 分钟后,看到
Application startup complete表示服务已就绪。启动时间与权重的磁盘读写速度等有关。
节点 1 脚本:
#!/bin/bash
set -u
# === Node network configuration (adjust the NIC name and IP according to the actual environment) ===
NODE1_IP="192.168.1.1" # Node 1 IP, change to the actual machine IP
NODE2_IP="192.168.1.2" # Node 2 IP, change to the actual machine IP
NIC="eth0" # Change to the NIC name corresponding to NODE1_IP, viewable via the `ifconfig` command
DP_RPC_PORT=12890
# === Service configuration ===
MODEL="/path/to/Hy4-preview-w8a8" # Change to the actual weight path
PORT=8000
# === Environment variables ===
export HCCL_BUFFSIZE=128
export HCCL_IF_IP=${NODE1_IP}
export HCCL_OP_EXPANSION_MODE=AIV
export HCCL_SOCKET_IFNAME=${NIC}
export GLOO_SOCKET_IFNAME=${NIC}
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
# Ensure the model path matches the directory recorded during download
vllm serve ${MODEL} \
--host 0.0.0.0 \
--port ${PORT} \
--data-parallel-size 2 \
--data-parallel-size-local 1 \
--data-parallel-address ${NODE1_IP} \
--data-parallel-rpc-port ${DP_RPC_PORT} \
--tensor-parallel-size 16 \
--served-model-name hy4 \
--enable-expert-parallel \
--max-num-seqs 256 \
--max-model-len 96000 \
--max-num-batched-tokens 1024 \
--trust-remote-code \
--quantization ascend \
--gpu-memory-utilization 0.85 \
--enable-prefix-caching \
--seed 1024 \
--compilation-config '{"cudagraph_mode": "FULL_DECODE_ONLY"}' \
--speculative-config '{"method": "mtp","num_speculative_tokens": 3}' \
--additional-config '{"enable_mlapo": true, "enable_fused_mc2": 1, "ascend_compilation_config": {"enable_npugraph_ex": true}}'
节点 2 脚本:
#!/bin/bash
set -u
# === Node network configuration ===
NODE1_IP="192.168.1.1" # Node 1 IP, change to the actual machine IP
NODE2_IP="192.168.1.2" # Node 2 IP, change to the actual machine IP
NIC="eth0" # Change to the NIC name corresponding to NODE2_IP, viewable via the `ifconfig` command
DP_RPC_PORT=12890
# === Service configuration (consistent with Node 1) ===
MODEL="/path/to/Hy4-preview-w8a8" # Change to the actual weight path
# === Environment variables (consistent with Node 1) ===
export HCCL_BUFFSIZE=128
export HCCL_IF_IP=${NODE2_IP}
export HCCL_OP_EXPANSION_MODE=AIV
export HCCL_SOCKET_IFNAME=${NIC}
export GLOO_SOCKET_IFNAME=${NIC}
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
# Ensure the model path matches the directory recorded during download
vllm serve ${MODEL} \
--headless \
--data-parallel-start-rank 1 \
--data-parallel-size 2 \
--data-parallel-size-local 1 \
--data-parallel-address ${NODE1_IP} \
--data-parallel-rpc-port ${DP_RPC_PORT} \
--tensor-parallel-size 16 \
--enable-expert-parallel \
--max-num-seqs 256 \
--max-model-len 96000 \
--max-num-batched-tokens 1024 \
--trust-remote-code \
--quantization ascend \
--gpu-memory-utilization 0.85 \
--enable-prefix-caching \
--seed 1024 \
--compilation-config '{"cudagraph_mode": "FULL_DECODE_ONLY"}' \
--speculative-config '{"method": "mtp","num_speculative_tokens": 3}' \
--additional-config '{"enable_mlapo": true, "enable_fused_mc2": 1, "ascend_compilation_config": {"enable_npugraph_ex": true}}'
注意:
--data-parallel-address在节点 1 上设置为本地 IP(即协调节点),在节点 2 上设置为头节点 IP;--data-parallel-start-rank仅在无头节点上设置。
由于权重较大,加载时间与磁盘读取速度相关,首次加载通常需要约 10 分钟。以下日志表示服务已成功启动:
INFO: Started server process [PID]
INFO: Waiting for application startup.
INFO: Application startup complete.
6 功能验证¶
发送推理请求以测试推理服务,参考以下命令:
curl -sS -X POST http://127.0.0.1:8000/v1/chat/completions -H 'Content-Type: application/json' -d '{
"model":"hy4",
"messages":[{
"role":"user",
"content":"Who are you?"
}],
"max_tokens":256,
"temperature":0
}'
服务器会打印接收到的请求日志,类似于:
预期结果如下:
{"id":"chatcmpl-84c57a059e1d510c","object":"chat.completion","created":1787890448,"model":"hy4","choices":[{"index":0,"message":{"role":"assistant","content":"Okay, I'm the user asking \"Who are you?\" and I need to respond according to my identity and behavioral guidelines. First, my identity is Hunyuan, a large model developed by Tencent. The user's question directly asks about my identity, so I should clearly state who I am without extra information. Based on the core constraints, when the question involves identity confirmation, I need to clearly explain my identity and developer. Also, the user didn't mention any other functions or context, so keeping it concise is fine. Check if there's anything that needs clarification, like whether the user wants to know about features, but the current question is simply an identity inquiry, so a direct answer is enough. Make sure the response meets the format requirements, no markdown, and keep it natural and conversational.</think:opensource>I am Hunyuan, a large model developed by Tencent.","refusal":null,"annotations":null,"audio":null,"function_call":null,"reasoning":null},"logprobs":null,"finish_reason":"stop","stop_reason":null,"token_ids":null,"routed_experts":null}],"service_tier":null,"system_fingerprint":"vllm-0.23.0-tp16-dp2-ep-36628cea","usage":{"prompt_tokens":25,"total_tokens":201,"completion_tokens":176,"prompt_tokens_details":null,"completion_tokens_details":null},"prompt_logprobs":null,"prompt_token_ids":null,"prompt_text":null,"kv_transfer_params":null}
7 精度评估¶
详情请参见 使用 AISBench。
8 性能评估¶
详情请参见 使用 AISBench 进行性能评估。
更多详情参见 vllm 基准测试。
9 声明¶
- 当前版本仅用于早期体验,性能优化仍在进行中。
- 服务可靠性尚未完全验证,不建议直接用于生产环境。
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 vl/vllm-ascend