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

fix legacy ds padding bug #9716

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,16 @@ def get_start_end_idx(self):
end_idx = start_idx + self.micro_batch_size
return start_idx, end_idx

def _get_padding_indices(self, pad_samples_num):
return range(-1, -pad_samples_num - 1, -1)

def __iter__(self):
dimapihtar marked this conversation as resolved.
Show resolved Hide resolved
batch = []
# Last batch will be dropped if drop_last is not set False
indices = range(self.consumed_samples, self.total_samples)
if (not self.drop_last) and self.pad_samples_to_global_batch_size:
pad_samples_num = -len(indices) % self.global_batch_size
pad_indices = [None] * pad_samples_num
pad_indices = self._get_padding_indices(pad_samples_num)
indices = chain(indices, pad_indices)

for idx in indices:
Expand All @@ -125,6 +128,11 @@ def __iter__(self):
yield batch[start_idx:end_idx]


class MegatronCorePretrainingSampler(MegatronPretrainingSampler):
def _get_padding_indices(self, pad_samples_num):
return [None] * pad_samples_num


class MegatronPretrainingRandomSampler(BaseMegatronSampler):
def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

from nemo.collections.common.parts.utils import extend_instance
from nemo.collections.nlp.data.language_modeling.megatron.data_samplers import (
MegatronCorePretrainingSampler,
MegatronPretrainingRandomSampler,
MegatronPretrainingSampler,
)
Expand Down Expand Up @@ -1605,8 +1606,13 @@ def build_pretraining_data_loader(
logging.info(f'Building dataloader with consumed samples: {consumed_samples}')
# Megatron sampler
if hasattr(self.cfg.data, 'dataloader_type') and self.cfg.data.dataloader_type is not None:
data_sampler = (
MegatronPretrainingSampler
if self.cfg.data.get('legacy_dataset', False)
else MegatronCorePretrainingSampler
)
if self.cfg.data.dataloader_type == 'single':
batch_sampler = MegatronPretrainingSampler(
batch_sampler = data_sampler(
total_samples=len(dataset),
consumed_samples=consumed_samples,
micro_batch_size=self.cfg.micro_batch_size,
Expand Down
Loading