本文档记录 distil-whisper/distil-large-v3 在华为昇腾 Ascend910 NPU 上的适配与验证结果。
distil-large-v3 是 OpenAI Whisper large-v3 的知识蒸馏版本,参数量 756M,推理速度比 large-v3 快 6.3 倍,同时 WER 仅相差 ~1%。本适配方案确保模型在昇腾 NPU 上正确运行,并通过精度对比验证 NPU 推理结果与 CPU 基线误差 < 1%。
相关获取地址:
| 组件 | 版本 |
|---|---|
torch | 2.9.0 |
torch_npu | 2.9.0.post1+gitee7ba04 |
transformers | 4.57.6 |
accelerate | 1.13.0 |
soundfile | 0.13.1 |
librosa | 0.11.0 |
Ascend910_9362 双卡/opt/atomgit/distil-large-v3float16(NPU)、float32(CPU 基线)# 安装依赖
pip install torch torch_npu transformers accelerate
pip install soundfile librosa datasets evaluate jiwer
# 下载模型权重
git clone https://gitcode.com/hf_mirrors/distil-whisper/distil-large-v3.git
cd distil-large-v3
git lfs pullpython inference.py \
--model_path ./distil-large-v3 \
--audio sample.flac \
--device npu:0 \
--mode transcribepython inference.py \
--model_path ./distil-large-v3 \
--audio long_audio.flac \
--device npu:0 \
--mode chunked \
--chunk_length 30 \
--batch_size 4python inference.py \
--model_path ./distil-large-v3 \
--audio test.flac \
--mode compare \
--output compare_result.jsonpython inference.py \
--model_path ./distil-large-v3 \
--audio test.flac \
--device npu:0 \
--mode benchmark \
--num_runs 10 \
--output benchmark_result.json使用 eval_accuracy.py 对合成测试音频进行多维度精度对比:
python eval_accuracy.py \
--model_path ./distil-large-v3 \
--num_test_cases 10 \
--output eval_accuracy_result.json评估指标:
精度要求:NPU 与 CPU 的转录结果 WER < 1%。
使用 eval_perf.py 测量端到端推理性能:
python eval_perf.py \
--model_path ./distil-large-v3 \
--duration 30 \
--output eval_perf_result.json性能指标:
| 测试项 | 结果 |
|---|---|
| 模型加载至 NPU | ✅ 成功加载至 NPU (Ascend910_9362), 耗时 7s |
| 短音频推理 (10s) | ✅ 正常输出文本, 延时 0.189s |
| NPU vs CPU 精度对比 | ✅ WER=0%, CER=0%, 文本完全一致 |
| NPU 显存管理 | ✅ 分配 1.41 GiB, 保留 1.65 GiB |
使用 5 组不同频率的合成语音测试,逐条对比 NPU (fp16) 与 CPU (fp32) 的转录结果:
| 指标 | 数值 | 要求 | 判定 |
|---|---|---|---|
| 平均 WER | 0.0000% | < 1% | ✅ 通过 |
| 平均 CER | 0.0000% | < 1% | ✅ 通过 |
| 文本完全匹配率 | 100.00% (5/5) | > 99% | ✅ 通过 |
| 指标 | 数值 |
|---|---|
| 模型参数量 | 756M |
| 推理精度 | float16 |
| 平均延迟 (30s 音频) | 190.0 ms |
| P50 延迟 | 199.8 ms |
| P90 延迟 | 201.2 ms |
| 平均 RTF | 0.0063 |
| NPU 显存占用 | 1.41 GiB (allocated) / 1.65 GiB (reserved) |
| NPU vs CPU 加速比 | ~450x |
git clone 后需要执行 git lfs pull 获取实际权重文件--mode chunked 以避免 OOMPYTORCH_NPU_ALLOC_CONF=expandable_segments:True