已合并
[fix] test_npu_graph_attention_function #28990
zhangqiongwen创建于 1月4日
[fix] test_npu_graph_attention_function #28990
已合并
zhangqiongwen创建于 1月4日
zhangqiongwen成员
1月4日

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind bug
/kind task
/kind feature

What does this PR do / why do we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewers:

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 zhangqiongwen 的贡献)
Zzhangqiongwen成员
1月4日 创建了 pull request,commit 5d5df432
ascend-robot
ascend-robot成员
1月4日 评论:

Thank your for your pull-request.

The full list of commands accepted by me can be found at here.

You can get sig-info at here

likedislike
ascend-robot
ascend-robot成员
1月4日 评论:

以下是根据您提交的修改文件推荐的Reviewer和Committer序列,需各模块评审通过后方可合入

Module List Reviewers Committers
repo-Ascend/pytorch shaoyf, yangkaixin, liangsongwei, qinchuanyu, yuhaiyan wangqiang160, wangchao430, shaoyf, rain-666, wangchao285
likedislike
ascend-robotascend-robot成员
1月4日 添加了label:stat/needs-squash
ascend-robotascend-robot成员
1月4日 添加了label:ascend-cla/yes
AtlasAccount
AtlasAccount成员
1月4日 评论:

问题/功能描述

本次PR主要包含两个核心内容:一是修复并重新激活了一个因核心转储(core dump)问题而被跳过的NPU融合注意力图算子的测试用例;二是对该算子的反向传播接口进行了功能扩展,增加了对Sinkhorn注意力机制相关张量(sink)和softmax_layout参数的支持,以完善其功能。

修改方案描述

  1. 测试修复:移除了测试文件test/_inductor/test_npu_fusion_attention_graph.pytest_npu_graph_attention_function方法上的@skip装饰器,使该测试能够重新执行,验证了核心转储问题的解决。
  2. 接口扩展:在torch_npu/_inductor/npu_fusion_attention_graph.py中,修改了npu_fa_backward算子的签名和实现。具体包括:将seedoffsetnumels参数类型从Tensor?改为int;新增softmax_layout(字符串)和sink(可选张量)参数;在元函数和反向传播方法中适配了新增参数的处理逻辑,并返回对应的梯度张量dsink
likedislike
AtlasAccount
AtlasAccount成员1月4日进行代码检视1
torch_npu/_inductor/npu_fusion_attention_graph.py
@@ -128,3 +130,3 @@
128130 # 反向传播逻辑
129131 # 这里假设有一个实现反向传播的函数 `npu_fusion_attention_backward`
130- grad_query, grad_key, grad_value, grad_pse = torch.ops.npu_graph.npu_fa_backward(
132+ grad_query, grad_key, grad_value, grad_pse, grad_sink = torch.ops.npu_graph.npu_fa_backward(
AtlasAccount
AtlasAccount1月4日评论:

参数传递错误: 在 NpuGraphAttentionFunction.backward 中,调用 torch.ops.npu_graph.npu_fa_backward 时,seed、offset、numels 参数传递的是 result4、result5、result6(Tensor 对象),但根据新的接口定义,这些参数应为 int 类型。这会导致类型不匹配,可能引发运行时错误或未定义行为。

问题类型: 参数传递错误
文件路径: torch_npu/_inductor/npu_fusion_attention_graph.py
行号: 132
问题代码:

grad_query, grad_key, grad_value, grad_pse, grad_sink = torch.ops.npu_graph.npu_fa_backward(
    query, key, value, grad_result0, ctx.head_num, ctx.input_layout, pse=pse, padding_mask=padding_mask,
    atten_mask=atten_mask, softmax_max=result1, softmax_sum=result2, softmax_in=result3, attention_in=result0,
    scale_value=ctx.scale, keep_prob=ctx.keep_prob, pre_tockens=ctx.pre_tockens, next_tockens=ctx.next_tockens,
    inner_precise=ctx.inner_precise, seed=result4, offset=result5, numels=result6, prefix=ctx.prefix,
    actual_seq_qlen=ctx.actual_seq_qlen, actual_seq_kvlen=ctx.actual_seq_kvlen, sparse_mode=ctx.sparse_mode,
    gen_mask_parallel=ctx.gen_mask_parallel, sync=ctx.sync
)

修改建议:

根据新的接口定义,seed、offset、numels 应为 int 类型。需要检查 result4、result5、result6 的结构(它们在前向传播中是通过 torch.tensor([seed], requires_grad=False) 等方式创建的),并提取其整数值。例如,使用 result4.item() 或 result4[0].item() 来获取 int 值。同时,需要确保这些值在合理的范围内(例如,seed 应为非负整数)。

此评论由代码审查工具自动生成

likedislike
Zzhangqiongwen成员
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: edbec83a5326e16bbc5749013f3eae965d23645e] virtual merging success
Zzhangqiongwen成员
1月4日 解决了最后一个问题
Zzhangqiongwen成员
1月4日 推送  1 个提交:25c42dd8-[fix] test_npu_graph_attention_function
Zzhangqiongwen成员
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: 3b33f91d1d29b87be36a7a999d3c2d6fc7d7d57e] virtual merging success
ascend-robot
ascend-robot成员
1月4日 评论:

以下是根据您提交的修改文件推荐的Reviewer和Committer序列,需各模块评审通过后方可合入

Module List Reviewers Committers
repo-Ascend/pytorch wangchao430, liangsongwei, culechan, anyrenwei, liwei386 li_jing_hw, wangchao430, wasd1111222, medivh-x, yanpengquan
likedislike
AtlasAccountAtlasAccount成员
1月4日 添加了label:ci-pipeline-failed
Zzhangqiongwen成员
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: fdd6d94810ad365f3b58f15bb697d93654ef669a] virtual merging success
Zzhangqiongwen成员
1月4日 强制推送  1 个提交:eb77a458-[fix] test_npu_graph_attention_function
Zzhangqiongwen成员
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: 49c0752f03121b1ff6b988e0cf8d2fb017b473ce] virtual merging success
ascend-robot
ascend-robot成员
1月4日 评论:

以下是根据您提交的修改文件推荐的Reviewer和Committer序列,需各模块评审通过后方可合入

Module List Reviewers Committers
repo-Ascend/pytorch guoqi1024, li_jing_hw, shaoyf, zhanJ, duchengkun li_jing_hw, wangchao430, wasd1111222, medivh-x, yanpengquan
likedislike
zhangqiongwen成员
1月4日 评论:

compile

likedislike
AtlasAccountAtlasAccount成员
1月4日 删除了label:ci-pipeline-failed
AtlasAccountAtlasAccount成员
1月4日 添加了label:ci-pipeline-failed
zhangqiongwen成员
1月4日 评论:

compile

likedislike
Zzhangqiongwen成员
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: bf35f2907f17b76b98a03184233eaf41aa23b11b] virtual merging success
Zzhangqiongwen成员
1月4日 强制推送  1 个提交:92ed8b10-[fix] test_npu_graph_attention_function
Zzhangqiongwen成员
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: a4e16ec44c6595138be0f14acbf331cd9fc0f710] virtual merging success
ascend-robot
ascend-robot成员
1月4日 评论:

以下是根据您提交的修改文件推荐的Reviewer和Committer序列,需各模块评审通过后方可合入

Module List Reviewers Committers
repo-Ascend/pytorch chenhao_1209, liangsongwei, liwei386, yanpengquan, zhanJ rain-666, wasd1111222, medivh-x, zqwenn, anyrenwei
likedislike
ascend-robot
ascend-robot成员
1月4日 评论:

CLA Signature Pass

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

likedislike
AtlasAccountAtlasAccount成员
1月4日 删除了label:ci-pipeline-failed
AtlasAccountAtlasAccount成员
1月4日 添加了label:ci-pipeline-failed
zhangqiongwen成员
1月4日 评论:

compile

likedislike
ascend-robotascend-robot成员
1月4日 删除了label:ci-pipeline-failed
ascend-robotascend-robot成员
1月4日 添加了label:ci-pipeline-running
ascend-robotascend-robot成员
1月4日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
1月4日 添加了label:ci-pipeline-failed
ascend-robot
ascend-robot成员
1月4日 评论:
流水线 PR-pipeline_pytorch#1313运行失败
阶段 任务名 状态 详情
编译构建 Build_X86 >>>
Build_LibTorch >>>
Build_ARM >>>
Build_ARM_inductor >>>
Build_X86_py311 🛑 >>>
Build_ARM_py311 🛑 >>>
dist_test_or_not >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 CodeCheck >>>
check_error >>>
开源片段检查 SCA >>>
开发者测试 UT_DIST_X86 🛑 >>>
UT_X86_Part_01 >>>
UT_X86_Part_02 >>>
UT_ARM_A2_Part_01 🛑 >>>
UT_ARM_A2_Part_02 🛑 >>>
UT_inductor_arm >>>
流水线 PR-pipeline_pytorch >>>
likedislike
ascend-robot
ascend-robot成员
1月4日 评论:
流水线 PR-pipeline_pytorch#1292运行失败
阶段 任务名 状态 详情
编译构建 Build_X86 >>>
Build_LibTorch >>>
Build_ARM >>>
Build_ARM_inductor >>>
Build_X86_py311 🛑 >>>
Build_ARM_py311 🛑 >>>
dist_test_or_not >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 CodeCheck >>>
check_error >>>
开源片段检查 SCA >>>
开发者测试 UT_DIST_X86 🛑 >>>
UT_X86_Part_01 >>>
UT_X86_Part_02 >>>
UT_ARM_A2_Part_01 🛑 >>>
UT_ARM_A2_Part_02 🛑 >>>
UT_inductor_arm >>>
流水线 PR-pipeline_pytorch >>>
likedislike
ascend-robotascend-robot成员
1月4日 删除了label:ci-pipeline-failed
ascend-robotascend-robot成员
1月4日 添加了label:ci-pipeline-running
ascend-robotascend-robot成员
1月5日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
1月5日 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
1月5日 评论:
流水线 PR-pipeline_pytorch#1362已完成
阶段 任务名 状态 详情
编译构建 Build_X86 >>>
Build_LibTorch >>>
Build_ARM >>>
Build_ARM_inductor >>>
Build_X86_py311 🛑 >>>
Build_ARM_py311 🛑 >>>
dist_test_or_not >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 CodeCheck >>>
check_error >>>
开源片段检查 SCA >>>
开发者测试 UT_DIST_X86 🛑 >>>
UT_X86_Part_01 >>>
UT_X86_Part_02 >>>
UT_ARM_A2_Part_01 🛑 >>>
UT_ARM_A2_Part_02 🛑 >>>
UT_inductor_arm >>>
流水线 PR-pipeline_pytorch >>>
likedislike
王超成员
1月6日 评论:

/approve

likedislike
ascend-robotascend-robot成员
1月6日 添加了label:lgtm
shaoyf成员
1月12日 评论:

/approve

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

Review Guide

This Pull-Request Passes Review.
Committers who wrote a comment of /approve are: wangchao430, shaoyf.
Reviewers who wrote a comment of /lgtm are: wangchao430, shaoyf.

likedislike
ascend-robotascend-robot成员
1月12日 合入了pull request