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

Align IterableDataset.shuffle with Dataset.shuffle #3842

Merged
merged 7 commits into from
Mar 7, 2022

Conversation

lhoestq
Copy link
Member

@lhoestq lhoestq commented Mar 7, 2022

From #3444 , Dataset.shuffle can have the same API than IterableDataset.shuffle (i.e. in streaming mode).

Currently you can pass an optional seed to both if you want, BUT currently IterableDataset.shuffle always requires a buffer_size, used for approximate shuffling. I propose using a reasonable default value (maybe 1000) instead.

In this PR, I set the default buffer_size value to 1,000, and I reorder the IterableDataset.shuffle arguments to match Dataset.shuffle, i.e. making seed the first argument.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

@mariosasko
Copy link
Collaborator

We should also add generator as a param to shuffle to fully align the APIs, no?

@lhoestq
Copy link
Member Author

lhoestq commented Mar 7, 2022

I added the generator argument.

I had to make a few other adjustments to make it work. In particular when you call set_epoch() on a streaming dataset, it updates the underlying random generator by using a new effective seed. The effective seed is generated using the previous generator and the epoch number.

Copy link
Collaborator

@mariosasko mariosasko left a comment

Choose a reason for hiding this comment

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

Thanks! One comment:

src/datasets/iterable_dataset.py Show resolved Hide resolved
@lhoestq lhoestq merged commit 2a5149b into master Mar 7, 2022
@lhoestq lhoestq deleted the align-iterable-dataset-shuffle branch March 7, 2022 19:03
@lhoestq lhoestq mentioned this pull request Mar 10, 2022
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.

4 participants