关联 PR:https://gitcode.com/Ascend/pytorch/pull/47449
优化 DVM 后端的 GroupNorm 分解、广播 matmul、内存分配代码生成和可选 permute lowering,降低相关模型开销,并记录验证范围。
aten.native_group_norm
_override_matmul_should_fold_for_npu()
NPUWrapperCodeGen.make_allocation
_empty_strided_npu
aten.permute
enable_fusion_permute
reinterpret_tensor
修改范围:torch_npu/_inductor/dvm/ 下的 config.py、decomp.py、mlir_fusion.py 和新增的 wrapper.py。详细设计见关联 PR。
torch_npu/_inductor/dvm/
config.py
decomp.py
mlir_fusion.py
wrapper.py
环境:Ascend910B3 / CANN 9.2.0.beta.2 / PyTorch 2.13,基于 PR !47318 构建并应用对应改动。时间单位为 ms/次,严格精度阈值为 rtol=atol=1e-4。以下引用 PR 已记录结果,创建本 Issue 时未重新测试。
rtol=atol=1e-4
git diff --check
3e76f0ecf45429273b2a20a2fc7c2a1b9898c6f2
PR-pipeline_pytorch#71518
关联 PR:https://gitcode.com/Ascend/pytorch/pull/47449
背景与目标
优化 DVM 后端的 GroupNorm 分解、广播 matmul、内存分配代码生成和可选 permute lowering,降低相关模型开销,并记录验证范围。
修改方案
aten.native_group_norm分解,使 DVM 可以融合其计算。_override_matmul_should_fold_for_npu(),将适用的 3D×2D matmul 转为 MM,减少权重广播和 BMM 开销。NPUWrapperCodeGen.make_allocation,生成_empty_strided_npu调用;非 NPU、内存生命周期跟踪、pinned 分配及子图保留原有路径。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 时未重新测试。aten.permute调用为 0。git diff --check通过;提交3e76f0ecf45429273b2a20a2fc7c2a1b9898c6f2的流水线PR-pipeline_pytorch#71518已通过。待完成项