Delicate02/distil-large-v3-npu
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

Distil-Whisper distil-large-v3 on Ascend NPU

1. 简介

本文档记录 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%。

相关获取地址:

  • 权重下载地址(GitCode):https://gitcode.com/hf_mirrors/distil-whisper/distil-large-v3
  • 权重下载地址(HuggingFace):https://huggingface.co/distil-whisper/distil-large-v3

2. 验证环境

组件版本
torch2.9.0
torch_npu2.9.0.post1+gitee7ba04
transformers4.57.6
accelerate1.13.0
soundfile0.13.1
librosa0.11.0
  • NPU:Ascend910_9362 双卡
  • 模型路径:/opt/atomgit/distil-large-v3
  • 推理精度:float16(NPU)、float32(CPU 基线)

3. 环境准备

# 安装依赖
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 pull

4. 推理脚本

4.1 短音频推理

python inference.py \
  --model_path ./distil-large-v3 \
  --audio sample.flac \
  --device npu:0 \
  --mode transcribe

4.2 长音频分块推理

python inference.py \
  --model_path ./distil-large-v3 \
  --audio long_audio.flac \
  --device npu:0 \
  --mode chunked \
  --chunk_length 30 \
  --batch_size 4

4.3 NPU vs CPU 精度对比

python inference.py \
  --model_path ./distil-large-v3 \
  --audio test.flac \
  --mode compare \
  --output compare_result.json

4.4 性能基准测试

python inference.py \
  --model_path ./distil-large-v3 \
  --audio test.flac \
  --device npu:0 \
  --mode benchmark \
  --num_runs 10 \
  --output benchmark_result.json

5. 精度评测

使用 eval_accuracy.py 对合成测试音频进行多维度精度对比:

python eval_accuracy.py \
  --model_path ./distil-large-v3 \
  --num_test_cases 10 \
  --output eval_accuracy_result.json

评估指标:

  • WER(词错误率): NPU 结果 vs CPU 基线的词级编辑距离
  • CER(字错误率): 字符级编辑距离
  • 文本完全匹配率: 逐字完全一致的比例

精度要求:NPU 与 CPU 的转录结果 WER < 1%。

6. 性能评测

使用 eval_perf.py 测量端到端推理性能:

python eval_perf.py \
  --model_path ./distil-large-v3 \
  --duration 30 \
  --output eval_perf_result.json

性能指标:

  • 端到端延迟: 从输入音频到输出文本的推理时间
  • RTF (Real-Time Factor): 推理时间 / 音频时长,RTF < 1 表示快于实时
  • 显存占用: NPU 显存分配量

7. 验证结果

7.1 功能验证

测试项结果
模型加载至 NPU✅ 成功加载至 NPU (Ascend910_9362), 耗时 7s
短音频推理 (10s)✅ 正常输出文本, 延时 0.189s
NPU vs CPU 精度对比✅ WER=0%, CER=0%, 文本完全一致
NPU 显存管理✅ 分配 1.41 GiB, 保留 1.65 GiB

7.2 精度验证

使用 5 组不同频率的合成语音测试,逐条对比 NPU (fp16) 与 CPU (fp32) 的转录结果:

指标数值要求判定
平均 WER0.0000%< 1%✅ 通过
平均 CER0.0000%< 1%✅ 通过
文本完全匹配率100.00% (5/5)> 99%✅ 通过

7.3 性能参考

指标数值
模型参数量756M
推理精度float16
平均延迟 (30s 音频)190.0 ms
P50 延迟199.8 ms
P90 延迟201.2 ms
平均 RTF0.0063
NPU 显存占用1.41 GiB (allocated) / 1.65 GiB (reserved)
NPU vs CPU 加速比~450x

8. 注意事项

  1. LFS 权重: 模型权重使用 Git LFS 管理,git clone 后需要执行 git lfs pull 获取实际权重文件
  2. 音频采样率: 模型期望输入 16kHz 单声道音频,不满足时会自动重采样
  3. FP16 推理: NPU 使用 float16 推理以节省显存并提升速度,精度损失在可接受范围
  4. 分块策略: 长音频(>30s)建议使用分块推理模式 --mode chunked 以避免 OOM
  5. 环境变量: 如遇显存不足,可设置 PYTORCH_NPU_ALLOC_CONF=expandable_segments:True

9. 参考

  • Distil-Whisper: Robust Knowledge Distillation via Large-Scale Pseudo Labelling
  • OpenAI Whisper large-v3
  • 昇腾社区
  • torch_npu