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

Add shuffling in Nanotron for subsequent epochs when data is repeated #247

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 18 additions & 8 deletions src/nanotron/data/nanoset.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,24 @@ def build_nanoset_index(self) -> np.ndarray:
dataset_index, dataset_sample_index = build_nanoset_index_helper(
n_samples=samples_per_epoch, weights=self.dataset_weights, dataset_sizes=self.dataset_lengths
)
# Shuffle the indexes the same way
numpy_random_state = np.random.RandomState(self.random_seed)
numpy_random_state.shuffle(dataset_index)
numpy_random_state = np.random.RandomState(self.random_seed)
numpy_random_state.shuffle(dataset_sample_index)
# Concatenate num_epochs the shuffled indexes
dataset_index = np.concatenate([dataset_index for _ in range(num_epochs)])
dataset_sample_index = np.concatenate([dataset_sample_index for _ in range(num_epochs)])

# Shuffle indices in each epoch with different random seeds and concatenate them
dataset_indices = []
dataset_sample_indices = []
for num_epoch in range(num_epochs):
# Shuffle the sample and dataset indices in epoch with a given seed
numpy_random_state = np.random.RandomState(self.random_seed + num_epoch)
numpy_random_state.shuffle(dataset_index)
numpy_random_state = np.random.RandomState(self.random_seed + num_epoch)
numpy_random_state.shuffle(dataset_sample_index)

dataset_indices.append(dataset_index)
dataset_sample_indices.append(dataset_sample_index)

# Concatenate the within-epoch shuffled indices
dataset_index = np.concatenate(dataset_indices)
dataset_sample_index = np.concatenate(dataset_sample_indices)

# Just keep the necessary samples
dataset_index = dataset_index[: self.train_split_num_samples]
dataset_sample_index = dataset_sample_index[: self.train_split_num_samples]
Expand Down