def __init__(self, data_source, batch_size=1, num_replicas=None, rank=None):
    '\n        Samples batches assuming they are in order of size to batch similarly sized samples together.\n        '
    super(DistributedBucketingSampler, self).__init__(data_source)
    if (num_replicas is None):
        num_replicas = get_world_size()
    if (rank is None):
        rank = get_rank()
    self.data_source = data_source
    self.ids = list(range(0, len(data_source)))
    self.batch_size = batch_size
    self.bins = [self.ids[i:(i + batch_size)] for i in range(0, len(self.ids), batch_size)]
    self.num_replicas = num_replicas
    self.rank = rank
    self.num_samples = int(math.ceil(((len(self.bins) * 1.0) / self.num_replicas)))
    self.total_size = (self.num_samples * self.num_replicas)
Samples batches assuming they are in order of size to batch similarly sized samples together.
def __init__(self, data_source, batch_size=1, num_replicas=None, rank=None):
    '\n        \n        '
    super(DistributedBucketingSampler, self).__init__(data_source)
    if (num_replicas is None):
        num_replicas = get_world_size()
    if (rank is None):
        rank = get_rank()
    self.data_source = data_source
    self.ids = list(range(0, len(data_source)))
    self.batch_size = batch_size
    self.bins = [self.ids[i:(i + batch_size)] for i in range(0, len(self.ids), batch_size)]
    self.num_replicas = num_replicas
    self.rank = rank
    self.num_samples = int(math.ceil(((len(self.bins) * 1.0) / self.num_replicas)))
    self.total_size = (self.num_samples * self.num_replicas)