w
gcw_uQ09W7jl/pyannote-segmentation-3.0-NPU
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

pyannote/segmentation-3.0 NPU 适配

本仓库为 pyannote/segmentation-3.0 在华为昇腾 910B (Ascend910_9362, npu:0) 上的适配验证。基于 PyanNet (SincNet 前端 + 4 层双向 LSTM + 2 层线性 + Sigmoid 分类器) 的自包含 PyTorch 实现,通过 torch_npu 在单卡 NPU 上实现端到端 audio → 语音段时间戳 推理。

模型信息

  • 模型:pyannote/segmentation-3.0 (MIT)
  • 权重:pytorch_model.bin (17M) — 通过本地 model_cache_pyannote_seg 离线加载,禁止在线下载
  • 配置:task.duration=5.0s, max_num_speakers=3, sample_rate=16000, sincnet.stride=10, lstm.hidden=128 x4 bidirectional monolithic, linear.hidden=128 x2
  • 后端:自包含 PyanNet (asteroid-filterbanks.ParamSincFB) + pyannote.audio VAD 后处理,无 pyannote.audio 依赖
  • VAD 超参:onset=0.8104, offset=0.4807, min_duration_on=0.0554s, min_duration_off=0.0979s

NPU 适配说明

  • 设备:真实 npu:0 执行,torch.npu.is_available()=True, device_count=2, device_name=Ascend910_9362,模型参数 / 输入 waveform / 输出概率张量均在 npu:0
  • VAD 管线:滑动窗口 (5s window, 0.5s step) → Hamming 加窗 overlap-add 聚合 → crop 至音频时长 → hysteresis 二值化 → min_duration 过滤
  • NPU 兼容:修补 torch.load 的 pyannote.* 桩模块以支持 checkpoint 反序列化;同步计时 torch.npu.synchronize() 区分首次编译与稳定推理
  • 输入契约:真实 13s 16kHz 单声道音频 (208000 samples),重采样 torchaudio.functional.resample,shape [1,1,80000] 窗口
  • 输出契约:非空、有限、单调递增的语音段集合 [[start,end], ...]

使用方法

pip install -r requirements.txt
# CPU
python inference.py --checkpoint pytorch_model.bin --audio audio.wav --output segments.json --device cpu
# NPU
python inference.py --checkpoint pytorch_model.bin --audio audio.wav --output segments.json --device npu:0
# Benchmark (生成 benchmark.jsonl 供 benchmark_model.py)
python inference.py --checkpoint pytorch_model.bin --audio audio.wav --device npu:0 --benchmark --samples 8 --warmup 1 --benchmark-output benchmark.jsonl
python ../scripts/benchmark_model.py benchmark.jsonl

验证结果

  • 测试音频:mlk.flac (13.00s, 16000Hz, 真实语音含语音/静音段) — 满足“时长覆盖语音与静音两种区域”要求
  • CPU 4 段:[1.118-2.278, 3.677-4.633, 6.340-8.746, 10.145-12.705]
  • NPU 4 段:[1.101-2.278, 3.677-4.633, 6.340-8.746, 10.145-12.688]
  • 一致性 (VAD):segment_count_delta=0, max_timestamp_delta=0.017s (<0.05s), coverage_delta≈0, region_iou=0.994 (>0.99) → PASS
  • 性能 (同步 NPU, warmup=1, samples=8):first_run_latency=100.35ms, stable_mean=67.76ms, p50=50.30ms, RTF=0.0052, frames/s≈12365 → PASS
  • 设备证明:model param device npu:0, input npu:0 (1,1,80000), output npu:0 (1,293,3), finite=True

证据图

agent workflow npu device call model result

许可

MIT