Merged
[refactor] reuse upstream interfaces for DeepSeek-V4.1 #1143
[refactor] reuse upstream interfaces for DeepSeek-V4.1 #1143
Merged
1Fire4Add on Oct 31
1Fire4
1Fire4Collaborators
Oct 31

描述

DeepSeek-V4.1 复用当前固定上游已提供的接口,减少重复实现:

  • 删除两个重复的层权重 key 映射 helper,直接继承 DeepSeekV3StateDictAdapter,保持非 MTP 配置的 checkpoint 转换语义。
  • 对已确定为 HostEngramTable 的实例直接调用 wire_sparse_grad_replicas,参数和调用时机保持一致。

类型

Checklist:

文档项不适用:内部接口复用,公开配置和 checkpoint 格式保持一致。

如何测试

最终 head 在 A3 服务器执行 CPU UT:

检查 实际结果
完整 pre_commit run --all-files --show-diff-on-failure PASS,包含 Pyrefly、Ruff 和架构边界检查;OAT 因无暂存文件未扫描
相关 CPU UT 16 passed / 7 skipped,4 warnings,退出码 0
修改前 helper 与固定上游的非 MTP 映射等价检查 PASS:28 组映射、双向转换、4 个层号、两种无 MTP 配置,共 448 次完全一致
git diff --check PASS

UT 包含新增的文本与多模态层权重往返、两进程 Gloo checkpoint 往返,以及 Engram eager / FullAC、MXFP8、分片和 aot_eager 稀疏更新检查。7 个跳过项来自仓库现有的视觉测试延期规则;新增两个往返用例均实际通过。

精度和性能验证结果

依据精度对齐开发指南第 3 节的非数值改动例外,跳过 3.1、3.3、3.4 的整网对齐:本次仅复用等价 key 映射和已有方法,计算公式、归约顺序及参数传递保持一致。局部行为通过上述 helper 等价检查和 CPU UT 验证。

未执行真实 NPU kernel / HCCL 集成、整网训练精度或性能验证。

其他信息

无。

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for 1Fire4's contribution.)
1Fire41Fire4Collaborators
Oct 31 Created pull request, commit d5cb4dbd
atomgit-bot
atomgit-botCollaborators
Oct 31 Comments:

变更摘要

本次重构主要目的是复用上游 DeepSeekV3StateDictAdapter 中已有的层权重映射实现,减少本地重复代码的维护成本。DeepSeekV41StateDictAdapter 删除了两个自定义 helper _map_from_hf_layer_key 与 _map_to_hf_layer_key,改为直接继承上游实现;deepseek_v4_1/parallelize.py 中将 Engram 表的梯度副本接线从可选方法探测改为直接调用 wire_sparse_grad_replicas,并更新了模块文档说明,纠正「仅支持 CP1」的过期描述,明确文本配置支持上下文并行、不支持流水线并行与 MTP。同时新增纯文本与多模态两种配置下的 HF → 本地 → HF 层权重往返测试,验证层权重映射语义保持不变。

主要改动

  • 移除本地层权重映射 helper: DeepSeekV41StateDictAdapter 删除 _map_from_hf_layer_key 和 _map_to_hf_layer_key 两个重复实现,直接继承上游 DeepSeekV3StateDictAdapter 的同名能力,保持非 MTP 配置的 checkpoint key 与权重转换语义。
  • 简化 Engram 梯度副本接线: _shard_engram_tables 中不再用 getattr 探测可选的 wire_sparse_grad_replicas,改为对 HostEngramTable 直接调用该方法并传入 edp_mesh、edp_mesh_dims。
  • 修正并行化模块文档字符串: parallelize.py 模块说明去掉「CP1-only」限定,改为说明 V4.1 文本配置在注意力与文档对齐兼容时支持上下文并行,不支持流水线并行与 MTP,decoder 使用通用(非 MTP)FSDP wrapper。
  • 新增层权重往返测试: test_state_dict_adapter.py 新增参数化用例,覆盖 deepseek_v4_1_debugmodel_text 与 deepseek_v4_1_debugmodel 两种配置,校验 from_hf 后 attention 与 moe router 权重映射正确,且 to_hf 能还原原始 key 与数值。
likedislike
Incorrect?
atomgit-bot
atomgit-botCollaborators
Oct 31 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Oct 31 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Oct 31 Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/torchtitan-npu ✅ xuyujun, zzyyjj012 (2/2) ✅ xuyujun (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

hitwdy, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
49 messages are collapsed here。 See more
titan-npu-reviewer
titan-npu-reviewer
26 days ago Comments:

实际位置是 .ci/architecture_import_baseline.json:31。

一般(S2): 【文档同步】需要补充或更新文档。

本 PR 的文档同步要求:
本区间把训练配置字段从 model_spec 改成 model,但 docs/feature_guides/mtp.md 的 MTP 深度示例仍写 config.model_spec,且把整个 trainer 配置传给 decoder_vocab_size(上游该函数签名要求传模型 config)。照文档抄会直接报错。该文档本区间有改动(第 77 行),属于应随接口一起更新的范围。

  1. docs/feature_guides/mtp.md:181:config.model_spec = model_registry(...) 改为 config.model = model_registry(...)。
  2. docs/feature_guides/mtp.md:184:decoder_vocab_size(config.model_spec) 改为 decoder_vocab_size(config.model)。
  3. docs/feature_guides/mtp.md:191:与第 181 行相同,改为 config.model = model_registry(...)。
  4. docs/feature_guides/mtp.md:196:与第 184 行相同,改为 decoder_vocab_size(config.model)。

未能定位到相关的 diff 行或行内评论发布失败,改为普通评论;未计入必须解决项。

审查版本:5f8c9ea328fada2fba49aacec8600d9c413743b3

likedislike
zzyyjj012
zzyyjj012Collaborators
26 days ago Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
26 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
26 days ago Merged pull request
1Fire41Fire4Collaborators
23 days ago Associated issue: [RFC] TorchTitan v0.4.0 分阶段升级规划与进度跟踪