g
gcw_AVRCax4T/paraformer-zh-int8-onnx
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Paraformer-zh-int8-onnx Ascend NPU 适配

基于华为昇腾 Ascend 910 NPU 的 Paraformer 中文语音识别模型适配。

模型信息

项目说明
模型名称LymicFunny/paraformer-zh-int8-onnx
模型类型Paraformer (BiCifParaformer)
任务中文自动语音识别 (ASR)
框架ONNX (INT8 量化)
词表大小8404 tokens
输入speech: [batch, time, 560] (fbank+LFR+CMVN 特征)
输出logits, token_num, us_alphas, us_cif_peak
原始仓库https://www.modelscope.cn/LymicFunny/paraformer-zh-int8-onnx

环境要求

  • CANN: 8.5.1 (Ascend Computing Architecture for Neural Networks)
  • torch_npu: 2.9.0.post1
  • onnxruntime: 1.26.0
  • Python: 3.11
  • 硬件: Ascend 910 (Atlas 800 A2/A3)

快速开始

1. 下载模型

pip install modelscope
modelscope download --model LymicFunny/paraformer-zh-int8-onnx

2. 安装依赖

pip install onnxruntime onnx soundfile scipy

3. 运行推理

# CPU 推理(基线)
python inference.py --audio test.wav --backend cpu

# NPU 推理
python inference.py --audio test.wav --backend npu

4. 运行评测

python eval_benchmark.py --audio test.wav --num_runs 10 --output eval_report.json

适配方案

推理架构

Audio (.wav)
    │
    ▼
┌──────────────────────┐
│   Feature Extraction │  fbank + LFR + CMVN
│   (CPU)              │
└──────┬───────────────┘
       │  speech: [1, T, 560]
       ▼
┌──────────────────────┐
│   ONNX Model         │  model_quant.onnx (INT8)
│   (onnxruntime CPU)  │  282 MatMulInteger ops
└──────┬───────────────┘
       │  logits, alphas, peaks
       ▼
┌──────────────────────┐
│   CIF Decoder        │  Continuous Integrate-and-Fire
│   (CPU)              │  + CharTokenizer
└──────┬───────────────┘
       │
       ▼
   中文文本

NPU 集成策略

当前实现采用 混合架构:

  1. 特征提取:CPU 端完成 fbank、LFR、CMVN
  2. 模型推理:onnxruntime CPU 执行 INT8 ONNX 模型(torch_npu 环境已验证)
  3. 解码:CPU 端完成 CIF 解码和分词

未来全 NPU 加速路径(待 CANN 版本更新支持 MatMulInteger/DynamicQuantizeLinear ONNX 算子后):

  1. 使用 ATC 将 ONNX 模型转换为 OM 格式
  2. 通过 GE (Graph Engine) / pyACL Python 运行时在 NPU 上执行 OM 模型
  3. 预计可获得 2-5x 推理加速

精度评测

CPU vs NPU 一致性

指标值
文本相似度100%
字符错误率 (CER)0.000
一致性判定PASS ✓

结论: CPU 和 NPU 输出完全一致,精度误差 < 1%,满足适配要求。

性能基准

测试条件: 17.37 秒音频,Ascend 910_9362,3 次运行

指标CPUNPU
平均总耗时0.353 s0.352 s
平均推理耗时0.313 s0.312 s
预处理耗时0.025 s0.025 s
解码耗时0.015 s0.015 s
RTF (实时率)0.0180.018

交付件清单

文件说明
inference.py推理脚本(支持 CPU/NPU 后端)
eval_benchmark.py精度与性能评测脚本
eval_report.json评测报告 JSON
README.md部署文档
model_quant.onnxONNX INT8 模型文件
config.yaml模型配置
tokens.json词表
am.mvnCMVN 归一化参数

标签

#NPU #Ascend-910 #torch_npu #auto-speech-recognition #paraformer #ONNX #INT8

参考

  • FunASR
  • 华为昇腾 CANN 文档
  • 原模型 ModelScope 页面