Restore latest and interval training checkpoints in PTL path - #847
Conversation
Co-authored-by: Borda <6035284+Borda@users.noreply.github.com> Agent-Logs-Url: https://github.com/roboflow/rf-detr/sessions/cb6dfc2c-b6e2-4937-ad66-28c1ef138f30
There was a problem hiding this comment.
Pull request overview
Restores legacy-style “latest” and “interval” training checkpoint artifacts in the PyTorch Lightning training path so users can resume from epoch snapshots (checkpoint.pth, checkpoint_<N>.pth) in addition to best-model checkpoints.
Changes:
- Added
RFDETRTrainCheckpointCallbackto write a full PTL checkpoint tocheckpoint.pthevery epoch and tocheckpoint_<N>.pthatcheckpoint_intervalboundaries. - Wired the new callback into
build_trainer(...)unconditionally and exported it fromrfdetr.training.callbacks. - Added regression tests covering latest/interval checkpoint behavior and trainer wiring.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/rfdetr/training/callbacks/train_checkpoint.py |
Implements new callback that saves latest + interval PTL checkpoints. |
src/rfdetr/training/trainer.py |
Always registers the new checkpoint callback in the standard trainer callback stack. |
src/rfdetr/training/callbacks/__init__.py |
Re-exports the new callback for a consistent callbacks module surface. |
tests/training/test_train_checkpoint_callback.py |
Unit tests for latest/interval checkpoint save behavior and global-rank gating. |
tests/training/test_build_trainer.py |
Ensures the trainer includes the callback and threads checkpoint_interval correctly. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #847 +/- ##
======================================
Coverage 76% 76%
======================================
Files 94 94
Lines 7269 7271 +2
======================================
+ Hits 5502 5508 +6
+ Misses 1767 1763 -4 🚀 New features to boost your workflow:
|
…point callback trainer.save_checkpoint() calls strategy.barrier(), a collective that requires all ranks to participate. The early return on non-global-zero ranks caused rank 0 to hang waiting for peers that had already exited. Removes the guard (PTL's DDP strategy already ensures the file write happens only on rank 0), replaces the test that validated the broken behaviour, and adds a test covering output_dir auto-creation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Removes ~60 lines of custom RFDETRTrainCheckpointCallback in favour of
two standard ModelCheckpoint instances — one for latest (last.ckpt,
every epoch) and one for interval archives (checkpoint_{epoch}.ckpt).
Using .ckpt extension eliminates the naming collision with weight-only
.pth artifacts from BestModelCallback.
Also adds ge=1 validation to TrainConfig.checkpoint_interval (previously
only validated inside the deleted callback's __init__).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Updated the PR description to match the current implementation pivot (native PTL |
* fix: restore latest and interval training checkpoints * refactor: replace custom checkpoint callback with PTL ModelCheckpoint --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Borda <6035284+Borda@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* fix: restore latest and interval training checkpoints * refactor: replace custom checkpoint callback with PTL ModelCheckpoint --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Borda <6035284+Borda@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
In v1.6.0, training stopped producing
checkpoint.pth(latest) andcheckpoint_<N>.pth(interval), leaving only best-model artifacts (checkpoint_best_*). This broke expected resume/retention behavior for epoch snapshots andcheckpoint_interval.Checkpoint behavior restoration
ModelCheckpointcallbacks to save:filename="last",every_n_epochs=1,save_top_k=1)filename="checkpoint_{epoch}",every_n_epochs=checkpoint_interval,save_top_k=-1)Trainer wiring
build_trainer(...)now always registers the two PTLModelCheckpointcallbacks with:dirpath=train_config.output_direvery_n_epochs=train_config.checkpoint_intervalfor interval snapshotscheckpoint_best_regular.pth,checkpoint_best_ema.pth,checkpoint_best_total.pth) unchanged.Targeted regression coverage
ModelCheckpointcallback is present (every_n_epochs == 1)ModelCheckpointcallback is present and usescheckpoint_intervalTrainConfigvalidation rejects invalidcheckpoint_intervalvaluesOriginal prompt
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.