code: def replace_sampler(dataloader, new_sampler):
      """
      使用 ``new_sampler`` 重新构建一个 ``BatchSampler``，并替换到 ``dataloader`` 中
      """
      batch_sampler = getattr(dataloader, "batch_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."
          )
      new_batch_sampler = deepcopy(dataloader.batch_sampler)
      new_batch_sampler.sampler = new_sampler
      return replace_batch_sampler(dataloader, new_batch_sampler)
  
imports: import socket
  import os
  import struct
  import random
  import inspect
  import numpy
  from copy import deepcopy
  from contextlib import ExitStack, closing
  from typing import Dict, Optional
  from fastNLP.envs.imports import _NEED_IMPORT_PADDLE
  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.utils import auto_param_call, paddle_to
  from fastNLP.core.log import logger
label_desc: Use image node_id 5 for calling a global function with example usage: replace_sampler(dataloader, new_sampler) and returns: replace_batch_sampler