|
| 1 | +.. _qwen35_deployment: |
| 2 | + |
| 3 | +Qwen3.5 模型部署指南 |
| 4 | +===================== |
| 5 | + |
| 6 | +LightLLM 支持 Qwen3.5 模型系列的部署。本指南以 `Qwen3.5-397B-A17B <https://huggingface.co/Qwen/Qwen3.5-397B-A17B>`_ 为例,介绍部署配置、思考/推理模式、多模态输入及推荐启动参数。 |
| 7 | + |
| 8 | +模型概述 |
| 9 | +-------- |
| 10 | + |
| 11 | +Qwen3.5-397B-A17B 是一个多模态混合专家模型,总参数量 397B,每个 token 激活 17B 参数。原生支持文本、图像和视频理解。 |
| 12 | + |
| 13 | +**主要特性:** |
| 14 | + |
| 15 | +- **混合注意力架构**:60 层排列为 15 个重复组 ``[3 × (Gated DeltaNet → MoE) → 1 × (Gated Attention → MoE)]``,交替使用线性注意力与全注意力(通过 ``full_attention_interval`` 控制) |
| 16 | +- **稀疏 MoE**:共 512 个专家,每个 token 激活 10 个路由专家 + 1 个共享专家 |
| 17 | +- **原生多模态**:内置视觉编码器,支持图像和视频理解,无需单独的 "-VL" 变体 |
| 18 | +- **长上下文**:原生支持 262K 上下文,通过 YaRN 缩放可扩展至 1M+ tokens |
| 19 | +- **多头旋转位置编码(MRoPE)**:交错旋转位置编码,``mrope_section=[11, 11, 10]``,用于空间/时间定位 |
| 20 | +- **思考/推理模式**:支持 ``qwen3`` 推理解析器,使用 ``<think>...</think>`` 标签(默认启用) |
| 21 | + |
| 22 | +**已注册的模型类型:** |
| 23 | + |
| 24 | +.. list-table:: |
| 25 | + :header-rows: 1 |
| 26 | + :widths: 30 30 40 |
| 27 | + |
| 28 | + * - 模型类型 |
| 29 | + - 架构 |
| 30 | + - 说明 |
| 31 | + * - ``qwen3_5`` |
| 32 | + - 稠密 + 多模态 |
| 33 | + - 稠密 MLP,带视觉编码器 |
| 34 | + * - ``qwen3_5_moe`` |
| 35 | + - MoE + 多模态 |
| 36 | + - 混合专家模型,带视觉编码器 |
| 37 | + |
| 38 | +.. note:: |
| 39 | + |
| 40 | + Qwen3.5 模型默认注册为多模态模型,多模态支持自动启用。若需纯文本部署,添加 ``--disable_vision`` 以跳过视觉编码器的加载,减少显存占用和启动时间。 |
| 41 | + |
| 42 | +推荐启动脚本 |
| 43 | +-------------- |
| 44 | + |
| 45 | +Qwen3.5-397B-A17B(8×H200) |
| 46 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 47 | + |
| 48 | +在 8 张 GPU 上部署完整的多模态 MoE 模型: |
| 49 | + |
| 50 | +.. code-block:: bash |
| 51 | +
|
| 52 | + LIGHTLLM_TRITON_AUTOTUNE_LEVEL=1 LOADWORKER=18 \ |
| 53 | + python -m lightllm.server.api_server \ |
| 54 | + --model_dir /path/to/Qwen3.5-397B-A17B/ \ |
| 55 | + --tp 8 \ |
| 56 | + --max_req_total_len 262144 \ |
| 57 | + --chunked_prefill_size 8192 \ |
| 58 | + --llm_prefill_att_backend fa3 \ |
| 59 | + --llm_decode_att_backend flashinfer \ |
| 60 | + --graph_max_batch_size 128 \ |
| 61 | + --reasoning_parser qwen3 \ |
| 62 | + --host 0.0.0.0 \ |
| 63 | + --port 8000 |
| 64 | +
|
| 65 | +**参数说明:** |
| 66 | + |
| 67 | +- ``LIGHTLLM_TRITON_AUTOTUNE_LEVEL=1``: 启用 Triton 自动调优以获得最佳内核性能 |
| 68 | +- ``LOADWORKER=18``: 模型加载线程数,加快权重加载速度 |
| 69 | +- ``--tp 8``: 8 卡张量并行(397B 参数模型必需) |
| 70 | +- ``--max_req_total_len 262144``: 最大请求总长度,与模型原生 262K 上下文匹配 |
| 71 | +- ``--chunked_prefill_size 8192``: 预填充处理的分块大小,降低峰值显存占用 |
| 72 | +- ``--llm_prefill_att_backend fa3``: 预填充阶段使用 FlashAttention3(推荐 H200) |
| 73 | +- ``--llm_decode_att_backend flashinfer``: 解码阶段使用 FlashInfer |
| 74 | +- ``--graph_max_batch_size 128``: CUDA graph 最大批处理大小(显存不足时可减小) |
| 75 | +- ``--reasoning_parser qwen3``: 启用 Qwen3 推理解析器,支持思考模式 |
| 76 | + |
| 77 | +纯文本模式(节省显存) |
| 78 | +~~~~~~~~~~~~~~~~~~~~~~~ |
| 79 | + |
| 80 | +跳过视觉编码器加载以减少显存占用: |
| 81 | + |
| 82 | +.. code-block:: bash |
| 83 | +
|
| 84 | + LIGHTLLM_TRITON_AUTOTUNE_LEVEL=1 LOADWORKER=18 \ |
| 85 | + python -m lightllm.server.api_server \ |
| 86 | + --model_dir /path/to/Qwen3.5-397B-A17B/ \ |
| 87 | + --tp 8 \ |
| 88 | + --max_req_total_len 262144 \ |
| 89 | + --chunked_prefill_size 8192 \ |
| 90 | + --llm_prefill_att_backend fa3 \ |
| 91 | + --llm_decode_att_backend flashinfer \ |
| 92 | + --graph_max_batch_size 128 \ |
| 93 | + --reasoning_parser qwen3 \ |
| 94 | + --disable_vision \ |
| 95 | + --host 0.0.0.0 \ |
| 96 | + --port 8000 |
| 97 | +
|
| 98 | +唯一区别是 ``--disable_vision``,阻止加载视觉编码器。此模式下模型仅接受文本输入。 |
| 99 | + |
| 100 | +思考/推理模式 |
| 101 | +------------- |
| 102 | + |
| 103 | +Qwen3.5 默认启用思考模式。模型在生成最终答案之前,会在 ``<think>...</think>`` 标签内生成思维链推理过程。 |
| 104 | + |
| 105 | +**启用推理模式:** |
| 106 | + |
| 107 | +在启动命令中添加 ``--reasoning_parser qwen3``(以上所有示例均已包含)。使用 OpenAI 兼容 API 时,在请求中设置 ``separate_reasoning: true`` 可单独获取思考内容: |
| 108 | + |
| 109 | +.. code-block:: bash |
| 110 | +
|
| 111 | + curl http://localhost:8000/v1/chat/completions \ |
| 112 | + -H "Content-Type: application/json" \ |
| 113 | + -d '{ |
| 114 | + "model": "Qwen3.5-397B-A17B", |
| 115 | + "messages": [{"role": "user", "content": "请逐步求解:23 * 47 等于多少?"}], |
| 116 | + "max_tokens": 500, |
| 117 | + "separate_reasoning": true |
| 118 | + }' |
| 119 | +
|
| 120 | +响应中将包含 ``reasoning_content`` 字段(模型思考过程)和 ``content`` 字段(最终答案)。 |
| 121 | + |
| 122 | +**针对特定请求禁用思考:** |
| 123 | + |
| 124 | +若需要更快的响应速度,可在请求中设置 ``enable_thinking: false`` 以使用非思考模式: |
| 125 | + |
| 126 | +.. code-block:: bash |
| 127 | +
|
| 128 | + curl http://localhost:8000/v1/chat/completions \ |
| 129 | + -H "Content-Type: application/json" \ |
| 130 | + -d '{ |
| 131 | + "model": "Qwen3.5-397B-A17B", |
| 132 | + "messages": [{"role": "user", "content": "你好"}], |
| 133 | + "max_tokens": 100, |
| 134 | + "enable_thinking": false |
| 135 | + }' |
| 136 | +
|
| 137 | +**推荐采样参数:** |
| 138 | + |
| 139 | +.. list-table:: |
| 140 | + :header-rows: 1 |
| 141 | + :widths: 30 35 35 |
| 142 | + |
| 143 | + * - 参数 |
| 144 | + - 思考模式 |
| 145 | + - 非思考模式 |
| 146 | + * - temperature |
| 147 | + - 0.6 |
| 148 | + - 0.7 |
| 149 | + * - top_p |
| 150 | + - 0.95 |
| 151 | + - 0.8 |
| 152 | + * - top_k |
| 153 | + - 20 |
| 154 | + - 20 |
| 155 | + * - presence_penalty |
| 156 | + - 0.0 |
| 157 | + - 1.5 |
| 158 | + |
| 159 | +测试与验证 |
| 160 | +---------- |
| 161 | + |
| 162 | +基础功能测试 |
| 163 | +~~~~~~~~~~~~ |
| 164 | + |
| 165 | +.. code-block:: bash |
| 166 | +
|
| 167 | + curl http://localhost:8000/generate \ |
| 168 | + -H "Content-Type: application/json" \ |
| 169 | + -d '{ |
| 170 | + "inputs": "什么是人工智能?", |
| 171 | + "parameters":{ |
| 172 | + "max_new_tokens": 100, |
| 173 | + "frequency_penalty": 1 |
| 174 | + } |
| 175 | + }' |
| 176 | +
|
| 177 | +OpenAI 兼容聊天接口 |
| 178 | +~~~~~~~~~~~~~~~~~~~ |
| 179 | + |
| 180 | +.. code-block:: bash |
| 181 | +
|
| 182 | + curl http://localhost:8000/v1/chat/completions \ |
| 183 | + -H "Content-Type: application/json" \ |
| 184 | + -d '{ |
| 185 | + "model": "Qwen3.5-397B-A17B", |
| 186 | + "messages": [{"role": "user", "content": "你好"}], |
| 187 | + "max_tokens": 100, |
| 188 | + "temperature": 0.7, |
| 189 | + "top_p": 0.8, |
| 190 | + "enable_thinking": false |
| 191 | + }' |
| 192 | +
|
| 193 | +多模态测试(图像输入) |
| 194 | +~~~~~~~~~~~~~~~~~~~~~ |
| 195 | + |
| 196 | +.. code-block:: bash |
| 197 | +
|
| 198 | + curl http://localhost:8000/v1/chat/completions \ |
| 199 | + -H "Content-Type: application/json" \ |
| 200 | + -d '{ |
| 201 | + "model": "Qwen3.5-397B-A17B", |
| 202 | + "messages": [ |
| 203 | + { |
| 204 | + "role": "user", |
| 205 | + "content": [ |
| 206 | + {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}, |
| 207 | + {"type": "text", "text": "请描述这张图片。"} |
| 208 | + ] |
| 209 | + } |
| 210 | + ], |
| 211 | + "max_tokens": 200 |
| 212 | + }' |
| 213 | +
|
| 214 | +硬件要求 |
| 215 | +-------- |
| 216 | + |
| 217 | +**Qwen3.5-397B-A17B:** |
| 218 | + |
| 219 | +- 总参数量 397B,每个 token 激活 17B(512 个专家,10 路由 + 1 共享) |
| 220 | +- **最低要求**:8× NVIDIA H100/H200 GPU(每卡 80GB HBM),需 NVLink 互联 |
| 221 | +- 必须使用 ``--tp 8`` 以将模型权重分布到各 GPU |
| 222 | +- 如遇到显存不足,可减小 ``--max_req_total_len`` 或 ``--graph_max_batch_size`` |
| 223 | +- 使用 ``--data_type fp8_e4m3`` 进行 FP8 KV 量化可进一步降低显存压力 |
0 commit comments