-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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 IterableDataset has __len__ defined #2437
Conversation
5dabf85
to
45a05c4
Compare
45a05c4
to
d00b2d5
Compare
Codecov Report
@@ Coverage Diff @@
## master #2437 +/- ##
======================================
Coverage 88% 88%
======================================
Files 69 69
Lines 5526 5527 +1
======================================
+ Hits 4887 4888 +1
Misses 639 639 |
Hello @awaelchli! Thanks for updating this PR. There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2020-07-01 11:33:06 UTC |
@@ -41,19 +43,33 @@ | |||
HOROVOD_AVAILABLE = True | |||
|
|||
|
|||
def _has_iterable_dataset(dataloader: DataLoader): | |||
return ITERABLE_DATASET_EXISTS and hasattr(dataloader, 'dataset') \ |
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.
if you encapsulate the if statement in () you do not need to use \
except TypeError: | ||
return False | ||
has_len = False | ||
except NotImplementedError: # e.g. raised by torchtext if a batch_size_fn is used | ||
return False | ||
has_len = False |
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.
if the resulting action is the same, lets write it in one
except (TypeError, NotImplementedError): # e.g. raised by torchtext if a batch_size_fn is used
has_len = False
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
What does this PR do?
Fixes #2429
torch < 1.4: An
IterableDataset
with__len__
defined raises a TypeErrortorch >= 1.4: It does not raise an error, but we still want to display a warning because it is most likely unintentional and could lead to side effects.
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 🙃