fix(train_dflash): atomic per-file checkpoint writes + _SUCCESS-gated resume#659
Open
jessiewei7 wants to merge 1 commit into
Open
fix(train_dflash): atomic per-file checkpoint writes + _SUCCESS-gated resume#659jessiewei7 wants to merge 1 commit into
_SUCCESS-gated resume#659jessiewei7 wants to merge 1 commit into
Conversation
… resume save_checkpoint() wrote every file (training_state.pt, draft weights, dflash.py) straight to its final path, and get_last_checkpoint() trusted any directory matching epoch_X_step_Y. A crash mid-write (OOM kill, preemption) could leave a partial file at its final "looks complete" name, which --resume would then silently load. This is worse on multi-node setups where args.output_dir isn't a single coherent POSIX filesystem: a directory can look complete by name while missing content another rank wrote that hasn't propagated yet (hit live on 2-node HW). Fix: - Each file is written to a <name>.tmp sibling, fsync'd, then atomically os.rename()'d into place -- rename gives atomic ordering, fsync gives durability against a hard crash resurrecting a truncated final-named file. - A _SUCCESS marker is written last by rank 0, after all files are renamed and a barrier confirms all ranks are done. - get_last_checkpoint() gains an opt-in require_success_marker (default False, so train_domino/eagle3/peagle are unaffected); train_dflash's --resume passes True. Skipped name-matching dirs lacking _SUCCESS are warned about, so a resume right after upgrading (older checkpoints predate the marker) doesn't silently restart from scratch. Adds a CUDA-free unit test for the marker gating. Two fork-only issues (per-rank makedirs visibility, collective rotation rmtree) are out of scope: neither has an applicable target on main's single-writer, no-rotation save_checkpoint().
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
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.
Summary
train_dflash.py'ssave_checkpoint()writes every checkpoint file(
training_state.pt, draft weights,dflash.py) directly to its final path,and
get_last_checkpoint()(specforge/utils.py) trusts any directory whosename matches
epoch_X_step_Y. So a crash mid-write (OOM kill, preemption, anyinterruption during
torch.save/save_pretrained/shutil.copy) can leave apartially-written file at its final, "looks complete" name, and a
--resumerun has no way to tell that apart from a finished checkpoint — itsilently loads the corrupt one.
This is worse on multi-node training, where
args.output_diris often not asingle, fully POSIX-coherent filesystem (per-node mounts bridged together,
weaker-consistency network filesystems, etc.). There a directory can look
complete by name while genuinely missing content another rank wrote that
hasn't propagated yet. We hit exactly this on real 2-node hardware: a save
logged
"Saved checkpoint to .../epoch_0_step_180"with no error, but theon-disk directory was missing content.
Fix
<name>.tmpsibling and atomicallyos.rename()'d into place by the process that created it, with anos.fsync()of the data before the rename. A crash can now only leave astray
.tmpbehind — never a partial file at the final name, and not even afinal-named file with unflushed content after a hard crash (
rename()givesatomic ordering, not durability; the
fsyncgives durability)._SUCCESSmarker written last by rank 0,only after every other file is renamed into place and a
dist.barrier()confirms all ranks are done.
get_last_checkpoint()gained an opt-inrequire_success_marker(defaultFalse). WhenTrue, a directory is trusted only if_SUCCESSis present.train_dflash.py's--resumepassesTrue; the default staysFalsesotrain_domino.py/train_eagle3.py/train_peagle.py(whose saversdon't write this marker) are unaffected.
_SUCCESSare nowlogger.warning'd when skipped, so a--resumeright after upgrading (oldercheckpoints predate the marker) doesn't silently restart from scratch — the
warning names them and shows how to opt one back in (
touch <dir>/_SUCCESS).Cost: the
fsyncadds some wall-time per save (most visible for large weightshards) — a deliberate correctness-over-speed trade.
Test plan
checkpoint directory on disk, confirming all expected files plus
_SUCCESSbefore it was treated as complete; then killed and
--resume'd, confirmingthe log showed a real decayed LR from the restored scheduler state (not a
fresh-init default) — genuine state restored, not silently reinitialized.
tests/test_utils/test_get_last_checkpoint.py(CUDA-free):latest-by-
(epoch, step)selection; default (no marker) behavior preserved;require_success_marker=Trueselects only marked dirs and returnsNonewhen all are unmarked; the upgrade-warning is emitted for skipped dirs.
Scope
The same unguarded-write pattern exists in
train_domino.py/train_eagle3.py/train_peagle.py; this PR fixes only the path wevalidated live (kill + resume) on real multi-node hardware. The shared
mechanism lives in
specforge/utils.py(atomic_torch_save/fsync_path/require_success_marker, defaultFalse), so extending it to the otherscripts is mechanical —
happy to do that in this PR or a follow-up, whichever you prefer.