Skip to content
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

[1/2] Add support for early stopping during training epoch end #6944

Merged
merged 18 commits into from
Apr 28, 2021

Conversation

ananthsub
Copy link
Contributor

@ananthsub ananthsub commented Apr 10, 2021

What does this PR do?

Fixes #7033
Part 1

In a follow up PR, we can remove https://github.com/PyTorchLightning/pytorch-lightning/blob/5bd3cd5f712b65d38812b27cf957261bb06b83c5/pytorch_lightning/trainer/training_loop.py#L152-L160

Before submitting

  • Was this discussed/approved via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you update the CHANGELOG? (not for typos, docs, test updates, or internal minor changes/refactorings)

PR review

Anyone in the community is free to review the PR once the tests have passed.
Before you start reviewing make sure you have read Review guidelines. In short, see the following bullet-list:

  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

Did you have fun?

Make sure you had fun coding 🙃

@codecov
Copy link

codecov bot commented Apr 10, 2021

Codecov Report

Merging #6944 (3b6b606) into master (cbc6e30) will decrease coverage by 4%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #6944    +/-   ##
=======================================
- Coverage      91%     87%    -4%     
=======================================
  Files         199     199            
  Lines       12783   12805    +22     
=======================================
- Hits        11659   11160   -499     
- Misses       1124    1645   +521     

Copy link
Contributor Author

@ananthsub ananthsub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is blocked on #6921 as the hook ordering is off, meaning we can't access the trainer's logger metrics as expected. the callback for on_train_epoch_end runs before training_epoch_end in the lightning module

@ananthsub ananthsub force-pushed the feat-early-stop-train branch from 04ae832 to dc55fd5 Compare April 15, 2021 05:22
@pep8speaks
Copy link

pep8speaks commented Apr 15, 2021

Hello @ananthsub! Thanks for updating this PR.

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-04-28 08:59:19 UTC

Copy link
Contributor

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow up PR, we can remove

Have you already tried it? Does it go without complications?

pytorch_lightning/callbacks/early_stopping.py Show resolved Hide resolved
@ananthsub
Copy link
Contributor Author

ananthsub commented Apr 17, 2021

@awaelchli see #7069 for the followup.

@ananthsub ananthsub changed the title Add support for early stopping during training epoch end [1/2] Add support for early stopping during training epoch end Apr 17, 2021
tests/callbacks/test_early_stopping.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/early_stopping.py Outdated Show resolved Hide resolved
CHANGELOG.md Show resolved Hide resolved
@mergify mergify bot removed the has conflicts label Apr 26, 2021
Copy link
Contributor

@tchaton tchaton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

pytorch_lightning/callbacks/early_stopping.py Show resolved Hide resolved
pytorch_lightning/callbacks/early_stopping.py Show resolved Hide resolved
losses = [8, 4, 2, 3, 4, 5, 8, 10]
val_loss = losses[self.current_epoch]
self.log('abc', torch.tensor(val_loss))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log with different keys on val/train for the test ?

[
([EarlyStopping(monitor='abc'), EarlyStopping(monitor='cba', patience=3)], 3, None, 1),
([EarlyStopping(monitor='abc'), EarlyStopping(monitor='cba', patience=3)], 3, False, None, 1),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carmocca id we simplify each EarlyStop we can fit to single line :P

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

@ananthsub ananthsub force-pushed the feat-early-stop-train branch from 1a48461 to a59c78a Compare April 28, 2021 08:06
@carmocca carmocca merged commit 947d1cb into Lightning-AI:master Apr 28, 2021
Comment on lines +415 to +424
([EarlyStopping('abc'), EarlyStopping('cba', patience=3)], 3, False, None, 1),
([EarlyStopping('cba', patience=3), EarlyStopping('abc')], 3, False, None, 1),
pytest.param([EarlyStopping('abc'), EarlyStopping('cba', patience=3)], 3, False, 'ddp_cpu', 2, **_NO_WIN),
pytest.param([EarlyStopping('cba', patience=3), EarlyStopping('abc')], 3, False, 'ddp_cpu', 2, **_NO_WIN),
([EarlyStopping('abc', **_ES_CHECK), EarlyStopping('cba', **_ES_CHECK_P3)], 3, True, None, 1),
([EarlyStopping('cba', **_ES_CHECK_P3), EarlyStopping('abc', **_ES_CHECK)], 3, True, None, 1),
pytest.param([EarlyStopping('abc', **_ES_CHECK),
EarlyStopping('cba', **_ES_CHECK_P3)], 3, True, 'ddp_cpu', 2, **_NO_WIN),
pytest.param([EarlyStopping('cba', **_ES_CHECK_P3),
EarlyStopping('abc', **_ES_CHECK)], 3, True, 'ddp_cpu', 2, **_NO_WIN),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean this @carmocca from #6944 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support early stopping during training inside of the early stopping callback
6 participants