Skip to content

Instantly share code, notes, and snippets.

@J3698
Last active June 27, 2021 18:03
Show Gist options
  • Save J3698/73695feac6755aca8234ec0fe9216268 to your computer and use it in GitHub Desktop.
Save J3698/73695feac6755aca8234ec0fe9216268 to your computer and use it in GitHub Desktop.
def __iter__(self):
worker_info = torch.utils.data.get_worker_info()
if worker_info is not None:
self.random.seed(round(1000 * random.random()))
length = ceil(self.length // worker_info.num_workers)
if worker_info.id == worker_info.num_workers - 1:
length = self.length - length * (worker_info.num_workers - 1)
assert length > 0
self.ilength = length
else:
self.ilength = self.length
return self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment