class_docstr: 专门测试 set_dist_repro_dataloader 函数的类
class_docstr_tok: ["\u4e13\u95e8\u6d4b\u8bd5","set_dist_repro_dataloader","\u51fd\u6570\u7684\u7c7b"]
docstr: 测试单卡下 set_dist_repro_dataloader 函数的执行结果是否正确
docstr_tok: ["\u6d4b\u8bd5\u5355\u5361\u4e0b","set_dist_repro_dataloader","\u51fd\u6570\u7684\u6267\u884c\u7ed3\u679c\u662f\u5426\u6b63\u786e"]
code: def check_set_dist_repro_dataloader(
      self, dataloader, replaced_loader, shuffle, use_dataloader
  ):
      """
      测试单卡下 set_dist_repro_dataloader 函数的执行结果是否正确
      """
      # 迭代两个 batch
      num_consumed_batches = 2
      already_seen_idx = set()
      replaced_loader.sampler.set_epoch(6)
      for idx, batch in enumerate(replaced_loader):
          if idx >= num_consumed_batches:
              break
          already_seen_idx.update(batch.tolist())
      sampler_states = replaced_loader.sampler.state_dict()
  
      # 重新加载，应该可以输出剩下的内容，且对于 JittorNormalDataset 来说，排序后应该是一个 range
      left_idxes = set()
      batch_size = replaced_loader.batch_size
      sampler_states["num_consumed_samples"] = (
          num_consumed_batches * batch_size
      )
      # 重新构造 dataloader
      if use_dataloader:
          dataset = deepcopy(replaced_loader.dataset.dataset)
      else:
          dataset = deepcopy(replaced_loader)
      new_loader = get_dataloader(
          dataset=dataset,
          use_dataloader=use_dataloader,
          sampler=RandomSampler(dataset, shuffle=shuffle),
          batch_size=batch_size,
          shuffle=shuffle,
          drop_last=False,
      )
      new_loader.sampler.load_state_dict(sampler_states)
      new_loader.sampler.set_epoch(6)
      for idx, batch in enumerate(new_loader):
          left_idxes.update(batch.tolist())
  
      print(already_seen_idx)
      print(left_idxes)
  
      assert (
          len(left_idxes) + len(already_seen_idx)
          == self.dataset.total_len
      )
      assert (
          len(left_idxes | already_seen_idx) == self.dataset.total_len
      )
  
imports: import pytest
  from copy import deepcopy
  from pathlib import Path
  from fastNLP.core.drivers.jittor_driver import JittorSingleDriver
  from fastNLP.core.samplers import ReproduceBatchSampler, RandomSampler
  from fastNLP.core.dataloaders import JittorDataLoader
  from tests.helpers.models.jittor_model import JittorNormalModel_Classification_1
  from tests.helpers.datasets.jittor_data import JittorNormalDataset, JittorNormalXYDataset
  from tests.helpers.datasets.torch_data import TorchNormalDataset
  from tests.helpers.models.torch_model import TorchNormalModel_Classification_1
  from fastNLP.envs.distributed import rank_zero_rm
  from fastNLP.envs.imports import _NEED_IMPORT_JITTOR, _NEED_IMPORT_TORCH
label_desc: Use image node_id 8 for calling the TestSetDistReproDataloader obj's underlying member method code with example usage: obj.check_set_dist_repro_dataloader(dataloader, replaced_loader, shuffle, use_dataloader) without return types