class_docstr: Adapted from `torch.utils.data.distributed.DistributedSampler`.
code: def __init__(
      self,
      dataset_size: int,
      shuffle: bool = True,
      random_seed: int = default_random_seed,
      distributed: DistributedStrategy = None,
  ):
      self.dataset_size = dataset_size
      self.num_replicas = distributed.size() if distributed else 1
      self.rank = distributed.rank() if distributed else 0
      self.epoch = 0
      self.num_samples = int(
          math.ceil(self.dataset_size * 1.0 / self.num_replicas)
      )
      self.total_size = self.num_samples * self.num_replicas
      self.shuffle = shuffle
      self.random_seed = random_seed
  
file_path: ludwig/ludwig/data/sampler.py
imports: import math
  import numpy
  from ludwig.distributed import DistributedStrategy
  from ludwig.utils.defaults import default_random_seed
label_desc: Use image node_id 1 to create a new DistributedSampler object  with example: obj = DistributedSampler(dataset_size, shuffle, random_seed, distributed)