Fix dataloader not reloading when resuming from checkpoint#21514
Open
littlebullGit wants to merge 3 commits intoLightning-AI:masterfrom
Open
Fix dataloader not reloading when resuming from checkpoint#21514littlebullGit wants to merge 3 commits intoLightning-AI:masterfrom
littlebullGit wants to merge 3 commits intoLightning-AI:masterfrom
Conversation
When resuming from a checkpoint with reload_dataloaders_every_n_epochs,
the dataloader was not being reloaded at the correct epoch. This was
because setup_data() was overwriting _last_train_dl_reload_epoch with
the current epoch during checkpoint restoration, losing the information
about when the dataloader was actually last reloaded.
The fix:
1. Save _last_train_dl_reload_epoch in checkpoint state
2. Restore _last_train_dl_reload_epoch from checkpoint on load
3. Only update _last_train_dl_reload_epoch when actually reloading
the dataloader or during initial setup (not when resuming)
This ensures _should_reload_train_dl returns the correct value after
resuming from a checkpoint.
Backward compatible: old checkpoints without this key will default to
float('-inf'), which triggers a reload (the safest behavior).
Fixes Lightning-AI#21492
5c24d70 to
6afeb53
Compare
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## master #21514 +/- ##
=========================================
- Coverage 87% 79% -8%
=========================================
Files 270 267 -3
Lines 24071 24021 -50
=========================================
- Hits 20867 18968 -1899
- Misses 3204 5053 +1849 |
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.
When resuming from a checkpoint with reload_dataloaders_every_n_epochs, the dataloader was not being reloaded at the correct epoch. This was because setup_data() was overwriting _last_train_dl_reload_epoch with the current epoch during checkpoint restoration, losing the information about when the dataloader was actually last reloaded.
The fix:
This ensures _should_reload_train_dl returns the correct value after resuming from a checkpoint.
Backward compatible: old checkpoints without this key will default to float('-inf'), which triggers a reload (the safest behavior).
Fixes #21492
📚 Documentation preview 📚: https://pytorch-lightning--21514.org.readthedocs.build/en/21514/