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

SoulX-Singer NPU 适配

SoulX-Singer 是一款高保真、零样本歌声合成模型,能让用户为未见过的歌手生成逼真的歌声。

本仓库包含基于 torch_npu 为 华为昇腾 910 设备适配的 SoulX-Singer 版本,包括推理脚本、精度评估和性能基准测试。


NPU 适配摘要

指标数值
模型参数704M
任务歌声合成(SVS)
框架PyTorch + torch_npu
NPU 硬件昇腾 910(Atlas 800 A2)
推理精度FP32
CPU 推理时间2.805s
NPU 推理时间0.126s
加速比22.2 倍

精度(CPU 与 NPU 对比)

指标梅尔频谱图音频波形
平均绝对误差(MAE)6.60e-081.09e-02
均方误差(MSE)2.68e-143.45e-04
最大绝对差值9.54e-076.29e-02
余弦相似度0.99999990.9999992
相对误差0.000009%0.171%
通过(<1%)✅ 通过✅ 通过

总体精度:✅ 通过——NPU 输出与 CPU 基准在数值精度容差范围内一致。

性能基准测试(在昇腾 910 上运行 10 次)

平均值标准差最小值最大值
0.126s0.002s0.124s0.129s

模型架构

SoulX-Singer 采用流匹配(Flow Matching)架构进行歌声合成:

  • 编码器:4 个嵌入表,分别用于文本(3000×512)、音高(256×512)、音符类型(256×512)和基频(F0,361×512)
  • 预流模块(Preflow):4 个带全局响应归一化(GRN)的 ConvNeXt 块
  • CFM 解码器:22 个 transformer 层(隐藏层=1024,头数=16),含 SwiGLU MLP 和 RMS 归一化
  • 声码器:30 个 ConvNeXt 块,带 iSTFT 头用于梅尔频谱图转波形

模型 checkpoint:model.pt(2.8 GB)


快速开始

环境搭建

# Install PyTorch NPU
pip install torch torch_npu

# Install other dependencies
pip install numpy pyyaml

下载模型

模型检查点(model.pt,2.8 GB)托管在 ModelScope 上。运行推理前请先下载该模型。

pip install modelscope
modelscope download --model Soul-AILab/SoulX-Singer --local_dir ./SoulX-Singer

或者,从 AtomGit Releases 下载(对于大文件,建议使用 Web UI 上传)。

运行推理

# CPU-only inference
python inference.py --skip-npu --output-dir output --n-steps 32

# Full NPU evaluation (CPU baseline + NPU inference + accuracy comparison + benchmark)
python inference.py --output-dir output --n-steps 32 --benchmark-runs 10

Python API

import torch, yaml
from model import SoulXSinger

with open('config.yaml') as f:
    config = yaml.safe_load(f)

model = SoulXSinger(config)
ckpt = torch.load('model.pt', map_location='cpu', weights_only=True)
model.load_state_dict(ckpt['state_dict'], strict=True)
model.eval()

# Run on NPU
model = model.npu()
text = torch.randint(0, 3000, (1, 100)).npu()
pitch = torch.randint(0, 256, (1, 100)).npu()
note_type = torch.randint(0, 256, (1, 100)).npu()
f0 = torch.randint(0, 361, (1, 100)).npu()
noise = torch.randn(1, 1, 128).npu()

with torch.no_grad():
    audio, mel = model(text, pitch, note_type, f0, n_steps=32, noise=noise)

文件

文件描述
model.py模型架构定义(587 个参数,总计 704M)
inference.pyNPU 推理脚本,包含 CPU 对比、精度检查和性能基准测试
config.yaml模型配置
model.pt预训练检查点(2.8 GB)—— 从 ModelScope 或 AtomGit Releases 下载
output/eval_results.json完整评估结果(JSON 格式)
output/run.log完整评估运行日志

注意: model.pt(2.8 GB)和 model-svc.pt(2.6 GB)未纳入 git 版本控制(详见 .gitignore)。请从 ModelScope 下载,或通过 AtomGit 网页界面手动上传。


NPU 适配详情

适配策略

  1. 架构重构:根据检查点的 587 个命名参数和 config.yaml 对完整模型架构进行了重构。
  2. 参数对齐:已验证全部 587 个参数的名称和形状均与官方检查点完全一致。
  3. 推理流程:实现了从文本/音高输入到音频波形输出的完整端到端推理。
  4. 精度验证:CPU 和 NPU 推理使用相同的输入噪声张量,以确保公平对比。

关键实现说明

  • 模型使用 nn.Embedding 作为输入编码器(文本、音高、类型、F0)
  • Preflow 模块采用基于 Linear 的逐点卷积(非 Conv1d),并进行 2 倍扩展(512→1024)
  • CFM 解码器在其内部 MLP 中使用 4 倍中间维度(4096)
  • 声码器(Vocoder)采用基于 Conv1d 的嵌入层和基于 Linear 的逐点卷积,并进行 4 倍扩展
  • 所有归一化(Norm)层均为自定义实现,以匹配检查点的 weight + bias 格式

引用

@misc{soulxsinger,
      title={SoulX-Singer: Towards High-Quality Zero-Shot Singing Voice Synthesis},
      author={Jiale Qian and Hao Meng and Tian Zheng and Pengcheng Zhu and Haopeng Lin and Yuhang Dai and Hanke Xie and Wenxiao Cao and Ruixuan Shang and Jun Wu and Hongmei Liu and Hanlin Wen and Jian Zhao and Zhonglin Jiang and Yong Chen and Shunshun Yin and Ming Tao and Jianguo Wei and Lei Xie and Xinsheng Wang},
      year={2026},
      eprint={2602.07803},
      archivePrefix={arXiv},
      primaryClass={eess.AS},
      url={https://arxiv.org/abs/2602.07803},
}

许可协议

Apache 2.0 许可协议——详情请参见 原始 SoulX-Singer 代码库。

联系方式

有关 NPU 适配问题,请在本代码库中提交 issue。

原作者:qianjiale@soulapp.cn,menghao@soulapp.cn,wangxinsheng@soulapp.cn