This repository contains the NPU adaptation of the WeNet U2++ Conformer streaming ASR model, originally trained on WenetSpeech and exported to ONNX format.
| Metric | Result |
|---|---|
| NPU Platform | Ascend910 (2x NPU) |
| CANN Version | 8.5.1 |
| Adaptation Method | onnx2torch → torch_npu |
| Encoder MAPE | 0.8653% ✅ (< 1%) |
| CTC MAPE | 0.0213% ✅ (< 1%) |
| Decoder MAPE | 0.0034% ✅ (< 1%) |
| Token Accuracy | 100.00% (argmax match) |
| Cosine Similarity | >0.999999 (all models) |
pip install torch torch_npu torchaudio onnx onnxruntime onnx2torch soundfile scipypip install modelscope
modelscope download --model manyeyes/wenet-u2pp-conformer-wenetspeech-onnx-online-20220506 --local_dir ./model# CPU inference (onnxruntime baseline)
python inference.py --backend cpu --wav test_wavs/0.wav
# NPU inference (torch_npu via onnx2torch)
python inference.py --backend npu --wav test_wavs/0.wav
# Evaluate NPU vs CPU accuracy
python evaluate_npu.pyTest audio 0.wav (3.55s):
Greedy text: 朱立楠在上书战的上
Beam+Attn: 朱立楠在上书战的上
RTF (CPU): 0.2462
RTF (NPU): 0.2833Audio (16kHz) → FBank [T, 80] → Streaming Conformer Encoder
↓
[T_enc, 512]
↙ ↘
CTC [T, 5538] Attention Decoder
↓ ↓
CTC Greedy Decoder Rescore
↓ ↓
Combined → Final Text| Component | Input | Output | Size |
|---|---|---|---|
| Encoder | chunk [1,T,80] + caches | [1,T_enc,512] + new caches | 343 MB |
| CTC | hidden [1,T_enc,512] | [1,T_enc,5538] | 11 MB |
| Decoder | hyps + encoder_out | [NBEST,L,5538] | 157 MB |
The ONNX models are converted to PyTorch FX GraphModules via onnx2torch,
then executed on Ascend NPU using torch_npu. This approach:
ONNX Model → onnx2torch.convert() → torch.fx.GraphModule → .to("npu") → torch_npu inference| Model | CPU (s) | NPU (s) | Speedup |
|---|---|---|---|
| Encoder | 0.4749 | 0.7772 | 0.61x |
| CTC | 0.0051 | 0.0026 | 1.97x |
| Decoder | 0.3929 | 0.2247 | 1.75x |
| Total | 0.8729 | 1.0045 | 0.87x |
Note: Encoder NPU performance includes onnx2torch graph optimization overhead. Further optimization possible via ATC OM conversion.
Full accuracy comparison between CPU (onnxruntime) and NPU (torch_npu) outputs:
| Model | Max Abs Error | Mean Abs Error | MAPE | Cosine Sim | Token Acc |
|---|---|---|---|---|---|
| Encoder | 0.01127 | 0.00048 | 0.8653% | 0.99999945 | 100.00% |
| CTC | 0.04132 | 0.00461 | 0.0213% | 0.99999997 | 100.00% |
| Decoder | 0.00240 | 0.00035 | 0.0034% | 1.00000000 | 100.00% |
| File | Description |
|---|---|
inference.py | Main inference script (CPU + NPU backends) |
evaluate_npu.py | NPU vs CPU accuracy evaluation script |
evaluation_results.json | Full accuracy + performance metrics |
encoder.onnx | Original encoder ONNX model |
decoder.onnx | Original decoder ONNX model |
ctc.onnx | Original CTC ONNX model |
tokens.txt | Vocabulary (5538 tokens) |
configuration.json | Model metadata |
test_wavs/ | Test audio samples (4 WAV files) |
@inproceedings{wenet2021,
title={WeNet: Production oriented Streaming and Non-streaming End-to-End Speech Recognition Toolkit},
author={Yao, Zhuoyuan and Wu, Di and Wang, Xiong and Zhang, Binbin and Yu, Fan and Yang, Chao and Peng, Zhendong and Chen, Xiaoyu and Xie, Lei and Lei, Xin},
booktitle={Proc. Interspeech},
year={2021}
}This model is released under the Apache License 2.0.