-
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
Callbacks continued #889
Callbacks continued #889
Conversation
8a7a829
to
b9a04f5
Compare
Hello @hadim! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-02-26 00:59:24 UTC |
21fbe62
to
aa40e34
Compare
1e1729e
to
5328e7b
Compare
@williamFalcon about immutability, I had a look and I don't think this is something easy todo in Python without heavy hacks. See https://discuss.python.org/t/immutability-in-python-is-really-hard/2536/2 I think we should just make it very clear in the doc/docstring that callbacks MUST NOT modify the pl module and the trainer. |
why do we want to add this limitation? shouldn’t the user be ok with messing around with the trainer or model if they want to in a callback? |
also, should we rethink the name “Callback”? this ALWAYS ends up needing a lengthy explanation about what it is. why not call it something more intuitive? Maybe something like: just brainstorming here lol. i just think it’s super confusing for newcomers and non engineers. |
I haven't totally incorporated the 3 already existant callbacks in the new system (they still use the new About the name, I like |
Regarding this, should we update the
|
Yes, but if the user can modify the trainer then the callback quickly transitions from non-essential to essential for reproducibility. However, there are cases when it would be desirable to modify objects in the trainer. For example, fast.ai has a callback for a learning rate finder which is quite useful. This would be something that the user would want to enable when first building a model but then disable once they find a good range and want to start training. |
Then we shall check that they are not duplicated, meaning when they are added via simple flag and later among callbacks? |
Ah yes, good point 😄 Perhaps in that case, we notice that an instance of
What do you think? Does this resolve any potential confusion? |
I think that the question is very hard because you do not have much clues if double callback (e.g. CheckPoint) is mistake or desired state... Maybe you would need to match also parameters of the ChP to determine whether or not they are identical... |
What do you think if we finish the design of the callback system and discuss the way we integrate the existing callbacks in a new PR/issue? Do you have any comments about the one implemented in this PR? |
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.
nice work on this! just a few comments
hparams = tutils.get_hparams() | ||
model = CurrentTestModel(hparams) | ||
|
||
class TestCallback(Callback): |
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.
should we also assert that the trainer
and pl_module
arg values are an instance of the expected class?
@@ -64,7 +64,7 @@ def __init__(self, monitor: str = 'val_loss', min_delta: float = 0.0, patience: | |||
self.monitor_op = mode_dict[mode] | |||
self.min_delta *= 1 if self.monitor_op == np.greater else -1 | |||
|
|||
self.on_train_begin() | |||
self.on_train_begin(None, None) |
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.
it's weird for a callback to invoke one of its own methods. i know this is how the EarlyStopping
callback was previously written, but do you happen to know why this is the case? i would expect on_train_begin
to be called when the TrainerCallbackHookMixin
invokes it.
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.
I agree it's weird and should be fixed.
@hadim could we consolidate the code such that model hooks and callbacks are invoked at the same time, and within the context of the a profiler?
|
Yes, we should. Not sure when I'll have time to work on this PR this week. So we could merge it as it is and improve it in other PRs or if someone wants to push some commits here, feel free (I can add you to my fork). |
@hadim why don't we merge this asap so we can get it in the release. Great job everyone! |
I agree @williamFalcon Will rebase soon. |
Rebasing wasn't a very funny moment here! Please merge whenever you can @williamFalcon! I'll open a new issue for what's next. |
happy to pick up the work on a separate PR |
@jeremyjordan look at #947 |
@hadim @jeremyjordan GREAT job! Pls could you update also the change log... |
* Add callback system + associated test * Add trainer and pl_module args to callback methods * typing * typo in docstring * Switch to on_.*_start() * fix on_test_start * fix the mess after rebasing
This PR is based on #849.
A new callback mechanism is added where a user can pass a list of callbacks to the trainer that is called during the various steps of the trainer's life.
It allows inserting custom logic in the training loop outside of the
LightningModule
.Let me know what do you guys think.