code: def replace_sampler(
      dataloader: Union["Dataset", "JittorDataLoader"], sampler
  ):
      batch_sampler = getattr(dataloader, "sampler")
      if batch_sampler is not None and isinstance(
          batch_sampler, ReproducibleBatchSampler
      ):
          raise RuntimeError(
              "It should not be running here, please report a bug to us."
          )
      if isinstance(dataloader, JittorDataLoader):
          init_params = dict(
              inspect.signature(dataloader.__init__).parameters
          )
          reconstruct_args = {
              name: getattr(dataloader, name, p.default)
              for name, p in init_params.items()
          }
          reconstruct_args["dataset"] = replace_sampler(
              reconstruct_args["dataset"].dataset,
              reconstruct_args["dataset"].sampler,
          )
          new_dataloader = type(dataloader)(**reconstruct_args)
          new_dataloader.dataset.set_attrs(sampler=sampler)
      else:
          new_dataloader = deepcopy(dataloader)
          new_dataloader.set_attrs(sampler=sampler)
  
      return new_dataloader
  
file_path: fastNLP/fastNLP/core/drivers/jittor_driver/utils.py
imports: import inspect
  import os
  import random
  from copy import deepcopy
  from typing import Union
  import numpy
  from fastNLP.core.dataloaders import JittorDataLoader
  from fastNLP.envs.imports import _NEED_IMPORT_JITTOR
  from fastNLP.envs.utils import get_global_seed
  from fastNLP.envs import get_global_rank, FASTNLP_BACKEND_LAUNCH, FASTNLP_GLOBAL_SEED
  from fastNLP.core.samplers import ReproducibleBatchSampler
  from fastNLP.core.log import logger
label_desc: Use image node_id 3 for calling a global function with example usage: replace_sampler(dataloader, sampler) and returns: new_dataloader