已合并
reduce scatter support tensorlist.size != world_size #44438
reduce scatter support tensorlist.size != world_size #44438
已合并
limuan创建于 7 天前
limuan
limuan成员
7 天前
# 【合入来源】 - [x] 需求 - [ ] 问题单 - [ ] issue/工单 - [ ] 重构优化 - [ ] 资料更新 # 【修改方案】 本提案修改 `torch_npu` 的 `ProcessGroupHCCL::reduce_scatter`,使其输入支持范围与 PyTorch 社区(NCCL)保持一致。 PyTorch 2.2 的 `reduce_scatter` 对输入张量列表有形状/计数约束(列表长度须等于 `world_size`、每张量 numel 须等于输出 numel 等),2.3 起去除了这些约束。pta(torch_npu)当前的 `reduce_scatter` 与 PyTorch 2.2 实现一致:输入是 tensor list,包含多个 tensor,数量与卡数一致。这与社区后续版本不一致,需要兼容输入只有一个 tensor 的场景等用例,和社区保持一致。 核心改动:在 `reduce_scatter` 的 same_size 分支新增展平函数 `flatten_for_reduce_scatter`,替代原先复用的 `flatten_for_scatter_gather`——移除"输入张量数须等于 world_size""每张量 numel 须等于输出 numel"两条校验,保留列表长度一致与 input/output 同设备校验,并新增非空检查。Python 层 `torch.distributed.reduce_scatter` 签名不变。) # 【资料变更】 不涉及 # 【接口变更】 不涉及 # 【功能验证】 1、基础功能验证:执行test_reduce_scatter.py用例 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/f7268922-2686-4d48-ae73-b7e6db142c49/image.png 'image.png') 2、dtype*op*tensorshape(1D,2D)*input_tensor_list.size(==,>,< world_size)*all_input_numbel(==, >, < )all_output_numbel reduce_scatter 全耦合输入,reduce_scatter算子输出与gpu结果对比 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/d40a1664-8aea-4a69-9fc4-190ab431c7bc/image.png 'image.png') 3、性能验证,修改前后pta调用reduce_scatter,用时基本无变化 ![image.png](https://raw.gitcode.com/user-images/assets/7404318/a90d0a4a-bd6b-4933-980c-0c5523dfc08a/image.png 'image.png') # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [ ] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常
likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 limuan 的贡献)
limuanlimuan成员
7 天前 创建了 pull request,commit 9f82d1b9
atomgit-bot
atomgit-bot
7 天前 评论:

变更摘要

此 PR 为 ProcessGroupHCCL::reduce_scatter 新增了专用的输入张量扁平化函数 flatten_for_reduce_scatter,使得 reduce_scatter 操作支持输入张量列表大小与 world_size 不一致的场景,行为与 NCCL 对齐。同时将原有对 flatten_for_scatter_gather 的调用替换为新的专用函数。

主要改动

  • 新增 flatten_for_reduce_scatter 函数:该函数以 tensor_lists.size() 作为设备数量(而非 world_size),使 reduce_scatter 的输入张量列表大小不必等于 world_size;同时校验输入列表与输出张量列表长度一致、对应的输入/输出张量位于同一设备。
  • 替换 reduce_scatter 中的扁平化调用:将原先调用 flatten_for_scatter_gather(inputTensors, outputTensors, size_) 改为调用 flatten_for_reduce_scatter(inputTensors, outputTensors),去除了对 size_(即 world_size)的依赖。
likedislike
atomgit-bot
atomgit-bot
7 天前 评论:

代码审查

审查总结

已审查的文件:

  • torch_npu/csrc/distributed/ProcessGroupHCCL.cpp:发现 1 个问题

各优先级问题统计:

  • P0:0
  • P1:0
  • P2:1
  • P3:0

总体风险评估:此变更引入了专用函数 flatten_for_reduce_scatter 以支持 reduce_scatter 操作中 tensor list 大小与世界大小不同的场景,整体设计合理。唯一需要关注的是新函数中缺少对内部 vector 为空的防御性检查,可能导致未定义行为,建议在合入前修复。其余变更逻辑正确,无安全、性能或兼容性问题。

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

💬 仅评论

likedislike
ascend-robotascend-robot成员
7 天前 添加了label:ascend-cla/yes
此处折叠了79条消息 查看更多
ascend-robotascend-robot成员
6 天前 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
6 天前 评论:
流水线 PR-pipeline_pytorch#60515 [ commitID:6b087be2 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 >>>
Build_ARM >>>
Build_LibTorch_x86 >>>
Build_LibTorch_ARM >>>
Build_X86_torchair 🛑 >>>
Build_ARM_torchair 🛑 >>>
patch_test 🛑 >>>
恶意代码检查 Antipoison >>>
编码安全与规范检查 codecheck_pre-commit >>>
check_error >>>
lintrunner >>>
开源片段检查 SCA >>>
开发者测试 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 >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[wujinyuan1, huangjingwei, liangsongwei, yashi999, culechan, Dring, wuyouqi1, L1919_snow, qq_52711437, WhiteNight12, nomiz, xiu_21, ffmh, wanglijun55, hss-shuai, husichao, smallsilly, lanshaozuishuai, jimmyisme1, lzy0920232, alpha-junh, Sunshine_Youngster, wei_zhuoyi, zhangyihuiben, zyw-hw, zzzkeke, rmch, yangch0324, LucciC, AACAES, renyujin, wjlflyer, senzhen-town, pengjingyou, qsc97, limuan, yule100, xiaoqi-zhou, kuhn7, chenxingying, hanye02, zichun_ye, anyrenwei, kkjocker, wangzili121, Lu_G, yvjc, puddingfjz, HandsoemLemon, bigprestigee1, huawuyi, zhenyu10, dairenjie, du-jin-hang, zou-jieyu, adelaideliu, TrHan, wanlinan, Windwindzzz, pengqihw, kisnwang, yuheng_wang, honghao_wang, jizewei, zhangguoguang, sunyu-xuan, chenrayray, hbhu_bin, liujunzhu, c_34, LiNuoh, maoyuanpeng1, zzhongmin, zhaoyu65, bellatan, jiabaolin, zhuofanshen, wencaiwen, lu_zhuge, caoshuyang, molly12, lyx324521, LQ1206, gitcode-chenjiao, cai-weiwei1989, CHDong, ogqin, yuanlipingGit, xuqinglin1, lqz2, zouwei1, chaoluoa, paradox325, jackzhang1116, yaoyao, akh, yujiacheng, dengjie0116, Hubert11111, Shine_Ws, wslhj555, longqiand, OYtao666, JiaqingQiang, luyyyy, Kingbelial, zhanghaiyu0101, wenxp1018, yanliu-luoluo, ksun_sekiro, liyong328, wgzheng, tangky, vivi_is_coding, aoiaoisola, weixin_44494597, wangmengmengwang65667, hid57809721, qq_35468730, comeonup, C547032, gcw_m5OQChA4, yao_yao_ling_xian, cnnbwcy, szqfes_12, cora_19, cann_lilin, can, shawnylee233, fanglanyue0916, hhz0, LiNuohang, taohuoquan, Jesse, WSs_321]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
ascend-robotascend-robot成员
6 天前 合入了pull request
ascend-robot
ascend-robot成员
6 天前 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
ascend-robot
ascend-robot成员
6 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#13957 [ commitID:6b087be2 ] 已完成
likedislike