code: def build_batch_data_loader(
      dataset,
      sampler,
      total_batch_size,
      *,
      aspect_ratio_grouping=False,
      num_workers=0,
      collate_fn=None,
      drop_last: bool = True,
      single_gpu_batch_size=None,
      **kwargs,
  ):
      """
      Build a batched dataloader. The main differences from `torch.utils.data.DataLoader` are:
      1. support aspect ratio grouping options
      2. use no "batch collation", because this is common for detection training
  
      Args:
          dataset (torch.utils.data.Dataset): a pytorch map-style or iterable dataset.
          sampler (torch.utils.data.sampler.Sampler or None): a sampler that produces indices.
              Must be provided iff. ``dataset`` is a map-style dataset.
          total_batch_size, aspect_ratio_grouping, num_workers, collate_fn: see
              :func:`build_detection_train_loader`.
          single_gpu_batch_size: You can specify either `single_gpu_batch_size` or `total_batch_size`.
              `single_gpu_batch_size` specifies the batch size that will be used for each gpu/process.
              `total_batch_size` allows you to specify the total aggregate batch size across gpus.
              It is an error to supply a value for both.
          drop_last (bool): if ``True``, the dataloader will drop incomplete batches.
  
      Returns:
          iterable[list]. Length of each list is the batch size of the current
              GPU. Each element in the list comes from the dataset.
      """
      if single_gpu_batch_size:
          if total_batch_size:
              raise ValueError(
                  """total_batch_size and single_gpu_batch_size are mutually incompatible.
                  Please specify only one. """
              )
          batch_size = single_gpu_batch_size
      else:
          world_size = get_world_size()
          assert (
              total_batch_size > 0
              and total_batch_size % world_size == 0
          ), "Total batch size ({}) must be divisible by the number of gpus ({}).".format(
              total_batch_size, world_size
          )
          batch_size = total_batch_size // world_size
      logger = logging.getLogger(__name__)
      logger.info(
          "Making batched data loader with batch_size=%d", batch_size
      )
  
      if isinstance(dataset, torchdata.IterableDataset):
          assert (
              sampler is None
          ), "sampler must be None if dataset is IterableDataset"
      else:
          dataset = ToIterableDataset(
              dataset, sampler, shard_chunk_size=batch_size
          )
  
      if aspect_ratio_grouping:
          assert (
              drop_last
          ), "Aspect ratio grouping will drop incomplete batches."
          data_loader = torchdata.DataLoader(
              dataset,
              num_workers=num_workers,
              collate_fn=operator.itemgetter(
                  0
              ),  # don't batch, but yield individual elements
              worker_init_fn=worker_init_reset_seed,
              **kwargs,
          )  # yield individual mapped dict
          data_loader = AspectRatioGroupedDataset(
              data_loader, batch_size
          )
          if collate_fn is None:
              return data_loader
          return MapDataset(data_loader, collate_fn)
      else:
          return torchdata.DataLoader(
              dataset,
              batch_size=batch_size,
              drop_last=drop_last,
              num_workers=num_workers,
              collate_fn=trivial_batch_collator
              if collate_fn is None
              else collate_fn,
              worker_init_fn=worker_init_reset_seed,
              **kwargs,
          )
  
imports: import itertools
  import logging
  import numpy
  import operator
  import pickle
  from collections import OrderedDict, defaultdict
  from typing import Any, Callable, Dict, List, Optional, Union
  import torch
  import torch.utils.data
  from tabulate import tabulate
  from termcolor import colored
  from detectron2.config import configurable
  from detectron2.structures import BoxMode
  from detectron2.utils.comm import get_world_size
  from detectron2.utils.env import seed_all_rng
  from detectron2.utils.file_io import PathManager
  from detectron2.utils.logger import _log_api_usage, log_first_n
  from .catalog import DatasetCatalog, MetadataCatalog
  from .common import AspectRatioGroupedDataset, DatasetFromList, MapDataset, ToIterableDataset
  from .dataset_mapper import DatasetMapper
  from .detection_utils import check_metadata_consistency
  from .samplers import InferenceSampler, RandomSubsetTrainingSampler, RepeatFactorTrainingSampler, TrainingSampler
label_desc: Use image node_id 6 for calling a global function with example usage: build_batch_data_loader(dataset, sampler, total_batch_size) and returns: MapDataset, torchdata, data_loader