Repository navigation
Torch: allow enable_checkpointing=False in trainer_kwargs - #3359
Open
Thanatos9404 wants to merge 1 commit into
Open
Thanatos9404 wants to merge 1 commit into
Thanatos9404 wants to merge 1 commit into
Conversation
PyTorchLightningEstimator.train_model always added its own ModelCheckpoint callback, so passing enable_checkpointing=False in trainer_kwargs made Lightning raise a MisconfigurationException. Only add the default checkpoint when checkpointing is enabled (Lightning treats None as enabled). Without it, a failure during fit is re-raised because there is nothing to recover from, and the last trained model is returned instead of the best checkpoint. Fixes awslabs#3203
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.
Issue #, if available: #3203
Description of changes:
PyTorchLightningEstimator.train_modelalways adds its ownModelCheckpoint, so passingenable_checkpointing=Falseintrainer_kwargsmade Lightning raise aMisconfigurationException. There was no way to train a torch estimator without writing checkpoints, which the reporter needs on a read-only filesystem.The default checkpoint is now only added when checkpointing is enabled (
None, the default, counts as enabled, as in Lightning). Without a checkpoint, the model at the end of training is returned, and iffitfails the original exception is re-raised.Tests: added
test_estimator_trains_with_checkpointing_disabledandtest_estimator_reraises_with_checkpointing_disabledtotest/torch/model/test_estimators.py. Both fail ondevand pass with this change.test_estimator_loads_best_checkpoint_by_defaultguards the existing behaviour.This touches the same
try/exceptintrain_modelas #3346, so whichever is merged second will have a one-line conflict.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Please tag this pr with at least one of these labels to make our release process faster: bug fix
Fixes #3203