code: def build_dataloader(
      cfg: mmcv.Config,
      split: "str",
      context: det_torch.PyTorchTrialContext,
      shuffle: bool,
  ) -> Tuple[torch_data.Dataset, det_torch.DataLoader]:
      """
      Build the dataset and dataloader according to cfg and sampler parameters.
  
      Arguments:
          cfg: mmcv.Config with dataset specifications.
          split: one of train, val, or test. If val or test, annotations are not loaded.
          context: PyTorchTrialContext with seed info used to seed the dataloader workers.
          shuffle: whether to shuffle indices for data loading.
      Returns:
          dataset and dataloader
      """
      assert split in [
          "train",
          "val",
          "test",
      ], "argument split must be one of train, val, or test."
      num_samples_per_gpu = context.get_per_slot_batch_size()
      num_replicas = context.distributed.get_size()
      num_workers = cfg.workers_per_gpu
      test_mode = False if split == "train" else True
  
      cfg = eval(f"cfg.{split}")
      maybe_download_ann_file(cfg)
  
      dataset = mmdet.datasets.build_dataset(
          cfg, {"test_mode": test_mode}
      )
      if test_mode:
          dataset = DatasetWithIndex(dataset)
      sampler = (
          GroupSampler(dataset, num_samples_per_gpu, num_replicas)
          if shuffle
          else None
      )
  
      return dataset, det_torch.DataLoader(
          dataset,
          batch_size=num_samples_per_gpu,
          num_workers=num_workers,
          sampler=sampler,
          collate_fn=functools.partial(
              mmcv.parallel.collate, samples_per_gpu=num_samples_per_gpu
          ),
          pin_memory=False,
          worker_init_fn=functools.partial(
              mmdet.datasets.builder.worker_init_fn,
              seed=context.get_trial_seed(),
              rank=context.distributed.get_rank(),
              num_workers=num_workers,
          ),
      )
  
imports: import functools
  import logging
  import math
  import os
  from typing import Any, Iterator, List, Tuple
  import filelock
  import mmcv
  import mmcv.parallel
  import mmdet.datasets
  import numpy
  import torch
  import torch.utils.data
  import determined.pytorch
label_desc: Use image node_id 2 for calling a global function with example usage: build_dataloader(cfg, split, context, shuffle) and returns: dataset,  det_torch