jsjs1258/AbelZimba-whisper-bemba-stt-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

AbelZimba/whisper-bemba-stt

#NPU

模型信息

属性值
模型名称AbelZimba/whisper-bemba-stt
任务类型automatic-speech-recognition
模型架构WhisperForConditionalGeneration (Whisper Small, 12 encoder/12 decoder, d_model 768)
Backendtransformers
来源Hugging Face (https://huggingface.co/AbelZimba/whisper-bemba-stt)
参数量~244M (model.safetensors 923M)

环境信息

属性值
NPUAscend910_9362 (Ascend910)
CANN8.5.1
Python3.11.14
PyTorch2.9.0+cpu
torch-npu2.9.0.post1+gitee7ba04
transformers4.57.6
soundfile0.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 调用结果

属性值
NPU 设备Ascend910_9362
torch.npu.is_available()True
device_count2
推理设备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 设备调用证据

设备证明来自本次真实 npu-smi info、check_npu.py、torch.npu.get_device_name(0) 和模型参数遍历。

模型推理结果

属性值
模型AbelZimba/whisper-bemba-stt
Backendtransformers (AutoModelForSpeechSeq2Seq)
设备npu:0
数据类型float32 (Whisper conv bias 需与 input_features 对齐)
输入音频sample.wav (30.00s, 16kHz, mono) — 来自 pyannote.audio sample (480000 samples)
输入 shapeinput_features [1,80,3000]
输出 shapepredicted_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 Code0

模型推理结果

转写结果来自 python submission/inference.py --audio sample.wav 的真实 NPU 输出(device:npu:0 同步后计时)。同一音频在 CPU 上的转写结果完全一致(text equal True),为确定性 smoke-consistency 验证,非完整数据集评测。

CPU-NPU 一致性验证(smoke)

对象指标值阈值结论
转写文本完全一致CPU == NPU (444 chars)必须非空且一致PASS
Encoder hidden statecosine 相似度0.999986>0.99PASS
Encoder hidden statemean abs diff0.00458<0.01PASS
Encoder hidden statemax abs diff1.607<5.0 (NPU float32 容差)PASS

说明:Whisper 在 NPU/CPU 上的浮点累积存在微小差异,mean/cosine 表明数值一致,文本完全一致证明端到端语义一致。

性能测试(NPU, batch=1, 30s 音频)

指标值
首次编译+推理~1.83s
稳定推理 avg (5 runs)1420.7 ms
稳定推理 min / max1402.7 ms / 1465.2 ms
RTF (30s / latency)~21.1 (stable) / 16.36 (first)
Throughput0.70 windows/s (30s窗口)
峰值内存NPU 3111 MB (HBM)

计时前后调用 torch.npu.synchronize(),区分首次编译与稳定推理。

Agent 适配流程

Agent 适配流程

流程覆盖:环境检查 → 获取模型(snapshot_download)→ 分析模型(inspect_model.py speech-seq2seq/whisper)→ NPU适配(processor+model to npu:0)→ NPU验证(CPU/NPU一致性+性能)→ 整理仓库 → 推送 GitCode。

已知限制

  • Bemba 语言代码 bem 不在 OpenAI Whisper 官方语言列表,本适配使用 language="en" 触发通用转写;如需 Bemba 解码,需在 generation_config.json 中自定义 forced_decoder_ids 或微调 tokenizer。
  • Whisper 在 NPU 上推荐 float32(float16 会因 conv bias dtype 不匹配报错 Input type (float) and bias type (Half) should be the same),已在推理脚本中固定为 float32。
  • 长音频(>30s)会自动截断到 30s 窗口(preprocessor_config.json: n_samples 480000),更长音频需分段。
  • 本仓库仅含推理代码与证据,不含权重(923M),需按“模型下载”一节另行获取。