本文档记录 kotoba-whisper-v2.0 模型在华为昇腾 Ascend NPU(Atlas 800 A2/A3)上的部署与验证结果。该模型为基于 Whisper 架构的日语自动语音识别(ASR)模型,由 kotoba-tech 团队开发。
模型架构为 WhisperForConditionalGeneration,编码器 32 层,解码器 2 层(Distil-Whisper 变体),参数量约 756M。
相关获取地址:
参考文档:
| 组件 | 版本 |
|---|---|
torch-npu | 2.9.0.post1+gitee7ba04 |
transformers | 4.57.6 |
soundfile | latest |
librosa | latest |
| CANN | 8.5.1 |
Ascend910B4(1 卡)hf-mirror.com 镜像下载)torch_npu + transformers 直接推理pip install transformers torch_npu soundfile librosaHF_ENDPOINT=https://hf-mirror.com python3 -c "
from transformers import WhisperForConditionalGeneration, WhisperProcessor
model = WhisperForConditionalGeneration.from_pretrained('kotoba-tech/kotoba-whisper-v2.0')
processor = WhisperProcessor.from_pretrained('kotoba-tech/kotoba-whisper-v2.0')
# 模型权重自动缓存至 HuggingFace Hub 缓存目录
"python3 inference.py --audio speech.wav --language ja --task transcribe| 参数 | 说明 | 默认值 |
|---|---|---|
--audio | 输入音频文件路径(.wav) | 必填 |
--language | 语言代码 | ja |
--task | 任务类型(transcribe/translate) | transcribe |
--device | 推理设备(npu/cpu) | npu |
基础功能检查:
python3 inference.py --audio test.wav验证结果:
测试条件:3 秒合成音频(16kHz),单卡 Ascend910B4,max_new_tokens=128。
| 指标 | CPU | NPU |
|---|---|---|
| 推理耗时 | 124.4s | 18.7s |
| 加速比 | - | 6.6x |
| RTF (Real-Time Factor) | 41.47 | 6.24 |
RTF = 推理时间 / 音频时长,值越小越好。RTF < 1 表示可实时处理。
使用合成测试音频(3s, 16kHz, 200-800Hz Sweep),对 NPU 与 CPU 推理输出进行逐 Token 的 logits 比对。
| 指标 | 数值 |
|---|---|
| 文本匹配 | PASS |
| 余弦相似度(logits) | 0.999999 |
| Logits 最大绝对误差 | 0.044278 |
| Logits 平均绝对误差 | 0.008331 |
| 相对误差(vs 信号范围) | 0.2008% |
| 精度结论 | PASS (< 1%) |
评测输出与 CPU 参考完全一致,余弦相似度 0.999999,误差远小于 1% 阈值。
运行精度评测:
python3 eval_accuracy.py运行性能评测:
python3 eval_performance.pyWhisperProcessor 对音频的 Mel 频谱特征提取基于 NumPy,在 CPU 上执行。仅模型 forward/generate 在 NPU 上运行。inference.py 会自动重采样多声道或不同采样率的音频。max_new_tokens=256,处理长音频时可根据需要调整。HF_ENDPOINT=https://hf-mirror.com 使用 HuggingFace 镜像。| 文件 | 说明 |
|---|---|
inference.py | NPU 推理脚本(支持 NPU/CPU 双端) |
eval_accuracy.py | 精度评测脚本(NPU vs CPU logits 比对) |
eval_performance.py | 性能基准测试脚本 |
README.md | 本文档 |