Skip to content

feat: track checkpoint progress in micro-batches - #195

Open
JYMiracle305 wants to merge 2 commits into
feat/named-parametersfrom
feat/checkpoint-consumed-micro-batches
Open

feat: track checkpoint progress in micro-batches#195
JYMiracle305 wants to merge 2 commits into
feat/named-parametersfrom
feat/checkpoint-consumed-micro-batches

Conversation

@JYMiracle305

@JYMiracle305 JYMiracle305 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Depends on #194

主要修改

该 PR 统一了 checkpoint 中训练进度的计量语义,将原先含义模糊的 consumed_batches 重命名为 consumed_micro_batches。

在不同流水线并行配置下,DataLoader 单次迭代包含的 micro-batch 数量不同。该 PR 将 checkpoint 中保存的进度统一为 micro-batch 数量,并在恢复训练时根据当前 PP 配置换算为对应的 DataLoader 位置,同时正确处理 DDP rank 和步长。

  • 将 checkpoint 数据结构、保存/恢复接口及 JSON 字段统一重命名为 consumed_micro_batches
  • PP 场景保存 checkpoint 时,将 DataLoader batch 进度转换为 micro-batch 进度
  • 恢复训练时,根据当前 PP 配置换算回 DataLoader batch 位置
  • 增加 PP batch 边界及 DDP stride 合法性检查
  • 同步修改 GPT-2、LLaMA3 训练入口和 checkpoint 测试

@JYMiracle305
JYMiracle305 changed the base branch from master to feat/named-parameters August 3, 2026 08:04
@JYMiracle305
JYMiracle305 changed the base branch from feat/named-parameters to master August 3, 2026 08:06
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-consumed-micro-batches branch from 49d8d4b to 57ab888 Compare August 3, 2026 08:27
@JYMiracle305
JYMiracle305 changed the base branch from master to feat/named-parameters August 3, 2026 09:52
@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-consumed-micro-batches branch from 57ab888 to 7689011 Compare August 4, 2026 07:43
struct TrainerState {
int64_t global_step = 0;
int64_t consumed_batches = 0;
int64_t consumed_micro_batches = 0;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前 ckpt 保存的是 DP × 每 rank 已处理 micro-batch 数,没有包含 batch_size。当恢复时改变 --batch_size,非 PP 路径会跳过相同数量的 micro-batch,却对应不同数量的样本;PP 路径还可能在整除检查处退出,或者跳到错误位置。建议参考 Megatron 风格的 consumed_train_samples 记法,或者加一个 FIXME,暂时提醒一下禁止 resume 时修改 bs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

将 ckpt 内记录的值改为 consumed_train_samples,现在支持 resume 时修改 bs 了

@JYMiracle305

Copy link
Copy Markdown
Contributor Author

精度对比

image

性能对比

image

@JYMiracle305
JYMiracle305 force-pushed the feat/checkpoint-consumed-micro-batches branch 2 times, most recently from 59a9674 to 9d99035 Compare August 6, 2026 08:44
@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
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.

2 participants