| # Magnetar 技术分析 |
|
|
| ## 初始判断 |
|
|
| - 模型来源是 GitHub 仓库 DiariZen,已隔离 clone 到任务目录,不修改上游源码。 |
| - 目标硬件为 AX650,编译配置需要设置 npu_mode=NPU3。 |
| - ACQUIRE 扫描未发现 *.pt/*.pth/*.onnx/*.safetensors 等权重,需从 README 或外部下载入口确认主模型。 |
| - 未提供 BOARD,因此 RUNONBOARD 按流程记录为跳过。 |
| |
| ## 主模型选择 |
| |
| - 根 README 的推理示例指定 ,因此将其作为默认主模型。 |
| - DiariZen 完整 pipeline 包含分割模型、embedding 模型和聚类后处理;AXMODEL 优先导出可 NPU 化的分割神经网络 ,聚类/RTTM 后处理保留在 SDK CPU 侧实现。 |
| |
| ## 主模型选择(修正) |
| |
| - 根 README 的推理示例指定 BUT-FIT/diarizen-wavlm-large-s80-md,因此将其作为默认主模型。 |
| - DiariZen 完整 pipeline 包含分割模型、embedding 模型和聚类后处理;AXMODEL 优先导出可 NPU 化的分割神经网络 pytorch_model.bin,聚类/RTTM 后处理保留在 SDK CPU 侧实现。 |
|
|
| ## 环境管理修正 |
|
|
| - 用户要求虚拟环境统一使用 uv 管理。 |
| - 已移除先前 python -m venv/pip 创建的半成品 cache/venv,后续使用 uv venv 与 uv pip。 |
|
|
| ## EXPORT 问题:opset17 LayerNormalization |
|
|
| - torch.onnx.export 使用 opset 17 时生成 `/LayerNormalization` 节点,ONNX checker 报 `input 1 is marked single but has an empty string`。 |
| - 判断为 PyTorch 2.1.1 对部分 LayerNorm/GroupNorm 图的 ONNX opset17 导出兼容问题。 |
| - 修复策略:降级到 opset 16,让 LayerNorm 分解为基础算子后再进行 ONNX checker 与 ONNXRuntime 对分。 |
|
|
| ## COMPILE 配置修正 |
|
|
| - Pulsar2 20260520 镜像中 `compiler.check` 是整数/枚举字段,不接受 JSON bool false。 |
| - 已移除该字段,避免配置解析失败;不启用 highest_mix_precision。 |
|
|
| ## COMPILE 问题:Pulsar2 Fuse_LayerNormalization_v2 transformation check |
|
|
| - 首次完整编译在 Pulsar2 ONNX 优化阶段失败,位置为 `float_optimizations.Fuse_LayerNormalization_v2`。 |
| - 差异约 max_abs_diff=0.00215,发生在输入 waveform 的前端归一化子图,属于 Pulsar2 transformation 校验容差失败。 |
| - 尝试配置 `onnx_opt.disable_transformation_check=true`,不修改 ONNX 语义,不启用 highest_mix_precision。 |
|
|
| ## COMPILE STOP:长序列 attention Gather tiling 失败 |
|
|
| - 16 秒输入产生 799 帧,WavLM attention 中出现 `(1,16,799,799)` 的注意力张量。 |
| - Pulsar2 在 AX650/NPU3 后端 tiling `/layers.0/attention/Gather_1` 时失败,workspace/mem_limit 不足或 Gather tiler 不支持该切片模式。 |
| - 这属于需要修改模型图或导出策略的 COMPILE STOP,按流程暂停等待用户确认。 |
| - 可选方案: |
| 1. 缩短静态输入窗口(例如 4s/8s),降低 attention 二次复杂度;需要重新 EXPORT/COMPILE/SIMULATE。 |
| 2. 拆分 WavLM 与后端 Conformer,只编译后端或部分子图;SDK 侧保留 WavLM CPU/其他后端。 |
| 3. 尝试不同 Pulsar2 版本或 compiler slice/tile 配置,但不保证解决 AxGather tiling。 |
| 4. 改导出策略规避 `Gather` attention pattern。 |
| |
| ## 4s 策略结果 |
| |
| - 已按用户确认将静态导出窗口从 16s 降到 4s。 |
| - 4s ONNX 与 PyTorch 对分通过,cosine 接近 1,说明导出本身有效。 |
| - Pulsar2 量化完成,MACs 降至约 16.6G,但 NPU 后端仍在同一 `/layers.0/attention/Gather_1` 失败。 |
| - 判断:当前主要阻塞是 WavLM attention 导出图里的 Gather pattern 与 AX650 NPU backend tiler 不兼容;仅缩短到 4s 不足以解决。 |
|
|
| ## Pulsar2 source patch validation |
|
|
| - User pointed out source Pulsar2 should be launched with `USE_PULSAR2` (`conda activate npu; source script/npu_dev`). |
| - In `/home/yrz/Codes/npu-codebase`, the AX650 gather builder bug was localized to `axnn/axnn/backend/ax650npu/oprimpl/gather.py`. |
| - Root cause: when `tx.strides[dim] > max_stride`, the split workaround used `tx[:, start:end]`, which supplies only two slice entries. For a collapsed 3-D tensor `(1,16,44576)`, this accidentally slices dimension 1 and fails `Tensor.__getitem__` because rank is 3. The intended split is along the last contiguous payload dimension. |
| - Patch: replace `tx[:, start:end]` with `tx[..., start:end]`, and reuse the same ellipsis slice for the output tensor. |
| - Source Pulsar2 validation (`compile_4s_srcpatch/compile.log`) no longer fails at `/layers.0/attention/Gather_1`; compilation proceeds past Gather tiling and now stops later at `AxQuantizedLayerNorm` for `/Gather_output_0` shape `(1,64000)`. |
|
|