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

Adds reshuffle_each_iteration argument to deterministic_data.create_dataset(). #356

Open
wants to merge 1 commit 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
10 changes: 9 additions & 1 deletion clu/deterministic_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ def create_dataset(dataset_builder: DatasetBuilder,
num_epochs: Optional[int] = None,
shuffle: bool = True,
shuffle_buffer_size: int = 10_000,
reshuffle_each_iteration: Optional[bool] = None,
prefetch_size: int = 4,
pad_up_to_batches: Optional[Union[int, str]] = None,
cardinality: Optional[int] = None,
Expand Down Expand Up @@ -402,6 +403,9 @@ def create_dataset(dataset_builder: DatasetBuilder,
forever.
shuffle: Whether to shuffle the dataset (both on file and example level).
shuffle_buffer_size: Number of examples in the shuffle buffer.
reshuffle_each_iteration: A boolean, which if true indicates that the
dataset should be pseudorandomly reshuffled each time it is iterated over.
(Defaults to `True`.)
prefetch_size: The number of elements in the final dataset to prefetch in
the background. This should be a small (say <10) positive integer or
tf.data.experimental.AUTOTUNE.
Expand Down Expand Up @@ -453,7 +457,11 @@ def create_dataset(dataset_builder: DatasetBuilder,
ds = ds.cache()

if shuffle:
ds = ds.shuffle(shuffle_buffer_size, seed=rngs.pop()[0])
ds = ds.shuffle(
shuffle_buffer_size,
seed=rngs.pop()[0],
reshuffle_each_iteration=reshuffle_each_iteration,
)
ds = ds.repeat(num_epochs)

if preprocess_fn is not None:
Expand Down
Loading