MCPcopy Create free account
hub / github.com/TorchSSL/TorchSSL / __iter__

Method __iter__

datasets/DistributedProxySampler.py:30–45  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

28 self.sampler = sampler
29
30 def __iter__(self):
31 # deterministically shuffle based on epoch
32 torch.manual_seed(self.epoch)
33 indices = list(self.sampler)
34
35 # add extra samples to make it evenly divisible
36 indices += indices[:(self.total_size - len(indices))]
37 if len(indices) != self.total_size:
38 raise RuntimeError("{} vs {}".format(len(indices), self.total_size))
39
40 # subsample
41 indices = indices[self.rank:self.total_size:self.num_replicas]
42 if len(indices) != self.num_samples:
43 raise RuntimeError("{} vs {}".format(len(indices), self.num_samples))
44
45 return iter(indices)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected