跳转至

Qwen3-Dense(Qwen3-0.6B/1.7B/4B/8B/14B/32B,W8A8,W4A8,W4A4)

1.简介

Qwen3 是通义千问系列最新一代大语言模型,提供全面的稠密和混合专家(MoE)模型。基于大规模训练,Qwen3 在推理、指令遵循、智能体能力和多语言支持方面取得了突破性进展。本文档涵盖的 Dense 变体包括 Qwen3-0.6B、1.7B、4B、8B、14B 和 32B,以及针对 Ascend NPU 部署优化的量化版本(W8A8、W4A8、W4A4)。

本文档将演示在 vLLM-Ascend 环境中对 Qwen3 Dense 模型的主要验证步骤,包括支持的特性、环境准备、模型量化、单节点和多节点部署,以及精度和性能评估。通过针对不同用例定制服务级配置,您可以确保在各种场景下获得最佳性能。

Qwen3 Dense 模型首次在 v0.8.4rc2 中支持。W8A8 量化首次在 v0.8.4rc2 中支持,W4A8 量化自 v0.9.1rc2 起支持,W4A4 自 v0.11.0rc1 起支持。本文档基于 vLLM-Ascend v0.21.0 验证和编写。所有 v0.21.0 及更高版本 均可稳定运行。要使用最新特性,建议使用最新的候选版本或正式版本。

2.支持的特性

请参阅支持的特性列表获取模型支持矩阵。

请参阅特性指南获取特性配置信息。

3.前提条件

3.1 模型权重

以下模型变体可用。建议将模型权重下载到所有节点均可访问的共享目录。

BF16 版本:

模型 硬件要求 下载
Qwen3-0.6B 1 Atlas 800I A3(64G × 16)或 1 Atlas 800I A2(64G × 8) 下载
Qwen3-1.7B 1 Atlas 800I A3(64G × 16)或 1 Atlas 800I A2(64G × 8) 下载
Qwen3-4B 1 Atlas 800I A3(64G × 16)或 1 Atlas 800I A2(64G × 8) 下载
Qwen3-8B 1 Atlas 800I A3(64G × 16)或 1 Atlas 800I A2(64G × 8) 下载
Qwen3-14B 1 Atlas 800I A3(64G × 16)或 1 Atlas 800I A2(64G × 8) 下载
Qwen3-32B 1 Atlas 800I A3(64G × 16)或 1 Atlas 800I A2(64G × 8) 下载

量化版本:

模型 量化 硬件要求 下载
Qwen3-8B-W4A8 W4A8 1 Atlas 800I A3(64G × 16)或 1 Atlas 800I A2(64G × 8) 下载
Qwen3-32B-W4A4 W4A4 1 Atlas 800I A3(64G × 16)或 1 Atlas 800I A2(64G × 8) 下载
Qwen3-32B-W8A8 W8A8 1 Atlas 800I A3(64G × 16)或 1 Atlas 800I A2(64G × 8) 下载

这些是推荐的卡数量,可以根据实际情况进行调整。

3.2 验证多节点通信

如果需要部署多节点环境,请按照验证多节点通信环境验证多节点通信。

4.安装

4.1 Docker 镜像安装

您可以使用 Qwen3 Dense 模型的官方一体化 Docker 镜像。

Docker 拉取:

docker pull quay.io/ascend/vllm-ascend:v0.22.1rc1

Docker 运行:

在每个节点上启动 Docker 镜像。

export IMAGE=quay.io/ascend/vllm-ascend:v0.22.1rc1-a3

docker run --rm \
    --name vllm-ascend-env \
    --shm-size=1g \
    --net=host \
    --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/davinci8 \
    --device /dev/davinci9 \
    --device /dev/davinci10 \
    --device /dev/davinci11 \
    --device /dev/davinci12 \
    --device /dev/davinci13 \
    --device /dev/davinci14 \
    --device /dev/davinci15 \
    --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 /root/.cache:/root/.cache \
    -it $IMAGE bash

Note

A3 has 8 NPUs with dual-die design (16 chips total: /dev/davinci[0-15]). If you are on a shared machine, map only the chips you need (e.g., /dev/davinci[0-7] for NPU 0-3).

export IMAGE=quay.io/ascend/vllm-ascend:v0.22.1rc1

docker run --rm \
    --name vllm-ascend-env \
    --shm-size=1g \
    --net=host \
    --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 /root/.cache:/root/.cache \
    -it $IMAGE bash

The default workdir is /workspace。vLLM 和 vLLM-Ascend 作为 Python 包安装在 site-packages 中。

Installation Verification: After starting the container, run the following command to verify the installation:

docker ps | grep vllm-ascend-env

预期结果:容器列出且状态为 Up。您还可以在容器内验证 vllm-ascend 版本:

pip show vllm-ascend

预期结果:显示版本信息,与拉取的镜像版本匹配。

4.2 源码安装

If you prefer to build from source instead of using the Docker image, install vLLM-Ascend following the Installation Guide.

To verify the source installation:

pip show vllm-ascend

预期结果:显示版本信息,确认安装成功。

Note

如果要部署多节点环境,需要在每个节点上设置环境。

5.在线服务部署

5.1 单节点在线部署

单节点部署在同一节点内完成 Prefill 和 Decode,适用于开发、测试以及中小规模推理场景。

启动服务器:

以下命令为示例配置,请根据实际场景调整参数。

Atlas 800I A2/A3:

Qwen3-32B-W8A8:

export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export TASK_QUEUE_ENABLE=1
export HCCL_OP_EXPANSION_MODE="AIV"

vllm serve your_model_path \
    --served-model-name qwen3 \
    --trust-remote-code \
    --async-scheduling \
    --quantization ascend \
    --distributed-executor-backend mp \
    --tensor-parallel-size 4 \
    --max-model-len 5500 \
    --max-num-batched-tokens 40960 \
    --compilation-config '{"cudagraph_mode": "FULL_DECODE_ONLY"}' \
    --port <port> \
    --gpu-memory-utilization 0.9 \
    --additional-config '{"enable_flashcomm1": true}'

Atlas 800I A2/A3:

Qwen3-32B-W4A4:

export ASCEND_RT_VISIBLE_DEVICES=0,1
export VLLM_USE_V1=1
export TASK_QUEUE_ENABLE=1
export HCCL_BUFFSIZE=1024
vllm serve your_model_path \
    --port 8004 \
    --data-parallel-size 1 \
    --tensor-parallel-size 2 \
    --served-model-name qwen3 \
    --distributed_executor_backend "mp" \
    --max-model-len 40960 \
    --max-num-batched-tokens 16384 \
    --max-num-seqs 64 \
    --trust-remote-code \
    --gpu-memory-utilization 0.9 \
    --quantization ascend \
    --compilation-config '{"cudagraph_capture_sizes": [64]}' \
    --additional-config '{"enable_flashcomm1": true}'

Atlas 800I A2/A3: Qwen3-8B-W4A8:

export ASCEND_RT_VISIBLE_DEVICES=0,1
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
vllm serve your_model_path \
    --served-model-name qwen3 \
    --max-model-len 4096 \
    --port 20001 \
    --additional-config '{"ascend_compilation_config": {"enable_npugraph_ex": false}}' \
    --quantization ascend

Note

服务验证:

如果服务启动成功,将显示以下启动日志:

(APIServer pid=<pid>) INFO:     Started server process [<pid>]
(APIServer pid=<pid>) INFO:     Waiting for application startup.
(APIServer pid=<pid>) INFO:     Application startup complete.

6 功能验证

服务启动后,可通过发送 prompt 来调用模型。

Chat Completions API:

curl http://localhost:<port>/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "qwen3",
        "messages": [
            {"role": "user", "content": "Give me a short introduction to large language models."}
        ],
        "temperature": 0.6,
        "top_p": 0.95,
        "top_k": 20,
        "max_completion_tokens": 4096
    }'

预期结果:HTTP 200,返回包含 choices 字段(含生成文本)的 JSON 响应。

7 精度评估

使用 AISBench

For setup details, including installation, 数据集 download, and configuration, please refer to 使用 AISBench.

以下是精度评估配置文件的示例配置:

精度评估配置文件:

# Example configuration: benchmarks/ais_bench/benchmark/configs/models/vllm_api/vllm_api_general_chat.py
from ais_bench.benchmark.models import VLLMCustomAPIChat
from ais_bench.benchmark.utils.model_postprocessors import extract_non_reasoning_content

models = [
    dict(
        attr="service",
        type=VLLMCustomAPIChat,
        abbr='vllm-api-general-chat',
        path="your_model_path",
        model="qwen3",
        request_rate = 0,
        retry = 2,
        host_ip = "127.0.0.1",
        host_port = 2001,
        max_out_len = 32768,
        batch_size = 32,
        trust_remote_code=False,
        generation_kwargs = dict(
            temperature = 0.6,
            top_k = 20,
            top_p = 0.95,
        ),
        pred_postprocessor=dict(type=extract_non_reasoning_content)
    )
]

以 aime2025 数据集为例运行精度评估:

ais_bench --models vllm_api_general_chat --datasets aime2025_gen_0_shot_chat_prompt --debug

--models 参数值对应上述配置文件中的 abbr 字段。请根据实际场景调整 max_out_len、batch_size 和数据集任务。

8 性能评估

使用 AISBench

有关安装、数据集下载和配置等设置详情,请参考使用 AISBench 进行性能评估

以下是精度评估配置文件的示例配置:

# Example configuration: benchmarks/ais_bench/benchmark/configs/models/vllm_api/vllm_api_stream_chat.py
from ais_bench.benchmark.models import VLLMCustomAPIChat
from ais_bench.benchmark.utils.postprocess.model_postprocessors import extract_non_reasoning_content

models = [
    dict(
        attr="service",
        type=VLLMCustomAPIChat,
        abbr="vllm-api-stream-chat",
        path="your_model_path",
        model="qwen3",
        stream=True,
        request_rate=0,
        use_timestamp=False,
        retry=2,
        host_ip="127.0.0.1",
        host_port=8004,
        max_out_len=1500,
        batch_size=90,
        trust_remote_code=False,
        generation_kwargs=dict(
            temperature=0,
            ignore_eos = True
        ),
    )
]

以 GSM8K 数据集为例运行性能评估:

ais_bench --models vllm_api_stream_chat --datasets gsm8k_gen_0_shot_cot_str_perf --debug --summarizer default_perf --mode perf --num-prompts 360

使用 vLLM 基准测试

更多详细信息请参考 vLLM 基准测试

有三个 vllm bench 子命令:

  • latency:基准测试单批次请求的延迟。
  • serve:基准测试在线服务的吞吐量。
  • throughput:基准测试离线推理的吞吐量。

serve 为例:

vllm bench serve \
    --model your_model_path \
    --served-model-name qwen3 \
    --port <port> \
    --dataset-name random \
    --random-input 200 \
    --num-prompts 200 \
    --request-rate 1 \
    --save-result \
    --result-dir ./

大约几分钟后,即可获得性能评估结果。

9 性能调优

9.1 推荐配置

注意:以下配置在特定测试环境中验证,仅供参考。最佳配置取决于最大输入/输出长度、前缀缓存命中率、精度要求和部署机器比例等因素。建议参考第 9.2 节根据实际情况进行调优。

表 1:场景概览

场景 部署模式 *NPU 总数 权重版本 关键考量
高吞吐 单节点 (TP4) 4 (A3) W8A8 4卡 TP 最大化并发请求处理
长上下文 单节点 (TP4) 4 (A3) W8A8 4卡 TP 扩展长序列的上下文窗口
低延迟 单节点 (TP8) 8 (A3) W8A8 8卡 TP 降低交互式响应的每 token 延迟

*Total NPUs表示所有节点使用的 NPU 总数。

表 2:详细节点配置

场景 配置 #NPU TP DP FUSED_MC2 EP 开关 异步调度
高吞吐 单节点 4 4 1 关闭 关闭 开启
长上下文 单节点 4 4 1 关闭 关闭 开启
低延迟 单节点 8 8 1 关闭 关闭 开启

有关详细参数说明,请参考第 5 节中的部署示例。

高吞吐配置:

export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export TASK_QUEUE_ENABLE=1
export HCCL_OP_EXPANSION_MODE="AIV"

vllm serve your_model_path \
  --served-model-name qwen3 \
  --trust-remote-code \
  --distributed-executor-backend mp \
  --tensor-parallel-size 4 \
  --max-model-len 5500 \
  --max-num-batched-tokens 40960 \
  --no-enable-prefix-caching \
  --async-scheduling \
  --quantization ascend \
  --compilation-config '{"cudagraph_mode":"FULL_DECODE_ONLY","cudagraph_capture_sizes":[4,8,64,72,76,80,96,100,120,140,144,160,192,216,240,252,288,320,336,360,384,400,408,416,420,432,480,540,576,600]}' \
  --additional-config '{"weight_prefetch_config":{"enabled":true}, "enable_flashcomm1": true, "pa_shape_list":[32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256]}' \
  --host <host_ip> \
  --port <port> \
  --block-size 128 \
  --gpu-memory-utilization 0.9

长上下文配置:

export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export TASK_QUEUE_ENABLE=1
export HCCL_OP_EXPANSION_MODE="AIV"

vllm serve your_model_path \
  --host <host_ip> \
  --port <port> \
  --served-model-name qwen3 \
  --trust-remote-code \
  --seed 1024 \
  --max-model-len 135000 \
  --max-num-batched-tokens 40960 \
  --tensor-parallel-size 4 \
  --distributed-executor-backend "mp" \
  --async-scheduling \
  --no-enable-prefix-caching \
  --speculative-config '{"method": "eagle3", "model":"your_eagle3_model_path", "num_speculative_tokens": 3}' \
  --compilation-config '{"cudagraph_mode": "FULL_DECODE_ONLY"}' \
  --hf-overrides '{"rope_parameters": {"rope_type":"yarn","rope_theta":1000000,"factor":4,"original_max_position_embeddings":131072}}' \
  --gpu-memory-utilization 0.9 \
  --quantization ascend \
  --additional-config '{"enable_flashcomm1": true}'

低延迟配置:

export ASCEND_RT_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export TASK_QUEUE_ENABLE=1
export HCCL_OP_EXPANSION_MODE="AIV"

vllm serve your_model_path \
  --served-model-name qwen3 \
  --trust-remote-code \
  --distributed-executor-backend mp \
  --tensor-parallel-size 8 \
  --max-model-len 5500 \
  --max-num-batched-tokens 40960 \
  --no-enable-prefix-caching \
  --async-scheduling \
  --quantization ascend \
  --compilation-config '{"cudagraph_mode": "FULL_DECODE_ONLY","cudagraph_capture_sizes":[1,2,4,8,16,32,64,72,76,80,96,100,120,140,144,160,192,216,240,252,288,320,336,360,384,400,408,416,420,432,480,540,576,600]}' \
  --speculative-config '{"method": "eagle3", "model":"your_eagle3_model_path", "enforce_eager": true, "num_speculative_tokens": 3}' \
  --port <port> \
  --block-size 128 \
  --gpu-memory-utilization 0.9

9.2 调优指南

9.2.1 通用调优参考

Please refer to the Public Performance Tuning Documentation for tuning methods. Please refer to the Feature Guide for detailed feature descriptions.

10 常见问题

For common environment, installation, and 生成eral parameter issues, please refer to the vLLM-Ascend FAQs. This section only covers issues specific to Qwen3 Dense models.