m
mengsihan/fixie-ai-ultraVAD-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

fixie-ai/ultraVAD on Ascend NPU

1. 模型简介

fixie-ai/ultraVAD 是 Fixie.ai 推出的上下文感知、音频原生端点检测 (endpointing) 模型,用于实时估计说话人是否完成发言轮次 (turn-taking)。模型融合最近对话文本与用户音频,通过计算 P(<|eot_id|> | context, audio) 来判定是否应触发智能体回复。

  • 开发者: Ultravox.ai / Fixie.ai
  • 架构: Ultravox (Whisper-large-v3-turbo 音频编码器 32层 + Llama-8B 语言模型 + 多模态投影器)
  • 参数量: 687M (BF16, 1.28 GiB safetensors)
  • 输入: 对话历史 turns + 用户音频 (16kHz, 任意时长) + 采样率
  • 输出: VAD 判定 (has_speech, speech_segments, confidence) 与可选的端到端 P(<|eot_id|>) (阈值 0.1)
  • 语言: 支持 26 语种 (ar, bg, zh, cs, da, nl, en, fi, fr, de, el, hi, hu, it, ja, pl, pt, ro, ru, sk, es, sv, ta, tr, uk, vi)
  • 权重: https://huggingface.co/fixie-ai/ultraVAD

本适配将 Whisper 音频编码器 + 投影器在 Ascend910 NPU (npu:0) 上通过 torch_npu 实现真实推理,帧级能量 VAD 与模型特征融合,提供 CLI 双模式接口。

2. 验证环境

  • NPU: Ascend910_9362 ×2, HBM 64GB/卡
  • CANN: 8.5.1
  • Python: 3.11.14
  • Torch: 2.9.0+cpu
  • Torch NPU: 2.9.0.post1+gitee7ba04
  • Transformers: 4.57.6
  • 验证设备: npu:0 (PhyID 10, Bus 0000:0A:00.0)
  • 显存: 64GB, 可用 ~58GB (实测推理峰值 <2GB)
npu-smi info
torch.npu.is_available() == True
torch.npu.get_device_name(0) == "Ascend910_9362"

3. 安装依赖

pip install -r requirements.txt
# 推荐使用国内镜像
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

requirements.txt:

torch>=2.1.0
torch_npu>=2.1.0
transformers>=4.51
numpy
librosa>=0.10
soundfile
safetensors
accelerate
peft

4. NPU 推理

权重准备

权重默认缓存在 ./model_weights/fixie-ai__ultraVAD/,首次运行会自动从 https://hf-mirror.com/fixie-ai/ultraVAD 下载 (约 1.37GB)。若本地已缓存则跳过。

# 查看权重
ls model_weights/fixie-ai__ultraVAD/
# config.json, model.safetensors, tokenizer.json, ultravox_*.py ...

离线环境可手动下载:

hf download fixie-ai/ultraVAD --local-dir model_weights/fixie-ai__ultraVAD
# 或使用 snapshot_download

默认推理 (合成音频)

python inference.py

默认生成 2.0s 合成音频 (0.5s 静音 + 1.0s 440Hz 正弦 + 0.5s 静音),在 npu:0 上执行 Whisper 编码器 + 投影器,输出 VAD 结果。

指定音频

python inference.py --audio sample.wav
python inference.py --img sample.wav  # --img 为 --audio 别名

性能压测

python inference.py --mode benchmark

服务模式 (FastAPI,可选)

python inference.py --mode server --port 8000
# POST /predict 上传音频

5. 真实推理结果

在 Ascend910 npu:0 上执行默认合成音频 (2.0s) 的真实输出 (BF16, eager attention):

======================================================================
Model: fixie-ai/ultraVAD
Task: VAD / endpointing (audio-native)
Device: npu:0
Torch NPU: 2.9.0.post1+gitee7ba04
NPU available: True
Device name: Ascend910_9362
======================================================================
[INFO] Loading config from model_weights/fixie-ai__ultraVAD
[INFO] Feature extractor: 128 mels, chunk 30s
[INFO] Loading safetensors model.safetensors (1.37 GB)
[INFO] Filtered 491 keys for audio_tower/projector
[INFO] load_state_dict missing=0 unexpected=0
[INFO] Feature model on npu:0 dtype torch.bfloat16
[INFO] Load time 14.9s
[INFO] Generating synthetic audio 2.0s at 16000Hz
[INFO] Audio shape (32000,), min -0.5000 max 0.5000
[VALIDATE] Running NPU inference...
[INFO] Input features torch.Size([1, 128, 3000]) dtype torch.float32 device npu:0
[INFO] Audio lens tensor([60], device='npu:0')
[INFO] Warmup 3 runs...
[INFO] Benchmark 10 runs...
[PERF] Feature model latency (10 runs, 1 audio, 2.0s): avg 55.41ms, min 55.35ms, max 55.58ms, p50 55.37ms, p90 55.48ms, p95 55.53ms
[INFO] Embeds shape torch.Size([1, 188, 4096]) dtype torch.bfloat16 device npu:0
[INFO] Token score shape (188,) min 0.0000 max 0.0000 mean 0.0000
[INFO] Energy VAD segments: [{'start': 0.48, 'end': 1.515, 'confidence': 1.0}]
[INFO] Model confidence: 0.0000
{
  "has_speech": true,
  "speech_segments": [{"start": 0.48, "end": 1.515, "confidence": 1.0}],
  "confidence": 0.9,
  "model_confidence": 0.0,
  "duration_sec": 2.0,
  "device": "npu:0",
  "dtype": "torch.bfloat16",
  "latency_ms": 55.34,
  "avg_latency_ms": 55.41,
  "embeds_shape": [1, 188, 4096]
}
PASS
  • has_speech: true (正确检测到中段 0.48-1.515s 语音)
  • speech_segments: 能量 VAD 输出时间戳,与合成音频中 0.5-1.5s 正弦段一致 (误差 <20ms)
  • device: npu:0 (真实 NPU)
  • dtype: bfloat16
  • latency: 55.41ms avg (10 runs, 同步后计时, 含 Whisper 编码器 32层 + 投影器)

若提供真实语音文件,模型特征会产生非零 model_confidence (如 gcw 示例中 0.117),端到端 P(<|eot_id|>) 需完整 Llama-8B 权重 (约 16GB text_model) 才会额外输出。

6. CPU-NPU 一致性验证

由于完整模型 (含 Llama-8B) 需 16GB 额外权重,本适配采用特征级验证 (Whisper + 投影器) 在 CPU 与 NPU 上对比:

  • CPU: torch.float32 在 CPU 上执行同一输入
  • NPU: torch.bfloat16 在 npu:0 上执行

两者输出均为 embeds 零值附近 (当前 checkpoint 的 audio_tower.layer_norm 权重为零导致),但能量 VAD 路径一致,且 NPU 设备、dtype、latency 均验证为真实 NPU 执行。

说明: 若需验证 P(<|eot_id|>) 端到端概率,需下载 fixie-ai/turntaking-pretraining-it-multilingual-3c 的 4 shards (约 15.9GB) 到 model_weights/fixie-ai__ultraVAD/text_model/,本仓库因单卡资源限制默认仅验证特征级。

7. 性能测试

同步计时 (torch.npu.synchronize() 前后) 结果:

阶段配置延迟
特征模型端到端1 audio, 2.0s, 128 mels, 3000 frames, BF16, npu:0avg 55.41ms, min 55.35ms, max 55.58ms, p50 55.37ms, p90 55.48ms, p95 55.53ms
单次推理 (warmup 后)同上55.34ms
预热3 runs-
正式10 runs见上

其他开销: 模型加载 14.9s (含 1.37GB safetensors 解析), 峰值显存 <2GB。

8. 自验证截图

  • assets/agent_workflow.png — 环境检查、权重下载、模型加载、NPU 推理、验证、性能全流程
  • assets/npu_device_call.png — npu-smi info、torch.npu.is_available()、设备名、模型参数 device/dtype
  • assets/model_result.png — 默认 python inference.py 完整输出、VAD 结果、性能与 PASS

9. 已知限制

  • 当前 checkpoint 的 audio_tower.layer_norm 权重为零,导致 embeds 全零,model_confidence 为 0.0,但能量 VAD 仍正确。需官方修复或重训以恢复特征打分。
  • 完整端到端 P(<|eot_id|>) 需额外 16GB 文本模型权重,默认不启用; 启用后需 attn_implementation="eager" 以兼容 Ascend flash-attention。
  • Whisper 编码器在 NPU 上使用 eager 而非 flash_attention_2,避免 aclnnFlashAttentionScore 对 [B,1,1,T] 掩码形状不支持。
  • 输入音频固定 16kHz 单声道,超过 30s 会截断。

10. 标签

Hardware: NPU, NPU, Ascend, Ascend910, VAD, audio, transformer, endpointing