Skip to content

Feat/checkpoint resharding - #196

Open
JYMiracle305 wants to merge 3 commits into
masterfrom
feat/checkpoint_resharding
Open

Feat/checkpoint resharding#196
JYMiracle305 wants to merge 3 commits into
masterfrom
feat/checkpoint_resharding

Conversation

@JYMiracle305

@JYMiracle305 JYMiracle305 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

背景

现有 distributed checkpoint 与保存时的 TP/PP 拓扑绑定,恢复训练时要求使用相同的并行配置。本 PR 引入基于全局张量坐标的 checkpoint resharding,使 checkpoint 可以在不同 TP/PP 配置之间恢复。

设计文档:Checkpoint Resharding 设计

主要修改

  • 新增 ShardedTensor / ShardedStateDict,描述张量的全局形状、本地分片、全局偏移和切分方式。
  • 新增 SavePlanner,统一规划模型参数和 Adam optimizer state 的本地写入布局,并生成可用于 reshard 的全局 metadata。
  • 新增 LoadPlanner,根据源 checkpoint 与当前目标拓扑的分片坐标计算重叠区间。
  • 新增 IndexedRegionLoadStrategy,按 metadata 中的文件和 offset 直接读取所需区域,在加载阶段完成重组,无需预先生成中间 checkpoint。
  • 支持 TP 扩大、缩小以及 PP stage 变化;支持 QKV 非连续分段布局、词表尾部 padding 和保存/目标 dtype 转换。
  • 模型与 Adam m/v 共用参数分片信息,训练状态和 LR scheduler 状态随 checkpoint 一并恢复。
  • 保存阶段仅由 dp_rank=0 的 TP/PP ranks 写入 shard,并在所有 rank metadata 就绪后原子发布全局 metadata。

当前限制

  • 仅支持 checkpoint version 3。
  • 每个张量目前只支持一个 fragmented axis;QKV 等非连续布局通过 segments 表达。
  • 暂不支持 DistributedOptimizer / ZeRO optimizer state 的保存和恢复。
  • optimizer resharding 依赖稳定的 named parameters。

测试

  • TP 2 -> 4、TP 4 -> 2 的 overlap planning。
  • 非均匀 shard 的显式 global offset。
  • QKV segmented layout 在 TP 变化后的重组。
  • PP stage 变化时只加载目标 stage 所需参数。
  • vocabulary padding、BF16 -> FP32 dtype 转换。
  • model/optimizer state metadata 和 checkpoint serialization round trip。

@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch 3 times, most recently from 5153a9e to a3f6181 Compare August 3, 2026 10:17
@JYMiracle305
JYMiracle305 changed the base branch from master to feat/checkpoint-consumed-micro-batches August 3, 2026 10:17
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-consumed-micro-batches branch from 57ab888 to 7689011 Compare August 4, 2026 07:43
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch 2 times, most recently from e0540b5 to c85e813 Compare August 6, 2026 07:13
@JYMiracle305
JYMiracle305 changed the base branch from feat/checkpoint-consumed-micro-batches to feat/checkpoint-optimizer-state-control August 6, 2026 07:16
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch from c85e813 to 7028203 Compare August 6, 2026 07:19
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-optimizer-state-control branch from 5514a0b to cf3cce5 Compare August 6, 2026 08:12
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch from 7028203 to 8e4012b Compare August 6, 2026 08:12
@JYMiracle305
JYMiracle305 changed the base branch from feat/checkpoint-optimizer-state-control to feat/checkpoint-consumed-micro-batches August 6, 2026 08:14
@JYMiracle305
JYMiracle305 changed the base branch from feat/checkpoint-consumed-micro-batches to feat/checkpoint-optimizer-state-control August 6, 2026 08:16
@JYMiracle305
JYMiracle305 changed the base branch from feat/checkpoint-optimizer-state-control to feat/checkpoint-consumed-micro-batches August 6, 2026 08:17
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch from 8e4012b to 83a73ee Compare August 6, 2026 08:44
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-consumed-micro-batches branch from 59a9674 to 9d99035 Compare August 6, 2026 08:44
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch from 83a73ee to 57bc905 Compare August 6, 2026 09:47
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-consumed-micro-batches branch from 9d99035 to 862a378 Compare August 6, 2026 09:47
@kilinchange
kilinchange force-pushed the feat/checkpoint-consumed-micro-batches branch from 862a378 to f6f4715 Compare August 7, 2026 02:18
@kilinchange
kilinchange force-pushed the feat/checkpoint_resharding branch from 57bc905 to 9928ff2 Compare August 7, 2026 02:18
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-consumed-micro-batches branch from f6f4715 to 9d30401 Compare August 12, 2026 01:37
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch 5 times, most recently from 845f617 to 8ba9890 Compare August 12, 2026 08:27
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-consumed-micro-batches branch from 9d30401 to 6799ce4 Compare August 12, 2026 14:55
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch 2 times, most recently from d64951e to 770fc02 Compare August 14, 2026 09:19
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-consumed-micro-batches branch from 6799ce4 to 9d406c9 Compare August 14, 2026 09:20
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-consumed-micro-batches branch from 9d406c9 to 86aefcd Compare August 14, 2026 09:35
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch from 770fc02 to 8a3ddc2 Compare August 14, 2026 09:35
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-consumed-micro-batches branch from 86aefcd to 48ca7e4 Compare August 20, 2026 08:56
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch from 8a3ddc2 to 340c458 Compare August 20, 2026 08:56
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch from 340c458 to 32b6d48 Compare August 25, 2026 03:24
@JYMiracle305
JYMiracle305 changed the base branch from feat/checkpoint-consumed-micro-batches to fix/adam-fp32-state August 25, 2026 03:34
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch from 32b6d48 to fb9fc5f Compare August 26, 2026 08:09
@kilinchange
kilinchange force-pushed the feat/checkpoint_resharding branch from fb9fc5f to 31e9655 Compare August 26, 2026 08:15
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch from 31e9655 to 40e28ec Compare August 27, 2026 01:33
@JYMiracle305
JYMiracle305 changed the base branch from fix/adam-fp32-state to master August 27, 2026 01:37
@JYMiracle305 JYMiracle305 changed the title [WIP] Feat/checkpoint resharding Feat/checkpoint resharding Aug 27, 2026
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint_resharding branch 2 times, most recently from 7f25f0a to 3328359 Compare August 27, 2026 06:14
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