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

Conversation

Lauler
Copy link

@Lauler Lauler commented Nov 24, 2024

Nanoset's index builder does not re-shuffle dataset and sample indices within epochs when training secondary, third, etc epochs. It instead concatenates a copy of the same indices for any repeated data. This PR adds unique within-epoch shuffling for each epoch.

See the following issue: #237

I ran the tests in tests/nanotron:

=========================================================================== warnings summary ===========================================================================
tests/helpers/context.py:7: 35 warnings
  /home/faton/projects/text/nanotron_dev/nanotron/tests/helpers/context.py:7: PytestCollectionWarning: cannot collect test class 'TestContext' because it has a __init__ constructor (from: nanoset/test_build_nanoset_dataloader.py)
    class TestContext:

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================================== 12 passed, 35 warnings in 44.55s ===================================================================

@TJ-Solergibert

Copy link
Member

@NouamaneTazi NouamaneTazi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! LGTM 🤗
Minor sugg before merging


# Shuffle indices in each epoch with different random seeds and concatenate them
r = np.random.RandomState(self.random_seed)
epoch_random_seeds = r.randint(0, 2**32 - 1, num_epochs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just use self.random_seed + num_epoch for easier reproducibility?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, makes it a lot simpler and clearer what's going on. I've changed the code to incorporate this in latest commit:

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)

@Lauler Lauler force-pushed the nanoset-shuffle-epochs-data branch from fe4aa4e to f060414 Compare November 28, 2024 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants