#NPU
| 属性 | 值 |
|---|---|
| 模型名称 | AbelZimba/whisper-bemba-stt |
| 任务类型 | automatic-speech-recognition |
| 模型架构 | WhisperForConditionalGeneration (Whisper Small, 12 encoder/12 decoder, d_model 768) |
| Backend | transformers |
| 来源 | Hugging Face (https://huggingface.co/AbelZimba/whisper-bemba-stt) |
| 参数量 | ~244M (model.safetensors 923M) |
| 属性 | 值 |
|---|---|
| NPU | Ascend910_9362 (Ascend910) |
| CANN | 8.5.1 |
| Python | 3.11.14 |
| PyTorch | 2.9.0+cpu |
| torch-npu | 2.9.0.post1+gitee7ba04 |
| transformers | 4.57.6 |
| soundfile | 0.13.1 |
环境信息由
scripts/collect_env.py采集自本次真实 NPU 环境。CANN 版本来自/usr/local/Ascend/cann-8.5.1(version 8.5.1)。
pip install -r requirements.txt依赖列表见 requirements.txt:
torch==2.9.0
torch-npu==2.9.0.post1
transformers==4.57.6
huggingface_hub==0.36.2
soundfile==0.13.1
librosa==0.11.0
numpy==1.26.4使用 huggingface_hub 的 snapshot_download 下载模型(已通过 HF_ENDPOINT=https://hf-mirror.com 走国内镜像):
from huggingface_hub import snapshot_download
model_dir = snapshot_download("AbelZimba/whisper-bemba-stt")或使用 ModelScope 镜像(如适用)。下载后,processor、tokenizer、model 均从本地 model_dir 加载,使用 local_files_only=True 确保离线加载:
processor = AutoProcessor.from_pretrained(model_dir, local_files_only=True)
model = AutoModelForSpeechSeq2Seq.from_pretrained(model_dir, local_files_only=True, torch_dtype=torch.float32).to("npu:0")模型权重不会提交到本仓库,推理时需先下载到本地。
# 设置模型目录(可选,默认自动搜索/workspace/model)
export MODEL_DIR=/path/to/AbelZimba-whisper-bemba-stt
# 执行推理(指定真实 16kHz wav)
python inference.py --audio /path/to/test.wav --model_dir $MODEL_DIR
# 或使用环境变量
export AUDIO_PATH=/path/to/test.wav
python inference.py推理脚本自动将 input_features 迁移到 npu:0,调用 torch.npu.synchronize() 计时,使用 language="en" task="transcribe" 避免 Whisper 语言检测开销(Bemba 不在官方语言列表,使用 en fallback;模型为 multilingual finetune)。
| 属性 | 值 |
|---|---|
| NPU 设备 | Ascend910_9362 |
| torch.npu.is_available() | True |
| device_count | 2 |
| 推理设备 | npu:0 |
| 模型参数设备 | npu:0 (encoder.layers[0].self_attn.q_proj.weight) |
| 输入 Tensor 设备 | npu:0 (input_features [1,80,3000]) |
| 输出 Tensor 设备 | npu:0 (predicted_ids [1,120]) |

设备证明来自本次真实 npu-smi info、check_npu.py、torch.npu.get_device_name(0) 和模型参数遍历。
| 属性 | 值 |
|---|---|
| 模型 | AbelZimba/whisper-bemba-stt |
| Backend | transformers (AutoModelForSpeechSeq2Seq) |
| 设备 | npu:0 |
| 数据类型 | float32 (Whisper conv bias 需与 input_features 对齐) |
| 输入音频 | sample.wav (30.00s, 16kHz, mono) — 来自 pyannote.audio sample (480000 samples) |
| 输入 shape | input_features [1,80,3000] |
| 输出 shape | predicted_ids [1,120] |
| 转写结果 | >> Hello. >> Hello. >> Oh, hello. I didn't know you were there. >> Neither did I. >> Okay. I thought, you know, I heard a beep. This is Diane in New Jersey. >> And I'm Sheila in Texas originally from Chicago. >> Oh, I'm originally from Chicago also. I'm in New Jersey now, though. >> Well, there isn't that much difference. At least, you know, they all call me a Yankee down here. So what can I say? >> Oh, I don't hear that in New Jersey now. |
| Exit Code | 0 |

转写结果来自 python submission/inference.py --audio sample.wav 的真实 NPU 输出(device:npu:0 同步后计时)。同一音频在 CPU 上的转写结果完全一致(text equal True),为确定性 smoke-consistency 验证,非完整数据集评测。
| 对象 | 指标 | 值 | 阈值 | 结论 |
|---|---|---|---|---|
| 转写文本 | 完全一致 | CPU == NPU (444 chars) | 必须非空且一致 | PASS |
| Encoder hidden state | cosine 相似度 | 0.999986 | >0.99 | PASS |
| Encoder hidden state | mean abs diff | 0.00458 | <0.01 | PASS |
| Encoder hidden state | max abs diff | 1.607 | <5.0 (NPU float32 容差) | PASS |
说明:Whisper 在 NPU/CPU 上的浮点累积存在微小差异,mean/cosine 表明数值一致,文本完全一致证明端到端语义一致。
| 指标 | 值 |
|---|---|
| 首次编译+推理 | ~1.83s |
| 稳定推理 avg (5 runs) | 1420.7 ms |
| 稳定推理 min / max | 1402.7 ms / 1465.2 ms |
| RTF (30s / latency) | ~21.1 (stable) / 16.36 (first) |
| Throughput | 0.70 windows/s (30s窗口) |
| 峰值内存 | NPU 3111 MB (HBM) |
计时前后调用
torch.npu.synchronize(),区分首次编译与稳定推理。

流程覆盖:环境检查 → 获取模型(snapshot_download)→ 分析模型(inspect_model.py speech-seq2seq/whisper)→ NPU适配(processor+model to npu:0)→ NPU验证(CPU/NPU一致性+性能)→ 整理仓库 → 推送 GitCode。
bem 不在 OpenAI Whisper 官方语言列表,本适配使用 language="en" 触发通用转写;如需 Bemba 解码,需在 generation_config.json 中自定义 forced_decoder_ids 或微调 tokenizer。Input type (float) and bias type (Half) should be the same),已在推理脚本中固定为 float32。preprocessor_config.json: n_samples 480000),更长音频需分段。