g
gcw_AVRCax4T/wenet-u2pp-conformer-wenetspeech-onnx-online-20220506
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

WeNet U2++ Conformer (WenetSpeech) - Ascend NPU Adaptation

Model Description

This repository contains the NPU adaptation of the WeNet U2++ Conformer streaming ASR model, originally trained on WenetSpeech and exported to ONNX format.

  • Model: wenet-u2pp-conformer-wenetspeech-onnx-online-20220506
  • Architecture: U2++ Conformer (Unified Two-pass with bidirectional encoder + CTC + attention decoder)
  • Task: Chinese Mandarin Automatic Speech Recognition (ASR)
  • Type: Streaming (online) speech recognition
  • Framework: ONNX → torch_npu (Ascend NPU)
  • Vocabulary: 5,538 tokens (Chinese characters + SentencePiece subwords)

NPU Adaptation Summary

MetricResult
NPU PlatformAscend910 (2x NPU)
CANN Version8.5.1
Adaptation Methodonnx2torch → torch_npu
Encoder MAPE0.8653% ✅ (< 1%)
CTC MAPE0.0213% ✅ (< 1%)
Decoder MAPE0.0034% ✅ (< 1%)
Token Accuracy100.00% (argmax match)
Cosine Similarity>0.999999 (all models)

Quick Start

Requirements

pip install torch torch_npu torchaudio onnx onnxruntime onnx2torch soundfile scipy

Download Model

pip install modelscope
modelscope download --model manyeyes/wenet-u2pp-conformer-wenetspeech-onnx-online-20220506 --local_dir ./model

Inference

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

Example Output

Test audio 0.wav (3.55s):

Greedy text:  朱立楠在上书战的上
Beam+Attn:    朱立楠在上书战的上
RTF (CPU):    0.2462
RTF (NPU):    0.2833

Architecture

Audio (16kHz) → FBank [T, 80] → Streaming Conformer Encoder
                                     ↓
                              [T_enc, 512]
                                ↙        ↘
                    CTC [T, 5538]    Attention Decoder
                         ↓                 ↓
                   CTC Greedy      Decoder Rescore
                         ↓                 ↓
                       Combined → Final Text

Model Components

ComponentInputOutputSize
Encoderchunk [1,T,80] + caches[1,T_enc,512] + new caches343 MB
CTChidden [1,T_enc,512][1,T_enc,5538]11 MB
Decoderhyps + encoder_out[NBEST,L,5538]157 MB

NPU Adaptation Method

The ONNX models are converted to PyTorch FX GraphModules via onnx2torch, then executed on Ascend NPU using torch_npu. This approach:

  1. Preserves the original model weights and computation graph
  2. Enables NPU acceleration without ATC model conversion
  3. Achieves bit-identical argmax output with CPU reference (100% token accuracy)
  4. MAPE < 1% for all three sub-models

Conversion Pipeline

ONNX Model → onnx2torch.convert() → torch.fx.GraphModule → .to("npu") → torch_npu inference

Performance

ModelCPU (s)NPU (s)Speedup
Encoder0.47490.77720.61x
CTC0.00510.00261.97x
Decoder0.39290.22471.75x
Total0.87291.00450.87x

Note: Encoder NPU performance includes onnx2torch graph optimization overhead. Further optimization possible via ATC OM conversion.

Accuracy Verification

Full accuracy comparison between CPU (onnxruntime) and NPU (torch_npu) outputs:

ModelMax Abs ErrorMean Abs ErrorMAPECosine SimToken Acc
Encoder0.011270.000480.8653%0.99999945100.00%
CTC0.041320.004610.0213%0.99999997100.00%
Decoder0.002400.000350.0034%1.00000000100.00%

Files

FileDescription
inference.pyMain inference script (CPU + NPU backends)
evaluate_npu.pyNPU vs CPU accuracy evaluation script
evaluation_results.jsonFull accuracy + performance metrics
encoder.onnxOriginal encoder ONNX model
decoder.onnxOriginal decoder ONNX model
ctc.onnxOriginal CTC ONNX model
tokens.txtVocabulary (5538 tokens)
configuration.jsonModel metadata
test_wavs/Test audio samples (4 WAV files)

Citation

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

License

This model is released under the Apache License 2.0.