Skip to content

fix(loss): 修正 loss parallel 下显式 TP 副本 AUX 的梯度倍率 - #366

Draft
xingleixu123 wants to merge 1 commit into
hf1s:refactor/xing4-construct-time-modulesfrom
xingleixu123:codex/lp-replicated-router-aux-20261107
Draft

xingleixu123 wants to merge 1 commit into
hf1s:refactor/xing4-construct-time-modulesfrom
xingleixu123:codex/lp-replicated-router-aux-20261107

Conversation

@xingleixu123

@xingleixu123 xingleixu123 commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?
/kind bug

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

TP loss parallel下,主CE产生词表分区梯度,完整序列router AUX却是TP副本;直接复用原生source-Replicate SUM会把AUX梯度放大TP倍。四卡真实原生因果实验已确认TP2下2×,修复后对独立FP64目标为1×,非LP原始梯度文件逐字节不变。

复用现有AutoScaler/context,仅3个生产文件:

  • context保存实际LP/TP元数据,Trainer不含模型专用分支;
  • 仅显式声明 tp_replicated=True 的完整副本均值在反向补所需倍率,声明及state对象保存在原autograd ctx;
  • Xing4全序列router声明该合同;其他5个生产调用(包括DSA/indexer)、TP1/nonLP/上下文外行为保持。无新collective,不改变forward/raw日志、FSDP规约、模型或优化器。

参考已合入JT_dev的 JT #284 的LP/副本归一化职责区分;当前master无该JT helper,故不复制旧模块或整体cherry-pick。此PR只在 mindspore-ai#1477 上新增1 commit,不改 mindspore-ai#1439/mindspore-ai#1477 历史。四卡 #1453与#364独立叠加,runtime三文件hunk保留它们的多foundation与统计域改动。

Which issue(s) this PR fixes:

Fixes #365

Related #362

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 (if there is no test case, please explain the reason)
  • Whether the API change is involved
  • Whether official document modification is involved

API仅新增默认不改行为的可选声明/上下文元数据,旧private二参数apply反向也保持兼容;说明写在函数docstring,没有官网改动。

验证:

  • 复用2个已有UT文件补必要行为:指定6测试+18subtests;相关Trainer/DSA回归9测试+8subtests,共15+26,均真实通过。
  • CP2TP2/GA4原生NPU前后对照:修前LPfalse=1×、true=2×;修后两者1×,relative L2≤5.70e-7,非LP原梯度字节不变。原生SUM factor.25/.5不改。
  • 原始合成梯度、独立oracle与复现命令。原12case的显式TP均值验证不冒充原生FSDP证明。
  • 当前完整TP续训验收继续由#362更新;单卡/纯FSDP/CP TP1不触发本补偿,保留原实测source身份,不冒称全部来自本head。
  • 增量只有标量倍率/metadata,无参数、持久状态或大激活布局变化;未取得独占稳态性能/allocator峰值实测,不据插桩耗时声称性能收益。当前head CI按真实结果记录,不以空checks称绿。

当前head的CI状态(与本地/NPU验证分开):
hf1s base repo 的 label-check run42278406132 为failure:Unable to verify a CI pass label less than 24 hours old.,即缺24小时内的外部CI通过回写;不是分类标签错误。head repo空checks不能代替PR base repo结果。已核对固定head的实际检查合同;当前公开fork配置/可信回写尚不能确认可执行的完整训练CI入口,不证明私有hook不存在。保持Draft;未手动加任何通过标签、改workflow或发未经证实支持的重测命令。本地15 tests+26 subtests及真实NPU证据不冒称CI已绿。

@xingleixu123

Copy link
Copy Markdown
Collaborator Author

本轮完整训练回归证据已归档:七组验收报告,总跟踪#362。

含此修复的真实source3292组合(1477+1420+1470+1453+364+366)已从共同旧FSDP1500完整状态独立续训1501–2500,不能写成bare #366或bare #1477无依赖通过:

四卡布局 signed mean LOSS差 signed mean rawMTP差
TP2CP2 +0.00007089864058039908 -0.000013107831971498562
TP2EP2/SP +0.0000357043592633941 -0.000055535430556125755

两项均按完整1000步abs(mean(目标−旧连续FSDP))≤0.005通过;实际4000全局样本、原生2500及独立CPU完整状态均闭合。AUX全原值/副本spread作为诊断保留,不设新阈值;TPCP原parent采集器AUX bitexact尾错及精确有界审计保留,未改写成clean parent退出。

原生CP与SP的修前2×/修后1×、非LP梯度字节不变仍是本修复的直接因果证据;整网loss接近不能替代该依据。未改Muon、模型、规约顺序或AUX系数。原head f8ec544b不变,保持Draft;外部CI label-check仍失败,不把独立NPU通过冒称合入门禁绿色。图表、逐步CSV、状态摘要和必要依赖见报告/总issue。

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