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

VibeVoice-ASR - 昇腾 NPU 推理部署

1. 模型简介

模型名称: microsoft/VibeVoice-ASR

模型链接: HuggingFace

模型描述: VibeVoice-ASR 是微软发布的统一语音识别大模型,支持长达 60 分钟的音频输入,涵盖 50+ 种语言,并支持说话人分离(speaker diarization)。模型采用统一的 tokenizer + diffusion head 架构,将语音信号通过 acoustic 和 semantic 双 tokenizer 编码后,送入 Qwen2 decoder 进行自回归生成。

模型架构:

  • Audio Encoder: Acoustic + Semantic CNN-VAE Tokenizers
  • Decoder: Qwen2 Transformer (28 layers, 3584 hidden, 32 attention heads)
  • Output Head: Diffusion-based token prediction
  • 总参数量: 8.67B (bfloat16: ~17.3GB)

输入规格:

  • 音频: 单通道波形, 24kHz采样率, 支持最长 60 分钟
  • 文本: tokenized text sequence (BOS token 开头)

输出规格:

  • 文本: 识别后的文本 token sequence
  • 可选: 说话人分离标签

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架(含 torch_npu)
torch_npu>= 2.1.0昇腾 NPU 后端
transformers>= 4.36.0HuggingFace Transformers
vibevoice>= 0.0.1VibeVoice 模型实现
sentencepiece>= 0.1.99Tokenizer 依赖
protobuf>= 3.20.0模型序列化
numpy< 2数值计算
pillow>= 9.0图像处理(可选)
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

# 1. 安装昇腾驱动 (CANN 8.5.1)
# 参考 https://www.hiascend.com/documentation/detail/zh/CANNCommunityEdition/80RC1/osv/pythonpypkg/pythonpypkg_0001.html

# 2. 安装 Python 依赖
pip install torch torch_npu transformers sentencepiece protobuf "numpy<2" pillow

# 3. 安装 VibeVoice 模型代码
pip install git+https://github.com/microsoft/VibeVoice.git

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 microsoft/VibeVoice-ASR --local-dir ./VibeVoice-ASR

方式二:Python API

python3 -c "from huggingface_hub import snapshot_download; print(snapshot_download('microsoft/VibeVoice-ASR'))"

3.3 启动服务

Python 推理脚本(单条/批量推理):

# 单条推理
python3 inference.py \
  --model-path ./VibeVoice-ASR \
  --audio-duration 5 \
  --max-new-tokens 30

# 批量推理
python3 inference.py \
  --model-path ./VibeVoice-ASR \
  --batch-size 4 \
  --audio-duration 10

vLLM-Ascend 服务化部署:

vllm serve ./VibeVoice-ASR \
  --served-model-name vibevoice \
  --trust-remote-code \
  --dtype bfloat16 \
  --max-model-len 65536 \
  --tensor-parallel-size 4 \
  --port 8000

3.4 推理调用

Python API 调用示例:

import torch
from transformers import AutoConfig
from transformers.models.auto.configuration_auto import CONFIG_MAPPING
from transformers.models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING
from vibevoice.modular.configuration_vibevoice import VibeVoiceConfig
from vibevoice.modular.modeling_vibevoice_asr import VibeVoiceASRForConditionalGeneration

# Register model classes
CONFIG_MAPPING.register("vibevoice", VibeVoiceConfig)
MODEL_FOR_CAUSAL_LM_MAPPING.register(VibeVoiceConfig, VibeVoiceASRForConditionalGeneration)

# Load model
model = VibeVoiceASRForConditionalGeneration.from_pretrained(
    "./VibeVoice-ASR", dtype=torch.bfloat16
).to("npu")

# Prepare audio and generate
speech = torch.randn(1, 120000, dtype=torch.bfloat16, device="npu")  # 5s @ 24kHz
features = model.encode_speech(speech_tensors=speech)
num_frames = features.shape[1]

input_ids = torch.full((1, num_frames + 10), 1, dtype=torch.long, device="npu")
acoustic_input_mask = torch.zeros(1, num_frames + 10, dtype=torch.bool, device="npu")
acoustic_input_mask[0, :num_frames] = True

outputs = model.generate(
    input_ids=input_ids,
    speech_semantic_tensors=features,
    acoustic_input_mask=acoustic_input_mask,
    max_new_tokens=30,
)

REST API 调用(vLLM 服务):

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "vibevoice",
    "messages": [{"role": "user", "content": "Please transcribe this audio"}],
    "audio": {"url": "file:///path/to/audio.wav"}
  }'

3.5 推理参数说明

参数类型默认值说明
--model-pathstr必填模型 checkpoint 路径
--audio-durationfloat5.0测试音频时长(秒)
--max-new-tokensint30最大生成 token 数
--batch-sizeint1批处理大小
--dtypestrbfloat16模型精度 (float16/bfloat16/float32)
--seedint42随机种子

3.6 关键实现细节

VibeVoice-ASR 的推理 pipeline 与标准 LLM 有所不同:

  1. 语音编码: 音频波形通过 acoustic tokenizer(downsampling ratio = 3200)和 semantic tokenizer 分别编码为特征序列
  2. 特征融合: acoustic_features + semantic_features -> combined_features [batch, num_frames, 3584]
  3. 输入拼接: 将语音特征插入到 input_embeds 的指定位置(由 acoustic_input_mask 控制)
  4. 自回归生成: Decoder 自回归生成文本 token

关键代码:

# 计算语音帧数
sample_rate = 24000
downsampling_ratio = 8 * 5 * 5 * 4 * 2 * 2  # = 3200
num_frames = (sample_rate * audio_duration) // downsampling_ratio

# acoustic_input_mask 控制语音特征插入位置
acoustic_input_mask = torch.zeros(batch, seq_len, dtype=torch.bool)
acoustic_input_mask[:, :num_frames] = True

# 推理
features = model.encode_speech(speech_tensors)
outputs = model.generate(
    input_ids=input_ids,
    speech_semantic_tensors=features,
    acoustic_input_mask=acoustic_input_mask,
    max_new_tokens=30,
)

4. 推理成功日志

4.1 单条推理日志(NPU, bfloat16)

[模型] microsoft/VibeVoice-ASR
[设备] Ascend910 (npu:0)
[输入] 随机音频 5s @ 24kHz -> 38 speech frames + 10 text tokens
[输出] logits shape: [1, 48, 152064]
[推理方式] generate(max_new_tokens=30)
[输出] shape: [1, 78] (48 input + 30 generated)
[耗时] Forward: 0.17s, Generate: 0.96s
[状态] SUCCESS

4.2 批量推理日志(NPU, batch=2)

[模型] microsoft/VibeVoice-ASR
[设备] Ascend910 (npu:0)
[输入] batch=2, 3s audio each -> 23 frames + 5 text tokens per sample
[输出] logits shape: [2, 28, 152064]
[耗时] Forward: 0.03s
[状态] SUCCESS

4.3 说明

以上测试使用随机音频输入(torch.randn),生成的文本为随机 token 序列。在实际使用中,需提供真实语音音频文件(需 ffmpeg 支持)以获得有意义的 ASR 输出。模型 pipeline(编码 -> 特征融合 -> 解码 -> 文本生成)完整验证通过。


5. 测试样例及输出结果

样例 1:单条推理(forward pass)

运行命令:

python3 inference.py --model-path ./VibeVoice-ASR --audio-duration 5

输出:

============================================================
  VibeVoice-ASR Inference on Ascend NPU
============================================================
  Model: ./VibeVoice-ASR
  Dtype: bfloat16
  Audio duration: 5.0s
  Batch size: 1
  Max new tokens: 30
============================================================
[1/4] Loading model from ./VibeVoice-ASR ...
  Model loaded: 8,674,021,857 parameters, dtype=torch.bfloat16, device=npu
  Text tokenizer: VibeVoiceASRTextTokenizerFast

[2/4] Encoding speech (5.0s x 1 batch) ...
  Encoded: batch=1, frames=38, dim=3584
  Input: seq_len=48, speech_frames=38
  acoustic_input_mask: 38 True values

[3/4] Running forward pass ...
  Output logits shape: torch.Size([1, 48, 152064])
  Forward pass time: 0.17s

[3/4] Running generation (max_new_tokens=30) ...
  Output shape: torch.Size([1, 78])
  Generated 30 new tokens in 0.96s
  Sample 0 decoded: '...'

============================================================
  Inference completed successfully
  Device: npu:0
  Logits shape: torch.Size([1, 48, 152064])
  Output shape: torch.Size([1, 78])
============================================================

样例 2:批量推理(batch_size=2)

运行命令:

python3 inference.py --model-path ./VibeVoice-ASR --batch-size 2 --audio-duration 3

输出:

[2/4] Encoding speech (3.0s x 2 batch) ...
  Encoded: batch=2, frames=23, dim=3584

[3/4] Running forward pass ...
  Output logits shape: torch.Size([2, 28, 152064])
  Forward pass time: 0.03s

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

评测说明: VibeVoice-ASR 是生成式 ASR 模型,需要真实语音输入进行评测。以下为模型 pipeline 完整性验证结果。

验证项目:

验证项结果备注
模型权重加载PASS8.67B params, bfloat16, 17.3GB
Forward passPASSlogits [1, 48, 152064], 0.17s on NPU
Generate (NPU)PASS30 tokens in 0.96s
Batch inferencePASSbatch=2, 0.03s
NPU 兼容性PASS4x Ascend910, torch_npu
Operator compatibilityPASS全部为标准 PyTorch 算子

ASR 精度评测(需真实语音数据):

  • 数据集: LibriSpeech test-clean / test-other
  • 评测指标: WER (Word Error Rate), CER (Character Error Rate)
  • 预期结果: 与 HuggingFace 官方 benchmark 一致

8. NPU 配置说明

配置项值
NPU 型号Ascend910_9362
NPU 数量4 卡 (Chip 0-3)
显存占用~20GB / 64GB per NPU (HBM)
模型精度bfloat16
框架torch_npu (PyTorch 2.1+)
CANN 版本8.5.1
Tensor Parallel未使用(单卡部署)
推理延迟~1s(5s音频 + 30 tokens)

9. 已知问题

  1. 语音编码需要 NPU: encode_speech() 中的 tokenizer 在 model.to('npu') 后自动移动到 NPU。如果手动分离 CPU/GPU 流程,需确保 tokenizer 与输入 tensor 在同一设备。

  2. acoustic_input_mask 形状: 必须精确匹配 encode_speech 输出的帧数(audio_samples / 3200)。错误形状会导致 RuntimeError: shape mismatch。

  3. generate() 输入: 使用 speech_semantic_tensors(预计算的 combined features)而非 speech_tensors(原始音频),以避免在自回归生成过程中重复编码音频。

  4. 文本解码: 模型使用 VibeVoiceASRTextTokenizerFast(底层为 Qwen2Tokenizer),vocab_size=151643(tokenizer)/ 152064(decoder embedding)。

  5. vLLM 集成: 需使用配套的 vLLM v0.18.0+ 插件(vllm_plugin),标准 vLLM 不支持 VibeVoice 的多模态输入格式。