class_docstr: `BucketizeBatchSampler` wrapper that distributes across each processor.
  
  Args:
      batch_sampler (BucketizeBatchSampler): the initialized bucketize batch sampler.
      num_replicas (int, optional): Number of processes participating in
          distributed training. By default, :attr:`world_size` is retrieved from the
          current distributed group.
      rank (int, optional): Rank of the current process within :attr:`num_replicas`.
          By default, :attr:`rank` is retrieved from the current distributed
          group.
      shuffle (bool, optional): if ``True``, the list of batch indices will be shuffled.
          (Default: ``True``)
      seed (int, optional): random seed used to shuffle the batch_sampler if
          :attr:`shuffle=True`. This number should be identical across all
          processes in the distributed group. (Default: ``0``)
      drop_last (bool, optional): if ``True``, then the sampler will drop the
          tail of the data to make it evenly divisible across the number of
          replicas. If ``False``, the sampler will add extra indices to make
          the data evenly divisible across the replicas. (Default: ``False``)
  
  Note:
      if ``shuffle`` is True, it will only shuffle the data once. Please set ``reload_dataloaders_every_n_epochs=1``
      in pytorch_lightning Trainer, and set `sampler.set_epoch(self.current_epoch)` before DataLoader initialization
      in `train_dataloader` method to enable shuffling every epoch.
class_docstr_tok: ["`","BucketizeBatchSampler","`","wrapper","that","distributes","across","each","processor",".","Args",":","batch_sampler","(","BucketizeBatchSampler",")",":","the","initialized","bucketize","batch","sampler",".","num_replicas","(","int",",","optional",")",":","Number","of","processes","participating","in","distributed","training",".","By","default",",",":","attr",":","`","world_size","`","is","retrieved","from","the","current","distributed","group",".","rank","(","int",",","optional",")",":","Rank","of","the","current","process","within",":","attr",":","`","num_replicas","`",".","By","default",",",":","attr",":","`","rank","`","is","retrieved","from","the","current","distributed","group",".","shuffle","(","bool",",","optional",")",":","if","``","True","``",",","the","list","of","batch","indices","will","be","shuffled",".","(","Default",":","``","True","``",")","seed","(","int",",","optional",")",":","random","seed","used","to","shuffle","the","batch_sampler","if",":","attr",":","`","shuffle=True","`",".","This","number","should","be","identical","across","all","processes","in","the","distributed","group",".","(","Default",":","``","0","``",")","drop_last","(","bool",",","optional",")",":","if","``","True","``",",","then","the","sampler","will","drop","the","tail","of","the","data","to","make","it","evenly","divisible","across","the","number","of","replicas",".","If","``","False","``",",","the","sampler","will","add","extra","indices","to","make","the","data","evenly","divisible","across","the","replicas",".","(","Default",":","``","False","``",")","Note",":","if","``","shuffle","``","is","True",",","it","will","only","shuffle","the","data","once",".","Please","set","``","reload_dataloaders_every_n_epochs=1","``","in","pytorch_lightning","Trainer",",","and","set","`","sampler.set_epoch","(","self.current_epoch",")","`","before","DataLoader","initialization","in","`","train_dataloader","`","method","to","enable","shuffling","every","epoch","."]
code: def __init__(
      self,
      batch_sampler: BucketizeBatchSampler,
      num_replicas: Optional[int] = None,
      rank: Optional[int] = None,
      shuffle: bool = True,
      seed: int = 0,
      drop_last: bool = False,
  ) -> None:
      self.batch_sampler = batch_sampler
      if num_replicas is None:
          if not dist.is_available():
              raise RuntimeError(
                  "Requires distributed package to be available"
              )
          num_replicas = dist.get_world_size()
      if rank is None:
          if not dist.is_available():
              raise RuntimeError(
                  "Requires distributed package to be available"
              )
          rank = dist.get_rank()
      self.num_replicas = num_replicas
      self.rank = rank
      self.shuffle = shuffle
      self.epoch = 0
      self.seed = seed
      self.drop_last = drop_last
      self.shuffle = shuffle
      indices = self.batch_sampler.iter_list
      if self.drop_last and len(indices) % self.num_replicas != 0:
          # Split to nearest available length that is evenly divisible.
          # This is to ensure each rank receives the same amount of data when
          # using this Sampler.
          self.num_samples = math.ceil(
              (len(indices) - self.num_replicas) / self.num_replicas
          )
      else:
          self.num_samples = math.ceil(len(indices) / self.num_replicas)
  
imports: import math
  import os
  import sys
  from pathlib import Path
  from typing import Dict, Iterator, List, Optional, Tuple, Union
  import numpy
  import torch
  import torch.distributed
  import torchaudio
  from torch import Tensor
  from torch.utils.data import BatchSampler, Dataset, DistributedSampler
  from utils import _get_label2id
label_desc: Use image node_id 1 to create a new DistributedBatchSampler object from inherited base classes: DistributedSampler with example: obj = DistributedBatchSampler(batch_sampler, num_replicas, rank, shuffle, seed, drop_last)