-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check early stopping metric in the beginning of the training #542
Merged
williamFalcon
merged 11 commits into
Lightning-AI:master
from
kuynzereb:early_stopping_callback_fix
Jan 23, 2020
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4c635ad
Early stopping fix
kuynzereb c06bad6
Update trainer.py
williamFalcon acda2b7
Don't force validation sanity check
kuynzereb 10e76f6
fix tests
kuynzereb aeb8bbd
Resolved conflicts
kuynzereb 25e1bda
update
kuynzereb 748640b
Added early_stopping check_metrics
kuynzereb 706d84f
Merge branch 'master' into early_stopping_callback_fix
kuynzereb 0f83b1a
Updated docs
kuynzereb 4e35bee
Update docs
kuynzereb 320e4c1
Do not call early stopping when validation is disabled
kuynzereb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,13 @@ def run_training_epoch(self): | |
if self.fast_dev_run or should_check_val: | ||
self.run_evaluation(test=self.testing) | ||
|
||
if (self.enable_early_stop and | ||
self.callback_metrics.get(self.early_stop_callback.monitor) is None): | ||
raise RuntimeError(f"Early stopping was configured to monitor " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
f"{self.early_stop_callback.monitor} but it is not available" | ||
f" after validation_end. Available metrics are: " | ||
f"{','.join(list(self.callback_metrics.keys()))}") | ||
|
||
# when logs should be saved | ||
should_save_log = (batch_nb + 1) % self.log_save_interval == 0 or early_stop_epoch | ||
if should_save_log or self.fast_dev_run: | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then you should return
True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly. Return
True
was before and it caused the interruption of the training if the required metric was not found. And now it just gives a warning and training just proceeds as though without early stopping. The point is that the callback should not stop the training if it can't find the metrics.Actually, in the current implementation this branch is not reachable because we check for the availability of the metric in the trainer initialization. But my idea was that if we decide to set early_stopping to True by default, then it can be used to give a warning but not to stop the training.
You can also look at #524 for better understanding.