weixin_62994174/MooER-MTL-80K
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

MooER-MTL-80K Ascend NPU Adaptation

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.


Model Architecture

ComponentDescriptionParameters
EncoderParaformer (SANMEncoder)158M
AdapterLinear Downsample + Projection9.4M
LLMQwen2-7B-Instruct + LoRA7.6B

Pipeline: Audio (16kHz) -> FBank -> LFR -> CMVN -> Paraformer Encoder -> Linear Adapter -> Qwen2-7B (with merged LoRA) -> Text


Ascend NPU Adaptation Details

Hardware & Software Environment

ItemVersion
NPUAscend 910 (2x)
CANN8.5.1
PyTorch2.9.0
torch_npuAvailable
Python3.11

Key Adaptations

  1. Device Registration: Added torch_npu support in mooer/utils/utils.py with priority-based device selection
  2. AMP Autocast: Replaced torch.musa.amp.autocast / torch.cuda.amp.autocast with torch.npu.amp.autocast
  3. Audio Loading: Used soundfile + scipy.signal.resample for audio I/O (torchcodec unavailable on NPU)
  4. Model Placement: All model components (encoder, adapter, LLM) moved to npu:0

Adapted Files

  • inference_npu.py - NPU inference script (single WAV and batch SCP modes)
  • eval_npu_simple.py - Precision & performance benchmark script
  • eval_accuracy.py - NPU vs CPU accuracy comparison script
  • src/mooer/utils/utils.py - Added NPU device registration

Evaluation Results

Precision Verification

MetricValueThresholdStatus
NPU vs CPU Text MatchExact Match< 1% errorPASS
Character Error Rate (CER)0.00%< 1%PASS
NPU Consistency (5 runs)100%-PASS

CPU Reference Output:

欢迎使用由摩尔线程开发的基于大语言模型的语音识别及语音翻译系统

NPU Output (all 5 runs identical):

欢迎使用由摩尔线程开发的基于大语言模型的语音识别及语音翻译系统

Performance Benchmark

MetricValue
Model Load Time134.75s
Avg Inference Time0.734s
Std Inference Time0.004s
CPU Inference Time277.29s
NPU Speedup vs CPU378x

Benchmark Iteration Details

RunTime (s)CERText Match
10.7340.00%PASS
20.7360.00%PASS
30.7380.00%PASS
40.7270.00%PASS
50.7330.00%PASS

Quick Start

1. Environment Setup

# Install dependencies
pip install torch_npu transformers peft soundfile scipy numpy
pip install modelscope

# Or use requirements
pip install -r requirements.txt

2. Download Model

# 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

3. Run Inference

# 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

4. Run Evaluation

# 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.py

SCP File Format

uttid1 /path/to/audio1.wav
uttid2 /path/to/audio2.wav

Model Source

Original model: MooreThreadsSpeech/MooER-MTL-80K

GitHub: MooreThreads/MooER

Paper: MooER: LLM-based Speech Recognition and Translation Model from Moore Threads


License

MIT License. See LICENSE for details.


Citation

@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}
}