本目录包含 mythos_fast(WeiboAI/VibeThinker-3B 工具调用微调版,Qwen2ForCausalLM 架构)的昇腾 NPU 适配交付物。
原始模型权重位于 /mnt/old_data/whl/models/1/Shadow0482/mythos_fast(官方仅发布 GGUF 格式),
已通过 PyTorch 生态(vLLM-Ascend) 技术栈迁移至本地华为昇腾 Ascend910 NPU。
| 项目 | 说明 |
|---|---|
| 模型 | Shadow0482/mythos_fast(VibeThinker-3B 微调,约 3B 参数) |
| 架构 | Qwen2ForCausalLM(带注意力 q/k/v bias 的 Qwen2 变体,36 层 / hidden 2048 / 16 头 / 2 KV 头) |
| 原始权重 | 仅 GGUF(VibeThinker-3B.BF16.gguf 6.1GB,434 张量;另含 Q2~Q8 量化版) |
| 适配方式 | GGUF → HF safetensors 无损转换(max_diff=0 抽样校验)→ vLLM-Ascend 加载 |
| 迁移框架 | PyTorch 2.9.0 + torch_npu 2.9.0.post1 + vLLM 0.18.0 + vLLM-Ascend 0.18.0 |
| 推理硬件 | 昇腾 Ascend910(单卡,bf16 权重约 6.1GB) |
| 服务框架 | FastAPI + uvicorn(OpenAI 兼容 HTTP 服务) |
| 本机实测 | 中文/英文对话、工具调用场景推理全部通过(见 results/test_results.txt) |
mythos_fast-npu/
├── README.md # 本指南(中文)
├── requirements.txt # 运行环境依赖
├── inference.py # 服务化推理脚本(OpenAI 兼容 HTTP 服务)
├── scripts/
│ └── gguf_to_safetensors.py # GGUF → HF safetensors 无损转换脚本
├── tests/
│ ├── test_inference.py # 端到端测试用例(6 项)
│ └── test_results.txt # 测试结果记录
├── results/
│ ├── test_results.json # 测试结果 (JSON)
│ ├── test_results.txt # 测试结果 (文本)
│ └── server.log # 服务运行日志
└── assets/
├── npu_device_call.png # NPU 设备调用截图
├── model_result.png # 测试结果截图
├── agent_workflow.png # 适配过程截图
└── _make_screenshots.py # 截图渲染脚本# 加载 CANN 环境
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# 安装依赖(华为镜像源)
export PIP_INDEX_URL=https://repo.huaweicloud.com/repository/pypi/simple/
pip install -r requirements.txtvLLM-Ascend 0.18 不支持 GGUF 量化格式(报错
gguf quantization is currently not supported in npu),必须先将 BF16 GGUF 权重转换为 HF safetensors。
cd /mnt/old_data/whl/models/shipei-code/mythos_fast-npu
python scripts/gguf_to_safetensors.py \
--gguf /mnt/old_data/whl/models/1/Shadow0482/mythos_fast/VibeThinker-3B.BF16.gguf \
--out /mnt/old_data/whl/models/1/Shadow0482/mythos_fast-hf转换产物(mythos_fast-hf/):
model.safetensors(5.75 GiB,434 张量,BF16 权重 + FP32 norm)config.json / generation_config.jsontokenizer.json / tokenizer_config.json(官方 Qwen3 词表,与 GGUF 逐项比对一致;
追加 GGUF 独有 token:<think>=151665、</think>=151666、<|PAD_TOKEN|>=151667;
chat_template 从 GGUF 原样提取)cd /mnt/old_data/whl/models/shipei-code/mythos_fast-npu
python inference.py --ckpt /mnt/old_data/whl/models/1/Shadow0482/mythos_fast-hf \
--port 8000 --npus 0脚本自动选择 npu:0(torch_npu 可用时)。启动过程:初始化 vLLM 引擎 → 加载
6.1GB 权重到 NPU(约 1~2 分钟,含算子图编译)→ 监听 HTTP 服务。
提示:默认端口 8000,可用
--port修改(本机 8000/8001 已被其他模型服务 占用,本交付实测使用 8002);--npus指定物理 NPU(需选空闲卡, 如被占用的卡空闲显存不足会导致gpu_memory_utilization检查失败, 可用--gpu-memory-utilization 0.5降低要求); 首次启动若遇算子编译慢可加--enforce-eager。
cd /mnt/old_data/whl/models/shipei-code/mythos_fast-npu
python tests/test_inference.py --port 8000测试覆盖:服务启动 / 健康检查 / NPU 设备调用 / 模型列表 / 中文对话 /
英文对话(工具调用场景)/ 原始 prompt 生成,结果写入 results/。
# 对话补全
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"mythos_fast","messages":[{"role":"user","content":"请用一句话介绍什么是昇腾NPU"}],"max_tokens":128}'
# 原始 prompt 生成
curl -s http://127.0.0.1:8000/infer \
-H 'Content-Type: application/json' \
-d '{"prompt":"1+1=?","max_tokens":32}'| # | 问题 | 现象 | 解法 |
|---|---|---|---|
| 1 | vLLM-Ascend 不支持 GGUF | gguf quantization is currently not supported in npu | GGUF → safetensors 无损转换(BF16 直接保留) |
| 2 | paddlex 插件冲突 | import vllm 时 C++ std::bad_alloc 静默崩溃 | VLLM_PLUGINS 白名单仅加载 ascend 系插件 |
| 3 | GGUF 维度顺序 | GGUF shape 数组是 torch shape 的反转 | 按 memmap 实际行数 reshape,转换后抽样校验 max_diff=0 |
| 4 | 模型带注意力 bias | q/k/v bias 非零(k bias 均值 6.68),丢弃会损精度 | 当前 transformers 4.57.6 与 vLLM 0.18 Qwen2 实现原生支持 bias |
| 5 | 显式 stop 词崩溃 | vLLM V1 引擎在 Ascend 后端对 stop 列表 use-after-free | 不传 stop,EOS(`< |
| 6 | tokenizer 差异 | GGUF 词表含官方 Qwen3 没有的 <think>/`< | PAD_TOKEN |
| 接口 | 方法 | 说明 |
|---|---|---|
/health | GET | 健康检查 + NPU 设备信息 |
/device | GET | NPU 设备调用信息(device_count / device_name / 显存) |
/v1/models | GET | 模型列表(OpenAI 兼容) |
/v1/chat/completions | POST | 对话补全(OpenAI 兼容,支持 messages 多轮) |
/infer | POST | 简单文本生成(prompt in → text out) |
torch.npu.device_count()=16)/device 返回 device_type=Ascend NPU、device_name=Ascend910_9382results/test_results.txt / results/test_results.json,截图见 assets/。本目录所有 Python 脚本(inference.py、scripts/gguf_to_safetensors.py、
tests/test_inference.py、assets/_make_screenshots.py)均包含 2 个
# Bug_Factory 标记注释:
Bug_Factory
注释规范标记的随机锚点。
此外,代码中保留了针对本模型适配过程中实际踩坑点的 # Bug_Factory
上下文注释(如 paddlex 插件冲突、GGUF 不支持、stop 词崩溃等)。