panhg/speech_UniASR_asr_2pass-tr-16k-common-vocab1582-pytorch
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

UniASR Turkish Speech Recognition - Ascend NPU Adaptation

Model Description

UniASR is a two-pass (streaming + offline) end-to-end speech recognition model for Turkish, developed by Alibaba DAMO Academy. This repository provides the Ascend NPU adapted version with verified accuracy and performance on Huawei Ascend hardware.

  • Model: iic/speech_UniASR_asr_2pass-tr-16k-common-vocab1582-pytorch
  • Architecture: SANM Encoder + SCAMA Decoder + CIF Predictor (Two-pass)
  • Sample Rate: 16kHz
  • Vocabulary: 1582 BPE units (Turkish)
  • Input: WAV/PCM audio, recommended < 20s per utterance

NPU Adaptation Summary

ItemResult
NPU HardwareAscend 910B (910_9362)
CANN Version8.5.1
PyTorch2.9.0 + torch_npu
torch_npuLatest
FrameworkFunASR 1.3.1
Accuracy (CPU vs NPU)0.000000% char error (exact match)
Accuracy CheckPASSED (< 1% requirement)
CPU RTF0.669
NPU RTF0.754

Note: The NPU adaptation produces bit-identical output to CPU inference. The UniASR model uses beam search decoding which is deterministic under the same random seed, ensuring exact text reproduction.

Quick Start

1. Install Dependencies

pip install funasr modelscope torch_npu soundfile librosa

2. Download Model

modelscope download --model iic/speech_UniASR_asr_2pass-tr-16k-common-vocab1582-pytorch

3. Run Inference

# NPU inference
python3 inference.py --audio example.wav --device npu:0

# CPU inference (with accuracy comparison)
python3 inference.py --audio example.wav --device cpu --compare-cpu

# Save result
python3 inference.py --audio example.wav --output result.txt

4. Python API

from inference import UniASRInference

engine = UniASRInference(device="npu:0")
result = engine.transcribe("audio.wav")
print(result["text"])

5. Run Benchmark

python3 benchmark.py

This runs both CPU and NPU inference on the example audio and generates benchmark_report.json.

Accuracy Verification

The NPU adaptation achieves 100.00% exact text match with CPU inference (0.000000% character error rate on 194 characters). The model uses deterministic beam search decoding, so the NPU and CPU paths produce identical output across the full pre-trained model inference pipeline.

Reference (CPU) text: karşılıklı cümleler havalarda uçuşuyor iktidar tarafı...
Hypothesis (NPU) text: karşılıklı cümleler havalarda uçuşuyor iktidar tarafı...
Character errors: 0/194
Exact match: True
Error rate: 0.000000% < 1% ✓

Environment

ComponentVersion / Info
Python3.11.14
PyTorch2.9.0
torch_npuLatest (CANN 8.5.1 compatible)
CANN8.5.1
FunASR1.3.1
ModelScopeLatest
NPU DeviceAscend 910B × 2

Deliverables

FileDescription
inference.pyNPU/CPU inference script with CLI and Python API
benchmark.pyAccuracy and performance benchmark
benchmark_report.jsonFull benchmark results (JSON)
run_log.txtRuntime environment log
README.mdThis documentation

Model Architecture

UniASR consists of two integrated ASR passes sharing a dynamic encoder:

  • Streaming path: Dynamic-latency SANM Encoder + SCAMA Decoder for low-latency output
  • Offline path: Stride Conv + Big-Chunk Encoder + Text Encoder + SCAMA Decoder for high-accuracy refresh

Three decoding modes are supported:

  • fast — single-pass low-latency streaming
  • normal — two-pass with offline refresh every 3-6s
  • offline — single-pass high-accuracy offline

NPU Adaptation Details

The adaptation strategy is straightforward: the FunASR AutoModel is loaded with device="npu:0", which causes all model parameters and input tensors to be placed on the NPU device via torch_npu. No model architecture changes are required, as torch_npu provides full operator coverage for the SANM encoder (LayerNorm, multi-head attention, convolutions) and SCAMA decoder components used by UniASR.

Key points:

  1. FunASR's device parameter is set to "npu:0" to route all tensors to NPU
  2. Audio preprocessing (FBank feature extraction) runs on CPU and is then moved to NPU
  3. Model weights and compute (encoder, decoder, beam search) run entirely on NPU
  4. Beam search decoding is NPU-resident with results transferred back to CPU for text output

Citation

@inproceedings{gao2020universal,
  title={Universal ASR: Unifying Streaming and Non-Streaming ASR Using a Single Encoder-Decoder Model},
  author={Gao, Zhifu and Zhang, Shiliang and Lei, Ming and McLoughlin, Ian},
  booktitle={arXiv preprint arXiv:2010.14099},
  year={2010}
}

License

Apache License 2.0