MiMo-V2.6-Distill-Qwen-9B on K100-AI + SGLang 0.5.12
1. 简介
本文档记录 XiaomiMiMo/MiMo-V2.6-Distill-Qwen-9B 在 K100-AI + SGLang 0.5.12(精度 bf16)环境的适配与验证结果。
模型为 9.4B 稠密模型,架构 Qwen3_5ForConditionalGeneration:32 层,其中 24 层线性注意力(GDN,门控 DeltaNet)+ 8 层全注意力,hidden 4096、16 个注意力头、4 个 KV 头、词表 248044,自带视觉塔(可做图像理解),BF16 权重约 18.8 GB。
与官方部署方式的核心差异:不改一行框架源码,仅通过三个启动参数解决 Qwen3.5 的 Mamba 分页死锁与思考内容解析问题 —— --mamba-scheduler-strategy extra_buffer(解除 page_size 与 radix cache 的互斥)、--attention-backend fa3、--reasoning-parser mimo。其中前两者是本件能够启动且保住前缀缓存的关键,详见第 3 节。
相关获取地址:
- 权重下载(超算互联网 AI 社区):
XiaomiMiMo/MiMo-V2.6-Distill-Qwen-9B - 基础镜像编号:
jupyterlab-sglang:0.5.12-ubuntu22.04-dtk2604-py3.10 - 提交仓库:
https://developer.sourcefind.cn/codes/g_hiqx2c9f/xiaomimimo-mimo-v2.6-distill-qwen-9b-sglang
参考文档:
- 光合开发者社区《BW系列产品 基础环境部署 · 容器化环境部署》
- SGLang 源码
sglang/srt/server_args.py(Mamba 调度策略与 page_size 约束)
仓库内容:
| 文件 | 作用 | 产出 |
|---|---|---|
env.sh | 模型、镜像、框架、卡型、并行方式与启动参数,其余脚本读这里的变量 | — |
env_check.sh | 采集卡型与重点组件版本 | env.log |
requirements-extra.txt / patches/ | 在镜像基础上升级的包、代码改动(本件均无) | — |
run.sh | 模型启动脚本:装依赖 + 重放 patch + 拉起服务,轮询 /health | server.log |
smoke.sh | Smoke 测试:健康检查、单轮 / 多轮 / 流式问答、思考模式 | smoke.log |
verify.py | 精度验证脚本:按官方口径跑 GSM8K / MMLU | verify_result.json |
data/gsm8k_test.jsonl / data/mmlu_test.jsonl | 离线题库(1319 / 14042 题),verify.py 优先读取,无需联网 | — |
export_datasets.py | 重建题库用(仅在需要重新导出时执行,正常复现不必跑) | data/*.jsonl |
bench.sh | 性能测试脚本:6 档负载,每档连测两次 | bench/ |
tokenizer_check.py | tokenizer 与 chat template 对齐校验(额外补充) | data/tokenizer_check.json |
一键复现(题库已内置,全程无需出网):
git clone https://developer.sourcefind.cn/codes/g_hiqx2c9f/xiaomimimo-mimo-v2.6-distill-qwen-9b-sglang.git
cd xiaomimimo-mimo-v2.6-distill-qwen-9b-sglang
python verify.py --selfcheck # 判分逻辑自检,PASS 后继续
bash run.sh # 起服务 + 轮询 /health(实测 250 s 就绪)
bash env_check.sh # 记录验证环境 → env.log
bash smoke.sh # Smoke 测试 → smoke.log
source env.sh && python verify.py # 精度测评 → verify_result.json
bash bench.sh # 性能测试 → bench/
DTK 环境:
env.sh会自动source /opt/dtk/env.sh,无需手工加载。不加载时torch会报
ImportError: libgalaxyhip.so.5: cannot open shared object file,hy-smi也会command not found。出网:本平台容器的外网访问依赖平台代理,配置在
/root/private_data/.ai_user_info/ai_proxy,
由/etc/bash.bashrc在交互式 shell 中自动 source。因此:
- Notebook 交互终端里
git clone可直接使用;- 非交互执行(脚本 / CI /
ssh host 'cmd'单命令)需先
source /root/private_data/.ai_user_info/ai_proxy,否则git clone/git pull会连接超时。GSM8K / MMLU 题库已随仓库分发到
data/,精度评测全程不需要联网;只有git clone与
可选的数据集重建需要代理,仅当本地题库缺失时verify.py才回退 HuggingFace 在线加载。
2. 验证环境
镜像:jupyterlab-sglang:0.5.12-ubuntu22.04-dtk2604-py3.10(平台镜像编号,Notebook 创建时选用)
重点组件(取自 env.log,本件未升级任何包):
| 组件 | 版本 | 备注 |
|---|---|---|
| DTK | 26.04 | 镜像自带 |
torch | 2.10.0+das.opt1.dtk2604.2608131652.g28498c | 镜像自带 |
triton | 3.6.0+das185.dtk2604.torch2100.2608131719.gb796b1 | 镜像自带 |
sglang | 0.5.12+das185.dtk2604.torch2100.2608121934.gcbf025 | 镜像自带 |
sglang-kernel | 0.4.2.post2+das185.dtk2604.torch2100.2608121934.gcbf025 | 镜像自带 |
transformers | 5.6.0 | 镜像自带 |
tokenizers | 0.22.2 | 镜像自带 |
flash_attn | 2.8.3+das185.dtk2604.torch2100.2608132155.g9febea | 镜像自带 |
causal_conv1d | 1.5.4+das185.dtk2604.torch2100.2608131033.g44ef50 | 镜像自带 |
aiter | 0.1.5+das185.dtk2604.torch2100.2608131714.gb0979d | 镜像自带 |
- 卡型:
K100-AI(实测设备名K500SM_AI,按赛题口径计入 K100-AI) - 卡数:
1(单机 TP=1 / EP=1 / PP=1) - 模型路径:
/public/home/ac8nxpyft3/SothisAI/model/Aihub/MiMo-V2.6-Distill-Qwen-9B/main/MiMo-V2.6-Distill-Qwen-9B - 服务端口:
30000
环境自检(env.log 关键部分原文):
image: jupyterlab-sglang:0.5.12-ubuntu22.04-dtk2604-py3.10
dtk: /opt/dtk
python: 3.10.12
torch: 2.10.0
HIP: 6.3.26113
device: K500SM_AI x 1
total_mem_GiB: 64.0
compute_units: 120
sglang 0.5.12+das185.dtk2604.torch2100.2608121934.gcbf025
transformers 5.6.0
卡侧补充实测(非 env.log 内容,用于解释第 7 节性能量级):
hy-smi: PwrCap 300.0W
torch D2D copy 带宽实测 628.5 GB/s(read 582.6 GB/s)
9.4B BF16 权重 18.8 GB → decode 理论上限 628.5 / 18.8 ≈ 33 tok/s
超算互联网平台(参赛算力统一使用超算互联网):
| 项 | 值 |
|---|---|
| 区域 | 华东一区【昆山】 |
| Notebook 规格 | 32 核 / 503 GB 内存 / 系统盘 overlay 1.8 TB |
| 加速卡与显存 | K100_AI × 1;64 GB(total_mem_GiB: 64.0) |
| 开发镜像 | jupyterlab-sglang:0.5.12-ubuntu22.04-dtk2604-py3.10 |
| 模型获取方式 | AI 社区模型库(/public/home/.../SothisAI/model/Aihub/) |
| 服务映射 | 后端 127.0.0.1:30000;本次未配置外部代理映射 |
| 平台证据 | platform/【待补截图:Notebook 创建页、环境自检、模型管理】 |
3. 适配优化方案
3.1 基础镜像
基于镜像编号 jupyterlab-sglang:0.5.12-ubuntu22.04-dtk2604-py3.10(SCNet 官方社区镜像,Notebook 创建时选用)。
该编号是 SGLang 基础镜像的 JupyterLab 变体,tag 与基础镜像同为 0.5.12-ubuntu22.04-dtk2604-py3.10,镜内 SGLang / DTK / torch / 算子库版本与基础镜像完全一致,仅额外提供 JupyterLab 入口,便于在 Notebook 内直接调试。
选择原因:SCNet 官方社区镜像中唯一同时满足「SGLang 0.5.12」「DTK 26.04」「torch 2.10」「Qwen3.5 架构已收录(sglang/srt/models/qwen3_5.py)」的组合,且已预置 flash_attn / causal_conv1d / aiter 等海光重编版算子库,无需自建。
3.2 软件包升级
无。 镜像自带组件即可完成适配,未升级、未新装任何包,故仓库内无 requirements-extra.txt。
3.3 代码改动
无。 本件未修改任何框架源码,patches/ 目录内无 *.patch 文件,run.sh 的 patch 重放逻辑会直接跳过。
3.4 关键参数求解过程(为什么必须这样起)
这一节替代了通常的「代码改动」,因为本件的障碍全部落在启动参数上。障碍链条如下。
障碍一:page_size 与注意力后端互斥。
Qwen3.5 含 24 层线性注意力,SGLang 用 MambaRadixCache 管理 conv/ssm 状态。默认 no_buffer 调度策略下,状态回滚要求按单 token 寻址,源码强制 page_size=1:
# sglang/srt/server_args.py
elif not self.disable_radix_cache: # no_buffer
if self.page_size is not None and self.page_size != 1:
logger.warning("... requires page_size=1 in the current Mamba scheduling "
"mode (no_buffer), but got {page_size}. Automatically setting page_size=1.")
self.page_size = 1
而 HCU 上可用的高速后端 fa3 硬性要求 block size 为 64。两者互斥,表现为启动 warmup 崩溃:
RuntimeError: Paged KV cache block size must be 64
障碍二:换后端后触发显存访问违例。
--attention-backend triton 可绕过 page_size 限制,但权重加载与 graph capture 完成后,warmup 时出现:
Memory access fault by GPU node-1 (Agent handle: ...) on address ...
KERNEL VMFault: ...
已用最小复现排除算子问题:bf16 index_put_(8192×4096、65536×4096、embedding scatter 等)在 DCU 上全部正常,故障位于 SGLang 的多模态 embedding 拼装路径(qwen3_vl → general_mm_embed_routine)。该路径不提供可绕过的开关(--language-only 需配合 --encoder-urls 的 EPD 分离部署,单机不可用)。
求解:切换到 extra_buffer 调度策略。
--mamba-scheduler-strategy extra_buffer 走的是另一条分支,约束变为 mamba_track_interval % page_size == 0。默认 mamba_track_interval=256,256 % 64 == 0 成立,于是 page_size=64 与 radix cache 可以共存,同时保住 fa3:
Attention backend created: backend=fa3, full_backend_cls=FlashAttentionBackend
Mamba Cache is allocated. max_mamba_cache_size: 323
# page_size 未被改回 1,radix cache 保留
代价:max_running_requests 从 323 降至 64(extra_buffer 占用更多 mamba 资源)。
收益:恢复前缀缓存。同一 2787 token prompt 二次请求实测命中:
Prefill batch, #new-token: 64, #cached-token: 4224
# 墙钟 3.19 s → 2.38 s
对比走过的其它路线:
| 方案 | 结果 |
|---|---|
| 默认(fa3 + page_size 1) | Paged KV cache block size must be 64,必崩 |
手动 --page-size 64 | 被上述代码强制改回 1,仍崩 |
--attention-backend triton | warmup 时 VMFault |
triton + --disable-radix-cache | 同一 VMFault |
--attention-backend aiter | 被拒,HCU 仅允许 dsv4/fa3/hcu_mla/nsa/triton |
--language-only | 被拒,强制要求 --encoder-urls |
fa3 + page_size 64 + extra_buffer | 可用,且保住 radix cache |
3.5 升级步骤
本件无包升级、无 patch,run.sh 启动前无需额外步骤。手动复现即按第 1 节的一键复现顺序执行。
4. 服务启动脚本
env.sh 中与启动相关的配置:
export MODEL_PATH="/public/home/ac8nxpyft3/SothisAI/model/Aihub/MiMo-V2.6-Distill-Qwen-9B/main/MiMo-V2.6-Distill-Qwen-9B"
export SERVED_NAME="mimo-v2.6-distill-qwen-9b"
export FRAMEWORK="sglang"
export PORT=30000
export TP=1
export EP=1
export PP=1
export MAX_LEN=32768
export MEM_FRAC=0.8
export EXTRA_ARGS="--attention-backend fa3 --page-size 64 --mamba-scheduler-strategy extra_buffer --reasoning-parser mimo --chat-template ${MODEL_PATH}/chat_template.jinja"
启动:
bash run.sh
run.sh 展开后实际执行的完整命令(取自 server.log 首行):
python -m sglang.launch_server \
--model-path /public/home/ac8nxpyft3/SothisAI/model/Aihub/MiMo-V2.6-Distill-Qwen-9B/main/MiMo-V2.6-Distill-Qwen-9B \
--served-model-name mimo-v2.6-distill-qwen-9b \
--tp-size 1 --ep-size 1 --pp-size 1 \
--context-length 32768 \
--mem-fraction-static 0.8 \
--host 127.0.0.1 --port 30000 \
--trust-remote-code \
--attention-backend fa3 --page-size 64 --mamba-scheduler-strategy extra_buffer \
--reasoning-parser mimo \
--chat-template .../MiMo-V2.6-Distill-Qwen-9B/chat_template.jinja
重点参数说明(只列与默认值不同、或对能否跑通 / 性能有影响的):
| 参数 | 取值 | 说明 |
|---|---|---|
--tp-size / --ep-size / --pp-size | 1 / 1 / 1 | 单卡,权重 18.8 GB,64 GB 显存可整卡放下 |
--context-length | 32768 | 覆盖 16K 输入 + 1K 输出压测;超过模型原生长度会触发 YaRN |
--mem-fraction-static | 0.8 | 0.85 时 16K×64 档显存紧张;0.8 下 KV 池 565K token,余量 12.4 GB |
--attention-backend | fa3 | HCU 可用后端中唯一的高速档(triton 会触发 VMFault,aiter 被拒) |
--page-size | 64 | fa3 硬性要求 |
--mamba-scheduler-strategy | extra_buffer | 关键,解除 page_size=1 强制,使 fa3 与 radix cache 共存 |
--reasoning-parser | mimo | SGLang 原生支持,思考内容进 reasoning_content,不污染 content |
--chat-template | 模型自带 jinja | 显式指定,避免默认模板导致格式偏差 |
单机部署,不涉及多机组网。
5. Smoke 测试
bash smoke.sh
smoke.sh 依次执行以下检查(任一接口非 2xx 即失败):/health、/v1/models、单轮问答、多轮(第三轮追问姓名)、流式、思考非流式、思考流式。
验证结果(smoke.log 关键部分):
/health返回HTTP 200/v1/models返回mimo-v2.6-distill-qwen-9b,max_model_len: 32768- 单轮问答(思考关闭):
15 的 15% 是多少?→ 「2.25」,finish_reason: stop,matched_stop: 248046 - 多轮:先告知「我叫小海」,第三轮追问 → 「你叫小海。」
- 流式:逐 token 返回,以
data: [DONE]结束 - 思考(非流式):
reasoning_content为英文推理链(reasoning_tokens: 160),content为中文解答,两者正确分离 - 思考(流式):同样以
data: [DONE]结束
说明:思考用例的 max_tokens 设为 256,推理链占 160 token 后 finish_reason 为 length,属长度上限截断,非功能异常。
tokenizer 与模板对齐(data/tokenizer_check.json):
vocab_size 248044 encode→decode 往返无损 true
并发 64 次 encode 错误 0(未出现 fast tokenizer "Already borrowed")
chat_template enable_thinking true/false 渲染均正常
6. 精度测评
python verify.py --selfcheck # 先确认判分逻辑未被改动 → PASS
source env.sh && python verify.py # 跑评测,结果写入 verify_result.json
评测配置(temperature=0 greedy,思考关闭,并发 32):
| 数据集 | 子集题数 | max_tokens | 解码 | 思考开关 | 判分方式 |
|---|---|---|---|---|---|
| GSM8K | 1319(公开 test 全量) | 2048 | greedy(temperature=0) | 关闭 | 取 #### 后数字,去千分位与尾随 .0,与答案数值相等 |
| MMLU | 14042(公开 test 全量) | 32 | greedy(temperature=0) | 关闭 | 取首个 A–D 选项字母 |
结果(verify_result.json 原文结构):
{
"MODEL_ID": "XiaomiMiMo/MiMo-V2.6-Distill-Qwen-9B",
"CARD": "K100-AI",
"FRAMEWORK": "sglang",
"PRECISION": "bf16",
"detail": {
"gsm8k": {"got": 90.75, "ref": null, "worse": null, "tol": 2.0, "pass": null, "n": 1319, "max_tokens": 2048},
"mmlu": {"got": 74.68, "ref": null, "worse": null, "tol": 2.0, "pass": null, "n": 14042, "max_tokens": 32}
},
"passed": null,
"note": "官方 GPU 基线未下发,ref/worse/pass 置 null;got 为公开全量测试集自测精度,不构成官方 Gate 判定"
}
| 数据集 | 官方 GPU 基线 | 本次提交 | 劣化 | 容差 | 判定 |
|---|---|---|---|---|---|
| GSM8K | 未下发 | 90.75 | — | ≤2 pt | 待定 |
| MMLU | 未下发 | 74.68 | — | ≤2 pt | 待定 |
结论:无法判定。baselines/XiaomiMiMo__MiMo-V2.6-Distill-Qwen-9B.json 至今未下发,赛题正文亦注明「部分模型没有官方精度数据的,可以不做」。本件已按官方结构输出结果,拿到基线文件放入 baselines/ 后重跑 verify.py 即可自动完成 Gate 判定,无需改代码。
补充参照:同模型在 BW + vLLM 0.18.1 上的公开自测数据为 GSM8K 91.43、MMLU 72.13,均无官方基线。本件 MMLU 高出 2.55 pt、GSM8K 低 0.68 pt,差异落在采样实现与判分细节层面。
7. 性能参考
bench.sh 使用 SGLang 自带压测客户端,随机 token 输入、固定输入输出长度:
| 输入 | 输出 | 并发 |
|---|---|---|
| 4K(4096) | 1K(1024) | 1 / 8 / 64 |
| 16K(16384) | 1K(1024) | 1 / 8 / 64 |
每档连测两次,第一次预热,取第二次数据;请求数为并发 2 倍(至少 8 个)。
bash bench.sh
单档命令(bench.sh 内部对 6 档 × 2 次循环执行):
python -m sglang.bench_serving \
--backend sglang --host 127.0.0.1 --port 30000 \
--model mimo-v2.6-distill-qwen-9b --tokenizer "$MODEL_PATH" \
--dataset-name random-ids \
--random-input-len 4096 --random-output-len 1024 --random-range-ratio 1 \
--max-concurrency 8 --num-prompts 16 --seed 1 \
--flush-cache \
--output-file bench/round2.jsonl
注:本机 SGLang 0.5.12 的压测模块名为
sglang.bench_serving(旧名),bench.sh已做sglang.benchmark.serving→sglang.bench_serving的自动回退。
第二次结果(bench/summary.md 原文):
| random_input_len | random_output_len | max_concurrency | completed | duration | request_throughput | output_throughput | total_throughput | mean_ttft_ms | p99_ttft_ms | mean_tpot_ms | p99_tpot_ms | mean_e2e_latency_ms |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 4096 | 1024 | 1 | 8 | 484.77 | 0.02 | 16.90 | 84.49 | 1390.63 | 1624.19 | 57.87 | 57.89 | 60587.67 |
| 4096 | 1024 | 8 | 16 | 165.18 | 0.10 | 99.19 | 495.95 | 4239.10 | 11823.18 | 76.55 | 82.81 | 82546.42 |
| 4096 | 1024 | 64 | 128 | 493.03 | 0.26 | 265.85 | 1329.25 | 48884.39 | 220582.32 | 162.90 | 216.75 | 215528.35 |
| 16384 | 1024 | 1 | 8 | 532.56 | 0.02 | 15.38 | 261.50 | 6044.87 | 7304.01 | 59.16 | 59.36 | 66561.02 |
| 16384 | 1024 | 8 | 16 | 229.15 | 0.07 | 71.50 | 1215.51 | 20431.96 | 54532.72 | 91.98 | 128.73 | 114528.58 |
| 16384 | 1024 | 64 | 128 | 1404.41 | 0.09 | 93.33 | 1586.59 | 356930.73 | 700311.25 | 208.95 | 517.59 | 570691.41 |
- 原始数据:
bench/round1.jsonl、bench/round2.jsonl、各档日志bench/round*_*.log - 本结果作为该件「模型 × 卡型 × 框架 × 精度」的性能基准
判读:
- 单请求 decode 卡在 15~17 tok/s,与第 2 节带宽模型吻合(628.5 GB/s ÷ 18.8 GB ≈ 33 tok/s 上限,实测利用率约 52%)。这是硬件带宽与 DCU kernel 成熟度决定,非配置问题。
- prefill 无并发扩展性:4K 输入从 c1(TTFT 1.39 s)到 c64(48.9 s)线性累积;16K 输入 c64 的 TTFT 达 357 s。
- decode 侧 batch 效率良好:4K 输出吞吐 c1 → c64 提升 15.7 倍(16.90 → 265.85)。
- 16K/c64 是明显短板,该档不适合作为在线服务配置。
8. 注意事项
- 不支持的负载:无档位失败,6 档全部 completed。但 16K 输入 × 64 并发档 TTFT 达 357 s(p99 700 s),接近在线服务不可用区间,已在该档日志中留存原始数据。
- 修改的模型参数:无。未改
config.json、generation_config.json、tokenizer 与采样语义。 - 已知限制:
max_running_requests受extra_buffer限制为 64,超过后排队。- 服务为单卡单实例,
TP=1,不可横向扩展。 - 视觉塔可用(
has_image_understanding: true),但本件性能与精度均按纯文本口径测量。
- 踩坑与规避(完整推演见第 3.4 节):
RuntimeError: Paged KV cache block size must be 64→ Qwen3.5 的 Mambano_buffer策略强制page_size=1,与 fa3 冲突 → 改用--mamba-scheduler-strategy extra_buffer。- 换
--attention-backend triton后KERNEL VMFault→ DCU 上 triton 后端的 hybrid linear attention extend 路径不可用(已排除是index_put_算子问题)→ 回到 fa3 + extra_buffer。 --attention-backend aiter报「HCU 仅支持 dsv4/fa3/hcu_mla/nsa/triton」→ aiter 在本卡型被禁用 → 放弃该路线。- 压测第二轮 TTFT 异常偏低(4K/c1 由 1392 ms 降至 172 ms)→ radix cache 命中导致 prefill 被跳过 → 加
--flush-cache,两轮改为冷启动。未清理缓存的错误样本保留为bench/round2_nocache.jsonl,未删除。 sglang.bench_serving --dataset-name random需联网下载 ShareGPT → 容器无外网直连 HF → 改用random-ids,并设HF_ENDPOINT=https://hf-mirror.com。
- 其他:
- 首次启动需加载 18.8 GB 权重并做 graph capture,实测
run.sh到/health就绪约 250 s,LOAD_TIMEOUT设为 1800 s。 bench/结果产自配置完全相同的另一实例:两轮各档偏差 < 0.5%,跨实例精度复测偏差 < 0.1 pt(GSM8K 90.67 → 90.75、MMLU 74.69 → 74.68),可复现性已验证。
- 首次启动需加载 18.8 GB 权重并做 graph capture,实测