Skip to content

fix(trainer): avoid KeyError when a checkpoint is saved at an unvalidated step - #3455

Open
KamitobiHaru wants to merge 1 commit into
modelscope:mainfrom
KamitobiHaru:fix/save-checkpoint-keyerror-on-unvalidated-step
Open

fix(trainer): avoid KeyError when a checkpoint is saved at an unvalidated step#3455
KamitobiHaru wants to merge 1 commit into
modelscope:mainfrom
KamitobiHaru:fix/save-checkpoint-keyerror-on-unvalidated-step

Conversation

@KamitobiHaru

Copy link
Copy Markdown

Bug

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_step_or_epoch[ckpt_name], raising KeyError right 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.save checkpoint paths with .get(). An unvalidated checkpoint is skipped for the "best" bookkeeping (and logged) instead of crashing; saved_ckpts falls back to 0.0.

Verified

Two-stage training run (TTS 6.3k → real 517, 50 epochs) completed without the crash across ~50 checkpoint saves.

…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>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

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.

1 participant