code: def replace_batch_sampler(dataloader, new_batch_sampler):
      r"""
      替换一个 dataloader 的 batch_sampler；
      """
      params_keys = [
          k for k in dataloader.__dict__.keys() if not k.startswith("_")
      ]
      for k in [
          "batch_size",
          "sampler",
          "drop_last",
          "batch_sampler",
          "dataset_kind",
      ]:
          if k in params_keys:
              params_keys.remove(k)
      params = {k: getattr(dataloader, k) for k in params_keys}
      params["batch_sampler"] = new_batch_sampler
  
      if not isinstance(dataloader, DataLoader):
          init_params = dict(
              inspect.signature(dataloader.__init__).parameters
          )
          has_variadic_kwargs = any(
              v.kind is v.VAR_KEYWORD for k, v in init_params.items()
          )
          if not has_variadic_kwargs:
              params = {
                  key: value
                  for key, value in params.items()
                  if key in init_params
              }
  
      return type(dataloader)(**params)
  
imports: import os
  from typing import Any, Dict, Optional
  from enum import IntEnum
  import contextlib
  import random
  import numpy
  import inspect
  from fastNLP.envs.imports import _NEED_IMPORT_ONEFLOW
  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
  from fastNLP.core.log import logger
label_desc: Use image node_id 4 for calling a global function with example usage: replace_batch_sampler(dataloader, new_batch_sampler) and returns: type