Skip to content

fix(xing4): 按 MoE 实际序列分片聚合路由辅助损失 - #364

Draft
xingleixu123 wants to merge 1 commit into
hf1s:refactor/xing4-construct-time-modulesfrom
xingleixu123:codex/fix-xing4-router-statistics-20261106
Draft

xingleixu123 wants to merge 1 commit into
hf1s:refactor/xing4-construct-time-modulesfrom
xingleixu123:codex/fix-xing4-router-statistics-20261106

Conversation

@xingleixu123

Copy link
Copy Markdown
Collaborator

What type of PR is this?

/kind bug

What does this PR do / why do we need it:

TP+EP 使用 sequence parallel 时,MoE 的 D-10 边界可以保留 TP 序列分片。mindspore-ai#1477 只给 router 绑定 CP group,导致完整序列的 sequencewise AUX 变成各本地片段的目标;不能仅依据配置中 TP>1 就加入 TP group,因为普通 TP 或 EP1/SP 会先 all-gather,router 已看到完整序列。

本修改按真实边界的 resolved input destination 选择仍为 sequence Shard 的 TP/CP 轴。counts 使用无梯度 SUM,概率和使用已有可微 SUM;不合并不同 DP 样本,也不改变 expert dispatch、load bias 的 token counts 或 Muon。CP 适配文件不再负责 router 统计绑定。

实现复用 DS4.1 已有 sequence_load_balancing_loss,提升到公共 functional 后保留原导入兼容。默认 DS4.1 路径不变,Xing4 只传入其既有 affinity epsilon。完整序列 fast path 保留原有表达式,避免引入无关算子或分配。recipe factory/inner wrapper 通过一个可选的只读 input_placements 上下文获取已解析布局;未声明该参数的现有扩展不受影响。

这是基于 主仓 #1477 head eb1121470917789ce641e3f12b4b6bad65b6ba54 的独立 stacked Draft,保留 mindspore-ai#1439/mindspore-ai#1477 原提交和全部检视线程。1 commit、7 files;其中一个文件仅调整已有两处 UT 的 mock 所有者路径,没有新增 UT/ST。

Which issue(s) this PR fixes:

关联并扩展已有 JT #338 的完整序列 AUX 统计域问题;此前 CP 实现 JT #341 不覆盖 TP+EP/SP 保留分片的边界。本修复对应 mindspore-ai#1439 检视 T40/T44,和 MTP AUX 累积倍率问题 JT #355/#1441 独立。

总跟踪:JT #362。

Test Plan and Test result:

  • 复用五个已有测试文件:67 passed、4 subtests;覆盖 plan overrides、EP local region、codegen 两种边界和 DS4.1 sequence AUX。语法和 diff 检查通过。
  • 四进程 CPU 因果对照使用真实 planner、precompiled boundary、forward rewriter 和 Xing4 MoE/router:EP1/SP、EP2/noSP 结果与梯度逐值不变;EP2/SP 使用同序列 TP group,DP 样本保持独立。
  • 129 四张 910B 上重复实际 planner/boundary/router 路径,H=3584、E=64、S=4096、两个不同样本、safe-token padding,基线与候选各 4 ranks × 3 场景,12 组配对原值及梯度完整。
  • EP2/SP 的两个样本中,基线 router 梯度相对完整序列 FP64 参考的 L2 误差分别为 1.2309854/0.3352200;修复后为 5.03e-7/7.10e-7。raw AUX 分别为 1.01054239/1.24736071,对应参考 1.01054245617/1.24736056711。完整序列场景 AUX 和 TP-mean 梯度逐值不变;全部 bias token counts、样本 ID 覆盖均精确一致。
  • 该 NPU 探针拦截了 experts、A2A、shared MLP,并显式对 TP router 梯度取平均以对照数学参考;不据此宣称完整 MoE、FSDP、优化器或1000步并行验收完成。候选全部 worker 结果已完成,但退出期间监测器把身份已归属的 D/R 清理态误判为外部进程并终止 elastic wrapper,controller rc=-15 原样保留;未将它记作正常 controller 退出。
  • Python3.12.14、Torch2.12.0+cpu、torch_npu2.12.0.post3、CANN9.2.0 B237。完整模型的状态重分片和1501–2500并行回归继续在 [草稿][PR #1477] Xing4 MF→HP 单卡及 TP/EP/CP/FSDP 精度总跟踪 #362 跟踪。
  • 新通信仅用于真实序列分片的统计轴,每轴 counts/probability 各一次 SUM;完整序列分支不新增 collective。新增通信代价及整网峰值显存待可比实测,不以本探针宣称性能收益。

Code review checklist [illustration]:

  • whether to verify the function's return value (It is forbidden to use void to mask the return values of security functions and self-developed functions. C++ STL functions can be masked if there is no problem)
  • Whether to comply with SOLID principle / Demeter's law
  • Whether there is UT test case && the test case is a valid (复用已有测试,仅维护迁移后的两处 mock 路径)
  • Whether the API change is involved (可选只读 recipe 上下文;旧调用兼容)
  • Whether official document modification is involved

Reuse sequencewise router statistics across the actual sequence-partition
groups and keep complete-sequence routing unchanged. Expose resolved input
placements to existing recipe factories and wrappers.
@xingleixu123

Copy link
Copy Markdown
Collaborator Author

补充本轮完整窗口证据:七组数值/状态/图表报告,必要顺序和触发场景置顶于总issue362。

统计域增量3b76915e在source496(四个TP1布局)与source3292(两个TP/LP布局)中均有明确身份。尤其TP2EP2/SP使用合法shared packed MLP复制plan并保留MoE序列分片/EP,完成1501–2500的1000次更新、4000实际全局样本与原生2500独立CPU状态核验;主LOSS/rawMTP signed mean相旧连续FSDP分别+0.0000357043592633941/-0.000055535430556125755,按原完整均值规则通过。

本PR负责resolved CP/TP序列统计域及router统计职责归属,复用DS4.1公共sequence AUX;LP显式TP副本在原生反向中重复累加是另一个独立根因,由#365/Draft#366处理。本次整网组合同时包含它,不能把该结果写成#364已单独解决LP倍率。原12case显式TP平均/LP=false探针和后续原生倍率证据的边界均保留。

保持Draft,当前外部CI尚无可信完整通过回写;原review线程和既有source/head未改。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant