已合并
[fa_v3]skip cpu check, register_sharding for npu_fusion_attention_v3 #30860
[fa_v3]skip cpu check, register_sharding for npu_fusion_attention_v3 #30860
已合并
王超创建于 2月12日
王超成员
2月12日
# 【合入来源】 > **如有社区issue,请关联issue链接**\ > **请勿携带内部流程信息(需求链接、问题单、内部issue等)** - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 1. torch_npu.npu_fusion_attention_v3适配支持DTensor策略注册。 2. graph_tree中支持根据torch_npu.\_inductor.config.npugraph_trees.disable_cpu_input_check配置开启时跳过cpu Tensor的相关检测,从而支持torch_npu.npu_fusion_attention_v3入graph_tree # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 新增DTensor测试用例 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [x] 代码注释完备,正确记录错误日志 - [x] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [x] PR持续集成流水线(CI)执行通过,代码检查无异常
likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 王超 的贡献)
王超成员
2月12日 创建了 pull request,commit e1b41a66
ascend-robotascend-robot成员
2月12日 添加了label:stat/needs-squash
ascend-robot
ascend-robot成员
2月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
repo-Ascend/pytorch liwei386, zqwenn (2/2) liwei386, zqwenn (2/1)
test liwei386, zqwenn (2/2) liwei386, zqwenn (2/1)
torch_npu/_inductor liwei386, zqwenn (2/2) liwei386, zqwenn (2/1)
torch_npu/distributed liwei386, zqwenn (2/2) zqwenn, liwei386 (2/1)
torch_npu/npu liwei386, zqwenn (2/2) liwei386, zqwenn (2/1)
torch_npu/utils liwei386, zqwenn (2/2) liwei386, zqwenn (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)
likedislike
ascend-robotascend-robot成员
2月12日 添加了label:ascend-cla/yes
王超成员
2月12日 评论:

compile

likedislike
ascend-robotascend-robot成员
2月12日 添加了label:ci-pipeline-running
AtlasAccount
AtlasAccount成员2月12日进行代码检视1
torch_npu/_inductor/config.py
@@ -66,4 +85,4 @@
6685# (1) 'all' means try to fallback all kernel to fx graph call.
6786# (2) [1, 2, 10] means try to fallback kernel like triton_xxx_1, triton_xxx_2 and triton_xxx_10
6887force_fallback_kernel_id = []
6988 
AtlasAccount
AtlasAccount2月12日评论:

代码逻辑和结构: 在_npugraph_trees.disable_cpu_input_check属性的setter方法中,逻辑存在矛盾。注释说明当disable_cpu_input_check为True时,应将slow_path_cudagraph_asserts设置为True以跳过CPU检查。但实际代码中,当value为True时,却将其设置为False。这会导致实际行为与注释描述相反,可能引发预期外的行为或错误。

问题类型: 代码逻辑和结构
文件路径: torch_npu/_inductor/config.py
行号: 66
问题代码:

        # When disable_cpu_input_check is True, set slow_path_cudagraph_asserts to True to skip the CPU check. 
        if value:
            torch._inductor.config.triton.slow_path_cudagraph_asserts = False

修改建议:

根据注释的意图,应将`torch._inductor.config.triton.slow_path_cudagraph_asserts`设置为True。建议修改为:`torch._inductor.config.triton.slow_path_cudagraph_asserts = True`。同时,建议检查`slow_path_cudagraph_asserts`配置项在PyTorch Inductor中的确切含义,确保修改后的逻辑符合预期。

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

likedislike
AtlasAccount
AtlasAccount成员2月12日进行代码检视2
torch_npu/distributed/tensor/_attention.py
已过期
@@ -401,2 +665,4 @@
665+ )
666+ elif op_call == npu.npu_fusion_attention_grad.default or op_call == npu.npu_fusion_attention_grad_v3.default:
401667 local_kwargs = get_redistributed_local_kwargs(
402668 _infer_npu_fusion_attention_grad_kwargs_spec, op_info, output_sharding
AtlasAccount
AtlasAccount2月12日评论:

语法错误: 第304行存在与第303行相同的语法错误。代码中使用了 'None, if actual_seq_kvlen is None else Replicate()',这在Python中是无效的语法。正确的语法应该是 'None if actual_seq_kvlen is None else Replicate()'。

问题类型: 语法错误
文件路径: torch_npu/distributed/tensor/_attention.py
行号: 304
问题代码:

            None, if actual_seq_kvlen is None else Replicate(),   # actual_seq_kvlen

修改建议:

将第304行的 'None, if actual_seq_kvlen is None else Replicate()' 修改为 'None if actual_seq_kvlen is None else Replicate()',删除多余的逗号。

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

likedislike
System
系统消息系统
2月12日 评论:
AtlasAccount
AtlasAccount成员2月12日进行代码检视2
torch_npu/distributed/tensor/_attention.py
已过期
@@ -446,3 +718,4 @@
446718}
447719 
448720old_handlers = DTensor._op_dispatcher._custom_op_handlers
AtlasAccount
AtlasAccount2月12日评论:

语法错误: 第347行存在与第303行相同的语法错误。代码中使用了 'None, if actual_seq_qlen is None else Replicate()',这在Python中是无效的语法。

问题类型: 语法错误
文件路径: torch_npu/distributed/tensor/_attention.py
行号: 347
问题代码:

                None, if actual_seq_qlen is None else Replicate(),    # actual_seq_qlen

修改建议:

将第347行的 'None, if actual_seq_qlen is None else Replicate()' 修改为 'None if actual_seq_qlen is None else Replicate()',删除多余的逗号。

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

likedislike
System
系统消息系统
2月12日 评论:
AtlasAccount
AtlasAccount成员2月12日进行代码检视2
torch_npu/distributed/tensor/_attention.py
已过期
@@ -446,3 +718,4 @@
446718}
447719 
448720old_handlers = DTensor._op_dispatcher._custom_op_handlers
AtlasAccount
AtlasAccount2月12日评论:

语法错误: 第348行存在与第304行相同的语法错误。代码中使用了 'None, if actual_seq_kvlen is None else Replicate()',这在Python中是无效的语法。

问题类型: 语法错误
文件路径: torch_npu/distributed/tensor/_attention.py
行号: 348
问题代码:

                None, if actual_seq_kvlen is None else Replicate(),   # actual_seq_kvlen

修改建议:

将第348行的 'None, if actual_seq_kvlen is None else Replicate()' 修改为 'None if actual_seq_kvlen is None else Replicate()',删除多余的逗号。

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

likedislike
System
系统消息系统
2月12日 评论:
AtlasAccount
AtlasAccount成员2月12日进行代码检视2
torch_npu/distributed/tensor/_attention.py
已过期
@@ -491,4 +752,4 @@
491752 None # sink
492753 ]
493754 )
494755 strategies.append(dp_sharding_strategy)
AtlasAccount
AtlasAccount2月12日评论:

语法错误: 第383行存在与第303行相同的语法错误。代码中使用了 'None, if actual_seq_qlen is None else Replicate()',这在Python中是无效的语法。

问题类型: 语法错误
文件路径: torch_npu/distributed/tensor/_attention.py
行号: 383
问题代码:

                None, if actual_seq_qlen is None else Replicate(),    # actual_seq_qlen

修改建议:

将第383行的 'None, if actual_seq_qlen is None else Replicate()' 修改为 'None if actual_seq_qlen is None else Replicate()',删除多余的逗号。

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

likedislike
System
系统消息系统
2月12日 评论:
AtlasAccount
AtlasAccount成员2月12日进行代码检视2
torch_npu/distributed/tensor/_attention.py
已过期
@@ -492,4 +753,4 @@
492753 ]
493754 )
494755 strategies.append(dp_sharding_strategy)
495756 
AtlasAccount
AtlasAccount2月12日评论:

语法错误: 第384行存在与第304行相同的语法错误。代码中使用了 'None, if actual_seq_kvlen is None else Replicate()',这在Python中是无效的语法。

问题类型: 语法错误
文件路径: torch_npu/distributed/tensor/_attention.py
行号: 384
问题代码:

                None, if actual_seq_kvlen is None else Replicate(),   # actual_seq_kvlen

修改建议:

将第384行的 'None, if actual_seq_kvlen is None else Replicate()' 修改为 'None if actual_seq_kvlen is None else Replicate()',删除多余的逗号。

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

likedislike
System
系统消息系统
2月12日 评论:
AtlasAccount
AtlasAccount成员2月12日进行代码检视2
torch_npu/distributed/tensor/_attention.py
已过期
@@ -447,3 +719,4 @@
447719}
448720 
449721old_handlers = DTensor._op_dispatcher._custom_op_handlers
AtlasAccount
AtlasAccount2月12日评论:

语法错误: 第427行存在语法错误。代码中使用了 'None, if seed is None else Replicate()',这在Python中是无效的语法。正确的语法应该是 'None if seed is None else Replicate()'。

问题类型: 语法错误
文件路径: torch_npu/distributed/tensor/_attention.py
行号: 427
问题代码:

            None, if seed is None else Replicate(),        # seed

修改建议:

将第427行的 'None, if seed is None else Replicate()' 修改为 'None if seed is None else Replicate()',删除多余的逗号。

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

likedislike
System
系统消息系统
2月12日 评论:
AtlasAccount
AtlasAccount成员2月12日进行代码检视2
torch_npu/distributed/tensor/_attention.py
已过期
@@ -447,3 +719,4 @@
447719}
448720 
449721old_handlers = DTensor._op_dispatcher._custom_op_handlers
AtlasAccount
AtlasAccount2月12日评论:

语法错误: 第428行存在语法错误。代码中使用了 'None, if offset is None else Replicate()',这在Python中是无效的语法。正确的语法应该是 'None if offset is None else Replicate()'。

问题类型: 语法错误
文件路径: torch_npu/distributed/tensor/_attention.py
行号: 428
问题代码:

            None, if offset is None else Replicate(),      # offset

修改建议:

将第428行的 'None, if offset is None else Replicate()' 修改为 'None if offset is None else Replicate()',删除多余的逗号。

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

likedislike
System
系统消息系统
2月12日 评论:
AtlasAccount
AtlasAccount成员2月12日进行代码检视2
torch_npu/distributed/tensor/_attention.py
已过期
@@ -447,3 +719,4 @@
447719}
448720 
449721old_handlers = DTensor._op_dispatcher._custom_op_handlers
AtlasAccount
AtlasAccount2月12日评论:

语法错误: 第430行存在语法错误。代码中使用了 'None, if actual_seq_qlen is None else Replicate()',这在Python中是无效的语法。正确的语法应该是 'None if actual_seq_qlen is None else Replicate()'。

问题类型: 语法错误
文件路径: torch_npu/distributed/tensor/_attention.py
行号: 430
问题代码:

            None, if actual_seq_qlen is None else Replicate(),  # actual_seq_qlen

修改建议:

将第430行的 'None, if actual_seq_qlen is None else Replicate()' 修改为 'None if actual_seq_qlen is None else Replicate()',删除多余的逗号。

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

likedislike
System
系统消息系统
2月12日 评论:
AtlasAccount
AtlasAccount成员2月12日进行代码检视2
torch_npu/distributed/tensor/_attention.py
已过期
@@ -447,3 +719,4 @@
447719}
448720 
449721old_handlers = DTensor._op_dispatcher._custom_op_handlers
AtlasAccount
AtlasAccount2月12日评论:

语法错误: 第431行存在语法错误。代码中使用了 'None, if actual_seq_kvlen is None else Replicate()',这在Python中是无效的语法。正确的语法应该是 'None if actual_seq_kvlen is None else Replicate()'。

问题类型: 语法错误
文件路径: torch_npu/distributed/tensor/_attention.py
行号: 431
问题代码:

            None, if actual_seq_kvlen is None else Replicate(), # actual_seq_kvlen

修改建议:

将第431行的 'None, if actual_seq_kvlen is None else Replicate()' 修改为 'None if actual_seq_kvlen is None else Replicate()',删除多余的逗号。

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

likedislike
System
系统消息系统
2月12日 评论:
AtlasAccount
AtlasAccount成员
2月12日 评论:

问题/功能描述

本次PR旨在增强NPU(昇腾)在PyTorch分布式训练和Inductor编译后端中的功能支持与性能优化。主要包含三个核心部分:1) 为npu_fusion_attention及其v3版本算子新增分布式张量(DTensor)测试,以验证其在多种输入布局和稀疏注意力模式下,于分布式环境中的前向与反向传播正确性;2) 扩展分布式张量计算框架,为npu_fusion_attention_v3npu_fusion_attention_grad_v3算子新增数据并行和张量并行的分片策略支持,以支持大规模模型训练;3) 优化NPU Inductor的图优化能力与日志系统,通过新增配置允许在特定场景下跳过CPU输入检查,从而优化图融合过程,并完善ACL图模块的日志记录功能。

修改方案描述

修改方案涉及多个文件,具体包括:1) 在测试文件test_attention_ops.py中新增四个测试方法,通过对比单设备基准结果与分布式环境下的计算结果,验证npu_fusion_attention算子在多种布局和稀疏模式下的分布式正确性。2) 在分布式策略注册中,新增npu_fusion_attention_v3_strategynpu_fusion_attention_grad_v3_strategy函数,定义了完整的复制、数据并行和张量并行策略,并更新统一处理函数以适配不同版本的算子。3) 在torch_npu/_inductor/config.py中新增_npugraph_trees配置类,提供disable_cpu_input_check属性以优化图融合;在torch_npu/_logging/_internal.py中注册"aclgraph"日志模块;并在多个图优化相关函数中引入对该配置的检查,以灵活处理CPU节点,同时将多处日志更新为f-string格式以提升可读性。

likedislike
ascend-robotascend-robot成员
2月12日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
2月12日 添加了label:ci-pipeline-failed
ascend-robot
ascend-robot成员
2月12日 评论:
流水线 PR-pipeline_pytorch#7274 运行失败
阶段 任务名 状态 详情
编译构建 Build_X86 🕚 >>>
Build_LibTorch 🕚 >>>
Build_ARM 🕚 >>>
Build_ARM_inductor 🕚 >>>
Build_X86_py311 🕚 >>>
Build_ARM_py311 🕚 >>>
恶意代码检查 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_Part_01 🕚 >>>
UT_inductor_Part_02 🕚 >>>
UT_inductor_Part_03 🕚 >>>
UT_inductor_Part_04 🕚 >>>
流水线 PR-pipeline_pytorch >>>
likedislike
王超成员
2月12日 update merge request[project id: 7404318, iid: 30860, commit_id: f2f9bd9f2a663a81d5f9a1bbd3453f72b79944d4] virtual merging success
王超成员
2月12日 推送  1 个提交:39e41cf2-fix with strategy register
王超成员
2月12日 update merge request[project id: 7404318, iid: 30860, commit_id: 52d87a5f962aaaeb9c467426f04838910d5c6992] virtual merging success
ascend-robot
ascend-robot成员
2月12日 评论:

CLA Signature Pass

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

likedislike
AtlasAccountAtlasAccount成员
2月12日 删除了label:ci-pipeline-failed
AtlasAccountAtlasAccount成员
2月12日 添加了label:ci-pipeline-failed
王超成员
2月12日 评论:

compile

likedislike
ascend-robotascend-robot成员
2月12日 删除了label:ci-pipeline-failed
ascend-robotascend-robot成员
2月12日 添加了label:ci-pipeline-running
ascend-robotascend-robot成员
2月12日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
2月12日 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
2月12日 评论:
流水线 PR-pipeline_pytorch#7280 已完成
阶段 任务名 状态 详情
编译构建 Build_X86 >>>
Build_LibTorch >>>
Build_ARM >>>
Build_ARM_inductor 🛑 >>>
Build_X86_py311 🛑 >>>
Build_ARM_py311 🛑 >>>
恶意代码检查 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_Part_01 🛑 >>>
UT_inductor_Part_02 🛑 >>>
UT_inductor_Part_03 🛑 >>>
UT_inductor_Part_04 🛑 >>>
流水线 PR-pipeline_pytorch >>>
likedislike
zhangqiongwen成员
2月14日 评论:

/approve

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

/approve

likedislike
ascend-robotascend-robot成员
2月14日 添加了label:lgtm
ascend-robot
ascend-robot成员
2月14日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: zqwenn, liwei386.
Reviewers who wrote a comment of /lgtm are: liwei386, zqwenn.

likedislike
ascend-robotascend-robot成员
2月14日 合入了pull request