class_docstr: Adapted from `torch.utils.data.distributed.DistributedSampler`.
code: def __iter__(self):
      if self.shuffle:
          # deterministically shuffle based on epoch and seed
          indices = (
              np.random.RandomState(seed=self.random_seed + self.epoch)
              .permutation(self.dataset_size)
              .tolist()
          )
      else:
          indices = list(range(self.dataset_size))
  
      # add extra samples to make it evenly divisible
      indices += indices[: (self.total_size - len(indices))]
      assert len(indices) == self.total_size
  
      # subsample
      indices = indices[self.rank : self.total_size : self.num_replicas]
      assert len(indices) == self.num_samples
  
      return iter(indices)
  
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 2 for calling the DistributedSampler obj's underlying member method code with example usage: obj.__iter__() and returns: iter