weixin_62994174/speech_sambert-hifigan_tts_zhiya_zh-cn_16k-npu
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Sambert-HifiGAN TTS - Ascend NPU Adaptation

NPU Verified

模型概述

本模型基于 ModelScope iic/speech_sambert-hifigan_tts_zhiya_zh-cn_16k 完成昇腾 NPU 适配,支持在华为昇腾 Atlas 800 A2/A3 设备上进行中文语音合成推理。

  • 模型名称: SAMBert-HifiGAN TTS (知雅-中文-16k)
  • 原始模型: ModelScope iic/speech_sambert-hifigan_tts_zhiya_zh-cn_16k
  • 任务类型: Text-to-Speech (语音合成)
  • 语言: 中文(支持中英混合)
  • 采样率: 16kHz
  • 声学模型: SAMBert (Self-Attention-Mechanism BERT)
  • 声码器: HifiGAN (GAN-based Neural Vocoder)

昇腾 NPU 适配说明

本仓库提供完整的昇腾 NPU 推理脚本,支持在华为 Ascend910 系列 NPU 上直接运行该 TTS 模型。适配工作包括:

  • 从 ModelScope checkpoint 加载预训练权重
  • SAMBert 声学模型 + HifiGAN 声码器的完整推理实现
  • CPU vs NPU 精度对齐验证
  • NPU 推理性能基准测试

环境要求

项目版本/要求
Python>= 3.8
PyTorch2.9.0
torch_npu2.9.0.post1
CANN8.5.1
NPUAscend910
NumPy>= 1.20
PyYAML>= 6.0

环境准备

# 安装 PyTorch NPU
pip install torch==2.9.0 torch_npu==2.9.0.post1

# 安装其他依赖
pip install numpy pyyaml

快速开始

1. 模型下载

pip install modelscope
modelscope download --model iic/speech_sambert-hifigan_tts_zhiya_zh-cn_16k

2. 运行推理

# 精度验证:CPU vs NPU 对比
python inference.py --mode validate

# 性能基准测试:NPU 推理性能
python inference.py --mode benchmark

# 端到端验证(精度 + 性能)
python inference.py --mode all

# 快速测试:CPU 前向传播
python inference.py --mode test

3. Python API

from inference import load_models, run_inference

# 在 NPU 上加载模型
am, voc = load_models('npu:0')

# 运行推理,seq_len 控制合成文本长度
audio = run_inference(am, voc, seq_len=30, device='npu:0')
print(f"输出音频: {audio.shape}, {audio.size} 采样点")

精度验证结果

CPU (PyTorch) vs NPU (torch_npu) 输出精度对比:

序列长度CPU 采样点NPU 采样点平均绝对误差最大绝对误差相对误差
Short (15帧)600060002.90e-061.90e-050.000290%
Medium (30帧)12000120003.03e-062.31e-050.000303%
Long (50帧)20000200003.15e-062.16e-050.000315%
  • 平均相对误差: 0.000303%
  • 最大相对误差: 0.000315%
  • 精度判定: ✅ PASS (误差 < 1%)

性能基准测试

在 Ascend910 上的推理性能(30帧固定序列):

指标数值
设备Ascend910 (2 devices)
预热次数3
测试次数10
平均推理时间0.080s
最小推理时间0.032s
最大推理时间0.096s
吞吐量12.53 it/s

模型架构

声学模型 SAMBert

SAMBert 将时长模型和声学模型联合建模:

  1. Encoder: 基于 Self-Attention-Mechanism (SAM),采用 BERT 初始化,引入文本信息提升韵律
  2. Variance Adaptor: 对音素级别的韵律轮廓(基频、能量、时长)进行粗粒度预测
  3. Decoder: 采用 PNCA AR-Decoder,自然支持流式合成

声码器 HifiGAN

基于 GAN 的生成器,使用多尺度判别器训练:

  • 输入: 80维 Mel 频谱
  • 上采样: (10, 5, 2, 2) 倍率实现 200x hop
  • 多感受野残差块: (3, 7, 11) 卷积核
  • 输出: 16kHz 单通道波形

模型参数

模块参数量
SAMBert 声学模型12,332,651
HifiGAN 声码器4,866,001
总计17,198,652

交付件清单

文件说明
inference.py推理脚本(含 SAMBert + HifiGAN 完整实现)
README.md部署文档(本文档)
results_accuracy.json精度评测结果
results_benchmark.json性能基准测试结果
validation_log.txt精度验证运行日志
fusion_result.jsonNPU 算子融合报告

模型局限性

  • 发音人支持中文及英文混合,TN 规则为中文
  • 输入文本建议不超过 30 字
  • 暂不支持 Windows 及 Mac 使用
  • 当前适配关闭了 NSF (Neural Source Filter) 模块,因 checkpoint 中 source_downs 卷积核尺寸与标准 HifiGAN 配置不匹配

引用

@inproceedings{li2020robutrans,
  title={Robutrans: A robust transformer-based text-to-speech model},
  author={Li, Naihan and Liu, Yanqing and Wu, Yu and Liu, Shujie and Zhao, Sheng and Liu, Ming},
  booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
  volume={34},
  number={05},
  pages={8228--8235},
  year={2020}
}

@article{kong2020hifi,
  title={Hifi-gan: Generative adversarial networks for efficient and high fidelity speech synthesis},
  author={Kong, Jungil and Kim, Jaehyeon and Bae, Jaekyoung},
  journal={Advances in Neural Information Processing Systems},
  volume={33},
  pages={17022--17033},
  year={2020}
}

许可证

Apache License 2.0