code: def update_dataloader(
      dataloader: DataLoader, new_batch_sampler: BatchSampler
  ) -> DataLoader:
      """Helper function to replace current batch sampler of the dataloader by a new batch sampler. Function returns new
      dataloader with new batch sampler.
  
      Args:
          dataloader: input dataloader
          new_batch_sampler: new batch sampler to use
  
      Returns:
          DataLoader
      """
      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
      return type(dataloader)(**params)
  
imports: import random
  import warnings
  from collections import OrderedDict
  from functools import wraps
  from typing import Any, Callable, Generator, Iterator, List, Optional
  import torch
  from torch.utils.data import DataLoader
  from torch.utils.data.sampler import BatchSampler
  from ignite.engine.engine import Engine
  from ignite.engine.events import Events
  from ignite.utils import manual_seed
label_desc: Use image node_id 1 for calling a global function with example usage: update_dataloader(dataloader, new_batch_sampler) and returns: type