code: def test_unrepeated_distributed_sampler(shuffle):
      """Test each rank will receive a different number of elements."""
      seed_everything(42)
      world_size = 4
      samplers = []
      dataset = range(103)
      for rank in range(world_size):
          samplers.append(
              UnrepeatedDistributedSampler(
                  dataset,
                  rank=rank,
                  num_replicas=world_size,
                  shuffle=shuffle,
              )
          )
  
      indices = [list(s) for s in samplers]
      assert len(indices[0]) == 26
      assert len(indices[1]) == 26
      assert len(indices[2]) == 26
      assert len(indices[3]) == 25
  
      assert indices[0][-1] == 18 if shuffle else 100
      assert indices[1][-1] == 30 if shuffle else 101
      assert indices[2][-1] == 29 if shuffle else 102
      assert indices[3][-1] == 35 if shuffle else 99
  
file_path: pytorch-lightning/tests/tests_pytorch/overrides/test_distributed.py
imports: from typing import Iterable
  import pytest
  import torch
  from lightning.fabric.utilities.data import has_len
  from lightning.pytorch import LightningModule, Trainer, seed_everything
  from lightning.pytorch.overrides.distributed import UnrepeatedDistributedSampler, _IndexBatchSamplerWrapper
  from torch.utils.data import BatchSampler, SequentialSampler
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 2 for calling a global function with example usage: test_unrepeated_distributed_sampler(shuffle) without return types