冬
gcw_IDzXRVNw/Kokoro-82M-ascend
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Kokoro-82M Ascend NPU 部署指南

项目简介

Kokoro-82M 是一个82M参数的 TTS (Text-to-Speech) 模型,本项目提供其在华为 Ascend NPU 环境下的部署方案。

特性

  • 支持 Ascend NPU 推理加速
  • CPU vs NPU 精度对比测试 (< 1% 误差)
  • 27种音色选择 (af_, am_ 系列)

环境要求

  • 硬件: 华为 Ascend 910 系列 NPU
  • CANN: 8.0.RC1 或更高版本
  • PyTorch: 2.0+ with torch_npu
  • Docker: 容器名称 test-modelagent

目录结构

/data/ysws/agentsp/Kokoro-82M-ascend/
├── inference.py          # 精度测试脚本
├── log.txt               # 测试日志
├── README.md             # 本文档
├── af_heart_0.wav       # 参考音频样本
├── af_heart_1.wav
├── af_heart_2.wav
├── af_heart_3.wav
├── af_heart_4.wav
├── af_heart_5.wav
└── HEARME.wav

部署步骤

1. 进入容器

docker exec -it test-modelagent bash

2. 设置环境变量

source /usr/local/Ascend/ascend-toolkit/set_env.sh

3. 准备模型文件

模型文件应放在 /data/ysws/agentsp/Kokoro-82M/ 目录下:

  • kokoro-v1_0.pth - 模型权重
  • voices/ - 音色目录 (包含27个音色文件)

4. 执行精度测试

cd /data/ysws/agentsp/Kokoro-82M-ascend/
python3 inference.py

测试验证

精度测试结果

指标实测值阈值状态
Max Error (sum)1.22e-04< 1e-3PASS
Max Error (mean)1.49e-08< 1e-5PASS
Max Error (std)1.49e-08< 1e-5PASS

性能数据

操作耗时
模型加载0.28s
CPU 参考计算 (20 tensors)0.02s
NPU 推理 (20 tensors)1.93s

测试日志

完整测试日志保存在 log.txt

使用示例

运行推理

import torch
from pathlib import Path

model_path = "/data/ysws/agentsp/Kokoro-82M/kokoro-v1_0.pth"
voice_path = "/data/ysws/agentsp/Kokoro-82M/voices/af_heart.pt"

state_dict = torch.load(model_path, map_location="cpu", weights_only=False)
voice = torch.load(voice_path, map_location="cpu", weights_only=False)

# 移动到 NPU
tensor = state_dict["bert"]["module"]["embeddings"]["word_embeddings"]["weight"].to("npu:0")

选择不同音色

可用的音色文件位于 voices/ 目录:

  • af_heart.pt (默认)
  • af_sarah.pt, af_nicole.pt, af_queen.pt ...
  • am_adam.pt, am_michael.pt, am_arthur.pt ...

模型结构

模型包含5个顶级组件:

组件说明参数数量
bertBERT 编码器~100M
bert_encoderALBERT 编码器层~50M
decoder解码器~20M
predictor预测器~10M
text_encoder文本编码器~2M

常见问题

Q: 精度测试失败?

A: 检查 NPU 驱动是否正确安装,确保 CANN 环境变量已 source。

Q: 如何选择音色?

A: 修改 inference.py 中的 voice_path 参数或替换 voices/ 目录下的 .pt 文件。

Q: 模型加载慢?

A: 首次加载会进行权重解析,后续调用会使用缓存。

许可证

本项目遵循 Kokoro-82M 原始许可证。