已合并
feat(profiler): add fused op flops formulas #38360
hhz0创建于 6月12日
feat(profiler): add fused op flops formulas #38360
已合并
hhz0创建于 6月12日
hhz0
hhz0成员
6月12日

【合入来源】

如有社区issue,请关联issue链接
请勿携带内部流程信息(需求链接、问题单、内部issue等)

https://gitcode.com/Ascend/pytorch/issues/2367

【修改方案】

  1. 在 profiler FLOPs 公式注册中补充融合算子默认 FLOPs 计算规则,新增支持 npu_all_gather_base_mmnpu_transpose_batchmatmulnpu_grouped_matmulnpu_quant_matmul_gelunpu_grouped_matmul_swiglu_quant_v2npu_alltoallv_gmmnpu_gmm_alltoallvnpu_block_sparse_attention
  2. 修正 npu_fusion_attention / npu_fused_infer_attention_score 的 Attention FLOPs 口径,按 QK^T + P @ V 统计,使用 q_dim + value_dim,不再误用 key_dim
  3. 统一只统计主 GEMM 或 Attention 矩阵乘 FLOPs,不统计通信、transpose/permute、bias、scale、量化/反量化、GELU/SwiGLU、softmax、dropout 等融合后处理。
  4. 补充对应 UT 覆盖融合算子基础 shape、grouped matmul group_list、block sparse attention 有效块统计、BNSD actual lengths,以及 value_dim != key_dim 回归场景。

【资料变更】

不涉及。

【接口变更】

不涉及。未新增或变更客户可见 API,仅补充 profiler 内部 FLOPs 默认计算公式。

【功能验证】

  1. 执行 python -m py_compile torch_npu/profiler/_flops_formulas.py test/profiler/test_flops_hook.py,通过。
  2. 执行 git diff --check,通过。
  3. 通过纯 Python 公式断言验证新增融合算子 FLOPs 计算结果,验证通过。
  4. 尝试执行 python -m pytest test/profiler/test_flops_hook.py -q,当前本地环境缺少编译扩展 torch_npu._C,收集阶段报 ModuleNotFoundError,未进入 UT 执行。

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 hhz0 的贡献)
hhz0hhz0成员
6月12日 创建了 pull request,commit 81ad8a24
hhz0hhz0成员
6月12日 关联了issue:[Feature]: 【Profiler】支持典型算子MFU分析
ascend-robotascend-robot成员
6月12日 添加了label:ascend-cla/yes
hhz0
hhz0成员
6月12日 评论:

compile

likedislike
ascend-robot
ascend-robot成员
6月12日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
test 李伟, 陈豪 (2/2) 李伟, 陈豪 (2/1)
torch_npu/profiler 李伟, 陈豪 (2/2) 李伟, 陈豪 (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

hhz0, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robot
ascend-robot成员
6月12日 评论:

当前仓库存在以下 保护分支

Protected Branch Version Release
master
v2.12.0
v2.11.0
v2.10.0
v2.7.1
v2.9.0
v2.7.1-26.1.0
v2.12.0-26.1.0
v2.9.0-26.1.0
v2.10.0-26.1.0
v2.11.0-26.1.0
ci-test
sync-pr28113--to-v2.9.0

评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
ascend-robotascend-robot成员
6月12日 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
6月12日 评论:

Ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
6月12日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
6月12日 评论:

Ascend docs pipeline is running...

likedislike
AtlasAccount
AtlasAccount成员
6月12日 评论:

/torch_npu/profiler/_flops_formulas.py
/torch_npu/profiler/_flops_hook.py

likedislike
ascend-robot
ascend-robot成员
6月12日 评论:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robot成员
6月12日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
6月12日 添加了label:docs-ci-pipeline-success
ascend-robot
ascend-robot成员
6月12日 评论:

✅ 跳过 docs ci 检查,没有需要检查的文档文件

likedislike
ascend-robotascend-robot成员
6月12日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
6月12日 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
6月12日 评论:
流水线 PR-pipeline_pytorch#31641 已完成
阶段 任务名 状态 详情
编译构建 Build_X86 >>>
Build_ARM >>>
Build_LibTorch_x86 >>>
Build_LibTorch_ARM >>>
Build_X86_torchair 🛑 >>>
Build_ARM_torchair 🛑 >>>
patch_test 🛑 >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 CodeCheck >>>
check_error >>>
CodeCheck_lintrunner >>>
开源片段检查 SCA >>>
开发者测试 UT_X86_Part_01 🛑 >>>
UT_X86_Part_02 🛑 >>>
UT_ARM_A3_Part_01 🛑 >>>
UT_ARM_A3_Part_02 🛑 >>>
UT_ARM_A2_Part_01 >>>
UT_ARM_A2_Part_02 >>>
UT_ARM_A2_Part_03 >>>
UT_inductor_Part_01 🛑 >>>
UT_inductor_Part_02 🛑 >>>
UT_inductor_Part_03 🛑 >>>
UT_inductor_Part_04 🛑 >>>
UT_DIST_ARM_Part_01 🛑 >>>
UT_DIST_ARM_Part_02 🛑 >>>
UT_DIST_ARM_Part_03 🛑 >>>
UT_DIST_ARM_Part_04 🛑 >>>
UT_ARM_A2_Select_Part_01 >>>
UT_ARM_A2_Select_Part_02 >>>
流水线 PR-pipeline_pytorch >>>
likedislike
chenhao_1209成员
6月12日 评论:

/approve

likedislike
ascend-robotascend-robot成员
6月12日 添加了label:approved
liwei386成员
6月12日 评论:

/approve

likedislike
ascend-robotascend-robot成员
6月12日 添加了label:lgtm
ascend-robotascend-robot成员
6月12日 合入了pull request
ascend-robot
ascend-robot成员
6月12日 评论:
流水线 pytorch_gitcode_PR_multiVersion#10618 [ commitID:8bdaa445 ] 已完成
likedislike