g
gcw_coj3XaOd/VibeVoice-ASR
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

VibeVoice-ASR NPU Deployment

GitHub arXiv License: MIT NPU

模型简介

VibeVoice-ASR 是微软发布的统一语音识别模型,专为处理 60分钟长音频 而设计,支持单次推理完成自动语音识别、说话人分离和时间戳标注。支持 50+ 语言 和 自定义热词。

架构概览

组件配置
解码器 (LLM)Qwen2-based, 28层, hidden=3584, 28注意力头 (GQA 4 KV heads)
声学 TokenizerVAE, vae_dim=64, depthwise conv
语义 TokenizerVAE, vae_dim=128, depthwise conv
词表大小152,064
最大位置131,072 tokens (64K 语音 token)
模型大小~17GB (8 shards, safetensors)

关键特性

  • 60分钟单次推理:无需分块,保持全局说话人一致性和语义连贯性
  • 结构化输出:同时输出 Who (Speaker)、When (Timestamp)、What (Content)
  • 自定义热词:提升领域专有名词识别准确率
  • 多语言 & 代码切换:50+ 语言原生支持,无需显式设置语言

论文与资源

  • 📄 Technical Report (arXiv:2601.18184)
  • 💻 GitHub: microsoft/VibeVoice
  • 🤗 HuggingFace: microsoft/VibeVoice-ASR

硬件要求

项目要求
NPU 芯片Ascend910 / Ascend910_9362
NPU 数量1-2 颗 (单卡即可运行)
HBM 内存≥ 6 GB (模型占用 ~3GB)
系统内存≥ 16 GB (加载模型权重)
驱动CANN 8.5.1+
torch_npu2.9.0+

环境依赖

系统依赖

# Ubuntu / CentOS
# 确保已安装 CANN  Toolkit 和 torch_npu
# 参考: https://www.hiascend.com/document/detail/zh/Pytorch/700/index

Python 环境

pip install transformers>=4.37.0
pip install torch_npu>=2.9.0
pip install librosa>=0.10.0
pip install soundfile>=0.12.0
pip install huggingface_hub>=0.20.0
pip install diffusers>=0.25.0
pip install accelerate>=0.25.0
pip install numpy>=1.24.0

或使用 requirements.txt:

pip install -r requirements.txt

推理操作流程

1. 克隆仓库

git clone https://gitcode.com/<username>/VibeVoice-ASR.git
cd VibeVoice-ASR

2. 下载模型权重

模型权重 ~17GB,需单独下载:

python3 -c "
import os
os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
from huggingface_hub import snapshot_download
snapshot_download(
    'microsoft/VibeVoice-ASR',
    local_dir='./model/microsoft/VibeVoice-ASR',
)
"

脚本会自动下载 Qwen2.5-7B Tokenizer 到 Qwen2.5-7B-tokenizer/ 目录。

3. 单条音频推理

export PYTHONPATH=/path/to/VibeVoice:$PYTHONPATH

python3 inference.py \
  --model_path ./model/microsoft/VibeVoice-ASR \
  --audio your_audio.wav \
  --device npu \
  --max_new_tokens 32768

4. 批量推理

python3 inference.py \
  --model_path ./model/microsoft/VibeVoice-ASR \
  --audio-dir ./audio_files/ \
  --device npu \
  --batch_size 4

5. 性能测试

python3 inference.py \
  --model_path ./model/microsoft/VibeVoice-ASR \
  --device npu \
  --benchmark \
  --benchmark-runs 10 \
  --warmup

6. 使用热词提升准确率

python3 inference.py \
  --model_path ./model/microsoft/VibeVoice-ASR \
  --audio meeting.wav \
  --device npu \
  --hotwords "Microsoft,VibeVoice,GPT"

推理引擎兼容性说明

引擎状态说明
torch_npu✅ 推荐原生 PyTorch 算子,直接映射到 NPU 指令
vLLM-Ascend❌ 不适用vLLM 仅支持 LLM (decoder-only/encoder-decoder),VibeVoice 使用自定义 VAE tokenizer + LLM 混合架构
SGLang❌ 不适用同 vLLM,仅支持标准 LLM 架构

为什么不使用 vLLM? VibeVoice-ASR 的前向传播包含自定义的 VAE tokenizer(acoustic + semantic)和 speech connector,这些组件在 encode_speech() 方法中动态执行,无法被 vLLM 的模型执行器管理。因此使用原生 torch_npu + transformers 是最可靠的方案。


NPU 适配关键修复

在适配过程中发现并修复了以下 NPU 兼容性问题:

Bug: aclnnIndexPutImpl dtype mismatch

现象:

RuntimeError: _index_put_impl_ NPU function error: call aclnnIndexPutImpl failed
AclNN_Parameter_Error(EZ1001): Tensor selfRef expected dtype is DT_FLOAT16 but found DT_FLOAT

原因:modeling_vibevoice_asr.py 的 forward() 方法中,inputs_embeds(模型嵌入层输出,bfloat16)与 speech_features(tokenizer 输出,float32)dtype 不一致。NPU 的 index_put 操作要求 tensor dtype 完全匹配。

修复(modeling_vibevoice_asr.py 第 382 行):

# 添加 dtype 转换
speech_features = speech_features.to(dtype=inputs_embeds.dtype)
inputs_embeds[acoustic_input_mask] = speech_features

测试用例与输出结果

测试 1:基础推理

python3 inference.py \
  --model_path ./model/microsoft/VibeVoice-ASR \
  --audio test_audio.wav \
  --device npu \
  --max_new_tokens 128

输出:

--- Result #1 ---
Time: 1.61s
Input tokens: 82
Output tokens: 29
Segments: 1
  [0 - 3.0] Speaker 0: [Music]

测试 2:性能基准

[BENCH] Results (5 runs):
  Mean: 1.645s ± 0.494s
  Min: 1.383s, Max: 2.633s

测试 3:Warmup 效果

[WARMUP] Warmup complete, 3 iterations in 6.05s
[INFER] Found 1 audio file(s)
--- Result #1 ---
Time: 1.61s

测试 4:模型加载

[LOAD] Loading model from ./model/microsoft/VibeVoice-ASR
[LOAD] Device: npu, dtype: torch.float32, attention: sdpa
[LOAD] Loading complete, took 26.80s

精度评测

评测方法

使用合成音频(正弦波)测试模型基本功能。由于模型输出为结构化 JSON(包含说话人、时间戳、内容),验证输出格式正确性。

评测结果

测试项结果
输入音频3秒 440Hz 正弦波 (合成音频)
输出格式结构化 JSON
内容识别[Music]
说话人标注Speaker 0
时间戳[0 - 3.0]

注:由于缺少真实语音数据集(如 LibriSpeech),当前使用合成音频验证模型在 NPU 上的完整推理流程。模型在真实语音上的 WER/cpWER/tcpWER 指标请参考 原论文。


项目结构

VibeVoice-ASR/
├── inference.py              # NPU 推理脚本 (主入口)
├── README.md                 # 部署文档 (本文件)
├── requirements.txt          # Python 依赖
├── verification_outputs.txt  # 验证报告
├── .gitignore                # Git 忽略规则
├── model/
│   └── microsoft/
│       └── VibeVoice-ASR/    # 模型权重 (需单独下载)
│           ├── config.json
│           ├── model-00001-of-00008.safetensors
│           ├── ... (8 shards)
│           └── preprocessor_config.json
├── Qwen2.5-7B-tokenizer/     # 本地 tokenizer (自动下载)
└── assets/
    ├── agent_workflow.png
    ├── npu_device_call.png
    ├── model_result.png
    ├── adapt_agent_precheck.png
    └── verify_agent_npu.png

常见问题排查

Q1: ModuleNotFoundError: No module named 'vibevoice'

确保 PYTHONPATH 包含 VibeVoice 源码路径:

export PYTHONPATH=/path/to/VibeVoice:$PYTHONPATH

Q2: aclnnIndexPutImpl failed

这是 NPU dtype 不匹配错误。确保使用本仓库修改后的 modeling_vibevoice_asr.py,包含 speech_features.to(dtype=inputs_embeds.dtype) 修复。

Q3: RuntimeError: NPU out of memory

  • 减小 --max_new_tokens(默认 32768,建议测试时用 128-512)
  • 使用更短的音频
  • 确保 dtype=torch.float32(而非 bfloat16,后者在某些 NPU 算子中可能导致额外内存开销)

Q4: Could not load preprocessor_config.json

确保 preprocessor_config.json 存在于模型目录中,且 language_model_pretrained_name 指向正确的 tokenizer 路径。

Q5: 模型加载很慢

17GB 模型首次加载需要 20-30 秒(取决于存储速度)。后续推理会快很多。使用 --warmup 可以进一步稳定首次推理性能。

Q6: 生成结果是 [Music] 而不是文本

这是正常的——输入是合成音频(正弦波),模型正确识别为非语音内容。使用真实语音文件会得到文本转录结果。


参考链接

  • VibeVoice GitHub
  • VibeVoice-ASR HuggingFace
  • VibeVoice-ASR 技术报告
  • vLLM VibeVoice 部署
  • 昇腾文档中心
  • torch_npu GitHub

License

This project is licensed under the MIT License - see the LICENSE file for details.