Skip to content
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

Bug fixing for bucketing dataset #6191

Merged
merged 3 commits into from
Mar 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions nemo/collections/asr/data/audio_to_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,19 +1245,21 @@ def _collate_fn(self, batch):

def __iter__(self):
return BucketingIterator(
wrapped_iter=self.wrapped_dataset._dataset.__iter__(), bucketing_batch_size=self.bucketing_batch_size
wrapped_ds=self.wrapped_dataset._dataset, bucketing_batch_size=self.bucketing_batch_size
).__iter__()

def __len__(self):
return int(math.ceil(len(self.wrapped_dataset) / float(self.bucketing_batch_size)))


class BucketingIterator:
def __init__(self, wrapped_iter, bucketing_batch_size):
self.wrapped_iter = wrapped_iter
def __init__(self, wrapped_ds, bucketing_batch_size):
self.wrapped_ds = wrapped_ds
self.wrapped_iter = None
self.bucketing_batch_size = bucketing_batch_size

def __iter__(self):
self.wrapped_iter = iter(self.wrapped_ds)
return self

def __next__(self):
Expand All @@ -1266,7 +1268,8 @@ def __next__(self):
try:
sample = next(self.wrapped_iter)
except StopIteration:
break
self.wrapped_iter = iter(self.wrapped_ds)
sample = next(self.wrapped_iter)
batches.append(sample)
if len(batches) == 0:
raise StopIteration
Expand Down