-
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
fix _reset_eval_dataloader() for IterableDataset #1560
Conversation
Hello @ybrovman! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-05-05 15:48:37 UTC |
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.
Good catch, but I don't understand why the test test_inf_val_dataloader
passes if this bug exists. How do I reproduce this actually? The description of this PR makes it look like this should fail with any IterableDataset, but I don't get this error.
I am not too familiar with the testing details here, however, I think the issue might be with the CustomInfDataloader. Perhaps since |
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 🤖
@ybrovman mind add a test for this iter dataset? |
Codecov Report
@@ Coverage Diff @@
## master #1560 +/- ##
======================================
Coverage 88% 88%
======================================
Files 69 69
Lines 4151 4151
======================================
Hits 3661 3661
Misses 490 490 |
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.
In which case is dl actually None? Have you considered removing the if statement completely?
@awaelchli I did remove the if statement in the original commit, however, added back the None check after @tullie 's comment. |
I tried to look at cases where it could be None and it's hard to track down exactly. However, i'm fairly sure it's only None if the val_dataloader or test_dataloader returns None. |
shall we raise a warning if any dataloader is none or just skip it... |
Yeah ideally we should raise a warning but not the biggest issue. |
so just a warning to logging or standard Runtime warning... and just once and then remove the None dataloader from the list @ybrovman mind send a followup PR? |
This function has the if statement `if (train_dataloader or val_dataloaders) and datamodule:`. The issue is similar to that in Lightning-AI#1560. The problem is that the `if(dl)` translates to `if(bool(dl))`, but there's no dataloader.__bool__ so bool() uses dataloader.__len__ > 0. But... dataloader.__len__ uses IterableDataset.__len__ for IterableDatasets for which __len__ is undefined. The fix is also the same, the `if dl` should be replaced by `if dl is not None`.
…2957) This function has the if statement `if (train_dataloader or val_dataloaders) and datamodule:`. The issue is similar to that in #1560. The problem is that the `if(dl)` translates to `if(bool(dl))`, but there's no dataloader.__bool__ so bool() uses dataloader.__len__ > 0. But... dataloader.__len__ uses IterableDataset.__len__ for IterableDatasets for which __len__ is undefined. The fix is also the same, the `if dl` should be replaced by `if dl is not None`. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
…ightning-AI#2957) This function has the if statement `if (train_dataloader or val_dataloaders) and datamodule:`. The issue is similar to that in Lightning-AI#1560. The problem is that the `if(dl)` translates to `if(bool(dl))`, but there's no dataloader.__bool__ so bool() uses dataloader.__len__ > 0. But... dataloader.__len__ uses IterableDataset.__len__ for IterableDatasets for which __len__ is undefined. The fix is also the same, the `if dl` should be replaced by `if dl is not None`. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Before submitting
What does this PR do?
I encountered the following error
TypeError: object of type 'MyIterableDataset' has no len()
from line 190 in _reset_eval_dataloader() in data_loading.py file when using anIterableDataset
for the validation dataset.The
if dl
caused the issue.if dl
is equivalent to bool(dl) =dataloader.__bool__
, but there is nodataloader.__bool__
so bool() usesdataloader.__len__
> 0. But...dataloader.__len__
usesIterableDataset.__len__
forIterableDataset
s for which__len__
is undefined.Resolving the issue by comparing to None,
if dl is not None
, in _reset_eval_dataloader().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?
👍