Whisper-Bemba-STT 是一个基于 OpenAI Whisper 架构的语音识别模型,专门针对本巴语(Bemba)进行训练。
本模型基于 Whisper Encoder-Decoder 架构,支持多语言语音识别任务。
| 属性 | 值 |
|---|---|
| 模型类型 | WhisperForConditionalGeneration |
| 参数量 | 241.73M |
| Encoder Layers | 12 |
| Decoder Layers | 12 |
| d_model | 768 |
| Mel Bins | 80 |
| 词汇表大小 | 51865 |
| 最大音频长度 | 3000 frames |
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| 操作系统 | CentOS 7.6+ / Ubuntu 18.04+ | 支持主流 Linux 发行版 |
| CANN | 5.0.RC2+ | 华为昇腾计算架构 |
| Python | 3.10 / 3.12 | 推荐 3.10+ |
| PyTorch | 2.0.0+ | 推荐 2.10 |
| torch_npu | 与 PyTorch 版本匹配 | 昇腾 PyTorch 扩展 |
| transformers | >=4.40.0 | 模型加载 |
| safetensors | >=0.4.0 | 权重加载 |
| accelerate | >=0.20.0 | 推理加速 |
# 1) 激活已预装 torch / torch_npu 的 conda 环境
conda activate pt2100
# 2) 安装模型依赖(使用华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple \
transformers>=4.40.0 safetensors accelerate torch_npu
# 3) 验证环境
python -c "
import torch, torch_npu, transformers
print('torch:', torch.__version__)
print('torch_npu:', torch_npu.__version__)
print('transformers:', transformers.__version__)
print('NPU 可用:', torch.npu.is_available())
"# 进入适配目录
cd /workspace/agent1/whisper-bemba-stt-ascend
# 确认上游权重存在
ls -la /workspace/agent2/AbelZimba/whisper-bemba-stt/
# 期望输出:config.json model.safetensors (~922MB) tokenizer.json ...# 检查 NPU 设备状态
npu-smi info
# 验证 torch_npu 安装
python -c "import torch; import torch_npu; print('NPU 可用:', torch.npu.is_available())"# 基本用法:默认参数 (NPU:0)
python inference.py --device npu:0
# 指定其他 NPU 卡
python inference.py --device npu:1
# CPU 模式(仅在 NPU 不可用时使用)
python inference.py --device cpuconda activate pt2100
cd /workspace/agent1/whisper-bemba-stt-ascend
python inference.py --device npu:0实际输出:
[W822 13:25:24.302053200 FunctionLoader.cpp:48] Warning: LD_PRELOAD detected...
[W822 13:25:31.321426180 NPUCachingAllocator.cpp:201] Warning: The current CANN and Soc versions require processing for 32 padding size, with memory allocation. (function operator())
Due to a bug fix in https://github.com/huggingface/transformers/pull/28687 transcription using a multilingual Whisper will default to language detection followed by transcription instead of translation to English.This might be a breaking change for your use case. If you want to instead always translate your audio to English, make sure to pass `language='en'`.
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
============================================================
Whisper-Bemba-STT 昇腾 NPU 推理
============================================================
[Device] npu:0
[Model Path] /workspace/agent2/AbelZimba/whisper-bemba-stt
[Loading] Whisper model with transformers...
Model loaded successfully
Total params: 241.73M
[Model Loaded] Allocated: 0.90 GB, Reserved: 0.99 GB
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 103.8 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 4498 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1318433 | python | 1130 |
+===========================+===============+====================================================+
[Creating] Dummy audio features (80 mel bins, 3000 frames)...
Input features shape: torch.Size([1, 80, 3000])
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 104.0 40 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 4501 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1318433 | python | 1132 |
+===========================+===============+====================================================+
[Running Speech Recognition]...
[npu-smi info]
+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.2 Version: 25.5.2 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(MB)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 0 910B2 | OK | 105.8 41 0 / 0 |
| 0 | 0000:C1:00.0 | 0 0 / 0 4728 / 65536 |
+===========================+===============+====================================================+
+---------------------------+---------------+----------------------------------------------------+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 0 0 | 1318433 | python | 1358 |
+===========================+===============+====================================================+
[Results]
Output_ids shape: torch.Size([1, 104])
Generated tokens: [50258, 50312, 50359, 50363, 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, 287, 287]...
Transcription: l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l l
[Memory After Inference] Allocated: 0.90 GB, Reserved: 1.17 GB
[Done]✅ 验证要点:
注: 当前输出为随机音频输入的演示结果。真实音频输入将产生有意义文本。
解决方案:
source /usr/local/Ascend/ascend-toolkit/latest/set_env.sh)npu-smi info 检查设备状态解释:Whisper 模型要求输入 Mel 频谱图为 3000 帧(30秒音频 @ 100fps)。使用真实音频时,需要使用 Whisper 的 feature extractor 进行预处理。
解释:Whisper 支持 100+ 语言,包括中文、英语、西班牙语、法语等。本模型针对本巴语(Bemba)进行了微调训练。
whisper-bemba-stt-ascend/
├── inference.py # 推理脚本(torch_npu 推理)
├── README.md # 本文档
├── requirements.txt # 依赖列表
└── assets/ # 资源占位目录上游权重目录(只读,未被修改):
/workspace/agent2/AbelZimba/whisper-bemba-stt/
├── config.json # 模型配置
├── model.safetensors # 权重 (~922MB)
├── tokenizer.json # Tokenizer
├── added_tokens.json # 额外 token
└── README.md # 原始文档# Whisper-Bemba-STT 昇腾 NPU 推理环境依赖
# 核心依赖(必须)
torch>=2.0.0
torch_npu
transformers>=4.40.0
safetensors>=0.4.0
numpy
accelerate>=0.20.0使用方式:
# 激活环境
conda activate pt2100
# 安装依赖(华为云源)
pip install --index-url https://repo.huaweicloud.com/repository/pypi/simple -r requirements.txt