fix(trainer): require complete multi-run checkpoint publication#3038
Open
peter941221 wants to merge 2 commits into
Open
fix(trainer): require complete multi-run checkpoint publication#3038peter941221 wants to merge 2 commits into
peter941221 wants to merge 2 commits into
Conversation
peter941221
marked this pull request as ready for review
July 15, 2026 13:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3037.
Problem
MultiCheckpointManager could publish checkpoints/step_N/STABLE when its matching policy snapshot was unavailable or incomplete: a rank could fail while writing trainer state, a filesystem broadcast could contain partial files without its own STABLE marker, or the copy into checkpoint storage could fail. A stable marker is the resumability contract, so those states could be selected for resume or retention without a restorable inference policy.
Fix
Checkpoint publication now has three consensus-gated phases: every rank writes its trainer state, the master copies a stable broadcast snapshot, then the master writes the checkpoint STABLE marker. Each result is reduced across ranks, so every rank either records the step or leaves it incomplete.
The copy requires broadcasts/step_N/STABLE, rejects partial broadcast directories, and replaces an unpublished partial weight snapshot on a same-step retry. Multi-run checkpoint history now includes only directories with both STABLE and weight/, so legacy corrupt markers cannot block a retry or evict the last resumable checkpoint.
Verification
Ruff check and format verification pass for the changed files. The focused multi-checkpoint test file passes all six cases: missing broadcast, unstable broadcast, a failed remote rank state write, retry after a partial weight copy, a legacy stable marker without weights, and successful publication. The isolated CPU test harness stubs only the unused optional ring_flash_attn import required during model-module collection.
Note
Medium Risk
Changes distributed checkpoint publication and resume eligibility for multi-run training; incorrect consensus logic could block saves or leave bad checkpoints, but scope is limited to multi_ckpt and is covered by new unit tests.
Overview
Multi-run checkpoints are only published when trainer state, weight copy, and
STABLEall succeed across ranks, so resume/retention no longer treats half-written steps as valid.MultiCheckpointManager.saveis split into three all_reduce(MIN)-gated phases: per-rank trainer writes, master copy frombroadcasts/step_Nonly if that broadcast has its ownSTABLE(replacing any unpublished partialweight/on retry), then mastermark_stable. The step is added tockpt_stepsonly when every rank agrees publication succeeded; otherwise the step stays incomplete and can be retried.On manager creation,
ckpt_stepsis rebuilt from stable steps that also have aweight/directory, ignoring legacySTABLEmarkers without matching policy snapshots.Adds six unit tests covering missing/unstable broadcasts, cross-rank save failure, partial weight retry, and successful publication.
Reviewed by Cursor Bugbot for commit 92e61ee. Bugbot is set up for automated code reviews on this repo. Configure here.