class_docstr: A fork of the PyTorch DistributedSampler that doesn't repeat data, instead allowing the number of batches per
  process to be off-by-one from each other. This makes this sampler usable for predictions (it's deterministic and
  doesn't require shuffling). It is potentially unsafe to use this sampler for training, because during training the
  DistributedDataParallel syncs buffers on each forward pass, so it could freeze if one of the processes runs one
  fewer batch. During prediction, buffers are only synced on the first batch, so this is safe to use as long as each
  process runs at least one batch. We verify this in an assert.
  
  Taken from https://github.com/jpuigcerver/PyLaia/blob/v1.0.0/laia/data/unpadded_distributed_sampler.py and
  https://github.com/pytorch/pytorch/issues/25162#issuecomment-634146002
class_docstr_tok: ["A","fork","of","the","PyTorch","DistributedSampler","that","does","n't","repeat","data",",","instead","allowing","the","number","of","batches","per","process","to","be","off-by-one","from","each","other",".","This","makes","this","sampler","usable","for","predictions","(","it","'s","deterministic","and","does","n't","require","shuffling",")",".","It","is","potentially","unsafe","to","use","this","sampler","for","training",",","because","during","training","the","DistributedDataParallel","syncs","buffers","on","each","forward","pass",",","so","it","could","freeze","if","one","of","the","processes","runs","one","fewer","batch",".","During","prediction",",","buffers","are","only","synced","on","the","first","batch",",","so","this","is","safe","to","use","as","long","as","each","process","runs","at","least","one","batch",".","We","verify","this","in","an","assert",".","Taken","from","https",":","\/\/github.com\/jpuigcerver\/PyLaia\/blob\/v1.0.0\/laia\/data\/unpadded_distributed_sampler.py","and","https",":","\/\/github.com\/pytorch\/pytorch\/issues\/25162","#","issuecomment-634146002"]
code: def __iter__(self) -> Iterator[List[int]]:
      if not isinstance(self.dataset, Sized):
          raise TypeError(
              "The given dataset must implement the `__len__` method."
          )
      if self.shuffle:
          # deterministically shuffle based on epoch
          g = torch.Generator()
          g.manual_seed(self.epoch)
          indices = torch.randperm(
              len(self.dataset), generator=g
          ).tolist()
      else:
          indices = list(range(len(self.dataset)))
  
      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)
  
imports: import itertools
  from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Sized, Union, cast
  import torch
  from torch import Tensor
  from torch.nn.parallel.distributed import DistributedDataParallel
  from torch.utils.data import DistributedSampler, Sampler
  from typing_extensions import Self
  from lightning.fabric.utilities.distributed import _DatasetSamplerWrapper
  from lightning.pytorch.utilities.rank_zero import rank_zero_debug, rank_zero_info
  from lightning.pytorch.utilities.types import _SizedIterable
label_desc: Use image node_id 2 for calling the UnrepeatedDistributedSampler obj's underlying member method code with example usage: obj.__iter__() and returns: iter