Qwen3-VL-8B-Instruct bf16 原版权重仓库(Ascend 910 适配),脚本 + 权重 + 推理服务一体部署。
scripts/download_weights.sh),已在 Ascend910_9362 单卡实测跑通两条命令,地址完整可单独复制:
① 一键部署(全新部署 / 容器刷新后恢复:clone 仓库 + curl 分片并行下载 16.33G 权重,断点续传,+ 起服务)
curl -fsSL "https://atomgit.com/api/v5/repos/xujiashuai/Qwen3-VL-8B-Instruct/raw/bootstrap.sh?ref=main" | bash② 只拉代码(不拉权重,clone 秒级;补齐权重见块内注释)
curl -fsSL "https://atomgit.com/api/v5/repos/xujiashuai/Qwen3-VL-8B-Instruct/raw/bootstrap.sh?ref=main" | SKIP_WEIGHTS=1 bash
# 补齐 16.33G 权重(断点续传,已完整的文件自动跳过):
# cd /data/Qwen3-VL-8B-Instruct && bash scripts/download_weights.sh容器平台会周期性刷新容器:
/opt/atomgit(NFS)保留,/data(empty-dir)会被清空。 刷新后重新执行命令 ① 即可全自动恢复(权重断点续传,已完整的文件自动跳过)。覆盖安装位置(
INSTALL_DIR)、是否自动起服务(DO_SERVE)、 分片并行数(CHUNK_N)等环境变量见bootstrap.sh头部注释。
部署完成后启动/停止服务:
cd /data/Qwen3-VL-8B-Instruct
./scripts/service.sh start|stop|status # 默认端口 8000端口与卡号:
./scripts/service.sh start 9000 1(端口 9000,卡 1)。MODEL_DIR=/path ./scripts/service.sh start可覆盖权重目录。一键部署的每一步说明(下载权重/校验/起服务/创作入口), 部署失败或需要排查问题时按步查看。
python scripts/client.py --image-dir ./frames/ --output shots.jsonl --batch 32
python scripts/client.py --chat --image a.jpg --text "画面里有几个人?"输出 JSONL,每行 {"image":..,"ok":..,"text":..,"tokens":..}。
初代 Ascend 910A(Chip V1)无原生 FP8 算力(910B 才有),所以只下 bf16 原版:
| 量化版 | 能否用 | 原因 |
|---|---|---|
| bf16 原版 | ✅ 采用 | 算子全通,实测精度正常 |
| FP8 | ❌ | 初代 910A 无 FP8 算力,算子 fallback 到 bf16,白减体积还掉精度 |
| AWQ / GPTQ | ❌ | vllm-ascend 仅实装 W8A8;主线 awq_marlin/gptq_marlin 是 CUDA 内核,NPU 跑不了 |
| 组件 | 配置 | 参数量级 |
|---|---|---|
| 语言模型 | 36 层 / hidden 4096 / 32 Q 头 / 8 KV 头 / head_dim 128 | ~7.5 B |
| 视觉编码器 | 27 层 / hidden 1152 / 16 头 / patch 16 / merge 2 | ~0.4 B |
| DeepStack 合并器 | 3 路(layers 8/16/24 引出,特征拼接) | 小 |
| 词表 | 151936(tokenizer.json 单文件,无 merges/vocab) | — |
max_position_embeddings=262144,比 Qwen2.5-VL 的 128k 大一倍,必须显式设 --max-model-len,否则超过 NPU KV cache 上限报 ValueError。mrope_interleaved=True,section=[24,20,20]),与 Qwen2.5-VL 的分段式不同;vllm-ascend 侧由 AscendMRotaryEmbedding + patch_qwen3vl.py 处理。Ascend910_9362(初代 910A,单卡 65.8 GB),--max-model-len 8192 --max-num-seqs 8:
| 项 | 实测值 |
|---|---|
| 权重下载 | 16.33 GB / 261 s(≈63 MB/s),4 shard SHA-256 全对 |
| 模型加载 | 66.0 s(含 torch.compile 17.1 s + ACLGraph 捕获 2 s) |
| 权重显存 | 16.77 GB |
| KV cache | 29.00 GiB → 211,072 tokens(8192/请求时并发上限 25.7×) |
| 单请求图文(640×480) | 6.25 s |
| 单请求图文(1920×1080) | 5.31 s |
| 批量 8 张(64 tokens) | 2.58 s → 3.10 张/秒 |
| 批量 16 张(64 tokens) | 5.01 s → 3.19 张/秒 |
| 崩溃 / OOM | 0 / 0 |
批量提交远快于逐张请求:vLLM 有 continuous batching,吞吐随并发增长。
适配时确认过的几点(不影响使用,排查问题时有参考价值):
| 维度 | Qwen2.5-VL-7B | Qwen3-VL-8B |
|---|---|---|
| 架构类 | Qwen2_5_VLForConditionalGeneration | Qwen3VLForConditionalGeneration |
| 权重前缀 | model.visual.* | model.language_model.* + model.visual.*(多一层 language_model) |
| DeepStack | 无 | deepstack_visual_indexes=[8,16,24],多路视觉特征拼接 |
| rope | 分段式 mrope | 交错式 mrope |
| 视觉 rotary | — | partial_rotary_factor=0.5 |
max_position_embeddings | 128k | 262144 |
vLLM 0.18.0 + vllm-ascend 0.18.0 已原生支持该架构(vllm/model_executor/models/qwen3_vl.py,
2344 行),vllm-ascend 侧有 patch/worker/patch_qwen3vl.py(mrope + deepstack TP 包装)与
compilation/passes/sequence_parallelism.py 的 Qwen3VLMiddleAllReduceRMSNormPattern。
所以不需要改任何框架代码,纯配置 + 脚本即可跑通。
启动后 http://127.0.0.1:8000/docs 有交互式文档。
| 接口 | 说明 |
|---|---|
GET /health | 健康检查 |
GET /v1/models | 模型列表 |
POST /v1/chat/completions | OpenAI 兼容图文对话(无图时自动 fallback 纯文本) |
POST /v1/vision/describe | 批量图片描述(一次并发跑完,最快) |
图片来源支持 本地路径 / URL / base64 / data URI 四种。
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model":"qwen3-vl","max_tokens":512,"messages":[{"role":"user","content":[
{"type":"image_url","image_url":{"url":"/data/frames/a.jpg"}},
{"type":"text","text":"描述这个画面, 留意画面中的文字"}]}]}'Qwen3-VL-8B-Instruct/
├── README.md # ⭐ 本文档
├── bootstrap.sh # ⭐ curl 一键部署 (clone + 权重 + 起服务)
├── docs/
│ ├── ascend-lock.md # ⭐ 环境固化清单: 硬件/CANN/包版本/环境变量/一键核对
│ ├── gotchas.md # ⭐ 踩坑记录: 11 个坑的现象/根因/解法
│ └── fine-tuning.md # ⭐ 微调可行性分析: 显存预算/ms-swift 配置/落地步骤
├── scripts/
│ ├── download_weights.sh # ⭐ 权重下载 (CDN 直链 + 16 连接分片并行 + 断点续传)
│ ├── verify_weights.sh # 完整性校验 (字节数 / sha256 / safetensors 头)
│ ├── serve.py # ⭐ 推理服务 (vLLM-Ascend + FastAPI, OpenAI 兼容)
│ ├── service.sh # ⭐ 常驻管理 (start/stop/restart/status/dual)
│ ├── client.py # 批量客户端 (提交 -> JSONL)
│ ├── infer.py # transformers 兜底推理 (无 vLLM 依赖)
│ ├── setup.sh # 本机已 clone 时的一键部署 (环境->下载->校验->冒烟)
│ └── requirements.txt # 依赖版本锁定(==), torch/vllm 由宿主机提供
├── weights/ # 权重本体 (bf16, 4 shard 共 16.33 GB, 已 gitignore)
├── logs/ # 服务日志 (已 gitignore)
└── .run/ # pid 文件 (已 gitignore)
setup.sh与bootstrap.sh的区别:bootstrap.sh面向全新部署 / 容器刷新后恢复 (自己 clone 仓库,适合 curl 管道一键执行);setup.sh面向仓库已在本机 (直接跑环境检查 / 依赖 / 冒烟,不 clone)。两者最终都调用同一套download_weights.sh+service.sh。换机器 / 容器刷新后恢复:先按
docs/ascend-lock.md核对环境, 跑不动时查docs/gotchas.md的对应坑。
只 source ascend-toolkit 会导致 vLLM 启动失败:
OSError: libatb.so: cannot open shared object file: No such file or directory
OSError: Could not load this library: .../torch_npu/lib/libop_plugin_atb.solibatb.so 只在 /usr/local/Ascend/nnal/atb/<ver>/atb/cxx_abi_*/lib/,需要额外 source:
source /usr/local/Ascend/ascend-toolkit/set_env.sh
source /usr/local/Ascend/nnal/atb/set_env.sh # ← 缺这行 vLLM 起不来setup.sh 和 serve.py 都已内置处理(serve.py 检测到缺失会自动重启补环境)。
Qwen2.5-VL 的下载脚本走 gitcode.com/.../info/lfs/objects/batch 换 CDN 直链,
但 Qwen3-VL-8B-Instruct 的这个接口返回 404(LFS 对象未同步到 gitcode 的 LFS 服务)。
所以本仓库换了一条路:
https://ai.gitcode.com/hf_mirrors/Qwen/Qwen3-VL-8B-Instruct/resolve/main/<file>
→ 302 →
https://lfs-ai-cdn.gitcode.com/lfs-objects/...?certificate=<JWT>&auth_key=...| 点 | 说明 |
|---|---|
| 签名 URL 时效 | 约 1 小时,每个 shard 开下前换一次;每轮重试也重新换 |
小文件禁 -C - | 302 落地 raw.gitcode.com 后不支持 Range,会报 curl: (33) HTTP server doesn't seem to support byte ranges |
| 429 限流 | ai.gitcode.com 并发过高或连续重试会触发;脚本大文件走 16 连接分片,小文件串行 + 自动退 hf-mirror |
| 备源 | HF_BASE 变量指向 hf-mirror,ai.gitcode 抽风时自动切换 |
| 项 | 要求 | 原因 |
|---|---|---|
| dtype | bfloat16 | 见「为什么是 bf16」 |
| 加载类(不用 vLLM 时) | AutoModelForImageTextToText | 用 AutoModelForCausalLM 会报 Unrecognized configuration class Qwen3VLConfig |
| attention(不用 vLLM 时) | eager | 昇腾上 flash_attention 不可用 |
max_new_tokens / max_tokens | ≥1024 | 实测 512 会截断长描述 |
max_model_len | 显式设 8192~16384 | 模型 max_position_embeddings=262144,不设会超 KV cache 上限 |
| Python | 3.11.14 | 系统默认 python3 是 3.10 且无 torch_npu;setup.sh 自动探测切换 |
| 显存 | --gpu-memory-utilization 0.80 | 卡上有其他进程时需调低,serve.py 启动前自动预检并提示 |
完整踩坑记录(11 个坑的现象 / 根因 / 解法)见 docs/gotchas.md。
Ascend910_9362(Chip V1)+ CANN 8.5.1 + Python 3.11.14 上的完整环境清单
(硬件 / 驱动 / CANN / 各包精确版本 / 环境变量 / 一键核对命令)见
docs/ascend-lock.md。
核心版本:
| 组件 | 固化版本 |
|---|---|
| CANN | 8.5.1 |
| Python | 3.11.14 |
| torch / torch-npu | 2.9.0+cpu / 2.9.0.post1+gitee7ba04 |
| vLLM / vllm-ascend | 0.18.0 / 0.18.0 |
| triton | 3.2.0 |
| transformers | 4.57.6 |
scripts/requirements.txt 已用 == 精确锁定 pip 可安装的那部分
(fastapi 0.123.10 / uvicorn 0.46.0 / pydantic 2.13.3 / pillow 12.2.0 /
requests 2.33.1 / numpy 1.26.4);torch / torch_npu / vllm / vllm_ascend / triton
由宿主机 editable 提供,锁不得也装不得。
numpy 锁 1.26.4 是有意的:torch 2.9.0+cpu 的官方 wheel 按 NumPy 1.x 编译, 装到 2.x 会在 import 时报 "A module that was compiled using NumPy 1.x cannot be run in NumPy 2.x"。
结论:可以微调,但只有 LoRA 一条路走得通。
全参微调光 Adam 优化器状态就要 99.4 GiB(8.767B × 3 × 4 字节), 加上权重和梯度共 132.5 GiB,双卡合计 131.6 GiB 都不够。 LoRA(冻结 ViT)单卡约 30 GiB 峰值,余量充足。
框架选 ms-swift 4.5.3(昇腾官方主推):已确认 MLLMModelType.qwen3_vl
注册、Qwen3VLTemplate、NPU patch(Qwen3VLTextRMSNorm/apply_rotary_pos_emb/
Qwen3VLTextMLP.forward)齐全,且 dry-run 验证过不升级 torch / torch-npu /
transformers / numpy,推理环境不会被破坏。
完整的显存预算表、数据格式、启动命令、参数理由、训完导出路径和 6 项风险清单见
docs/fine-tuning.md。
/vllm-workspace/vllm-ascend/docs/source/tutorials/models/Qwen-VL-Dense.md/vllm-workspace/vllm-ascend/docs/source/user_guide/support_matrix/supported_models.md(Qwen3-VL 行 ✅)/vllm-workspace/vllm-ascend/tests/e2e/models/configs/Qwen3-VL-8B-Instruct.yamlweights/、logs/、.run/ 均已 gitignore,运行时产物不入库。scripts/download_weights.sh curl 直链 GitCode CDN 分片并行下载,不走 git-lfs 客户端、无 .git/lfs 双份缓存(首次安装约 16.33 G)。scripts/download_weights.sh 与 verify_weights.sh 里的 SHA-256 是硬性校验,大小不符会删除重下。