MCPcopy Create free account
hub / github.com/RingBDStack/GDAP / __init__

Method __init__

seq2seq/utils.py:370–391  ·  view source on GitHub ↗
(self, dataset, batch_size, num_replicas=None, rank=None, add_extra_examples=True, shuffle=True)

Source from the content-addressed store, hash-verified

368 """Copied from torch DistributedSampler"""
369
370 def __init__(self, dataset, batch_size, num_replicas=None, rank=None, add_extra_examples=True, shuffle=True):
371 if num_replicas is None:
372 if not dist.is_available():
373 raise RuntimeError("Requires distributed package to be available")
374 num_replicas = dist.get_world_size()
375 if rank is None:
376 if not dist.is_available():
377 raise RuntimeError("Requires distributed package to be available")
378 rank = dist.get_rank()
379 self.dataset = dataset
380 self.num_replicas = num_replicas
381 self.rank = rank
382 self.epoch = 0
383 if add_extra_examples:
384 self.num_samples = int(math.ceil(len(self.dataset) * 1.0 / self.num_replicas))
385 self.total_size = self.num_samples * self.num_replicas
386 else:
387 self.total_size = len(dataset)
388 self.num_samples = len(self.available_indices)
389 self.batch_size = batch_size
390 self.add_extra_examples = add_extra_examples
391 self.shuffle = shuffle
392
393 def __iter__(self) -> Iterable:
394 g = torch.Generator()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected