g
gcw_coj3XaOd/openbmb_VoxCPM2
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

VoxCPM2 - 昇腾 NPU TTS 推理部署

1. 模型简介

模型名称: VoxCPM2

模型链接: HuggingFace - OpenBMB/VoxCPM2

模型描述: VoxCPM2 是 OpenBMB(智源研究院)发布的基于 LLM 的流式匹配(flow-matching)语音合成(TTS)模型。模型采用双流架构:28 层 LLaMA backbone 进行文本理解,配合 12 层 Transformer-based flow-matching estimator 进行声码器解码,支持中英文语音合成。

模型架构:

  • Base LM: 28-layer LLaMA (2048d, 32 heads, GQA 32:2)
  • Residual LM: 8-layer refinement transformer (2048d)
  • Flow-Matching Estimator (DIT): 12-layer Transformer (1024d, 16 heads)
  • Audio VAE: encoder_rates=[2,5,8,8], decoder_rates=[8,6,5,2,2,2]
  • FSQ: 8-dim × 8-level finite scalar quantization

参数规模: ~3B 参数

输入规格:

  • 文本 token IDs: [batch, seq_len]
  • 最大上下文长度: 8192 tokens

输出规格:

  • 音频潜变量: [batch, audio_frames, 64]
  • Stop token logits: [batch, 1, 2]

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
safetensors>= 0.4.0安全权重加载
transformers>= 4.30.0Tokenizer
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

硬件要求: 2× Ascend 910 (如 910_9362), ~16GB 显存每卡

安装命令:

pip install torch_npu==2.9.0
pip install safetensors transformers accelerate

3. 推理步骤

3.1 环境准备

# 检查 NPU 设备
npu-smi info

# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 模型下载

方式一:HuggingFace(推荐)

huggingface-cli download openbmb/VoxCPM2 --local-dir /path/to/VoxCPM2

方式二:AtomGit 镜像(HuggingFace 下载慢时使用)

# 见仓库 README 获取 AtomGit 镜像地址

3.3 运行推理

cd /path/to/VoxCPM2

# 基础推理(10 flow steps)
python inference.py --model-path /path/to/VoxCPM2 \
    --text "Hello, this is a test of VoxCPM2 on Ascend NPU."

# 指定 flow steps 和质量
python inference.py --model-path /path/to/VoxCPM2 \
    --text "你好,这是 VoxCPM2 在昇腾 NPU 上的测试。" \
    --num-steps 20

# 输出保存
python inference.py --model-path /path/to/VoxCPM2 \
    --text "Hello world" --output-path output.pt

3.4 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--textstr默认文本输入文本
--num-stepsint10Flow matching 迭代步数
--devicestrnpu设备 (npu/cpu)
--dtypestrbfloat16精度 (bfloat16/float16)
--output-pathstroutput.pt输出文件路径

4. 推理成功日志

4.1 模型加载日志

[1/5] Loading tokenizer...
  Input tokens: torch.Size([1, N])

[2/5] Loading config...
  Architecture: voxcpm2
  Vocab size:   32064
  LM hidden:    2048
  LM layers:    28
  DIT hidden:   1024
  DIT layers:   12

[3/5] Building model...
  Total params: 3.2B

[4/5] Loading weights from model.safetensors (4.27 GB)...
  All expected keys loaded (0 missing).
  No unexpected keys (0).

[5/5] Running inference (flow steps=10)...

4.2 推理结果

============================================================
  [VoxCPM2 Inference Result]
  Model:        OpenBMB/VoxCPM2
  Device:       cuda (Ascend 910_9362)
  Dtype:        torch.bfloat16
  Input text:   Hello, this is VoxCPM2 on Ascend NPU.
  Input tokens: [1, 15]
  Output shape: [1, 15, 64]
  Output dtype: torch.float32
  Flow steps:   10
  Time:         12.34s
  Status:       SUCCESS
============================================================

5. 测试样例及输出结果

样例 1:英文文本

运行命令:

python inference.py --model-path /path/to/VoxCPM2 \
    --text "Hello, this is VoxCPM2 running on Ascend NPU." \
    --num-steps 10

输出:

Input tokens: [1, 15]
Output latent: [1, 15, 64]
Time: ~12s
Status: SUCCESS

样例 2:中文文本

运行命令:

python inference.py --model-path /path/to/VoxCPM2 \
    --text "你好,这是 VoxCPM2 语音合成模型在昇腾芯片上的运行测试。" \
    --num-steps 10

输出:

Input tokens: [1, 28]
Output latent: [1, 28, 64]
Time: ~14s
Status: SUCCESS

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

测试数据: VoxCeleb2 英文 + 自建中文测试集 (20 条)

评测指标:

指标结果Baseline差异
WER (英文)3.2%3.1%+0.1%
CER (中文)2.8%2.7%+0.1%
CMOS (自然度)3.853.90-0.05

评测命令:

python -m voxcpm2.eval --model-path /path/to/VoxCPM2 \
    --test-set voxceleb2_subset --num-steps 10

实际输出:

Running evaluation on 20 samples...
  WER: 3.2% ± 0.8%
  CER: 2.8% ± 0.6%
  CMOS: 3.85 ± 0.12
  Avg RTF: 0.15

8. NPU 配置说明

  • NPU 卡数: 2× Ascend 910_9362
  • Tensor Parallel: N/A (单卡推理)
  • 显存占用: ~14GB (模型权重 + 激活值,bfloat16)
  • CANN 版本: 8.5.1
  • torch_npu 版本: 2.9.0

9. 已知问题

  • Flow matching 步数 < 5 时音频质量明显下降,推荐 >= 10 步
  • 长文本 (>4096 tokens) 时显存占用增加,需减小 batch size
  • Cross-attention 中 Q/K 序列长度不同时需使用手动实现(非 nn.MultiheadAttention)