Skip to content

Commit

Permalink
fix shuffling for ShufflerIterDataPipe instances (#376)
Browse files Browse the repository at this point in the history
* fix shuffling for ShufflerIterDataPipe instances

* add versioning test for Pytorch

* fix minimum Pytorch version

Co-authored-by: Loubna ben allal <loubnabenallal@gmail.com>
  • Loading branch information
loubnabnl and Loubna ben allal committed May 20, 2022
1 parent b922c63 commit 3c45b6f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/accelerate/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,21 @@ class DataLoaderDispatcher(DataLoader):
"""

def __init__(self, dataset, split_batches: bool = False, **kwargs):
shuffle = False
if version.parse(torch.__version__) >= version.parse("1.11.0"):
from torch.utils.data.datapipes.iter.combinatorics import ShufflerIterDataPipe

# We need to save the shuffling state of the DataPipe
if isinstance(dataset, ShufflerIterDataPipe):
shuffle = dataset._shuffle_enabled
super().__init__(dataset, **kwargs)
self.split_batches = split_batches
if version.parse(torch.__version__) < version.parse("1.8.0"):
raise ImportError(
"Using `DataLoaderDispatcher` requires PyTorch 1.8.0 minimum. You have {torch.__version__}."
)
if shuffle:
torch.utils.data.graph_settings.apply_shuffle_settings(dataset, shuffle=shuffle)

def __iter__(self):
state = AcceleratorState()
Expand Down

0 comments on commit 3c45b6f

Please sign in to comment.