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.
| File | Size | Description |
|---|---|---|
| encoder.onnx | 565 MB | Zipformer encoder (audio → embeddings) |
| encoder.int8.onnx | 148 MB | INT8 quantized encoder |
| decoder.onnx | 4.9 MB | Stateless prediction network |
| decoder.int8.onnx | 1.2 MB | INT8 quantized decoder |
| joiner.onnx | 3.9 MB | Joiner network (encoder+decoder → logits) |
| joiner.int8.onnx | 1.0 MB | INT8 quantized joiner |
| tokens.txt | 39 KB | BPE token vocabulary |
pip install torch torch_npu onnx onnxruntime onnx2torch scipypip install modelscope
modelscope download --model manyeyes/k2transducer-zipformer-th-onnx-offline-yfyeung-20240620python3 inference.py --audio input.wavpython3 inference.py --audio input.wav --npupython3 inference.py --evaluate --npu --output results.jsonpython3 inference.py --compareThe model has been adapted for Ascend NPU inference using a hybrid approach:
| Component | Backend | Method |
|---|---|---|
| Encoder | CPU (onnxruntime) | ONNX Runtime with graph optimizations |
| Decoder | CPU (onnxruntime) | ONNX Runtime inference |
| Joiner | NPU (torch_npu) | onnx2torch conversion → torch_npu execution |
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"| Test File | CPU CER | NPU CER | Error Diff |
|---|---|---|---|
| 0.wav | 2.47% | 2.47% | 0% |
| 1.wav | 2.47% | 2.47% | 0% |
| 2.wav | 9.21% | 9.21% | 0% |
| Average | 4.62% | 4.62% | 0% ✓ |
CPU vs NPU accuracy difference: 0% — well within the < 1% requirement.
| # | Reference | Prediction |
|---|---|---|
| 0 | ซึ่งตรงท่าเรือนี้ครับเป็นจุดที่เหมาะมากนะครับสําหรับการอยู่อาศัยของเพนกวินนั่นเอง | ซึ่งตรงท่าเรือนี้ครับเป็นจุดที่เหมาะมากนะครับสําหรับการอยู่อาศัยของแนนกวินนั่นเอง |
| 1 | เอ่อเคยถามอาจารย์แล้วล่ะฮะแล้วก็คนที่สิบสี่ปีที่แล้วอยู่ในที่ห้องประชุมคงจะจําได้ | เอ่อเคยถามอาจารย์แล้วนะฮะแล้วก็คนที่สิบสี่ปีที่แล้วอยู่ในที่ห้องประชุมคงจะจําได้ |
| 2 | ตั้งอยู่ในเอเชียตะวันออกเฉียงใต้และเป็นหนึ่งในสิบประเทศของประชาคมอาเซียนนะฮะ | อยู่ในเอเชียตะวันออกเฉียงใต้และเป็นหนึ่งใน๑๐ประเทศของประชาคมอาเซียนนะฮะ |
| Backend | RTF (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.
from modelscope import snapshot_download
model_dir = snapshot_download('manyeyes/k2transducer-zipformer-th-onnx-offline-yfyeung-20240620')Apache License 2.0
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.