-
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
warn user when dropping unpicklable hparams #2874
Conversation
Hello @monney! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-08-11 18:44:01 UTC |
@monney is this wip or ready to review? at this point I would suggest to extract a helper function EDIT: oops just saw tests are failing, I will check what's going on. |
@awaelchli Should be good to go now. Build is failing, but I believe the test case is broken. Should be checking for nn.CosineEmbeddingLoss but is checking for nn.CrossEntropyLoss. |
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.
@monney I can confirm, test case needs to be fixed by checking for CosineEmbeddingLoss. While debugging this I wrote a test case for your bugfix, could you add it, maybe below test_hparams_pickle
?
class UnpickleableArgsEvalModel(EvalModelTemplate):
""" A model that has an attribute that cannot be pickled. """
def __init__(self, foo='bar', pickle_me=(lambda x: x + 1), **kwargs):
super().__init__(**kwargs)
assert not is_picklable(pickle_me)
self.save_hyperparameters()
def test_hparams_pickle_warning(tmpdir):
model = UnpickleableArgsEvalModel()
trainer = Trainer(default_root_dir=tmpdir, max_steps=1)
with pytest.warns(UserWarning, match="attribute 'pickle_me' removed from hparams because it cannot be pickled"):
trainer.fit(model)
assert 'pickle_me' not in model.hparams
With this test case I think the PR is ready 👍
@awaelchli I added your test case and changed the warning to rank_zero_warn, I think everything should be good to go now! |
@monney There are test failures, they must be because of the new way of cleaning the namespace, but not sure what needs to be changed. Have you seen it? |
@awaelchli it is because of the new way of cleaning. Something prevented that test case either from being run or failing previously. The property that it’s checking for would have been completely removed by the old way of cleaning, I’m not sure why that did not trigger a failure though. The new way causes it to fail because it should be checking for CosineEmbedding. |
Ah I thought I already confirmed it. Yes, please change to CosineEmbeddingLoss I agree. |
You did. That’s my bad. Doesn’t it need to be changed in the CI server? Or if I change it in my code will it update |
It's in the same file you added the test, above in a fuction called test_collect_init_arguments. You change it there, push your commit and it will show here in the tab for changed files :) |
I got it now, I didn't realize it ran the test cases, from the commit itself, and thought you had update it elsewhere. Thank you! :) |
Codecov Report
@@ Coverage Diff @@
## master #2874 +/- ##
========================================
- Coverage 90% 89% -1%
========================================
Files 79 81 +2
Lines 7226 9204 +1978
========================================
+ Hits 6519 8235 +1716
- Misses 707 969 +262 |
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.
@monney thanks for the fix
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.
LGTM 🚀
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.
LGTM 👍
@@ -25,26 +28,28 @@ def str_to_bool(val): | |||
raise ValueError(f'invalid truth value {val}') | |||
|
|||
|
|||
def is_picklable(obj: object) -> bool: |
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.
this can be quite a time costly especially for large objects or calling this function quite often...
What does this PR do?
PR changes namespace cleaning to be more general. Makes sure it only removes items which can't be pickled, and warns user when doing so.
Fixes #2676
Fixes #2444
Before submitting
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 🙃