MooER (摩耳) is an LLM-based Speech Recognition and Translation model from MooreThreads, adapted for Huawei Ascend NPU.
This repository contains the Ascend NPU adapted version of MooER-MTL-80K with verified inference, precision validation, and performance benchmarking.
| Component | Description | Parameters |
|---|---|---|
| Encoder | Paraformer (SANMEncoder) | 158M |
| Adapter | Linear Downsample + Projection | 9.4M |
| LLM | Qwen2-7B-Instruct + LoRA | 7.6B |
Pipeline: Audio (16kHz) -> FBank -> LFR -> CMVN -> Paraformer Encoder -> Linear Adapter -> Qwen2-7B (with merged LoRA) -> Text
| Item | Version |
|---|---|
| NPU | Ascend 910 (2x) |
| CANN | 8.5.1 |
| PyTorch | 2.9.0 |
| torch_npu | Available |
| Python | 3.11 |
torch_npu support in mooer/utils/utils.py with priority-based device selectiontorch.musa.amp.autocast / torch.cuda.amp.autocast with torch.npu.amp.autocastsoundfile + scipy.signal.resample for audio I/O (torchcodec unavailable on NPU)npu:0inference_npu.py - NPU inference script (single WAV and batch SCP modes)eval_npu_simple.py - Precision & performance benchmark scripteval_accuracy.py - NPU vs CPU accuracy comparison scriptsrc/mooer/utils/utils.py - Added NPU device registration| Metric | Value | Threshold | Status |
|---|---|---|---|
| NPU vs CPU Text Match | Exact Match | < 1% error | PASS |
| Character Error Rate (CER) | 0.00% | < 1% | PASS |
| NPU Consistency (5 runs) | 100% | - | PASS |
CPU Reference Output:
欢迎使用由摩尔线程开发的基于大语言模型的语音识别及语音翻译系统NPU Output (all 5 runs identical):
欢迎使用由摩尔线程开发的基于大语言模型的语音识别及语音翻译系统| Metric | Value |
|---|---|
| Model Load Time | 134.75s |
| Avg Inference Time | 0.734s |
| Std Inference Time | 0.004s |
| CPU Inference Time | 277.29s |
| NPU Speedup vs CPU | 378x |
| Run | Time (s) | CER | Text Match |
|---|---|---|---|
| 1 | 0.734 | 0.00% | PASS |
| 2 | 0.736 | 0.00% | PASS |
| 3 | 0.738 | 0.00% | PASS |
| 4 | 0.727 | 0.00% | PASS |
| 5 | 0.733 | 0.00% | PASS |
# Install dependencies
pip install torch_npu transformers peft soundfile scipy numpy
pip install modelscope
# Or use requirements
pip install -r requirements.txt# Download MooER-MTL-80K
modelscope download --model MooreThreadsSpeech/MooER-MTL-80K
# Download Qwen2-7B-Instruct
modelscope download --model Qwen/Qwen2-7B-Instruct --local_dir ./pretrained_models/Qwen2-7B-Instruct# Single file inference
PYTHONPATH=src:$PYTHONPATH python3 inference_npu.py \
--wav_path demo/resources/demo.wav \
--task asr
# Batch inference with SCP file
PYTHONPATH=src:$PYTHONPATH python3 inference_npu.py \
--wav_scp test.scp \
--task asr \
--batch_size 10# Quick NPU benchmark (5 iterations)
PYTHONPATH=src:$PYTHONPATH python3 eval_npu_simple.py
# Full NPU vs CPU accuracy comparison
PYTHONPATH=src:$PYTHONPATH python3 eval_accuracy.pyuttid1 /path/to/audio1.wav
uttid2 /path/to/audio2.wavOriginal model: MooreThreadsSpeech/MooER-MTL-80K
GitHub: MooreThreads/MooER
Paper: MooER: LLM-based Speech Recognition and Translation Model from Moore Threads
MIT License. See LICENSE for details.
@article{liang2024mooer,
title = {MooER: an LLM-based Speech Recognition and Translation Model from Moore Threads},
author = {Zhenlin Liang, Junhao Xu, Yi Liu, Yichao Hu, Jian Li, Yajun Zheng, Meng Cai, Hua Wang},
journal = {arXiv preprint arXiv:2408.05101},
url = {https://arxiv.org/abs/2408.05101},
year = {2024}
}