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

consolidate callbacks and hooks #950

Merged

Conversation

jeremyjordan
Copy link
Contributor

@jeremyjordan jeremyjordan commented Feb 26, 2020

Before submitting

  • Was this discussed/approved via a Github issue? (no need for typos, doc improvements)
  • Did you read the contributor guideline?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?
  • If you made a notable change (that affects users), did you update the CHANGELOG?

What does this PR do?

Fixes #947

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in Github issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

@hadim
Copy link
Contributor

hadim commented Feb 26, 2020

Thanks! Could you also update the changelog? I forgot to do it in the last PR.

@jeremyjordan
Copy link
Contributor Author

@hadim sure thing :)

@jeremyjordan
Copy link
Contributor Author

jeremyjordan commented Feb 27, 2020

To do

  • Consolidate model hooks and callbacks system. Make the calls at the same moment: Callbacks continued #889 (comment)
  • Fix on_train_begin() being called in the early stopping callbacks: Callbacks continued #889 (comment)
  • Assert pl_module and trainer are excepted object instances in the callback system train tests: Callbacks continued #889 (comment)
  • Incorporate existing callbacks into the new callback system.
  • Edit the changelog

@williamFalcon
Copy link
Contributor

@jeremyjordan let's get this into this release?

@jeremyjordan
Copy link
Contributor Author

@williamFalcon for sure! would like to wrap this one up tonight

@williamFalcon
Copy link
Contributor

williamFalcon commented Feb 28, 2020

idk if this is out of scope, but we have the other callbacks which are trainer specific.
(backward, init_ddp, etc...) that are deferred to the lightningModule.

Do we want to put all of those in the hooks file as well? or structure them differently?

No change to the user, just the docs

@jeremyjordan
Copy link
Contributor Author

@williamFalcon that's a good question. i think those methods make sense where they are in the docs, but i do agree the doc page for LightningModule is pretty lengthy. i do it would really help for readability and quick reference if we could copy the "Shortcuts" panel that PyTorch has in their docs.

Screen Shot 2020-02-27 at 9 43 53 PM

@jeremyjordan
Copy link
Contributor Author

jeremyjordan commented Feb 28, 2020

I'm thinking that I'll hold off integrating the existing callbacks for a subsequent PR, then we can have more discussion regarding the best way to address integration concerns (eg. #889 comment). For now we can manually invoke the callback events as we're doing currently.

@jeremyjordan jeremyjordan changed the title [WIP] consolidate callbacks and hooks consolidate callbacks and hooks Feb 28, 2020
@Borda Borda added the feature Is an improvement or enhancement label Feb 28, 2020
@Borda Borda added this to the 0.7.0 milestone Feb 28, 2020
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

LGTM 🚀, just move tests to a separate file

tests/trainer/test_trainer.py Outdated Show resolved Hide resolved
tests/trainer/test_trainer.py Outdated Show resolved Hide resolved
Copy link
Member

@Borda Borda left a comment

Choose a reason for hiding this comment

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

it would be nice to unify name convention between model and trainer in particular is_function_implemented in trainer and is_overriden in model

pytorch_lightning/trainer/training_loop.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/training_loop.py Outdated Show resolved Hide resolved
pytorch_lightning/trainer/training_loop.py Outdated Show resolved Hide resolved
tests/trainer/test_callbacks.py Outdated Show resolved Hide resolved
tests/trainer/test_callbacks.py Show resolved Hide resolved
@jeremyjordan
Copy link
Contributor Author

it would be nice to unify name convention between model and trainer in particular is_function_implemented in trainer and is_overriden in model

is there a reason we check for is_overriden in model rather than just having the default hooks pass and always calling the hooks?

@jeremyjordan
Copy link
Contributor Author

@williamFalcon are you still hoping to get this into the next release?

@williamFalcon
Copy link
Contributor

yup! was focused on the .test thing. will merge today

@Borda Borda added the ready PRs ready to be merged label Mar 2, 2020
@Borda
Copy link
Member

Borda commented Mar 2, 2020

just stay tuned, because with some extensive PRs we may come to solving complex collisions 🤖

@williamFalcon williamFalcon merged commit 705e576 into Lightning-AI:master Mar 3, 2020
@Borda Borda mentioned this pull request Mar 4, 2020
tullie pushed a commit to tullie/pytorch-lightning that referenced this pull request Apr 3, 2020
* consolidate callbacks and hooks

* ensure callbacks recieve proper arg types

* remove model from init callback events

* clean up early stopping event

* update changelog

* remove on_fit_start and on_fit_end

* fix args for on_init_start and on_init_end

* handle case where early stopping is not used

* show all callback methods

* wrap checkpoint callback logic into proper class

* fix check for main process in checkpoint callback

* move callbacks test to separate file

* refactor arg checks

* get model and call hook on same line

* define trainer_options dict in one call

* add more asserts to callback test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement ready PRs ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve callback system
4 participants