已合并
[fix] test_npu_graph_attention_function #28990
zhangqiongwen创建于 1月4日
[fix] test_npu_graph_attention_function #28990
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 zhangqiongwen 的贡献)1月4日 创建了 pull request,commit 5d5df432
ascend-robot
1月4日 评论:
1月4日 评论:
AtlasAccount
1月4日 评论:
1月4日 评论:
ascend-robot
1月4日 评论:
1月4日 评论:
以下是根据您提交的修改文件推荐的Reviewer和Committer序列,需各模块评审通过后方可合入
| Module List | Reviewers | Committers |
|---|---|---|
| repo-Ascend/pytorch | shaoyf, yangkaixin, liangsongwei, qinchuanyu, yuhaiyan | wangqiang160, wangchao430, shaoyf, rain-666, wangchao285 |


1月4日 添加了label:stat/needs-squash
1月4日 添加了label:ascend-cla/yes
AtlasAccount
1月4日 评论:
1月4日 评论:
问题/功能描述
本次PR主要包含两个核心内容:一是修复并重新激活了一个因核心转储(core dump)问题而被跳过的NPU融合注意力图算子的测试用例;二是对该算子的反向传播接口进行了功能扩展,增加了对Sinkhorn注意力机制相关张量(sink)和softmax_layout参数的支持,以完善其功能。
修改方案描述
- 测试修复:移除了测试文件
test/_inductor/test_npu_fusion_attention_graph.py中test_npu_graph_attention_function方法上的@skip装饰器,使该测试能够重新执行,验证了核心转储问题的解决。 - 接口扩展:在
torch_npu/_inductor/npu_fusion_attention_graph.py中,修改了npu_fa_backward算子的签名和实现。具体包括:将seed、offset、numels参数类型从Tensor?改为int;新增softmax_layout(字符串)和sink(可选张量)参数;在元函数和反向传播方法中适配了新增参数的处理逻辑,并返回对应的梯度张量dsink。


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(
参数传递错误: 在 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 应为非负整数)。
此评论由代码审查工具自动生成


Zzhangqiongwen
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: edbec83a5326e16bbc5749013f3eae965d23645e] virtual merging success
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: edbec83a5326e16bbc5749013f3eae965d23645e] virtual merging success
1月4日 解决了最后一个问题
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
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: 3b33f91d1d29b87be36a7a999d3c2d6fc7d7d57e] virtual merging success
ascend-robot
1月4日 评论:
1月4日 评论:
以下是根据您提交的修改文件推荐的Reviewer和Committer序列,需各模块评审通过后方可合入
| Module List | Reviewers | Committers |
|---|---|---|
| repo-Ascend/pytorch | wangchao430, liangsongwei, culechan, anyrenwei, liwei386 | li_jing_hw, wangchao430, wasd1111222, medivh-x, yanpengquan |


1月4日 添加了label:ci-pipeline-failed
Zzhangqiongwen
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: fdd6d94810ad365f3b58f15bb697d93654ef669a] virtual merging success
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: fdd6d94810ad365f3b58f15bb697d93654ef669a] virtual merging success
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
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: 49c0752f03121b1ff6b988e0cf8d2fb017b473ce] virtual merging success
ascend-robot
1月4日 评论:
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 |


zhangqiongwen
1月4日 评论:
1月4日 评论:
compile


1月4日 删除了label:ci-pipeline-failed
1月4日 添加了label:ci-pipeline-failed
zhangqiongwen
1月4日 评论:
1月4日 评论:
compile


Zzhangqiongwen
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: bf35f2907f17b76b98a03184233eaf41aa23b11b] virtual merging success
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: bf35f2907f17b76b98a03184233eaf41aa23b11b] virtual merging success
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
1月4日 update merge request[project id: 7404318, iid: 28990, commit_id: a4e16ec44c6595138be0f14acbf331cd9fc0f710] virtual merging success
ascend-robot
1月4日 评论:
1月4日 评论:
以下是根据您提交的修改文件推荐的Reviewer和Committer序列,需各模块评审通过后方可合入
| Module List | Reviewers | Committers |
|---|---|---|
| repo-Ascend/pytorch | chenhao_1209, liangsongwei, liwei386, yanpengquan, zhanJ | rain-666, wasd1111222, medivh-x, zqwenn, anyrenwei |


ascend-robot
1月4日 评论:
1月4日 评论:
CLA Signature Pass
@zqwenn, thanks for your pull request. All authors of the commits have signed the CLA. 👍


1月4日 删除了label:ci-pipeline-failed
1月4日 添加了label:ci-pipeline-failed
zhangqiongwen
1月4日 评论:
1月4日 评论:
compile


1月4日 删除了label:ci-pipeline-failed
1月4日 添加了label:ci-pipeline-running
1月4日 删除了label:ci-pipeline-running
1月4日 添加了label:ci-pipeline-failed
ascend-robot
1月4日 评论:
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 | ❌ | >>> |


ascend-robot
1月4日 评论:
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 | ❌ | >>> |


1月4日 删除了label:ci-pipeline-failed
1月4日 添加了label:ci-pipeline-running
1月5日 删除了label:ci-pipeline-running
1月5日 添加了label:ci-pipeline-passed
ascend-robot
1月5日 评论:
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 | ✅ | >>> |


1月6日 添加了label:lgtm
1月12日 添加了label:approved
ascend-robot
1月12日 评论:
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.


1月12日 合入了pull request
What type of PR is this?
What does this PR do / why do we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewers: