class_docstr: Enhance PyTorch DistributedSampler to support non-evenly divisible sampling.
  
  Args:
      dataset: Dataset used for sampling.
      even_divisible: if False, different ranks can have different data length.
          for example, input data: [1, 2, 3, 4, 5], rank 0: [1, 3, 5], rank 1: [2, 4].
      num_replicas: number of processes participating in distributed training.
          by default, `world_size` is retrieved from the current distributed group.
      rank: rank of the current process within `num_replicas`. by default,
          `rank` is retrieved from the current distributed group.
      shuffle: if `True`, sampler will shuffle the indices, default to True.
      kwargs: additional arguments for `DistributedSampler` super class, can be `seed` and `drop_last`.
  
  More information about DistributedSampler, please check:
  https://pytorch.org/docs/stable/data.html#torch.utils.data.distributed.DistributedSampler.
class_docstr_tok: ["Enhance","PyTorch","DistributedSampler","to","support","non-evenly","divisible","sampling",".","Args",":","dataset",":","Dataset","used","for","sampling",".","even_divisible",":","if","False",",","different","ranks","can","have","different","data","length",".","for","example",",","input","data",":","[","1",",","2",",","3",",","4",",","5","]",",","rank","0",":","[","1",",","3",",","5","]",",","rank","1",":","[","2",",","4","]",".","num_replicas",":","number","of","processes","participating","in","distributed","training",".","by","default",",","`","world_size","`","is","retrieved","from","the","current","distributed","group",".","rank",":","rank","of","the","current","process","within","`","num_replicas","`",".","by","default",",","`","rank","`","is","retrieved","from","the","current","distributed","group",".","shuffle",":","if","`","True","`",",","sampler","will","shuffle","the","indices",",","default","to","True",".","kwargs",":","additional","arguments","for","`","DistributedSampler","`","super","class",",","can","be","`","seed","`","and","`","drop_last","`",".","More","information","about","DistributedSampler",",","please","check",":","https",":","\/\/pytorch.org\/docs\/stable\/data.html","#","torch.utils.data.distributed.DistributedSampler","."]
code: def __init__(
      self,
      dataset: Dataset,
      even_divisible: bool = True,
      num_replicas: int | None = None,
      rank: int | None = None,
      shuffle: bool = True,
      **kwargs,
  ):
      super().__init__(
          dataset=dataset,
          num_replicas=num_replicas,
          rank=rank,
          shuffle=shuffle,
          **kwargs,
      )
  
      if not even_divisible:
          data_len = len(dataset)  # type: ignore
          if data_len < self.num_replicas:
              raise ValueError(
                  "the dataset length is less than the number of participating ranks."
              )
          extra_size = self.total_size - data_len
          if self.rank + extra_size >= self.num_replicas:
              self.num_samples -= 1
          self.total_size = data_len
  
file_path: MONAI/monai/data/samplers.py
imports: from __future__ import annotations
  from collections.abc import Sequence
  import torch
  from torch.utils.data import Dataset
  from torch.utils.data import DistributedSampler
label_desc: Use image node_id 1 to create a new DistributedSampler object from inherited base classes: _TorchDistributedSampler with example: obj = DistributedSampler(dataset, even_divisible, num_replicas, rank, shuffle)