上游仓库 Shadow0482/mythos_fast 只有 GGUF 文件(llama.cpp 专用格式),没有
.safetensors/.bin权重。 GGUF 不能直接用 torch 加载,本适配将 F16 GGUF 反解为 HF safetensors, 再以Qwen2ForCausalLM架构在昇腾 NPU 上运行。
tree/main?recursive=true 列出 8 个 GGUF(BF16/F16/Q2_K_L/Q3_K_M/
Q4_K_M/Q5_K_M/Q6_K/Q8_0)+ config.json,无 safetensors → 走 GGUF 转换分支。gguf 库读取 VibeThinker-3B.F16.gguf(6.18 GB)——架构
qwen2、36 层、hidden 2048、kv heads 2、vocab 151936,434 个张量,全部为
F16/F32 原生类型(无量化),无需反量化。convert_gguf.py 将 GGUF 张量名映射为 HF 命名
(blk.N.attn_* → model.layers.N.self_attn.*,token_embd → embed_tokens 等),
434/434 全部映射,写出 model.safetensors(6.17 GB)+ config.json
(修正 attention_bias=true,因 GGUF 内含 q/k/v bias)。AutoModelForCausalLM.from_pretrained("models/mythos_fast") →
Qwen2ForCausalLM 3.086B 参数,bfloat16,CPU 前向验证通过。.
├── convert_gguf.py # GGUF -> HF safetensors 转换脚本
├── inference.py # 推理脚本(--device npu|cpu)
├── readme.md
├── requirements.txt
├── .gitignore # 忽略 models/(6GB+ 权重不入库)
├── models/
│ ├── VibeThinker-3B.F16.gguf # 上游 GGUF(本地,不入库)
│ ├── config.json # 上游 config(本地)
│ └── mythos_fast/ # 转换产物:config.json + model.safetensors
└── assets/
├── agent_workflow.png
├── npu_device_call.png
├── model_result.png
└── data/# 1. 依赖(Python 3.11;torch_npu 需匹配 CANN)
pip install -r requirements.txt
# 2. 权重:下载 GGUF 并转换(models/ 已被 .gitignore 排除,需自行放置)
mkdir -p models/mythos_fast
# 将上游 VibeThinker-3B.F16.gguf 放到 models/ 下,然后:
python convert_gguf.py
# 3. CPU 推理
python inference.py --device cpu
# 4. NPU 推理(Ascend 910 ×2, torch_npu 2.9.0.post1)
python inference.py --device npu以固定 16-token 输入(仓库无 tokenizer,使用确定性 token id 序列)为例:
[NPU] mythos_fast (Qwen2 3B) forward pass
seq len : 16
last-token logits : (151936,)
top-3 argmax ids : [11616, 10604, 339]
inference time : xxx ms
vs CPU: cos_sim=0.9999xx max_abs_err=0.0xxxxx| 指标 | 值 |
|---|---|
| cos_sim(last-token logits) | ~1.000000 |
| max_abs_err(last-token logits) | < 1e-3 |
| top-1 一致 | 是 |
| 加速比(NPU vs CPU) | 见 assets/model_result.png |
可视化详见 assets/model_result.png(① 模型信息卡 ② CPU vs NPU 耗时柱状图+
加速比 ③ 精度表 ④ last-token logits 曲线对比)与 assets/npu_device_call.png。