class_docstr: Base class for DistributedDataParallel Sampler.
  
  Every subclass should implement `__iter__` method, providing a way to iterate
  over indices of dataset elements.
  
  Args:
      opts: command line argument
      n_data_samples: Number of samples in the dataset
      is_training: Training or validation mode. Default: False
class_docstr_tok: ["Base","class","for","DistributedDataParallel","Sampler",".","Every","subclass","should","implement","`","__iter__","`","method",",","providing","a","way","to","iterate","over","indices","of","dataset","elements",".","Args",":","opts",":","command","line","argument","n_data_samples",":","Number","of","samples","in","the","dataset","is_training",":","Training","or","validation","mode",".","Default",":","False"]
code: def __init__(
      self,
      opts: argparse.Namespace,
      n_data_samples: int,
      is_training: bool = False,
      *args,
      **kwargs,
  ) -> None:
      batch_size_gpu0: int = get_batch_size_from_opts(
          opts, is_training=is_training
      )
  
      if not dist.is_available():
          raise RuntimeError(
              "Requires distributed package to be available"
          )
  
      num_replicas = dist.get_world_size()
      rank = dist.get_rank()
      gpus_node_i = max(1, torch.cuda.device_count())
  
      num_samples_per_replica = int(
          math.ceil(n_data_samples * 1.0 / num_replicas)
      )
      total_size = num_samples_per_replica * num_replicas
  
      img_indices = [idx for idx in range(n_data_samples)]
      img_indices += img_indices[: (total_size - n_data_samples)]
      assert len(img_indices) == total_size
  
      self.img_indices = img_indices
      self.n_samples_per_replica = num_samples_per_replica
      self.shuffle = True if is_training else False
      self.epoch = 0
      self.rank = rank
      self.batch_size_gpu0 = batch_size_gpu0
      self.num_replicas = num_replicas
      self.skip_sample_indices = []
      self.node_id = rank // gpus_node_i
  
      self.num_nodes = max(1, num_replicas // gpus_node_i)
      self.local_rank = rank % gpus_node_i
      self.num_gpus_node_i = gpus_node_i
  
      self.sharding = False
      self.num_repeats = 1
      self.trunc_rep_aug = False
      self.disable_shuffle_sharding = False
      if is_training:
          self.sharding = getattr(opts, "sampler.use_shards")
          self.num_repeats = getattr(opts, "sampler.num_repeats")
          self.trunc_rep_aug = getattr(
              opts, "sampler.truncated_repeat_aug_sampler"
          )
          self.disable_shuffle_sharding = getattr(
              opts, "sampler.disable_shuffle_sharding"
          )
  
      sample_multiplier = 1 if self.trunc_rep_aug else self.num_repeats
      self.n_samples_per_replica = (
          num_samples_per_replica * sample_multiplier
      )
  
imports: import argparse
  import copy
  import math
  import random
  from typing import Any, Iterator, List, Tuple
  import numpy
  import torch
  import torch.distributed
  from torch.utils.data.sampler import Sampler
label_desc: Use image node_id 1 to create a new BaseSamplerDDP object from inherited base classes: Sampler with example: obj = BaseSamplerDDP(opts, n_data_samples, is_training)