openbmb/VoxCPM2 的 Ascend NPU 适配镜像。 VoxCPM2 是 tokenizer-free、diffusion autoregressive Text-to-Speech 模型,2B 参数、30 种语言、 48 kHz 音频输出、训练于 200 万+ 小时多语种语音数据。
voxcpm2(自回归 LM + 残差 LM + AudioVAE V2 + DiT CFM 解码器)hidden_size=2048,28 层,num_attention_heads=16,num_kv_heads=2,
vocab_size=73448,max_position_embeddings=32768,LongRoPE(long_factor/short_factor 等长缩放)audiovae.pth(encoder_dim=128、latent_dim=64、decoder_dim=2048),
sample_rate=16000 → out_sample_rate=48000(AudioVAE V2 内置超分)tokenization_voxcpm2.py(VoxCPM2Tokenizer,拆分多字中文 token 为单字 ID)mkdir -p /data/VoxCPM2 && cd /data/VoxCPM2
HF_ENDPOINT=https://hf-mirror.com HF_HUB_DOWNLOAD_TIMEOUT=120 \
python3 -c "from huggingface_hub import snapshot_download; \
snapshot_download('openbmb/VoxCPM2', local_dir='/data/VoxCPM2/models')"
pip install -r requirements.txt依赖:torch 2.9.0 + torch_npu 2.9.0.post1 + CANN 8.5.1 + Ascend 910 + voxcpm(pip install voxcpm)。
推荐 load_denoiser=False 以减少首装等待;推理需要 audiovae.pth 已就位。
# Ascend NPU
python3 inference.py --device npu
# CPU(回归基线)
python3 inference.py --device cpu
# 自定义文本 / seed / 步数
python3 inference.py --device npu \
--text "VoxCPM2 brings multilingual TTS to Ascend NPUs." \
--seed 42 --max_tokens 128 --inference_timesteps 10脚本会在 outputs/ 下写入 metrics_npu.json 与 metrics_cpu.json:
load_time_s / generate_time_s / total_time_swav_samples / wav_seconds / wav_stats(mean / std / min / max)stft_shape并保存 wav_*.npy(原始波形)与 stft_mag_*.npy(STFT 幅度谱)用于 CPU vs NPU 对比。
| 指标 | NPU | CPU | 差异 |
|---|---|---|---|
| load_time_s | (见 outputs/metrics_npu.json) | (见 outputs/metrics_cpu.json) | — |
| generate_time_s | 同上 | 同上 | — |
| total_time_s | 同上 | 同上 | — |
| wav_samples | 同上 | 同上 | — |
| wav_seconds | 同上 | 同上 | — |
| STFT shape | 同上 | 同上 | — |
| cos_sim | — | — | outputs/compare.json |
| max_abs_err | — | — | 同上 |
| mean_abs_err | — | — | 同上 |
| 参数 | 默认值 | 说明 |
|---|---|---|
--device | 必填 | 推理设备:npu / cpu |
--model | ./models | 模型目录(含 model.safetensors + audiovae.pth + tokenization_voxcpm2.py) |
--text | 示例英文 | 待合成文本 |
--seed | 42 | 随机种子 |
--max_tokens | 128 | 生成 token 数上限 |
--cfg_value | 2.0 | CFG 引导强度(与 CFM 一致) |
--inference_timesteps | 10 | DiT 去噪步数 |
--outdir | ./outputs | 输出目录 |
.
├── inference.py # 双设备推理脚本(--device npu|cpu)
├── readme.md # 本文件
├── requirements.txt # 依赖清单
├── models/ # 权重(.gitignore 排除,含 audiovae.pth + 自定义 tokenizer)
└── assets/ # 3 张 2x2 多面板适配信息图audiovae.pth 单独存放,与 model.safetensors 一起使用;缺失会导致 VAE 编码/解码失败。tokenization_voxcpm2.py 把多字中文 token 拆成单字 ID,避免推理时乱码。assets/model_result.pngassets/model_result.pngoutputs/compare.json