luck_dog_hehe/OmniVoice_verison01
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

OmniVoice on Ascend NPU

OmniVoice 是大规模多语言零样本 TTS(文生语音)扩散模型,覆盖 600+ 种语言,由 k2-fsa (Xiaomi AI Lab) 开发。本项目提供模型在华为昇腾 Ascend 910 NPU 上的推理适配方案。

模型简介

  • 架构: 两阶段扩散语言模型
    • Stage 0 (Generator): Qwen3-0.6B 双向 Transformer,32 步迭代去掩码 + 无分类器引导 (CFG)
    • Stage 1 (Decoder): HiggsAudioV2 RVQ + DAC 卷积解码器,输出 24kHz 波形
  • 推理模式:
    • Auto Voice: 纯文本合成,无需参考音频
    • Voice Cloning: 3-10 秒参考音频实现零样本声音克隆
    • Voice Design: 自然语言描述控制声音属性(性别、年龄、音高、口音等)
  • 原仓库: k2-fsa/OmniVoice
  • 权重: ModelScope
  • 论文: arXiv:2604.00688

昇腾 NPU 适配

环境要求

组件版本
CANN8.5.1
torch2.9.0
torch_npu2.9.0.post1
transformers>= 5.3.0 (5.10.2 测试通过)
omnivoice0.1.5
Python3.11

安装

# 1. 安装 OmniVoice 核心包
pip install omnivoice

# 2. 确保 transformers >= 5.3.0
pip install 'transformers>=5.3.0'

# 3. 下载模型权重
python -c "
from modelscope import snapshot_download
snapshot_download('k2-fsa/OmniVoice', cache_dir='/tmp/models/OmniVoice')
"

# 4. 设置 NPU 环境变量
export PYTORCH_NPU_ALLOC_CONF=expandable_segments:True
export ASCEND_RUNTIME_OPTIONS=task_queue_enable:1

使用方法

Docker 方式(推荐)

# 1. 构建镜像
bash docker_build.sh

# 2. 准备模型目录(首次运行自动下载)
mkdir -p /tmp/models

# 3. 运行推理
bash docker_run.sh --text "Hello world" --output /tmp/test.wav

# 自定义模型路径和 NPU 设备
OMNI_MODEL_DIR=/data/models OMNI_NPU_DEVICE=1 bash docker_run.sh --text "你好世界"

# Voice Design
bash docker_run.sh --text "Hello" --instruct "female, low pitch, british accent"

命令行方式

# Auto Voice(无参考音频)
python omnivoice_npu_infer.py \
  --model /tmp/models/OmniVoice/k2-fsa/OmniVoice \
  --text "Hello world, this is OmniVoice on Ascend NPU." \
  --output output.wav

# 中文合成
python omnivoice_npu_infer.py \
  --text "你好世界,这是昇腾NPU上的语音合成。" \
  --output zh.wav

# 快速模式(8步)
python omnivoice_npu_infer.py \
  --text "Quick test." \
  --num_step 8 \
  --output fast.wav

# Voice Design
python omnivoice_npu_infer.py \
  --text "Hello" \
  --instruct "female, low pitch, british accent" \
  --output design.wav

Python API

from omnivoice_npu_infer import OmniVoiceNPU

engine = OmniVoiceNPU("/tmp/models/OmniVoice/k2-fsa/OmniVoice")
audio = engine.generate(
    text="Hello world.",
    num_step=32,
    guidance_scale=2.0,
)
engine.save(audio, "output.wav")

适配要点

  1. 无需 vLLM: OmniVoice 是扩散 TTS 模型,直接用 torch_npu 运行
  2. flash_attn 非必需: SDPA Flash Attention 在 Ascend 上自动走优化路径
  3. torch.rand_like 警告: NPU 上创建随机张量使用 base format 而非 internal format,不影响功能,是 torch_npu 已知行为
  4. torch.compile: 当前 Ascend Triton 后端有兼容性问题,SDPA 已提供优化注意力路径,暂不需要 compile

测试结果

维度结果数据
数值精度✅ 通过CPU fp32 vs NPU fp16 Logits 余弦相似度 0.9992
功能完整性✅ 通过Auto Voice / Voice Design / 多语言 (7种) / 长文本 (44s) / Non-verbal tags
内存稳定性✅ 通过连续 5 次推理,HBM 增长 0%,1.91 GB
音频有效性✅ 通过全部输出无 NaN/Inf,幅值范围 [-0.5, 0.5]
性能 (RTF)✅ 通过长文本 28.7x 实速,短文本 3.6-5.5x

详细测试报告见 test_report.md。