Closed
[perf] DVM GroupNorm、matmul、内存分配与可选 permute lowering 优化 #5282
SorryNaCNAdd on  Oct 8Closed at  11 days ago
SorryNaCN
SorryNaCNCollaborators
Oct 8 Create

关联 PR:https://gitcode.com/Ascend/pytorch/pull/47449

个人仓库跟踪 Issue:https://gitcode.com/SorryNaCN/pytorch_8420/issues/10

背景与目标

优化 DVM 后端的 GroupNorm 分解、广播 matmul、内存分配代码生成和可选 permute lowering,降低相关模型开销,并记录验证范围。

修改方案

  1. 默认允许 aten.native_group_norm 分解,使 DVM 可以融合其计算。
  2. 复用 _override_matmul_should_fold_for_npu(),将适用的 3D×2D matmul 转为 MM,减少权重广播和 BMM 开销。
  3. 新增 DVM wrapper,普通 NPU 分配复用 Triton-ex 的 NPUWrapperCodeGen.make_allocation,生成 _empty_strided_npu 调用;非 NPU、内存生命周期跟踪、pinned 分配及子图保留原有路径。
  4. 将 aten.permute 放入生成白名单,新增默认关闭的 enable_fusion_permute 配置;开启后允许 DVM 融合并生成 reinterpret_tensor 视图。

修改范围:torch_npu/_inductor/dvm/ 下的 config.py、decomp.py、mlir_fusion.py 和新增的 wrapper.py。详细设计见关联 PR。

已记录的验证结果

环境:Ascend910B3 / CANN 9.2.0.beta.2 / PyTorch 2.13,基于 PR !47318 构建并应用对应改动。时间单位为 ms/次,严格精度阈值为 rtol=atol=1e-4。以下引用 PR 已记录结果,创建本 Issue 时未重新测试。

  • GroupNorm:functorch_dp_cifar10 / opacus_cifar10 设备时间分别降至 2.60 / 2.63;单算子精度通过,全网严格精度仍未通过。
  • Matmul:CLIP E2E 30.41 → 23.58,设备时间 29.69 → 21.29,严格精度通过。
  • 快速分配:复用前后 144 组分配代码生成结果一致。
  • Permute:开启、关闭各 5 项 NPU 用例通过;开启后 8 项动态形状、dtype、stride、offset、别名等视图用例通过,生成代码中独立 aten.permute 调用为 0。
  • Python 语法检查与 git diff --check 通过;提交 3e76f0ecf45429273b2a20a2fc7c2a1b9898c6f2 的流水线 PR-pipeline_pytorch#71518 已通过。

待完成项

  • GroupNorm 全网严格精度问题仍需跟进。
  • 快速分配和新 permute 开关的独立全网性能收益尚未测量。
  • 仓库 UT 看护及自验证截图待补充。
likedislike
TorchNPU-BotTorchNPU-BotCollaborators
Oct 8 Added label: triage-reviewmodule: graph-mode
TorchNPU-Bot
TorchNPU-BotCollaborators
Oct 8 Comments:

无报错,属性能优化建议/需求;主题为 DVM 后端图编译与 lowering 优化
添加分类标签:module: graph-mode。
当前分类由社区bot提供,如分类有误请在评论中回复。

likedislike
TorchNPU-BotTorchNPU-BotCollaborators
Oct 8 Added label: bot-triaged; Removed label: triage-review
TorchNPU-Bot
TorchNPU-BotCollaborators
Oct 8 Comments:

检测到当前 issue 已关联 PR,自动添加标签:bot-triaged

likedislike
chenrayray
chenrayrayCollaborators
11 days ago Comments:

关联的 PR(!47449)已全部合入,先关闭这个 issue。如问题仍存在或需要继续跟踪,欢迎补充信息后重新打开。

likedislike
chenrayraychenrayrayCollaborators
11 days ago Close issue
chenrayraychenrayrayCollaborators
11 days ago changed custom state from TODO to DONE
chenrayraychenrayrayCollaborators
11 days ago changed custom state from TODO to DONE
ascend-robotascend-robotCollaborators
11 days ago Added label: resolved