-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1437 from lrzpellegrini/ffcv_support_pt2
Fixed issues with 0 length samplers
- Loading branch information
Showing
2 changed files
with
64 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# See the accompanying LICENSE file for terms. # | ||
# # | ||
# Date: 01-12-2020 # | ||
# Author(s): Antonio Carta # | ||
# Author(s): Antonio Carta, Lorenzo Pellegrini # | ||
# E-mail: [email protected] # | ||
# Website: avalanche.continualai.org # | ||
################################################################################ | ||
|
@@ -33,9 +33,8 @@ | |
from avalanche.benchmarks.utils.data_attribute import DataAttribute | ||
from avalanche.distributed.distributed_helper import DistributedHelper | ||
|
||
from torch.utils.data.sampler import BatchSampler | ||
from torch.utils.data.sampler import Sampler, BatchSampler | ||
from torch.utils.data import ConcatDataset | ||
from torch.utils.data.sampler import Sampler | ||
|
||
|
||
def return_identity(x): | ||
|
@@ -571,6 +570,11 @@ def __init__( | |
self.termination_dataset_idx = -1 | ||
self.termination_dataset_iterations = 10 ** 10 | ||
self.oversample_small_datasets = True | ||
|
||
if sum(len(x) for x in self.samplers) == 0: | ||
raise RuntimeError( | ||
'The never ending sampler must able to create a mini-batch' | ||
) | ||
else: | ||
# termination_dataset_idx => dataset used to determine the epoch end | ||
self.termination_dataset_idx = termination_dataset_idx | ||
|
@@ -621,6 +625,14 @@ def __iter__(self): | |
if sampler is None: | ||
continue | ||
|
||
if len(sampler) == 0: | ||
if is_term_dataset and (not self.never_ending): | ||
return | ||
|
||
samplers_list[dataset_idx] = None | ||
sampler_iterators[dataset_idx] = None | ||
continue | ||
|
||
should_stop_if_ended = ( | ||
is_term_dataset or | ||
not self.oversample_small_datasets | ||
|
@@ -672,7 +684,6 @@ def _next_batch( | |
|
||
# Re-create the iterator | ||
# This time, do not catch StopIteration | ||
|
||
if isinstance(sampler, BatchSampler): | ||
if isinstance(sampler.sampler, DistributedSampler): | ||
sampler.sampler.set_epoch( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters