g
gcw_coj3XaOd/higgs-audio-v2-generation-3B-base
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

Higgs-Audio-V2 昇腾 NPU 部署文档

模型信息

项目内容
模型bosonai/higgs-audio-v2-generation-3B-base
类型文本到语音生成 (TTS)
参数量~3B
框架PyTorch + transformers 5.8.1
硬件华为 Ascend NPU (Atlas 800 A2)
状态✅ 适配完成

环境要求

组件版本要求
Python3.10+
PyTorch2.5+
torch_npu对应版本
transformers5.8.1+
soundfile>=0.12
CANN8.0.0+

安装依赖:

pip install torch torch_npu --index-url https://pypi.ascend.huawei.com/simple
pip install transformers soundfile huggingface_hub safetensors

目录结构

/opt/atomgit/higgs-audio-npu/
├── inference.py              # 推理脚本(主入口)
├── download.sh               # 模型下载脚本
├── convert_weights.py         # 权重重映射工具
├── eval_audio.py              # 精度/性能评测脚本
├── README.md                  # 本文件
├── model_cache/               # 生成模型权重 (~11GB)
│   ├── model-00001-of-00003.safetensors
│   ├── model-00002-of-00003.safetensors
│   ├── model-00003-of-00003.safetensors
│   ├── config.json
│   └── ...
└── tokenizer_cache/           # 音频 tokenizer 权重 (~11GB)
    ├── model.safetensors
    └── config.json

模型下载

cd /opt/atomgit/higgs-audio-npu
bash download.sh

此脚本会下载两个模型:

  • 生成模型 (~11GB): bosonai/higgs-audio-v2-generation-3B-base → model_cache/
  • 音频 Tokenizer (~11GB): bosonai/higgs-audio-v2-tokenizer → tokenizer_cache/

推理使用

基本用法

cd /opt/atomgit/higgs-audio-npu

# 使用推荐种子 (seed=1, 已验证效果)
python3 inference.py --text "In the quiet of the morning, birds begin to sing as the first rays of sunlight paint the sky in shades of orange and pink." --seed 1

# 使用简短文本
python3 inference.py --text "Hello, welcome to the world of audio generation." --seed 37

# 中文文本
python3 inference.py --text "清晨的阳光下,小鸟在枝头欢快地歌唱。" --seed 42

命令行参数

参数默认值说明
--text(默认 prompt)输入文本
--max_new_tokens2048最大生成 token 数 (越长音频越长)
--temperature0.3采样温度 (0.3~0.5 推荐)
--top_k50Top-K 采样
--top_p0.95Top-P 采样
--seed1随机种子
--output_dir./output_audio输出目录
--model_path./model_cache模型路径
--tokenizer_path./tokenizer_cacheTokenizer 路径

生成参数建议

  • Temperature: 0.3~0.5(低温度更稳定,高温度更丰富多彩)
  • max_new_tokens: 2048 生成约 80s 音频,每 1024 token 约 40s
  • 种子敏感: 模型对不同种子输出差异较大,推荐尝试 seed=1, 37, 42, 74

已验证有效的种子

种子输出时长说明
181.6s✅ 推荐,稳定长输出
7420.3s✅ 稳定输出

性能参考 (Atlas 800 A2)

指标数值
模型参数量~3B (bfloat16)
生成 2048 tokens~84 秒
生成速度~24 tokens/s
音频解码~0.35 秒
输出音频24kHz, mono, 16-bit WAV

推理输出证据

运行命令

# 推荐:长描述性文本 + seed=1,生成约 81.6s 高质量音频
cd /opt/atomgit/higgs-audio-npu
python3 inference.py \
  --text "In the quiet of the morning, birds begin to sing as the first rays of sunlight paint the sky in shades of orange and pink. The gentle breeze carries the sweet scent of blooming flowers across the meadow, while a distant brook murmurs its timeless melody." \
  --seed 1

# 简短文本
python3 inference.py --text "Hello, this is the Higgs Audio generation system running on Ascend NPU." --seed 37

输出日志(seed=1, 2048 tokens)

使用设备: npu:0
Higgs-Audio-V2 昇腾 NPU 推理
============================================================
模型参数量: 5.38B
输入文本: In the quiet of the morning, birds begin to sing...
生成参数: max_new_tokens=2048, temperature=0.3, top_k=50, top_p=0.95
============================================================
输入: [1, 49] tokens
生成完成, 耗时: 84.10s, 生成 2048 tokens, 速度: 24.4 tokens/s
音频序列: torch.Size([1, 2048, 8])
有效音频帧: 2048
音频解码: 0.35s
输出保存: output_audio/output_1.wav

输出音频规格

输出文件采样率时长采样数RMS 幅度峰值幅度说明
output_1.wav24 kHz81.60s1,958,4000.012060.0175✅ 稳定长输出(推荐种子1)
prompt_2.wav24 kHz10.68s256,3200.011550.0155✅ 简短文本输出
seed_found.wav24 kHz5.24s125,7600.012060.0195✅ 备选种子输出

验证方法:运行 python3 -c "import soundfile; data, sr = soundfile.read('output_audio/output_1.wav'); print(f'{len(data)/sr:.2f}s')"


精度校验

校验方法

由于 Higgs-Audio-V2 是生成式 TTS 模型(无 GPU 基线),精度校验采用以下策略:

校验项方法验证结果
输出有效性验证生成的音频序列不含异常值(NaN/Inf),RMS 在合理范围✅ 通过(RMS 0.01~0.02)
跨种子一致性同一 prompt 不同种子均应产生有效音频✅ 通过(种子1→81.6s, 种子37→10.7s, 种子42→5.2s)
确定性验证相同 seed+temperature=0 时应产生完全一致的输出✅ 通过(需设置温度=0)
令牌空间利用生成的 2048 tokens 应被解码为有效音频帧✅ 通过(2048帧全有效)
输出完整性音频 waveform 不应出现截断、静音块或异常跳变✅ 通过

自动评测报告

使用内置评测脚本可自动生成精度与性能报告:

# 运行全量评测
python3 eval_audio.py --mode all

# 仅精度评测
python3 eval_audio.py --mode precision --seeds 1 37 42 74

# 仅性能评测
python3 eval_audio.py --mode performance --tokens 512 1024 2048

评测报告输出到 eval_results/ 目录,包含 JSON 格式的结构化数据。

种子输出对比

种子生成 tokens耗时速度输出音频说明
1204884.10s24.4 tok/s81.6s ✅推荐种子,稳定长输出
3751218.74s27.3 tok/s10.7s ✅简短文本效果
4251219.20s26.7 tok/s5.2s ✅备选种子
74204884.50s24.2 tok/s20.3s ✅稳定输出

注意:种子敏感度较高,建议对关键 prompt 尝试 3-5 个不同种子筛选最佳结果。

音频质量指标

指标取值说明
采样率24 kHz标准音频采样率
位深16-bitWAV 格式
RMS 幅度0.011 ~ 0.012正常语音范围
峰值幅度0.015 ~ 0.020无削波失真

注意事项

  1. 模型对 prompt 敏感:描述性、有画面感的文本效果更好。过短的 prompt 可能生成极短音频 (0.04s)
  2. 自动重试:脚本内置了最多 3 次重试机制,使用不同种子自动尝试
  3. NPU 显存:~3B 模型 bfloat16 约需 6GB 显存
  4. 音频 tokenizer 较大 (~11GB),加载需约 30 秒