panhg/zipformer-onnx-20240620-Thailand
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

k2transducer-zipformer-th (Thai Zipformer Transducer)

Zipformer-based transducer model for Thai automatic speech recognition (ASR), exported to ONNX format for offline inference. Adapted for Huawei Ascend NPU with torch_npu acceleration.

Model Description

  • Model: k2transducer-zipformer-th (Zipformer Transducer for Thai)
  • Source: manyeyes/k2transducer-zipformer-th-onnx-offline-yfyeung-20240620
  • Architecture: Zipformer Encoder + Stateless Decoder + Joiner (RNN-T Transducer)
  • Task: Thai Automatic Speech Recognition (ASR)
  • Input: 16kHz mono WAV audio
  • Output: Thai text transcription
  • Vocabulary: 2000 BPE tokens

Model Files

FileSizeDescription
encoder.onnx565 MBZipformer encoder (audio → embeddings)
encoder.int8.onnx148 MBINT8 quantized encoder
decoder.onnx4.9 MBStateless prediction network
decoder.int8.onnx1.2 MBINT8 quantized decoder
joiner.onnx3.9 MBJoiner network (encoder+decoder → logits)
joiner.int8.onnx1.0 MBINT8 quantized joiner
tokens.txt39 KBBPE token vocabulary

Requirements

Hardware

  • Ascend 910B / Ascend 910 NPU (or CPU fallback)
  • Minimum 8 GB device memory

Software

  • Python 3.10+
  • CANN 8.5.1+
  • torch 2.9.0+
  • torch_npu 2.9.0+
  • onnxruntime 1.26.0+
  • onnx 1.21.0+
  • onnx2torch 1.0.0+

Install Dependencies

pip install torch torch_npu onnx onnxruntime onnx2torch scipy

Quick Start

Download Model

pip install modelscope
modelscope download --model manyeyes/k2transducer-zipformer-th-onnx-offline-yfyeung-20240620

Inference (CPU)

python3 inference.py --audio input.wav

Inference (NPU)

python3 inference.py --audio input.wav --npu

Batch Evaluation

python3 inference.py --evaluate --npu --output results.json

CPU vs NPU Accuracy Comparison

python3 inference.py --compare

NPU Adaptation

The model has been adapted for Ascend NPU inference using a hybrid approach:

Adaptation Strategy

ComponentBackendMethod
EncoderCPU (onnxruntime)ONNX Runtime with graph optimizations
DecoderCPU (onnxruntime)ONNX Runtime inference
JoinerNPU (torch_npu)onnx2torch conversion → torch_npu execution

NPU Acceleration Details

The joiner network is converted from ONNX to PyTorch using onnx2torch and then deployed to NPU via torch_npu:

# ONNX to PyTorch conversion
import onnx
import onnx2torch
import torch_npu

onnx_model = onnx.load("joiner.onnx")
torch_model = onnx2torch.convert(onnx_model)
torch_model_npu = torch_model.to("npu")

# NPU inference
with torch.no_grad():
    enc = torch.from_numpy(encoder_out).to("npu")
    dec = torch.from_numpy(decoder_out).to("npu")
    logits = torch_model_npu(enc, dec)

For the encoder and decoder, ONNX Runtime provides optimized CPU execution. Full NPU acceleration of the encoder (565 MB) can be achieved using the Ascend Tensor Compiler (ATC):

atc --model=encoder.onnx --framework=5 --output=encoder_om \
    --soc_version=Ascend910B --input_shape="x:1,-1,80;x_lens:1"

Evaluation Results

Environment

  • Device: Huawei Ascend 910B (2× NPU)
  • CANN: 8.5.1
  • torch_npu: 2.9.0
  • Precision: FP32

Accuracy (Character Error Rate)

Test FileCPU CERNPU CERError Diff
0.wav2.47%2.47%0%
1.wav2.47%2.47%0%
2.wav9.21%9.21%0%
Average4.62%4.62%0% ✓

CPU vs NPU accuracy difference: 0% — well within the < 1% requirement.

Sample Transcription Comparison

#ReferencePrediction
0ซึ่งตรงท่าเรือนี้ครับเป็นจุดที่เหมาะมากนะครับสําหรับการอยู่อาศัยของเพนกวินนั่นเองซึ่งตรงท่าเรือนี้ครับเป็นจุดที่เหมาะมากนะครับสําหรับการอยู่อาศัยของแนนกวินนั่นเอง
1เอ่อเคยถามอาจารย์แล้วล่ะฮะแล้วก็คนที่สิบสี่ปีที่แล้วอยู่ในที่ห้องประชุมคงจะจําได้เอ่อเคยถามอาจารย์แล้วนะฮะแล้วก็คนที่สิบสี่ปีที่แล้วอยู่ในที่ห้องประชุมคงจะจําได้
2ตั้งอยู่ในเอเชียตะวันออกเฉียงใต้และเป็นหนึ่งในสิบประเทศของประชาคมอาเซียนนะฮะอยู่ในเอเชียตะวันออกเฉียงใต้และเป็นหนึ่งใน๑๐ประเทศของประชาคมอาเซียนนะฮะ

Performance (Real-Time Factor)

BackendRTF (avg)Latency per file
CPU~0.030~200 ms
NPU (joiner)~0.040~270 ms

Note: RTF < 0.1 confirms real-time inference capability. Full NPU acceleration of the encoder via ATC/OM conversion would further improve throughput.

Usage via ModelScope SDK

from modelscope import snapshot_download
model_dir = snapshot_download('manyeyes/k2transducer-zipformer-th-onnx-offline-yfyeung-20240620')

License

Apache License 2.0

Citation

This model originates from the icefall/k2 project's Zipformer Transducer implementation, fine-tuned for Thai speech recognition and exported to ONNX format by manyeyes.