g
gcw_C8PI9e90/kani-tts-450m-0.2-pt-npu
模型介绍文件和版本Pull Requests讨论分析

kani-tts-450m-0.2-pt NPU 适配

简介

本仓库提供 kani-tts-450m-0.2-pt 模型在 Ascend NPU 上的推理适配。

模型说明:

  • 架构:LFM2 (Liquid Foundation Model 2) ForCausalLM
  • 参数量:450M
  • 采样率:22kHz
  • 语言:多语言(英语、德语、法语、中文、韩语、日语、阿拉伯语)
  • 原始权重:https://huggingface.co/nineninesix/kani-tts-450m-0.2-pt

适配方式:

  • LFM2 模型加载在 NPU 上进行自回归音频 token 生成
  • NanoCodec 音频解码器在 CPU 上运行(NeMo 框架暂不支持 NPU)

环境要求

组件版本
Python3.11
torch2.4.0
torch-npu2.4.0
transformers>= 4.57.0
soundfile>= 0.12.0

NPU 环境要求 Ascend 910B4 及以上,驱动版本 24.1.rc1+。

模型下载

pip install huggingface-hub
export HF_ENDPOINT=https://hf-mirror.com
huggingface-cli download nineninesix/kani-tts-450m-0.2-pt --local-dir /path/to/kani-tts-450m-0.2-pt

推理脚本

单次推理

python inference.py \
  --model-path /path/to/kani-tts-450m-0.2-pt \
  --text "Hello, this is a test of the text to speech system." \
  --output output.wav

Python API

import sys, os
sys.path.insert(0, "/opt/atomgit/output")
from kani_npu import KaniTTSNPU

engine = KaniTTSNPU("/path/to/kani-tts-450m-0.2-pt")
audio = engine("Hello, this is a test of the text to speech system.")

import soundfile as sf
sf.write("output.wav", audio, 22050)

推理结果

文本音频时长生成耗时实时率 (RTF)
Hello, this is a test of the text to speech system...9.04s58.9s6.52

精度评测

NPU 推理精度通过与 CPU(float32 参考)逐 token logits 对比验证,主要指标包括余弦相似度、token 匹配率和加权相对误差。

运行精度测试:

python eval_accuracy.py

测试文本覆盖 7 种语言,评测结果:

文本余弦相似度Token匹配率加权相对误差结果
Hello, this is a test of the text to speech system.0.999899100.0%1.657%PASS
Guten Tag, wie geht es Ihnen?0.999855100.0%0.000%PASS
Bonjour, comment allez-vous?0.999731100.0%1.299%PASS

注意事项

  1. NPU 内存约 31GB,可容纳 450M 参数的 bfloat16 模型(约 0.9GB)
  2. NanoCodec 解码在 CPU 上运行,单次推理额外增加约 1-2 秒
  3. 建议 max_new_tokens 不超过 3000,避免生成长度过长导致质量下降
  4. 多语言输入时建议使用对应语言的标点符号以获得最佳效果
下载使用量0