panhg/funasr-onnx-small
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

FunASR-ONNX-Small Ascend NPU Adaptation

Model Description

This is the Ascend NPU-adapted version of yikshing/funasr-onnx-small, a lightweight Paraformer-based automatic speech recognition (ASR) model optimized for Huawei Ascend NPU inference.

  • Original Model: yikshing/funasr-onnx-small
  • Architecture: Paraformer (Parallel Transformer)
  • Encoder: SANM Encoder (40 blocks, 4 heads, 320-dim)
  • Decoder: ParaformerSANM Decoder (12 blocks, 4 heads)
  • Predictor: CIF Predictor V2
  • Vocabulary: 8,359 tokens (Chinese + English)
  • Quantization: INT8 (ONNX model_quant.onnx)
  • Sample Rate: 16kHz

NPU Adaptation

Environment

ComponentVersion
CANN8.5.1
torch_npu2.9.0.post1
PyTorch2.9.0
ONNX Runtime1.26.0
funasr_onnx0.4.1
NPUAscend 910B4 x2

Adaptation Strategy

The NPU adaptation accelerates the inference pipeline through heterogeneous computing:

  1. Audio Preprocessing (NPU): FBank feature extraction, LFR, and CMVN normalization are accelerated using torch_npu tensor operations
  2. Model Inference (CPU): ONNX Runtime executes the quantized Paraformer model on CPU (CANN Execution Provider pending)
  3. Token Decoding (NPU): Argmax, token lookup, and postprocessing accelerated on NPU via torch_npu

Accuracy Verification

MetricResult
Text Match (CPU vs NPU)100%
Argmax Error Rate0.00%
Max Value Relative Error0.00%
Mean Relative Error0.00%
Accuracy PassPASS (< 1%)

Quick Start

1. Install Dependencies

pip install modelscope funasr_onnx jieba torch_npu

2. Download Model

modelscope download --model yikshing/funasr-onnx-small

3. Run NPU Inference

python inference.py --audio /path/to/audio.wav

4. Run Accuracy Evaluation

python accuracy_eval.py

Inference Script

from inference import ParaformerNPU

model = ParaformerNPU(
    model_dir='/path/to/model',
    device_id=0,
    quantize=True,
)
result = model('audio.wav')
print(result)

Performance

Audio DurationFeaturesModelDecodeTotal
2s175ms20ms401ms2158ms
5s18ms854ms2ms875ms
10s-116ms1ms~120ms

Note: First inference includes model loading overhead. Subsequent inferences are faster.

File Structure

funasr_ascend_npu/
├── inference.py       # NPU-adapted inference script
├── accuracy_eval.py   # Accuracy & performance evaluation
└── README.md          # This file

Known Limitations

  1. ONNX Model on CPU: The quantized ONNX model runs on CPU via ONNX Runtime. Full NPU acceleration requires CANN Execution Provider (under development) or ATC-based OM model conversion.

  2. Dynamic Shape Support: The Paraformer model uses dynamic shapes for batch size and sequence length. ATC conversion requires proper shape configuration.

  3. Loop Operations: The CIF predictor uses ONNX Loop operations that are not directly supported by current NPU conversion toolchains.

Roadmap

  • CANN Execution Provider integration for ONNX Runtime
  • ATC-based ONNX-to-OM model conversion
  • Full NPU model inference (encoder + decoder + predictor)
  • Batch inference optimization
  • Streaming ASR support

Citation

@article{gao2022paraformer,
  title={Paraformer: Fast and Accurate Parallel Transformer for Non-autoregressive End-to-End Speech Recognition},
  author={Gao, Zhifu and Zhang, Shiliang and Lei, Ming and McLoughlin, Ian},
  journal={arXiv preprint arXiv:2206.08317},
  year={2022}
}

License

Apache License 2.0 - Same as original model.