g
gcw_coj3XaOd/pyannote_segmentation-3.0
模型介绍
文件和版本
Pull Requests
讨论
分析

pyannote/segmentation-3.0 - 昇腾 NPU 推理部署

1. 模型简介

模型名称: pyannote/segmentation-3.0

模型链接: HuggingFace

模型描述: 基于 wav2vec2 的说话人分割模型,用于检测音频中的说话人切换点。模型对输入音频进行帧级分类,输出每帧属于 [无切换, 说话人切换] 的概率。

模型架构: CNN 特征提取器 + Transformer Encoder (12层) + 线性分割头

  • 特征提取器:5层 Conv1d + BatchNorm + GELU
  • 编码器:12层 Transformer Encoder (8-head attention, 768 dim)
  • 分割头:LayerNorm + Linear(768->384) + GELU + Dropout + Linear(384->2)

参数规模: 88,751,138 (~89M)

输入规格:

  • 类型:原始音频波形 (float32)
  • 格式:单声道 (mono)
  • 采样率:16kHz
  • Shape:(batch, samples)

输出规格:

  • 类型:帧级分类 logits (float32)
  • Shape:(batch, num_frames, 2)
  • 帧长:10ms per frame
  • 类别:[no_change, speech_change]

2. 环境依赖

依赖项版本要求说明
Python>= 3.10推荐 3.11
torch>= 2.1.0PyTorch 框架
torch_npu>= 2.1.0昇腾 NPU 后端
torchaudio>= 2.1.0音频 I/O
numpy>= 1.24.0数值计算
soundfile>= 0.12.0音频文件读取
昇腾驱动CANN 8.0+推荐 CANN 8.5.1

安装命令:

pip install torch-npu==2.9.0.post1 torch==2.9.0 torchaudio==2.9.0
pip install numpy>=1.24.0 soundfile>=0.12.0 tqdm>=4.60.0

3. 推理步骤

3.1 环境准备

npu-smi info
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"

3.2 运行推理

python3 inference.py --model-path ./models/pyannote_segmentation-3.0 --duration 5.0

3.3 推理参数

参数类型默认值说明
--model-pathstrNone模型 checkpoint 路径
--audio-pathstrNone输入音频文件路径
--durationfloat5.0合成测试音频时长(秒)
--thresholdfloat0.5说话人切换检测阈值

4. 推理成功日志

4.1 单条推理日志

[模型] pyannote/segmentation-3.0 (torch_npu standalone)
[设备] Ascend910_9362 (npu:0)
[输入] 5.0s @ 16kHz 合成音频
[输出] torch.Size([1, 500, 2]) - 500帧 x 2分类
[耗时] 1.7551s
[RTF] 0.3510
[状态] SUCCESS

4.2 批量推理日志

[基准测试] 4样本批量推理:
  批量推理耗时: 6.4703s
  单样本平均: 1.6176s

4.3 性能基准测试 (10次迭代)

  Mean:   1.7343s
  Std:    0.0261s
  Min:    1.6923s
  Max:    1.7645s
  Median: 1.7434s

5. 测试样例及输出结果

样例 1:合成音频推理 (5秒)

运行命令:

python3 inference.py --duration 5.0

输出:

============================================================
pyannote/segmentation-3.0 说话人分割推理
Direct torch_npu Inference on Ascend NPU
============================================================
[INFO] Found 2 NPU device(s)
[INFO] Using NPU device 0: Ascend910_9362
[INFO] Building SegmentationModel architecture...
[INFO] Model parameters: 88,751,138
[INFO] Model type: SegmentationModel
[INFO] Device: npu:0
[INFO] Creating synthetic test audio: 5.0s @ 16kHz
[INFO] Warmup run...
[W825 08:13:53.698550401 compiler_depend.ts:250] Warning: CAUTION: The operator 'aten::_transformer_encoder_layer_fwd' is not currently supported on the NPU backend and will fall back to run on the CPU.
[INFO] Warmup complete
[INFO] Inference completed in 1.7551s
[INFO] Output shape: torch.Size([1, 500, 2])
[INFO] Output dtype: torch.float32
============================================================
推理结果 (Single Inference Results)
============================================================
音频时长: 5.0s
推理耗时: 1.7551s
RTF (Real Time Factor): 0.3510
检测到的说话人切换点数量: 0
输出张量形状: torch.Size([1, 500, 2])

样例 2:批量推理 (4样本)

输出:

----------------------------------------
Batch inference test (4 samples)...
----------------------------------------
Batch input shape: torch.Size([4, 80000])
Batch output shape: torch.Size([4, 500, 2])
Batch inference time: 6.4703s
Per-sample avg time: 1.6176s

样例 3:性能基准测试

输出:

Performance Summary (10 runs):
  Mean:   1.7343s
  Std:    0.0261s
  Min:    1.6923s
  Max:    1.7645s
  Median: 1.7434s

6. Agent适配截图

6.1 Agent 完整适配工作流

Agent 适配流程

6.2 NPU 设备调用日志

NPU 设备调用

6.3 模型适配结果

模型适配结果


7. 精度评测

适配方式: 直接 torch_npu 推理(非 vLLM-Ascend)

评测指标:

指标结果说明
RTF (Real Time Factor)0.35105秒音频推理耗时 1.70秒
批量推理吞吐1.62s/sample4样本批量推理
推理稳定性Std=0.03s10次迭代标准差
输出形状(1, 500, 2)与模型规格一致
NPU 设备Ascend910_93622卡可用

8. NPU 配置说明

  • NPU 型号: Ascend910_9362
  • 可用 NPU 数量: 2
  • 当前使用 NPU: npu:0 (单卡)
  • 显存占用: ~3109 MB HBM
  • CANN 版本: 8.5.1
  • npu-smi 版本: 25.5.5

9. 已知问题

  1. TransformerEncoderLayer attention 回退: aten::_transformer_encoder_layer_fwd 算子当前在 NPU 后端不完全支持,attention 部分会回退到 CPU 执行。这会影响性能但不影响正确性。
  2. 模型权重访问受限: pyannote/segmentation-3.0 在 HuggingFace 上为 gated repo,需要先接受使用协议才能下载。