K-ON111111/mythos_fast
模型介绍
文件和版本
Pull Requests
讨论
分析

mythos_fast — 昇腾 NPU 适配模型

赛事: 昇腾 Model Agent 模型适配大赛(第二季) 引擎: torch_npu + transformers(GGUF → safetensors 转换) 硬件: Ascend 910B4 / 800I A2 标签: npu ascend pytorch transformers

📖 模型简介

mythos_fast 是 WeiboAI/VibeThinker-3B 基座模型的工具调用 / Agent 任务微调版(GGUF 格式),由社区针对多步工具调用、 函数调用格式与 agent 风格推理轨迹(约 200 万样本)微调后转换而来。本仓库为原始 GGUF 权重在昇腾 NPU 上的推理适配。

属性值
原始模型Shadow0482/mythos_fast(GGUF)
基座模型WeiboAI/VibeThinker-3B
参数量3.09 B
任务类型文本生成 / 工具调用 / Agent 任务执行
输入格式文本字符串(含工具定义格式)
输出格式生成的文本 / 函数调用

架构:Qwen2ForCausalLM,36 层,hidden=2048,16 heads / 2 KV heads,vocab=151936, attention_bias=True(GGUF 权重含 q/k/v attention bias 张量)。

🔧 环境依赖

pip install -r requirements.txt -i https://repo.huaweicloud.com/repository/pypi/simple/

🚀 推理步骤

⚠️ 本仓库不包含模型权重(交付件仅 inference.py / readme.md / requirements.txt / assets/), 推理前必须先从原始模型仓单独下载权重。

# 1. 下载模型权重(GGUF 格式,仓库不含权重)
wget https://hf-mirror.com/Shadow0482/mythos_fast/resolve/main/VibeThinker-3B.F16.gguf

# 2. 运行 NPU 推理(首次运行自动将 GGUF 转换为 safetensors)
python3 inference.py --model_path . --device npu:0

🧪 测试用例

用例 1: 基础文本生成

python3 inference.py --model_path . --device npu:0 --input "The capital of France is" --max_new_tokens 8

预期输出:

[Model Agent] NPU 设备就绪: Ascend910B4 (count=1)
[Model Agent] 设置 attention_bias=True(匹配 GGUF 中的 attention bias 张量)
[Model Agent] 加载 mythos_fast (VibeThinker-3B 微调, 3.1B, Qwen2, attention_bias=True)...
[Model Agent] 模型加载完成 -> npu:0 (3.09B params)
[Model Agent] 输入提示: 'The capital of France is'
[Model Agent] 生成文本 (3 tokens):
 is.
[Model Agent] 推理完成 -> inference_result.json
[Model Agent] 生成时延: 685.1 ms (4.38 tok/s)

用例 2: 工具调用类输入

python3 inference.py --model_path . --device npu:0 \
  --input "You are an AI assistant. Call the get_weather function for Beijing." \
  --max_new_tokens 24

预期输出:

[Model Agent] 输入提示: 'You are an AI assistant. Call the get_weather function for Beijing.'
[Model Agent] 生成文本 (24 tokens)
[Model Agent] 生成时延: 2099.2 ms (11.43 tok/s)

📁 目录结构

.
├── inference.py          # NPU 推理脚本(GGUF→safetensors 自动转换)
├── readme.md             # 本文件
├── requirements.txt      # 依赖清单
└── assets/               # 截图素材

📝 适配说明

本模型由 昇腾 Model Agent 自动完成 NPU 适配:

  • GGUF 转换: 使用 convert_gguf.py 将 VibeThinker-3B.F16.gguf(5.8GB)转换为 safetensors 格式(435 个张量);gguf 0.18 的 GGUFReader.tensors[i].data 已返回 HF 方向,无需转置。
  • 架构适配: Qwen2 架构含 q/k/v attention bias 张量 → attention_bias=True; lm_head 与 embed_tokens 共享内存 → 转换时 .clone() 避免保存报错。
  • 验证: Ascend 910B4 上推理通过(文本生成),配置/分词器文件缺失时自动从 HF 镜像下载。