本文档记录 KaniTTS-400M-English(英文语音合成模型)在华为昇腾 Ascend NPU 上的部署与验证结果。
KaniTTS 是一个基于 LFM2(Liquid Foundation Model 2)骨干网络和 NVIDIA NanoCodec 音频编解码器的高性能文本转语音(TTS)模型。该模型通过因果语言模型生成音频 token,再经由 NanoCodec 解码为波形。
模型规格:
相关资源:
| 组件 | 版本 |
|---|---|
| 操作系统 | Ubuntu 22.04 (aarch64) |
| NPU | Ascend 910B4 (31GB) |
| Python | 3.11.14 |
| torch | 2.9.0+cpu |
| torch_npu | 2.9.0.post1 |
| transformers | 5.8.0 |
使用 Hugging Face 镜像站下载模型权重到本地:
# 设置镜像
export HF_ENDPOINT=https://hf-mirror.com
# 下载模型
python3 -c "
from huggingface_hub import snapshot_download
snapshot_download(repo_id='nineninesix/kani-tts-400m-en', local_dir='./kani-tts-400m-en')
"inference.py 是 NPU 推理脚本,支持单次文本和批量文件输入。
# 单句合成
python inference.py --text "Hello, how are you?" --speaker andrew --output output.wav
# 从文件读取文本
echo "Hello, how are you today?" > input.txt
python inference.py --text-file input.txt --output-dir ./output
# 自定义参数
python inference.py \
--text "Hello, how are you today?" \
--temperature 0.7 \
--top-p 0.9 \
--max-tokens 3000 \
--output output.wav推理分为两个阶段:
以下为 NPU 上的推理测试结果:
| 项目 | 数值 |
|---|---|
| 模型加载时间 | ~11s |
| Token 生成时间 | ~27s |
| 音频解码时间 | ~18s |
| 输出音频时长 | ~6s |
| 采样率 | 22050 Hz |
| 峰值显存 | ~2.5 GB |
注:以上为单次推理耗时,实际性能受文本长度和 max-tokens 参数影响。
NPU vs CPU 精度对比(通过对比前向传播 logits):
| 指标 | 数值 |
|---|---|
| Token 匹配率 | 100% |
| 均方误差 (MSE) | 3.3e-2 |
| 余弦相似度 | > 0.99995 |
| 对称 KL 散度 | < 1e-6 |
评测方法:在相同输入下,分别采集 NPU 和 CPU 前向传播的输出 logits,计算逐 token 的误差指标。
精度结论:该模型已完成 Ascend NPU 适配部署,CPU 与 NPU 推理结果一致性验证通过,精度误差低于 1% 要求。
python eval_accuracy.pytorch_npu 以支持 NPU 推理nemo-toolkitsoundfile 库--speaker 参数基于现有评测数据,CPU 与 NPU 的 余弦相似度 精度误差为 0.005%,小于 1% 的精度要求。
本仓库提供完整的推理脚本,支持 CPU 和 NPU 双平台推理:
# NPU 推理
python3 inference.py --device npu
# CPU 推理
python3 inference.py --device cpu推理完成后会输出推理结果和耗时,表明模型在 NPU 上推理成功。