-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Error if callbacks are passed wrongly #1544
Error if callbacks are passed wrongly #1544
Conversation
i think we actually want to allow this behavior, and instead limit the scope of i think we want to standardize towards having all of the callbacks passed into the |
Right, that is a much better way of handling this in the future. @jeremyjordan should I go ahead and make the change that you propose? It would be a change that is not backward compatible so some |
for callback in self.callbacks: | ||
if isinstance(callback, ModelCheckpoint): | ||
raise MisconfigurationException( | ||
'You passed a `ModelCheckpoint` callback to trainer argument `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.
'You passed a `ModelCheckpoint` callback to trainer argument `callback`, ' | |
'You passed a `ModelCheckpoint` callback to trainer argument `callback`,' |
|
||
if isinstance(callback, EarlyStopping): | ||
raise MisconfigurationException( | ||
'You passed a `EarlyStopping` callback to trainer argument `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.
'You passed a `EarlyStopping` callback to trainer argument `callback`, ' | |
'You passed a `EarlyStopping` callback to trainer argument `callback`,' |
@@ -95,3 +96,15 @@ def configure_early_stopping(self, early_stop_callback): | |||
else: | |||
self.early_stop_callback = early_stop_callback | |||
self.enable_early_stop = True | |||
|
|||
def check_callback_config(self): | |||
for callback in self.callbacks: |
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.
what about rather just filter and drop the wrong one meaning having [CB, CM, ES, CB] returns [CB, CB] and raise warnings that [CM, ES] was removed...
I agree about the standardize callbacks stack, but I would rather have in some protected variable and here (user input) keep filtering of callbacks only... |
the pattern should be: pass in the actual callback to modify the behavior to the callback arg OR the list of callbacks. otherwise you end up having to have 2 arguments to turn on a callback. =True, callbacks=[...] instead of the easier |
This pull request is now in conflict... :( |
@Borda can you elaborate?
if we allow users to pass in the callback object (eg. |
I was thinking about having inter
Totally agree that this is not solved yet/well, the order may significantly affect the workflow... I have seen in other packages (like computing MultipleObjectTtracking metrics) introducing dependency so each callback has written what/if it depends on other callback... but I see that this can be nice for a user if we also provide dependency chart but a bit harder to implement... cc: @PyTorchLightning/core-contributors thought? |
I think I will close this PR for now. It opened up a longer discussion that is worth taking, about rethinking some aspects of the callback interface. I have created issue #1592 for future discussion. |
@jeremyjordan for the callbacks list the user should know they should order callbacks. |
@williamFalcon so you say that the executive order shall be:
|
I think this should be merged for now. It can be reverted if the discussion on callbacks came to a conclusion (which it didn't - it was closed by stale bot). It is really annoying to learn only after one epoch that I passed the callbacks wrongly. |
Before submitting
What does this PR do?
Fixes #1524.
If the user pass a
ModelCheckpoint
to trainer argumentcallback
instead ofcheckpoint_callback
, it will give a non-informative error. This PR implement a simple check that callbacks passed to trainer argumentcallback
are not instances ofModelCheckpoint
orEarlyStopping
since these need to be passed to other trainer args.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 🙃