已合并
将 BIRS 批量不变性扩展至 AllReduce(AllReduceBIAR) #2348
Davydov_Danil创建于 7月28日
将 BIRS 批量不变性扩展至 AllReduce(AllReduceBIAR) #2348
已合并
Davydov_Danil创建于 7月28日
Davydov_Danil
7月28日

Description

RFC 0001 已为 HcclReduceScatter 引入 BIRS(Batchsize Invariant ReduceScatter)算法:在 A3(SIO + HCCS 混合拓扑)上对大消息相比 RHD 提升带宽利用,并保证确定性规约顺序(bit-identical)。但 RFC 0001 仅覆盖 ReduceScatter,其 Open Question #1 明确声明批次不变 AllReduce 将以独立 PR 提交。

当前 AllReduce 在 A3 仍走 level0 NP_MESH/NHR/NB/Ring 路径,无法同时打满 SIO 与 HCCS 两类链路,且在大消息批量不变场景下缺少对应算法——这与 RFC 0001 §Background 列举的 RLHF/PPO、vLLM 批量不变性、CI 复现等需求存在缺口。

https://gitcode.com/cann/hccl/issues/533

Testing

  • UT(test/ut/all_reduce_biar/,随 bash build.sh --experimental -u 运行):
    • biar_selector_test.cc(10 用例):覆盖选路判定——serverNum==0、单机双卡、每 server 3 rank、rankSize==1 等拒绝场景;每 server ≥4 rank 的 910_93 偶数 rank 选中;非 A3 / 奇数 rankSize 不选中。
    • biar_core_test.cc(30 用例):覆盖 PrepareDataSlice 均匀/余数/边界切片、TreeReduceRs 拓扑与规约顺序、HCCS/SIO/LocalCopy 的 RS/AG 环路、Preprocess 校验、RunAsync 端到端序列与失败传播。
  • ST(仿真,test/st/algorithm/testcase/all_reduce_testcase_a3.cc,ST 目标 all_reduce_a3,随 bash build.sh --experimental -s 运行):15 个用例在 DEV_TYPE_910_93(A3,SIO+HCCS 混合拓扑)仿真环境验证 AllReduceBIAR:
    • 单机 4/6/8/10/12/14/16 rank,含 count 不能整除切片数的 *_rem 余数用例;
    • HCCL_REDUCE_SUM / MIN / MAX 多 reduceOp(18_min、116_rem_max、1416_max);
    • 跨服务器 st_all_reduce_1416_test(1 SuperPod × 4 Server × 16 卡,共 64 rank)。

注:上述 UT/ST 均仅在 --experimental(ENABLE_EXPERIMENTAL=ON)构建时编译运行,不影响默认 CI 构建与测试。

Documentation Update

Type Label

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 Davydov_Danil 的贡献)
DDavydov_Danil
7月28日 创建了 pull request,commit 357a5b7c
DDavydov_Danil
7月28日 关联了issue:[Documentation|文档反馈]: 资料建议增加,hccl test相关文档集成、 roadmap 、Changelog,[Requirement] 将 BIRS 批量不变性扩展至 AllReduce(AllReduceBIAR)
atomgit-bot
atomgit-bot
7月28日 评论:

变更摘要

此 PR 将 RFC 0001 中已为 ReduceScatter 引入的 BIRS(批量不变性)算法扩展至 AllReduce,新增名为 AllReduceBIAR 的实验性算法实现。该算法在 A3(SIO + HCCS 混合拓扑)上针对 DEV_TYPE_910_93 设备,采用 ReduceScatter + AllGather 两阶段模式,通过 3 线程并行利用 SIO 和 HCCS 两类链路完成确定性的归约与广播。整体变更通过 ENABLE_EXPERIMENTAL 编译选项控制,新增了完整的 executor 基础框架、BIAR 模板实现、算法选择逻辑及仿真测试用例。

主要改动

  • 新增 AllReduceBIARExecutor 与 AllReduceExecutorBase 框架: 在 experimental/ops/all_reduce/biar/ 下新增 executor 基类和 BIAR 专用子类,AllReduceExecutorBase::Orchestrate 负责参数还原与多线程编排,AllReduceBIARExecutor::CalcResRequest 为单/多服务器 A3 拓扑分别计算资源(level0 NP_MESH + 3 线程),并通过 REGISTER_EXEC 注册为 "AllReduceBIARExecutor"。

  • 新增 AllReduceBIAR 模板实现: 在 experimental/ops/all_reduce/biar/template/all_reduce_biar.cc 中实现两阶段通信模板——RunReduceScatter(HCCS 写入 + SIO 带 reduce 写入 + 本地 Tree Reduce)和 RunAllGather(HCCS 写入 + SIO 读取 + 本地拷贝),以 TEMPLATE_ALL_REDUCE_BIAR(类型值 1005)注册到模板工厂。

  • 算法选择与调度入口: op_common_experimental.cc 新增 SelectAlgAllReduce 函数,对 DEV_TYPE_910_93 且 rank 数为偶数时选中 AllReduceBIARExecutor;all_reduce_op_experimental.cc 新增 AllReduceExperimental 入口,先通过 MatchBIRS() 判断,命中 BIAR 路径时调用 ProcessA3 执行。

  • 编译控制与集成: build.sh 新增 ENABLE_EXPERIMENTAL 选项传导至 CMake;src/ops/all_reduce/all_reduce_op.cc 在 ENABLE_EXPERIMENTAL 宏下将 HcclAllReduce 重定向至 AllReduceExperimental;all_reduce_op.h 条件包含实验性头文件。

  • 仿真测试用例: 添加 test/st/algorithm/testcase/all_reduce_testcase_a3.cc,覆盖 4/6/8/10/12/14/16 卡及 1 超节点×4 服务器×16 卡等多 rank 规模,验证 V-style 分片(含余数)下的归约正确性。

likedislike
不准确?
atomgit-bot
atomgit-bot
7月28日 评论:

代码审查

审查完成 — 逐文件总结

# 文件 审查结论
1 CMakeLists.txt 无新增问题
2 build.sh 无新增问题
3 cmake/device/CMakeLists.txt 无新增问题
4 experimental/ops/CMakeLists.txt 无新增问题
5 experimental/ops/all_reduce/CMakeLists.txt 无新增问题(新文件,缺文件尾换行)
6 experimental/ops/all_reduce/all_reduce_op_experimental.cc P1: beginTime 未初始化; P3: userRankSize 未使用、重复校验
7 experimental/ops/all_reduce/all_reduce_op_experimental.h 无新增问题(新文件,缺文件尾换行)
8 experimental/ops/all_reduce/biar/CMakeLists.txt 无新增问题(新文件)
9 experimental/ops/all_reduce/biar/all_reduce_biar_executor.cc P2: %u/%zu 格式不匹配、dynamic_cast 无 else; P3: 未使用变量、冗余 make_unique
10 experimental/ops/all_reduce/biar/all_reduce_biar_executor.h 无新增问题(新文件)
11 experimental/ops/all_reduce/biar/all_reduce_executor_base.cc 无新增问题(新文件)
12 experimental/ops/all_reduce/biar/all_reduce_executor_base.h 无新增问题(新文件)
13 experimental/ops/all_reduce/biar/template/CMakeLists.txt 无新增问题(新文件)
14 experimental/ops/all_reduce/biar/template/all_reduce_biar.cc P2: std::vector<u32> 截断 u64 偏移量; P3: 未使用变量
15 experimental/ops/all_reduce/biar/template/all_reduce_biar.h P3: #endif 注释粘贴错误、未使用成员 vec
16 experimental/ops/op_common/op_common_experimental.cc 无新增问题
17 experimental/ops/op_common/template/alg_template_base_experimental.h 无新增问题
18 src/ops/all_reduce/all_reduce_op.cc 无新增问题
19 src/ops/all_reduce/all_reduce_op.h 无新增问题
20 test/st/algorithm/testcase/all_reduce_testcase_a3.cc 无新增问题(新文件)

总结

  • P1: 1 个 — AllReduceOutPlaceCustom 中 beginTime 未初始化即按值传递,触发未定义行为。
  • P2: 3 个 — TreeReduceRs 中用 u32 容器存储 u64 字节偏移导致大消息数据损坏;日志格式 %u/%zu 不匹配;dynamic_cast 失败时静默跳过操作。
  • P3: 7 个 — 未使用变量、复制粘贴残留注释、冗余校验/分配等代码清理项。

整体风险评估:中等。P1 的未初始化变量在实际未启用 profiling 时有 UB 风险但概率较低;P2 的 u32 截断问题在大消息(单 slice 超过 ~4 GiB)时会静默数据损坏,是最值得关注的逻辑缺陷。建议在合入前至少修复 P1 和 P2 级别问题。

类型 数量
🔴 阻塞 1
🟡 建议 4

⛔ 需要修改

likedislike
不准确?
CANN-robotCANN-robot成员
7月28日 添加了label:cann-cla/yes
此处折叠了406条消息 查看更多
CANN-robot
CANN-robot成员
4 天前 评论:

/ai review force

likedislike
atomgit-bot
atomgit-bot
4 天前 评论:

🤖 AI 代码检视正在进行中,请稍候…

likedislike
不准确?
bz_lee成员
4 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
4 天前 添加了label:lgtmapproved
CANN-robotCANN-robot成员
4 天前 合入了pull request