Whisper Tiny 是OpenAI推出的轻量级语音识别模型(37.8M参数),改编自ModelScope仓库 manyeyes/whisper-tiny-onnx。本仓库提供了通过torch_npu在华为昇腾910 NPU上运行Whisper Tiny的NPU适配推理脚本及评估结果。
| 组件 | 配置 |
|---|---|
| 编码器层数 | 4 |
| 解码器层数 | 4 |
| 隐藏层维度 | 384 |
| 注意力头数 | 6 |
| 词汇表大小 | 51,865 |
| 梅尔频谱带数 | 80 |
| 最大音频上下文 | 1,500(16kHz下30秒) |
| 最大文本上下文 | 448 |
| 参数数量 | 37.8M(FP32格式144 MB) |
| 支持语言 | 99种(多语言) |
# Install ModelScope
pip install modelscope
# Download model
modelscope download --model manyeyes/whisper-tiny-onnx --local_dir ./model
# Install dependencies
pip install torchaudio soundfile scipy librosa# Generate test audio and run CPU inference (baseline)
python inference.py --audio /tmp/test_audio.wav --generate-audio --device cpu
# NPU inference
python inference.py --audio /tmp/test_audio.wav --device npu:0
# Accuracy comparison (CPU vs NPU)
python inference.py --audio /tmp/test_audio.wav --device npu:0 --compare
# Performance benchmark with 20 iterations
python inference.py --audio /tmp/test_audio.wav --device npu:0 --benchmark 20from inference import load_model, load_audio, compute_mel, greedy_decode, decode_tokens
# Load model on NPU
model = load_model("model/tiny.pt", device="npu:0")
# Load and preprocess audio
audio = load_audio("audio.wav")
mel = compute_mel(audio, device="npu:0")
# Run inference
tokens, enc_time = greedy_decode(model, mel, language="en", device="npu:0")
text = decode_tokens(tokens)
print(text)| 项目 | 规格 |
|---|---|
| NPU | Ascend 910 (9362) x2 |
| CANN | 8.5.1 |
| PyTorch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1+gitee7ba04 |
| 精度 | FP32 |
| 测试日期 | 2026-05-17 |
评估指标:稳健相对误差——对于 CPU 参考值 > 1e-6 的情况,计算 |NPU - CPU| / |CPU| 并对所有元素取平均值。质量标准:< 1%。
| 测试用例 | 输入形状 | 输出形状 | 最大绝对误差 | 稳健相对误差 | 状态 |
|---|---|---|---|---|---|
| 5秒音频 | [1, 80, 500] | [1, 250, 384] | 0.009542 | 0.4754% | 通过 |
| 10秒音频 | [1, 80, 1000] | [1, 500, 384] | 0.009686 | 0.6799% | 通过 |
| 20秒音频 | [1, 80, 2000] | [1, 1000, 384] | 0.009594 | 0.5687% | 通过 |
| 30秒音频 | [1, 80, 3000] | [1, 1500, 384] | 0.014266 | 0.7118% | 通过 |
精度判定:全部通过
| 指标 | 值 |
|---|---|
| CPU-NPU 文本匹配 | 是(100%) |
| 特征最大绝对误差 | 0.001993 |
| 特征平均绝对误差 | 0.000196 |
| 特征相对误差 | 0.0200% |
| 音频时长 | CPU 时间(毫秒) | NPU 时间(毫秒) | CPU p99(毫秒) | NPU p99(毫秒) | 加速比 | NPU RTF |
|---|---|---|---|---|---|---|
| 5秒 | 86.28 | 2.25 | 87.04 | 2.32 | 38.3x | 0.00045 |
| 10秒 | 185.19 | 2.24 | 197.99 | 2.29 | 82.6x | 0.00022 |
| 20秒 | 833.95 | 2.17 | 3644.53 | 2.22 | 384.1x | 0.00011 |
| 30秒 | 899.05 | 2.90 | 912.05 | 2.93 | 309.7x | 0.00010 |
| 组件 | 延迟(毫秒) |
|---|---|
| 编码器 | 3.37 |
| 解码器(20个token) | 49.68 |
| 每token解码器 | 2.48 |
| 端到端总计 | 53.05 |
| 编码器吞吐量 | 890,007 mel-frames/s |
准确性:CPU-NPU 特征级鲁棒相对误差为 0.71%(最坏情况),通过了 1% 的质量标准。CPU 与 NPU 的文本级输出完全一致。在真实音频推理中,特征级相对误差仅为 0.02%。
性能:在编码器推理方面,NPU 相比 CPU 实现了 38 倍–384 倍的加速。实时因子(RTF)远低于 0.001,为实时流式语音识别提供了充足的余量。
内存:FP32 模式下模型占用约 144 MB 内存,可轻松适配 Ascend 910 的 64 GB HBM。
稳定性:在所有输入时长下,NPU 推理时间几乎保持恒定(2.2–2.9 ms),而 CPU 时间则随音频长度呈线性增长。
| 文件 | 描述 |
|---|---|
inference.py | 适配 NPU 的推理脚本,支持 CPU/NPU 后端,包含准确性对比和基准测试功能 |
eval_benchmark.py | 全面的准确性和性能评估套件 |
eval_results.json | 结构化评估结果(准确性 + 性能) |
run_log.log | 完整的评估运行日志 |
README.md | 部署文档和评估报告 |
model/ | 已下载的模型文件(tiny.pt、ONNX 编码器/解码器) |
whisper-tiny-onnx-npu/
├── README.md # This document
├── inference.py # NPU inference script
├── eval_benchmark.py # Evaluation suite
├── eval_results.json # Evaluation results (structured)
├── run_log.log # Full run log
└── model/ # Model files
├── tiny.pt # PyTorch checkpoint
├── encoder.onnx # ONNX encoder (FP32)
├── encoder.int8.onnx # ONNX encoder (INT8)
├── decoder.onnx # ONNX decoder (FP32)
├── decoder.int8.onnx # ONNX decoder (INT8)
├── conf.json # Model config
└── configuration.json # Additional config@misc{whisper-tiny-onnx-npu,
title={Whisper Tiny ONNX - Ascend NPU Adaptation},
author={Model Agent},
year={2026},
note={Adapted from manyeyes/whisper-tiny-onnx on ModelScope. Evaluated on Huawei Ascend 910 NPU.}
}#NPU #Hardware/NPU #Ascend #Ascend910 #CANN #torch_npu #Whisper #ASR #ONNX #pretrained