-
Notifications
You must be signed in to change notification settings - Fork 119
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
Make ValDataLoaderIter
able to be reset only when it is acquired by the syntax of normal iterator
#60
Conversation
acquired by the syntax of normal `iterator` In `LRFinder.range_test()`, `val_iter` won't be reset after it runs out of values, and it makes `LRFinder._validate()` failed to work correctly after the first iteration of `range_test()`. To fix it, we add a counter to count the times a `ValDataLoaderIter` has run (i.e. times of `__next__()` is called). And reset it only when its `__iter__()` is called. So that it won't be reset automatically like the way `TrainDataLoaderIter` works. See also davidtvs#59 and the docstring of `ValDataLoaderIter` for further details.
used in `range_test()`
It seems that "ci-build / ci-build (3.7, 0.4.1)" stuck at step "Upload coverage to Codecov" 😲 |
Comparing with successful jobs before, there is only three build results uploaded to codecov. Expected result (4 coverage files, committed at Aug, 8): Got result (3 coverage files, committed at today): It seems that we cannot re-run this job through UI of GitHub Action currently, see also this post. But I found this post stated that we can push a empty commit to trigger it. If it's necessary to get those coverage reports from all 4 builds, feel free to let me know to do this. |
I reran the jobs and now they ran normally. I'm merging this. Thanks! |
Thanks 👍 |
ValDataLoaderIter
is not reset after each iteration, and it results in the problem shown in issue #59.See also this comment: #59 (comment) for further details.
In this PR, tests related to
TrainDataLoaderIter
andValDataLoaderIter
are also added.UPDATE:
Purpose of the changes in this PR is to make
ValDataLoader
work liketorch.data.DataLoader
. When we want to iterate over atorch.data.DataLoader
, we can use the following approaches:iterate it through a for-loop
(
DataLoader.__iter__()
is called implicitly by for loop)iterate it through an iterator created by
iter()
And the first approach is how we use
val_loader
before commit 52c189a. An iterator ofval_loader
will be created whenever it is iterated through the for-loop inself._validate()
.pytorch-lr-finder/torch_lr_finder/lr_finder.py
Lines 197 to 200 in ed21825
In commit 52c189a,
ValDataLoaderIter
was introduced to solve the problem of unpacking multiple values returned by a data loader. However, since an instance ofValDataLoaderIter
is created, the iterator we can acquire by either a for-loop oriter()
is always the same object (i.e.ValDataLoaderIter()
itself). That means it can't be reset by those approaches mentioned above, and that's why it makesself._validate()
failed to work as before.With the changes made in this PR,
ValDataLoaderIter
should work like how we usetorch.data.DataLoader
.Besides, the reason why we didn't just apply these changes to
DataLoaderIter
is thatTrainDataLoaderIter
relies on it's behavior. SinceTrainDataLoaderIter
should be capable of resetting itself whenauto_reset
is True, it should return itself when we acquire an iterator throughTrainDataLoaderIter.__iter__()
.