Pull Request已成功合入, 合并人@ascend-robot
(感谢 xiaoqi-zhou 的贡献)变更摘要
此 PR 主要针对 A5(Ascend950)环境进行两项适配:一是在 ProcessGroupHCCL 的集合通信操作(allreduce、reduce、reduce_scatter)中,当执行 ReduceOp::AVG 平均操作且张量为整数类型时,将 tensor.div_() 的取整模式从默认行为改为 trunc(向零取整);二是通过 SupportedDevices 装饰器将部分分布式测试用例限定在 Ascend910A/B/910_93 设备上运行,从而在 A5 环境跳过相关测试(对应跳过 ND→NC1HWC0 格式转换)。
主要改动
ProcessGroupHCCL::allreduce/reduce/reduce_scatter整数除法取整模式适配:在三个方法中新增 A5 环境判断(GetSocVersion() >= Ascend950),当ReduceOp::AVG且张量为整数类型时,调用tensor.div_(getSize(), "trunc")替代默认的tensor.div_(getSize()),确保 A5 上整数除法的行为一致。- 分布式测试用例的设备限定:在
test_allgather.py、test_allgather_base.py、test_allgather_into_tensor.py、test_reduce.py、test_reduce_scatter.py、test_reduce_scatter_base.py六个测试文件中,为核心测试方法添加@SupportedDevices(['Ascend910A', 'Ascend910B', 'Ascend910_93'])装饰器,使这些用例仅在指定设备上执行,A5 环境不再运行。 - 测试文件 import 清理:上述测试文件中移除了未使用的
unittest、os、randint、mp等导入,并从common_utils统一导入SupportedDevices。


代码审查
审查总结
我逐一审查了全部 7 个变更文件:
| 文件 | 审查结论 |
|---|---|
test/distributed/test_allgather.py |
无问题(import 整理 + 添加 @SupportedDevices 装饰器,变更清晰正确) |
test/distributed/test_allgather_base.py |
无问题(移除未使用的 import,添加 @SupportedDevices,删除 TestCase 和 torch_npu 等未直接使用的导入,因父类已导入故无影响) |
test/distributed/test_allgather_into_tensor.py |
无问题(为 test_all_gather_into_tensor_dist 添加 @SupportedDevices,从 _internal_format_and_offset 测试中移除,与其他文件模式一致) |
test/distributed/test_reduce.py |
无问题(import 整理 + 添加 @SupportedDevices 装饰器) |
test/distributed/test_reduce_scatter.py |
无问题(import 整理 + 添加 @SupportedDevices 装饰器) |
test/distributed/test_reduce_scatter_base.py |
无问题(import 整理 + 添加 @SupportedDevices 装饰器) |
torch_npu/csrc/distributed/ProcessGroupHCCL.cpp |
1 个问题:P2 — A5 整数类型 div_ 修复遗漏了 5 个 AVG 后处理路径 |
发现统计: P0: 0, P1: 0, P2: 1, P3: 0
总体评估: 该 diff 的核心 C++ 变更方向正确(在 A5 上对整数类型使用 div_ 的 "trunc" rounding_mode),但应用范围不完整——仅在 3 个 AVG 后处理路径中添加了 A5 检测,而同一文件中还有 5 个路径未被覆盖(allreduce_coalesced、_reduce_oop、_reduce_scatter_base_uneven_inner、reduce_scatter V 路径、reduce_scatter_tensor_coalesced)。这些遗漏路径在 A5 设备上使用整数 tensor 调用 AVG reduce 操作时会触发运行时错误。Python 测试文件的变更均为 import 清理和设备限制装饰器的规范化调整,无逻辑问题。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


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 命令关闭


| 阶段 | 任务名 | 状态 | 详情 |
|---|---|---|---|
| 编译构建 | 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 : 停止流水线


ascend docs pipeline is running...


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


🟡 Medium Priority
本 diff 在 3 个 AVG 后处理路径中新增了 A5 整数类型 div_ 的 "trunc" rounding_mode 修复(allreduce、reduce、reduce_scatter 同尺寸路径),但同一文件中还有 5 个 AVG div_(getSize()) 路径未被修复:
allreduce_coalesced(第 4989 行):bool/byte tensor 会在 AVG 之前被 cast 为 int32,然后在 A5 上div_无 rounding_mode 将报错。_reduce_oop(第 5150 行):同上,bool/byte cast 为 int32 后会触发。_reduce_scatter_base_uneven_inner(第 5287 行):直接对 outputTensors_ 做 div_,整数类型会触发。reduce_scatterV 路径(第 6000 行):hcclReduceScatterV 分支的输出后处理。reduce_scatter_tensor_coalesced(第 6171 行):coalesced 路径的输出后处理。
这些路径在 A5 设备上对整数 tensor 使用 AVG reduce 时都会触发 div_ 不支持整数类型且无 rounding_mode 的运行时错误。
注:reduce_scatter_tensor 路径(第 6102-6108 行)已在之前的提交中修复,不在本 diff 范围内。
| 4989
| - |
|
4989 | + 在这 5 个未修复的 AVG 路径中,对 `tensor.div_(getSize())` 调用应用与已修复 3 个路径相同的模式:先检测 `is_atlas_a5 && at::isIntegralType(tensor.scalar_type(), false)`,满足条件时使用 `tensor.div_(getSize(), "trunc")`,否则使用 `tensor.div_(getSize())`。 |


ascend docs pipeline is running...


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


compile


ascend docs pipeline is running...


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


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 : 停止流水线


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.




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