fix(trainer): avoid KeyError when a checkpoint is saved at an unvalidated step - #3455
Open
KamitobiHaru wants to merge 1 commit into
Open
Conversation
…ated step When save_checkpoint_interval is not a multiple of validate_interval, a checkpoint can be saved at a step that was never validated. The best-ckpt comparison then indexes val_acc/val_loss_step_or_epoch[ckpt_name], raising KeyError right after the checkpoint was already written and aborting the run. Guard both the DeepSpeed and the torch.save checkpoint paths with .get() so an unvalidated checkpoint is skipped for the "best" bookkeeping (and logged) instead of crashing; fall back to 0.0 when recording saved_ckpts. Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
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.
Bug
When
save_checkpoint_intervalis not a multiple ofvalidate_interval, a checkpoint can be saved at a step that was never validated. The best-ckpt comparison then indexesval_acc_step_or_epoch[ckpt_name], raisingKeyErrorright after the checkpoint was written and aborting the whole run.Reproduce
save_checkpoint_interval=5000,validate_interval=2000→ crash at step 5000:KeyError: 'model.pt.ep0.5000'.Fix
Guard both the DeepSpeed and the
torch.savecheckpoint paths with.get(). An unvalidated checkpoint is skipped for the "best" bookkeeping (and logged) instead of crashing;saved_ckptsfalls back to0.0.Verified
Two-stage training run (TTS 6.3k → real 517, 50 epochs) completed without the crash across ~50 checkpoint saves.