code: def test_set_distributed(self):
      dataset = TorchNormalDataset(num_of_data=100)
      sampler = RandomSampler(dataset, shuffle=False)
      sampler.set_distributed(num_replicas=2, rank=0, pad=False)
      assert len(sampler) == 50
      count = 0
      for i in sampler:
          assert i % 2 == 0
          count += 1
      assert count == 50
  
      sampler.set_distributed(num_replicas=2, rank=1, pad=False)
      assert len(sampler) == 50
      count = 0
      for i in sampler:
          assert i % 2 == 1
          count += 1
      assert count == 50
  
      dataset = TorchNormalDataset(num_of_data=101)
      sampler = RandomSampler(dataset, shuffle=False)
      sampler.set_distributed(num_replicas=2, rank=0, pad=True)
      assert len(sampler) == 51
      count = 0
      for i in sampler:
          assert i % 2 == 0
          count += 1
      assert count == 51
  
      sampler.set_distributed(num_replicas=2, rank=1, pad=True)
      assert len(sampler) == 51
      count = 0
      for i in sampler:
          if i != 0:
              assert i % 2 == 1
          count += 1
      assert count == 51
  
imports: import numpy
  import pytest
  from functools import partial
  from itertools import chain
  from copy import deepcopy
  from fastNLP.core.samplers.reproducible_sampler import RandomSampler, SortedSampler, SequentialSampler
  from tests.helpers.datasets.torch_data import TorchNormalDataset
label_desc: Use image node_id 3 for calling the TestRandomSamplerYh obj's underlying member method code with example usage: obj.test_set_distributed() without return types