已合并
[sync] PR-40262: bugfix for profiler FLOPs when actual seq len can be zero #40379
[sync] PR-40262: bugfix for profiler FLOPs when actual seq len can be zero #40379
已合并
ascend-robot创建于 7月7日
ascend-robot
ascend-robot成员
7月7日

1. Origin pull request:

https://gitcode.com/Ascend/pytorch/merge_requests/40262

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

Sha Datetime Message
3de75982 2026-07-07 08:26:24 +0800 CST bugfix for profiler FLOPs when actual seq len can be zero
likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 ascend-robot 的贡献)
ascend-robotascend-robot成员
7月7日 创建了 pull request,commit 8303ff38
ascend-robotascend-robot成员
7月7日 关联了issue:[Bug]: profiling计算attention算子FLOPs时需要考虑实际序列长度可能为0,head_num不一致的情况
atomgit-bot
atomgit-bot
7月7日 评论:

变更摘要

此PR修复了profiler FLOPs计算中一个边界条件判断问题:在 _calculate_tnd_layout_flops 函数中,原先对 actual_seq_qlen / actual_seq_kvlen 的校验将长度为0的情况也视为非法输入并抛出异常,但实际上序列长度可以合法地为零。修复后将校验条件从 <= 0 放宽为 < 0,仅拒绝负数长度,允许零长度通过,从而避免在实际段落长度为零时错误抛出异常。

主要改动

  • 放宽序列长度校验条件:在 torch_npu/profiler/_flops_formulas.py_calculate_tnd_layout_flops 函数中,将 any(length <= 0 for length in q_lens + kv_lens) 改为 any(length < 0 for length in q_lens + kv_lens),使零长度序列不再被拒绝,仅真正无效的负数长度触发 ValueError
likedislike
atomgit-bot
atomgit-bot
7月7日 评论:

代码审查

✅ 未发现问题

likedislike
ascend-robotascend-robot成员
7月7日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
7月7日 评论:

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
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

ascend-ds-bot, thanks for your pull request. All authors of the commits have signed the CLA. 👍

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

ascend docs pipeline is running...

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

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

likedislike
ascend-robotascend-robot成员
7月7日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
7月7日 添加了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
7月7日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
7月7日 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
7月7日 评论:
流水线 PR-pipeline_pytorch#42092 [ commitID:23a4b8aa ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 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 >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[wujinyuan1, huangjingwei, liangsongwei, yashi999, culechan, Dring, wuyouqi1, L1919_snow, qq_52711437, WhiteNight12, nomiz, xiu_21, ffmh, wanglijun55, hss-shuai, husichao, smallsilly, lanshaozuishuai, jimmyisme1, lzy0920232, alpha-junh, Sunshine_Youngster, wei_zhuoyi, zhangyihuiben, zyw-hw, zzzkeke, rmch, yangch0324, LucciC, AACAES, renyujin, wjlflyer, senzhen-town, pengjingyou, qsc97, limuan, yule100, xiaoqi-zhou, kuhn7, chenxingying, hanye02, zichun_ye, anyrenwei, kkjocker, wangzili121, Lu_G, yvjc, puddingfjz, HandsoemLemon, bigprestigee1, huawuyi, zhenyu10, dairenjie, du-jin-hang, zou-jieyu, adelaideliu, TrHan, wanlinan, Windwindzzz, pengqihw, kisnwang, yuheng_wang, honghao_wang, jizewei, zhangguoguang, sunyu-xuan, chenrayray, hbhu_bin, liujunzhu, c_34, LiNuoh, maoyuanpeng1, zzhongmin, zhaoyu65, bellatan, jiabaolin, zhuofanshen, wencaiwen, lu_zhuge, caoshuyang, molly12, lyx324521, LQ1206, gitcode-chenjiao, cai-weiwei1989, CHDong, ogqin, yuanlipingGit, xuqinglin1, lqz2, zouwei1, chaoluoa, paradox325, jackzhang1116, yaoyao, akh, yujiacheng, dengjie0116, Hubert11111, Shine_Ws, wslhj555, longqiand, OYtao666, JiaqingQiang, luyyyy, Kingbelial, zhanghaiyu0101, wenxp1018, yanliu-luoluo, ksun_sekiro, liyong328, wgzheng, tangky, vivi_is_coding, aoiaoisola, weixin_44494597, wangmengmengwang65667, hid57809721, qq_35468730, comeonup, C547032, gcw_m5OQChA4, yao_yao_ling_xian, cnnbwcy, szqfes_12, cora_19, cann_lilin, can, shawnylee233, fanglanyue0916, hhz0]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
chenhao_1209成员
7月8日 评论:

/approve

likedislike
ascend-robotascend-robot成员
7月8日 添加了label:approved
wangchao285成员
7月8日 评论:

/approve

likedislike
ascend-robotascend-robot成员
7月8日 添加了label:lgtm
ascend-robotascend-robot成员
7月8日 合入了pull request