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

[2 / 3] improvements to saving and loading callback state #7187

Merged
merged 67 commits into from
Aug 24, 2021

Conversation

awaelchli
Copy link
Contributor

@awaelchli awaelchli commented Apr 23, 2021

What does this PR do?

Fixes #6467

It is now possible to save and resume with multiple callbacks of the same time, provided they have a suitable state_id property that defines the equivalence class. See the added docs section for more information of how it works.

This is now possible without sacrifice:

Trainer(
    callbacks=[ModelCheckpoint(monitor="val_loss"), ModelCheckpoint(monitor="other", mode="max")],
)

and resuming from an existing checkpoint:

Trainer(
    resume_from_checkpoint"path/to/ckpt",
    callbacks=[ModelCheckpoint(monitor="val_loss"), ModelCheckpoint(monitor="other", mode="max")],
)

will load the internal state of BOTH these callbacks, where previously this wouldn't work with stateful callbacks.

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 🙃

@awaelchli awaelchli added feature Is an improvement or enhancement checkpointing Related to checkpointing callback labels Apr 23, 2021
@awaelchli awaelchli added this to the v1.4 milestone Apr 23, 2021
@awaelchli awaelchli force-pushed the feature/callback-state/part3 branch from 37244b5 to e0559fe Compare April 23, 2021 09:34
@pep8speaks
Copy link

pep8speaks commented Apr 23, 2021

Hello @awaelchli! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 87:9: W503 line break before binary operator

Line 50:9: W503 line break before binary operator

Comment last updated at 2021-08-13 11:48:25 UTC

@codecov
Copy link

codecov bot commented Apr 23, 2021

Codecov Report

Merging #7187 (184f412) into master (1a2468f) will decrease coverage by 4%.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master   #7187    +/-   ##
=======================================
- Coverage      92%     88%    -4%     
=======================================
  Files         178     178            
  Lines       14694   14702     +8     
=======================================
- Hits        13526   12925   -601     
- Misses       1168    1777   +609     

pytorch_lightning/callbacks/early_stopping.py Outdated Show resolved Hide resolved
pytorch_lightning/callbacks/base.py Outdated Show resolved Hide resolved
@edenlightning edenlightning modified the milestones: v1.4, v1.3.x Jul 6, 2021
@edenlightning edenlightning removed this from the v1.3.x milestone Jul 21, 2021
@mergify mergify bot added the ready PRs ready to be merged label Aug 13, 2021
@awaelchli awaelchli force-pushed the feature/callback-state/part3 branch from f16af3a to 77e7027 Compare August 13, 2021 11:47
tests/callbacks/test_early_stopping.py Outdated Show resolved Hide resolved
tests/checkpointing/test_model_checkpoint.py Outdated Show resolved Hide resolved
docs/source/extensions/callbacks.rst Outdated Show resolved Hide resolved
@mergify mergify bot removed the has conflicts label Aug 19, 2021
@awaelchli awaelchli requested a review from Borda August 19, 2021 12:14
Copy link
Contributor

@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.

pytorch_lightning/callbacks/base.py Show resolved Hide resolved
pytorch_lightning/callbacks/early_stopping.py Show resolved Hide resolved
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
@awaelchli awaelchli enabled auto-merge (squash) August 24, 2021 17:07
@awaelchli awaelchli merged commit b9443a0 into master Aug 24, 2021
@awaelchli awaelchli deleted the feature/callback-state/part3 branch August 24, 2021 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
callback checkpointing Related to checkpointing feature Is an improvement or enhancement priority: 0 High priority task ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] Support checkpointing multiple callbacks of the same type
8 participants