fixie-ai/ultraVAD 是 Fixie.ai 推出的上下文感知、音频原生端点检测 (endpointing) 模型,用于实时估计说话人是否完成发言轮次 (turn-taking)。模型融合最近对话文本与用户音频,通过计算 P(<|eot_id|> | context, audio) 来判定是否应触发智能体回复。
turns + 用户音频 (16kHz, 任意时长) + 采样率has_speech, speech_segments, confidence) 与可选的端到端 P(<|eot_id|>) (阈值 0.1)本适配将 Whisper 音频编码器 + 投影器在 Ascend910 NPU (npu:0) 上通过 torch_npu 实现真实推理,帧级能量 VAD 与模型特征融合,提供 CLI 双模式接口。
npu:0 (PhyID 10, Bus 0000:0A:00.0)npu-smi info
torch.npu.is_available() == True
torch.npu.get_device_name(0) == "Ascend910_9362"pip install -r requirements.txt
# 推荐使用国内镜像
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simplerequirements.txt:
torch>=2.1.0
torch_npu>=2.1.0
transformers>=4.51
numpy
librosa>=0.10
soundfile
safetensors
accelerate
peft权重默认缓存在 ./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_downloadpython 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 benchmarkpython inference.py --mode server --port 8000
# POST /predict 上传音频在 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若提供真实语音文件,模型特征会产生非零 model_confidence (如 gcw 示例中 0.117),端到端 P(<|eot_id|>) 需完整 Llama-8B 权重 (约 16GB text_model) 才会额外输出。
由于完整模型 (含 Llama-8B) 需 16GB 额外权重,本适配采用特征级验证 (Whisper + 投影器) 在 CPU 与 NPU 上对比:
torch.float32 在 CPU 上执行同一输入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/,本仓库因单卡资源限制默认仅验证特征级。
同步计时 (torch.npu.synchronize() 前后) 结果:
| 阶段 | 配置 | 延迟 |
|---|---|---|
| 特征模型端到端 | 1 audio, 2.0s, 128 mels, 3000 frames, BF16, npu:0 | avg 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。
assets/agent_workflow.png — 环境检查、权重下载、模型加载、NPU 推理、验证、性能全流程assets/npu_device_call.png — npu-smi info、torch.npu.is_available()、设备名、模型参数 device/dtypeassets/model_result.png — 默认 python inference.py 完整输出、VAD 结果、性能与 PASSaudio_tower.layer_norm 权重为零,导致 embeds 全零,model_confidence 为 0.0,但能量 VAD 仍正确。需官方修复或重训以恢复特征打分。P(<|eot_id|>) 需额外 16GB 文本模型权重,默认不启用; 启用后需 attn_implementation="eager" 以兼容 Ascend flash-attention。eager 而非 flash_attention_2,避免 aclnnFlashAttentionScore 对 [B,1,1,T] 掩码形状不支持。Hardware: NPU, NPU, Ascend, Ascend910, VAD, audio, transformer, endpointing