Pull Request已成功合入, 合并人@ascend-robot
(感谢 xiaoqi-zhou 的贡献)变更摘要
本PR主要包含两方面改动:一是在 Atlas A5(Ascend950)环境下,对 ProcessGroupHCCL 中 allreduce、reduce、reduce_scatter 三个集合通信操作在 AVG 归约后的除法行为进行修正——当张量类型为整型时,调用 tensor.div_ 时显式传入 rounding_mode="trunc" 以执行截断除法,避免默认行为在整型场景下的语义差异;二是为 5 个分布式测试文件中的关键测试用例添加 @SupportedDevices 装饰器,限定其仅在 Ascend910A、Ascend910B、Ascend910_93 设备上执行,同时清理了未使用的导入。
主要改动
-
A5 环境整型张量的 AVG 除法行为修正: 在
ProcessGroupHCCL::allreduce、ProcessGroupHCCL::reduce和ProcessGroupHCCL::reduce_scatter中,新增is_atlas_a5判断逻辑,当检测到当前为 A5 环境且张量为整型时,对tensor.div_(getSize())追加"trunc"取整模式参数,其余类型保持原有除法行为不变。 -
分布式测试用例设备限定: 在
test_allgather.py、test_allgather_base.py、test_reduce.py、test_reduce_scatter.py、test_reduce_scatter_base.py中,为test_all_gather_dist、test_all_gather_base_dist、test_reduce_dist、test_reduce_scatter等多个测试方法添加@SupportedDevices(['Ascend910A', 'Ascend910B', 'Ascend910_93'])装饰器,使这些集合通信测试仅在指定 NPU 设备上运行。 -
测试文件导入清理: 上述 5 个测试文件中移除了未使用的
unittest、os、randint、mp、TestCase等导入,并统一引入SupportedDevices装饰器。


代码审查
审查总结
已逐一审查全部 6 个变更文件,结论如下:
| 文件 | 审查结果 |
|---|---|
test/distributed/test_allgather.py |
无问题(import 清理 + @SupportedDevices 装饰器添加正确) |
test/distributed/test_allgather_base.py |
无问题(移除未使用的 import + 添加装饰器正确) |
test/distributed/test_reduce.py |
无问题(import 清理 + 装饰器正确) |
test/distributed/test_reduce_scatter.py |
无问题(import 清理 + 装饰器正确) |
test/distributed/test_reduce_scatter_base.py |
无问题(import 清理 + 装饰器正确) |
torch_npu/csrc/distributed/ProcessGroupHCCL.cpp |
1 个 P3 发现 |
发现统计:P0: 0, P1: 0, P2: 0, P3: 1
总体风险评估:低风险。C++ 变更对 allreduce、reduce、reduce_scatter 三个关键函数的 A5 整数除法修复逻辑正确 —— is_atlas_a5 标志被正确提升到循环外、at::isIntegralType 排除了 bool、div_ 的 rounding_mode="trunc" 参数语义匹配需求。Python 测试文件的 import 清理(移除未使用的 unittest、os、randint、mp 等)和 @SupportedDevices 装饰器添加均合理:SUM 类测试在 A5 上因格式转换差异被跳过,AVG 类测试保留在 A5 上运行以覆盖新的截断行为。唯一的 P3 发现是同文件中其他 5 个 AVG 后处理路径(allreduce_coalesced、_reduce_oop 等)未获得相同的 A5 整数修复,属于一致性改进建议,不影响本次变更引入的三个路径的正确性。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


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 | ✅ wjlflyer, renyujin (2/2) | ✅ wjlflyer (1/1) |
| torch_npu/csrc/distributed | ✅ wjlflyer, renyujin (2/2) | ✅ wjlflyer (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
xiaoqi-zhou, thanks for your pull request. All authors of the commits have signed the CLA. 👍


Linking Issue Notice
@xiaoqi-zhou , the pull request must be linked to at least one issue.
If an issue has already been linked, but the needs-issue label remains, you can remove the label by commenting /check-issue .


当前仓库存在以下 保护分支 :
| Protected Branch | Version | Release |
|---|---|---|
| master | ||
| v2.7.1 | ||
| v2.9.0 | ||
| v2.10.0 | ||
| v2.11.0 | ||
| v2.12.0 | ||
| v2.9.0-26.1.0 | ||
| v2.10.0-26.1.0 | ||
| v2.7.1-26.1.0 | ||
| v2.12.0-26.1.0 | ||
| v2.11.0-26.1.0 | ||
| ci-test |
评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作
注意:
- /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
- 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭


通过PR创建命令启动流水线PR-pipeline_pytorch失败:获取流水线webHook失败!


ascend docs pipeline is running...


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


compile


ascend docs pipeline is running...


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


retry


retry


retry


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 | ✅ | >>> |
- compile、compile_inductor、compile_torchair : 运行流水线
- retry : 重试流水线所有失败子任务
- retry <任务名> : 仅重试指定失败子任务
- stop : 停止流水线




【合入来源】
issue:https://gitcode.com/Ascend/pytorch/issues/2827
【修改方案】
【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
【CheckList】