-
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
fix get dataloader size #2375
fix get dataloader size #2375
Conversation
try: | ||
num_batches = len(dataloader) | ||
except (TypeError, NotImplementedError): | ||
num_batches = float('inf') |
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.
try: | |
num_batches = len(dataloader) | |
except (TypeError, NotImplementedError): | |
num_batches = float('inf') | |
num_batches = len(dataloader) if callable(getattr(dataloader, "__len__", None)) else float("inf") |
Wouldn't that be better?
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 think it is bad to use exceptions for control flow like this. If the user implements len
but has a type error, we catch it and the program crashes somewhere else, making it much harder for the user to debug their dataset. (#2266 )
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.
seems like the suggestion did not work, so reverting it back... :(
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.
:(
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 was the error? (we have a _has_len defined in the same file btw)
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 num_batches = len(dataloader) if _has_len(dataloader) else float('inf')
?
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 seems to be a longterm solution.
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.
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.
the problem is raising an exception in the __len__
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.
yeah my orignal suggestions was wrong sorry. my new suggestion is to use the already existing _has_len method
num_batches = len(dataloader) if _has_len(dataloader) else float('inf')
but not a big deal, would just be cleaner.
@@ -155,7 +154,7 @@ def test_accumulation_and_early_stopping(tmpdir): | |||
'Learning rate was not altered after running learning rate finder' | |||
assert len(lrfinder.results['lr']) == 100, \ | |||
'Early stopping for learning rate finder did not work' | |||
assert lrfinder._total_batch_idx == 100 * 2, \ | |||
assert lrfinder._total_batch_idx == 190, \ |
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.
how is this related?
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.
not really but the test was skipped completely
dbe540a
to
9412f7e
Compare
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.
Looks good to me.
* Start accumulate gradients schedule at epoch 0 * Undo change in #2375 * Update test_trainer.py::test_gradient_accumulation_scheduling * Fix pep8 formatting * Remove 'Datasets/' folder * Split args for readability * Fix pep8 formatting
What does this PR do?
smhow the master is still failing
Fixes #2293 #2307
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 🙃