fix(megatron): finalize checkpoints before pruning - #2145
Draft
bvolpato wants to merge 1 commit into
Draft
Conversation
Signed-off-by: bvolpato <brunocvcunha@gmail.com>
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.
With Megatron async checkpointing, the trainer can advance
latest_ckpt_global_step.txtand delete the previous checkpoint while the new save is still pending. Megatron writes its completion metadata during finalization, so completed background tensor writes alone do not make the new checkpoint loadable. Withmax_ckpts_to_keep=1, an interrupted run can lose its last resumable checkpoint.This waits for policy and critic checkpoint finalization before publishing the latest step or running retention. It covers PPO, SFT, and fully async PPO. The fully async trainer also writes its required UID/epoch state before the base trainer publishes the checkpoint.
Related to #1838. This fixes publication ordering; it does not change the checkpoint format or make marker-file writes atomic.
Reproduction and validation
The new tests hold model writes pending until finalization, exercise policy and critic failures, and verify that retention keeps the previous checkpoint until the new one completes:
345ce86using normal imports.--noconftestavoids the unrelated session-wide Ray startup for these filesystem tests.Downsides
Trainer checkpoint saves now wait for the background disk write and finalization. Async checkpoint writes no longer overlap subsequent training steps. Direct worker saves retain their asynchronous behavior. This keeps the fix small and avoids introducing concurrent finalization collectives or a separate pending-publication lifecycle.
Risk and rollback
The change adds a completion barrier to each trainer checkpoint save; synchronous backends use their existing no-op finalization. If reverting, disable
async_dist_ckpt_savefirst to avoid restoring the publication/retention race.