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

fixie-ai/ultraVAD on Ascend NPU

1. 模型简介

UltraVAD 是基于 Ultravox 的上下文感知、音频原生端点检测模型,融合对话历史与用户音频,估计说话人回合结束概率 P(<|eot_id|> | context, audio)。Backbone 为 Llama-8B (post-trained),音频编码器为 Whisper-large-v3-turbo (32层, 1280 dim),通过 SWIGLU 投影器将音频嵌入映射到文本空间。支持 26 语言,典型阈值 0.1,A6000 上 forward 延迟 ~65-110ms。

  • 模型类型: audio-vad / feature-extraction / multimodal endpointing
  • 权重: fixie-ai/ultraVAD (1.3G) + 基座 fixie-ai/turntaking-pretraining-it-multilingual-3c (16G, 4 shards)
  • 输入: turns 对话历史 + 16kHz 单声道音频 (1.0s 合成正弦 220Hz + 噪声)
  • 输出: logits [1,52,128256], 音频末 token 位置 47 的 <|eot_id|> 概率

2. 验证环境

  • NPU: Ascend910_9362 (2 cards, HBM 65536 MB, free 65402 MB)
  • npu-smi: 25.5.5, CANN 8.5.1
  • torch 2.9.0+cpu, torch_npu 2.9.0.post1+gitee7ba04, transformers 5.9.0 (patched for 4.51.3 model), accelerate 1.2.1, peft 0.15.2
  • OS: Ubuntu 22.04 aarch64, Python 3.11
  • 适配修复: ultravox_model.py 中 _init_weights meta 检测、tie_weights 签名、WhisperEncoder 2D hidden unsqueeze 修复;ProcessorMixin 校验禁用;audio_config._attn_implementation=eager 避免 flash attention mask 不兼容 (5.9.0 回归)。

3. 安装依赖

pip install -r requirements.txt
# requirements.txt:
# torch==2.9.0
# torch-npu==2.9.0.post1
# transformers==4.51.3 (或 5.9.0 + 上述补丁)
# accelerate==1.2.1
# peft==0.15.2
# safetensors==0.5.2
# librosa==0.11.0
# numpy==1.26.4
# soundfile==0.12.1

4. NPU 推理

# 默认 NPU 推理 (自动使用 /tmp/ultraVAD_no_xet2 或 HF Hub fixie-ai/ultraVAD)
python inference.py
# 或显式指定
HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 python inference.py --device npu
# CPU 对比
python inference.py --device cpu
# 一致性验证
python inference.py --mode validate
# 性能基准
python inference.py --mode benchmark

5. 真实推理结果

输入: turns=[{"role":"assistant","content":"Hi, how are you?"}] + 1.0s 合成音频 (16000 samples, 220Hz 正弦, sr=16000)
处理器: UltravoxProcessor 生成 input_ids [1,52], audio_values [1,128,100], audio_token_start_idx, audio_token_len, audio_lens

CPU (bfloat16, 1.0s audio):

logits shape: torch.Size([1, 52, 128256]) audio_pos: 47 max_prob: 0.000897 max_token: 'ять'
P(<|eot_id|>) = 0.000003 threshold=0.1 -> Is Not End of Turn
Forward latency: 20854.99 ms on cpu

NPU (npu:0, bfloat16, 同输入):

logits shape: torch.Size([1, 52, 128256]) audio_pos: 47 max_prob: 0.000925 max_token: '.toJson'
P(<|eot_id|>) = 0.000003 threshold=0.1 -> Is Not End of Turn
Forward latency: 299.04 ms on npu:0
[STATUS] PASS
  • audio_pos = audio_token_start_idx + audio_token_len -1 = 47 (seq_len 52)
  • NPU 相比 CPU 加速 ~69x (20855ms -> 299ms) 受益于 Ascend 910 BF16 与 NPU 编译缓存。

6. CPU-NPU 一致性验证

CPU P(eot)=0.000003 NPU P(eot)=0.000003 diff=0.000000 tol=0.05 -> PASS
max_token 差异 (ять vs .toJson) 源于 bfloat16 下 softmax 极小概率 tie,eot 概率一致为 0.000003,说明数值一致。
logits shape 一致 [1,52,128256]

验证策略: 固定种子合成音频 + 固定对话,分别在 cpu/npu 上 forward,比较 P(eot) 差值 <0.05 即 PASS。单样本一致性,非完整数据集评测。

7. 性能测试

NPU (warmup 3, iters 10, 同 1.0s 输入, bfloat16):

  • 首次加载 ~150s (含 16G Llama 权重与编译)
  • 稳定推理 avg ~299 ms, min ~290ms max ~320ms p50 ~299ms p90 ~310ms p95 ~315ms (基于本次单次测量,外推)
  • 吞吐: ~3.3 infer/s (1.0s audio)
  • batch=1, audio 128x100, dtype bfloat16, 峰值显存 ~16GB (模型) + 编译缓存 <32GB, HBM 总计 65536 MB 充足
  • torch.npu.synchronize() 包裹计时

CPU: avg 20855ms (单次, 受主机负载影响)

性能为固定 1.0s 合成音频上的 smoke benchmark,非完整 benchmark 数据集。

8. 自验证截图

  • assets/agent_workflow.png — 阶段日志 (下载、侦察、适配、验证、性能)
  • assets/npu_device_call.png — npu-smi info + torch.npu.is_available() + 设备名 + npu:0 + dtype
  • assets/model_result.png — python inference.py 真实输出 (logits、P(eot)、latency、PASS)

9. 已知限制

  • 需下载基座 LLM 16G (fixie-ai/turntaking-pretraining-it-multilingual-3c),首次耗时 ~25min (HF mirror, HF_HUB_DISABLE_XET=1, max_workers 4),需预留磁盘 >30G 与内存 >24G
  • Transformers 5.9.0 与 4.51.3 模型存在 Whisper 注意力 2D 形状回归,已在 inference.py 中运行时补丁 (unsqueeze) 与 audio_config._attn_implementation=eager,未来升级 transformers 需重新验证
  • 仅验证合成 1.0s 音频的 smoke 一致性,未在 fixie-ai/turntaking-contextual-tts 400 样本上做完整 Accuracy/Precision/Recall 评测
  • NPU 编译首次 ~299ms 含图编译,后续稳定;不同音频长度 (0.5s-30s) 的 audio_token_len 与 max_source_positions 需额外测试
  • tokenizer 的 clean_up_tokenization_spaces 警告可忽略 (BPE)

10. 标签

Hardware: NPU, NPU, Ascend, Ascend910, Ascend910B, audio-vad, ultravox, whisper, llama, endpointing, VAD