Skip to content

Commit

Permalink
Better version
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerzr committed Nov 7, 2023
1 parent 34170ec commit 9f1cd95
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/accelerate/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ class SeedableRandomSampler(RandomSampler):
If a custom `generator` is passed, it will rely on its initial seed as well as the current iteration it is on
(stored in `self.epoch`).
A manual seed can also be used by setting the `ACCELERATE_SEED` environmental variable.
"""

def __init__(self, *args, **kwargs):
Expand All @@ -85,8 +83,10 @@ def __init__(self, *args, **kwargs):
def __iter__(self):
if self.generator is None:
self.generator = torch.Generator()
else:
self.seed = self.generator.initial_seed()
# Allow `self.epoch` to modify the seed of the generator
seed = self.epoch + (self.seed if self.seed is not None else self.generator.initial_seed())
seed = self.epoch + self.seed
self.generator.manual_seed(seed)
yield from super().__iter__()
self.set_epoch(self.epoch + 1)
Expand Down

0 comments on commit 9f1cd95

Please sign in to comment.