Last active
June 27, 2021 18:03
-
-
Save J3698/73695feac6755aca8234ec0fe9216268 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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