硬件平台: 华为昇腾 Ascend NPU (910B/910C)
推理框架: torch_npu 2.9.0.post1 + transformers 4.57.6
模型来源: mistralai/Voxtral-Mini-4B-Realtime-2602
适配仓库: ohhoohho/Voxtral-Mini-4B-Realtime-2602
Voxtral-Mini-4B-Realtime-2602 是 Mistral 推出的实时语音转文字(Speech-to-Text)模型,参数量约 4B。模型架构包含:
特点:
| 组件 | 版本 |
|---|---|
| Python | 3.11 |
| torch_npu | 2.9.0.post1 |
| CANN | 8.5.1 |
| transformers | 4.57.6 |
| mistral_common | 1.11.1 |
| soundfile | ≥0.13 |
| safetensors | ≥0.4 |
Voxtral-Mini-4B-Realtime-2602/
├── inference.py # 推理脚本(主入口)
├── README.md # 本文档
├── requirements.txt # 环境依赖
├── voxtral_realtime/ # Vendored 模型源码包
│ ├── __init__.py
│ ├── configuration_voxtral_realtime.py
│ ├── modeling_voxtral_realtime.py
│ ├── feature_extraction_voxtral_realtime.py
│ └── processing_voxtral_realtime.py
└── assets/ # 截图素材
├── agent_workflow.png
├── npu_device_call.png
└── model_result.pngpip install -r requirements.txt# 自动下载权重并运行推理(使用内置测试音频)
python inference.py
# 使用自定义音频文件
python inference.py --audio /path/to/your/audio.wav --max-tokens 256
# 仅下载权重
python inference.py --download-only[INFO] NPU available: True, device=npu:0
[INFO] Downloading weights from https://hf-mirror.com/mistralai/Voxtral-Mini-4B-Realtime-2602 ...
[INFO] Creating model (vocab=131072, text_layers=26, audio_layers=32) ...
[INFO] Loaded 268 weight tensors, loading into model ...
[INFO] Weights loaded successfully
[INFO] Extracting mel features ...
[INFO] Running inference ...
[INFO] Generated 42 tokens in 2.35s (17.9 tok/s)
================================================================
[OUTPUT] <transcribed text from audio>
================================================================
[NPU] Device: Ascend 910B
[NPU] Memory: 62.0 GB
[NPU] Cached: 8.2 GB | Allocated: 7.6 GB权重从 HuggingFace Mirror 自动下载,本地缓存至 /tmp/models/Voxtral-Mini-4B-Realtime-2602/。
支持两种下载通道:
https://hf-mirror.com,通过 huggingface_hub.snapshot_downloadhttps://gitcode.com/hf_mirrors/mistralai/Voxtral-Mini-4B-Realtime-2602由于 transformers 4.57.6 未内置 VoxtralRealtimeForConditionalGeneration 架构,本项目采用 vendor 源码 策略:
transformers.xxx 绝对 import@auto_docstring 装饰器(仅在 transformers 5.x 中可用)PretrainedConfig 的 __post_init__ 改为 __init__(transformers 4.57.6 的 PretrainedConfig 非 dataclass)@use_kernelized_func 装饰器(4.57.6 无此功能)maybe_autocast → torch.autocastmerge_with_config_defaults / capture_outputs(非必需装饰器)| 算子类型 | 昇腾兼容性 | 备注 |
|---|---|---|
| PyTorch 原生算子 | ✅ 全兼容 | 主要运算均为原生 torch 操作 |
| RoPE 旋转位置编码 | ✅ 兼容 | 使用 eager 实现 |
| 滑动窗口注意力 | ✅ 兼容 | 使用 eager 注意力后端 |
| 因果卷积(Conv1d) | ✅ 兼容 | Conv1d 在 NPU 上原生支持 |
| RMSNorm | ✅ 兼容 | 纯 PyTorch 实现 |
| STFT/Mel 频谱 | ✅ 兼容 | 使用 torch.stft,在 CPU 上提取 |
以下为初步测试数据,实际性能取决于硬件配置和负载。
| 指标 | 数值 |
|---|---|
| 模型参数量 | ~4B |
| 推理精度 | bfloat16 |
| 生成速度 | ~15-20 tok/s (NPU 910B) |
| 峰值显存 | ~8-10 GB |
VoxtralRealtimeProcessor 和 padding_cache 机制。/tmp/models/Voxtral-Mini-4B-Realtime-2602/ 目录。attn_implementation="eager"),避免 flash attention 兼容性问题。Apache 2.0