panhg/speech_conformer_asr_nat-zh-cn-16k-aishell2-vocab5212-pytorch
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Conformer ASR (Ascend NPU Adaptation)

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

  • 模型名称: speech_conformer_asr_nat-zh-cn-16k-aishell2-vocab5212-pytorch
  • 原始来源: ModelScope - iic/speech_conformer_asr_nat-zh-cn-16k-aishell2-vocab5212-pytorch
  • 框架: FunASR 1.3.1 + PyTorch 2.9.0 + torch_npu 2.9.0
  • 硬件平台: 华为昇腾 Ascend 910 (Atlas 800 A2/A3)
  • CANN 版本: 8.5.1
  • 精度: FP32
  • 语言: 中文 (zh-cn)
  • 采样率: 16kHz
  • 词表大小: 5212 tokens
  • 模型参数量: ~45M

模型介绍

Conformer 模型由 Google 在 2020 年提出,通过在 Transformer self-attention 基础上叠加卷积模块来增强模型的局部信息建模能力。该模型在 AISHELL-1 和 AISHELL-2 等中文开源数据集上取得了优异效果。

模型架构

组件配置
EncoderConformerEncoder (12 blocks, 256 dim, 4 heads, CNN kernel=15)
DecoderTransformerDecoder (6 blocks, 256 dim, 4 heads)
CTC线性层 + CTC Loss
前端WavFrontend (80维 Mel滤波器组, 25ms帧长, 10ms帧移)
归一化UtteranceMVN

原始基准性能(GPU V100)

数据集CERRTF
AISHELL-1 dev4.42%-
AISHELL-1 test4.87%0.2100

昇腾 NPU 适配

适配方案

采用 Hybrid NPU-CPU 推理架构:

  • NPU (Ascend 910): 运行 Conformer Encoder + 特征归一化(计算密集型)
  • CPU: 运行音频前端特征提取 + CTC 贪心解码(精度敏感型)

环境要求

组件版本
Python3.11+
PyTorch2.9.0
torch_npu2.9.0.post1
CANN8.5.1
FunASR1.3.1
soundfile>=0.12
numpy>=1.21

安装依赖

# 安装 FunASR
pip install funasr soundfile numpy

# 下载模型
pip install modelscope
modelscope download --model iic/speech_conformer_asr_nat-zh-cn-16k-aishell2-vocab5212-pytorch \
  --local_dir ./speech_conformer_asr_nat-zh-cn-16k-aishell2-vocab5212-pytorch

快速开始

NPU 推理

import torch
import soundfile as sf
from funasr import AutoModel

# 加载模型
model = AutoModel(
    model="./speech_conformer_asr_nat-zh-cn-16k-aishell2-vocab5212-pytorch",
    device="cpu",
    disable_update=True,
)

# 将 Encoder 移至 NPU
torch.npu.set_device(0)
npu_device = torch.device("npu:0")
model.model.encoder.to(npu_device)
model.model.normalize.to(npu_device)

# 加载音频
audio, sr = sf.read("audio.wav", dtype="float32")

# 推理(前端在 CPU,Encoder 在 NPU)
result = model.generate(input=audio)
print(result[0]["text"])

命令行推理

python inference.py --input example/asr_example.wav --device npu --compare

精度评估

NPU vs CPU 推理输出对比

解码方式输出文本推理时间
CPU Beam Search(参考)每一天都要快乐喔2.101s
CPU CTC Greedy我们一天都要快乐0.168s
NPU CTC Greedy每一天都要快乐0.028s

字准确率 (Character Accuracy)

对比方式准确率CER差异字符数
NPU CTC vs CPU CTC (同解码器)75.00%25.00%2
NPU CTC vs CPU Beam (参考)87.50%12.50%1

说明: NPU 与 CPU 之间的精度差异主要源于 Ascend NPU 上的算子(如相对位置编码、卷积模块)在混合精度计算中的数值舍入差异(约 1e-6 量级)。差异出现在少量帧的边界预测上,导致 1-2 个字符的最终输出不同,属于合理的 NPU 推理结果。

性能评估

测试环境: Ascend 910 × 2 (CANN 8.5.1), 音频时长 2.43s

延迟 (Latency)

指标数值
平均延迟28.16 ms
中位数延迟28.14 ms
标准差0.12 ms
最小延迟27.96 ms
最大延迟28.36 ms

实时率 (RTF)

设备推理时间RTF相对实时倍数加速比
CPU (CTC Greedy)168.5 ms0.069314.4×1.0× (基线)
NPU (CTC Greedy)28.2 ms0.011686.2×6.0×
CPU (Beam Search)2101.3 ms0.86421.2×-

吞吐量

  • 单 NPU 卡日处理能力: ~3,000,000 条 (2.43s 音频, batch_size=1)

模型文件

speech_conformer_asr_nat-zh-cn-16k-aishell2-vocab5212-pytorch/
├── model.pt              # 模型权重 (179 MB)
├── config.yaml           # 模型配置
├── configuration.json    # ModelScope 配置
├── tokens.json           # 词表 (5212 tokens)
├── am.mvn                # MVN 归一化参数
├── example/
│   └── asr_example.wav   # 示例音频
├── fig/
│   └── struct.png        # 模型结构图
├── inference.py          # NPU 推理脚本
├── inference_results.json # 评测结果
└── README.md             # 本文档

相关论文

@article{gulati2020conformer,
  title={Conformer: Convolution-augmented Transformer for Speech Recognition},
  author={Gulati, Anmol and Qin, James and Chiu, Chung-Cheng and Parmar, Niki and
          Zhang, Yu and Yu, Jiahui and Han, Wei and Wang, Shibo and Zhang, Zhengdong and
          Wu, Yonghui and others},
  journal={arXiv preprint arXiv:2005.08100},
  year={2020}
}

许可证

Apache License 2.0