weixin_62994174/Paraformer-zh-streaming
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Paraformer-zh-streaming (NPU Adapted)

基于 FunASR 框架的 Paraformer 流式中文语音识别模型,已适配华为昇腾 (Ascend) NPU。

模型介绍

Paraformer-zh-streaming 是阿里巴巴达摩院 FunASR 团队推出的非自回归端到端流式语音识别模型,支持实时流式中文语音识别。本仓库已将其适配至华为昇腾 NPU (Ascend910),支持 NPU 高效推理。

  • 原始模型: iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online
  • 框架: FunASR + PyTorch
  • 任务: 自动语音识别 (ASR)
  • 语言: 中文
  • 采样率: 16000 Hz
  • 模型大小: ~840 MB

模型架构

组件类型参数
EncoderSANMEncoderChunkOpt50 blocks, 4 heads, 512 dim
DecoderParaformerSANMDecoder16 blocks, 4 heads, 2048 linear
PredictorCifPredictorV2512 dim, threshold 1.0
FrontendWavFrontendOnline80 mel bins, lfr_m=7, lfr_n=6

昇腾 NPU 适配

硬件环境

项目详情
NPU 型号Ascend910_9362
NPU 数量2
CANN 版本8.5.1
torch_npu 版本2.9.0.post1
FunASR 版本1.3.1
Python 版本3.11

适配说明

本模型通过 FunASR 框架的 AutoModel 接口实现昇腾 NPU 适配。关键适配点:

  1. 设备映射: 通过 device="npu:0" 参数将模型加载至 NPU
  2. 精度保持: NPU 推理输出与 CPU 完全一致 (CER = 0.00%)
  3. 性能提升: NPU 推理速度相比 CPU 提升 2.41x
  4. 实时率 (RTF): NPU RTF = 0.2073,远低于实时要求 (RTF < 1.0)

快速开始

环境准备

# 安装依赖
pip install funasr torch_npu soundfile librosa editdistance

# 安装 ModelScope (用于模型下载)
pip install modelscope

下载模型

# ModelScope SDK 下载
modelscope download --model shuai1618/paraformer-zh-streaming --local_dir ./paraformer-zh-streaming

# 或通过 Git
git clone https://www.modelscope.cn/shuai1618/paraformer-zh-streaming.git

推理示例

from funasr.auto.auto_model import AutoModel
import soundfile as sf

# 加载模型到 NPU
model = AutoModel(
    model="./paraformer-zh-streaming",
    device="npu:0",    # 使用昇腾 NPU
    disable_pbar=True,
)

# 加载音频 (16kHz, mono)
audio, sr = sf.read("your_audio.wav")

# 推理
cache = {}
result = model.generate(input=audio, cache=cache, is_final=True)
print(f"识别结果: {result[0]['text']}")

命令行推理

# 运行推理
python inference.py --audio your_audio.wav --device npu:0 --output result.json

# 运行完整评测
python benchmark.py --audio your_audio.wav --output benchmark_result.json --runs 10

精度评测

评测方法

  • 基准: CPU 推理结果作为 Ground Truth
  • 指标: Character Error Rate (CER)
  • 通过标准: CER < 1%

评测结果

指标结果状态
CER0.0000%✅ PASS
字符准确率100.00%✅
NPU 输出与 CPU 一致是✅
CPU Reference : 嗯 (与 NPU 输出完全一致)
NPU Output    : 嗯
CER           : 0.000000 (0.0000%)

性能评测

评测配置

  • 测试音频: 3.0 秒, 16kHz, mono
  • Warmup 轮次: 3
  • 评测轮次: 10

性能结果

指标CPUNPU提升
推理时间 (均值)1.5015s0.6220s2.41x
RTF (实时率)0.50050.20732.41x
标准差-0.0039s-
最小延迟-0.6157s-
最大延迟-0.6277s-

延迟分布 (10 次运行)

RunLatency (s)
10.6255
20.6195
30.6176
40.6182
50.6267
60.6221
70.6157
80.6277
90.6237
100.6236

文件说明

paraformer-zh-streaming/
├── inference.py          # NPU 推理脚本
├── benchmark.py          # 精度/性能评测脚本
├── benchmark_result.json # 评测结果
├── inference_result.json # 推理结果
├── config.yaml           # 模型配置
├── configuration.json    # 模型元信息
├── model.pt              # 模型权重
├── tokens.json           # 词表
├── seg_dict              # 分词词典
├── am.mvn                # 均值方差归一化
└── README.md             # 本文档

交付件清单

交付件文件说明
推理脚本inference.pyNPU 模型推理入口
评测脚本benchmark.py精度与性能评测
评测结果benchmark_result.json完整评测数据
推理结果inference_result.json推理输出
部署文档README.md本文档

引用

@inproceedings{gao2023paraformer,
  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 Chen, Xie},
  booktitle={INTERSPEECH},
  year={2023}
}

License

Apache License 2.0