Skip to content

fix(checkpoint): 保留专家反向转换的单例维度 - #1442

Closed
xingleixu123 wants to merge 1 commit into
mindspore-ai:masterfrom
xingleixu123:codex/checkpoint-expert-inverse-20261104
Closed

xingleixu123 wants to merge 1 commit into
mindspore-ai:masterfrom
xingleixu123:codex/checkpoint-expert-inverse-20261104

Conversation

@xingleixu123

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

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

复用 Transformers MergeModulelist 的前向及其 Split 目标名逻辑,仅将反向 squeeze() 限定到专家轴,避免原权重的单例维度被额外删除。例:(1,1) -> (E,1,1) -> (1,1);原上游逆转换得到标量。

将薄兼容放入现有 components/checkpoint/weight_conversion.py,模型适配器组合公共 Merge、Transpose、WeightConverter 与 HF Concatenate,不再各自实现 Pack/Unpack。上游已有同一修复 Transformers #49773,核验时仍 open;本修改保留已锁定依赖版本的可逆语义,不 monkeypatch 上游模块。

仅一个 Python 逻辑文件;本轮按要求不带 UT/ST,实际复现和测试代码独立归档。此问题不被归因为 29B 历史训练精度差异。

Which issue(s) this PR fixes:

Related: https://github.com/hf1s/hyper-parallel/issues/357;总跟踪 hf1s#353,供 模型 #1439 复用。保持 Draft,不自动关闭问题。

Test Plan and Test result:

  • Python 3.12、PyTorch 2.12.0+cpu、Transformers 5.22.1;基于 master d4b9242922143481824fb8587680f2112ccd1cdb。
  • 真实 HuggingFaceCheckpointer legacy 和 DCP/HFLoadPlanner,两个 layer、12 experts,普通 (H,I)=(3,2) 与单例 (1,1):每组加载及逆导出的 72 个 FQN shape/dtype/值逐项一致。
  • eager/meta、不同 requires_grad;已有专家权重与梯度回归两项通过。pylint、diff 检查通过。
  • CPU 可选后端导入 shim 不提供 kernel,不把这些结果表述为 NPU 性能或完整训练状态恢复验收。

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

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