code: def build_batch_data_loader(
      dataset,
      sampler,
      total_batch_size,
      *,
      aspect_ratio_grouping=False,
      num_workers=0,
  ):
      """
      Build a batched dataloader for training.
  
      Args:
          dataset (torch.utils.data.Dataset): map-style PyTorch dataset. Can be indexed.
          sampler (torch.utils.data.sampler.Sampler): a sampler that produces indices
          total_batch_size (int): total batch size across GPUs.
          aspect_ratio_grouping (bool): whether to group images with similar
              aspect ratio for efficiency. When enabled, it requires each
              element in dataset be a dict with keys "width" and "height".
          num_workers (int): number of parallel data loading workers
  
      Returns:
          iterable[list]. Length of each list is the batch size of the current
              GPU. Each element in the list comes from the dataset.
      """
      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
      if aspect_ratio_grouping:
          data_loader = torch.utils.data.DataLoader(
              dataset,
              sampler=sampler,
              num_workers=num_workers,
              batch_sampler=None,
              collate_fn=operator.itemgetter(
                  0
              ),  # don't batch, but yield individual elements
              worker_init_fn=worker_init_reset_seed,
          )  # yield individual mapped dict
          return AspectRatioGroupedDataset(data_loader, batch_size)
      else:
          batch_sampler = torch.utils.data.sampler.BatchSampler(
              sampler, batch_size, drop_last=True
          )  # drop_last so the batch always have the same size
          return torch.utils.data.DataLoader(
              dataset,
              num_workers=num_workers,
              batch_sampler=batch_sampler,
              collate_fn=trivial_batch_collator,
              worker_init_fn=worker_init_reset_seed,
          )
  
imports: import itertools
  import random
  import logging
  import operator
  import dill
  import pickle
  from pprint import pformat
  from typing import List, Optional, Union
  import numpy
  import torch
  import torch.utils.data
  from ..structures import BoxMode
  from ...utils.comm import get_world_size
  from ...utils.random import seed_all_rng
  from ..transforms import instance_transforms
  from ..registry.catalog import DatasetCatalog, MetadataCatalog
  from .detection_utils import check_metadata_consistency
  from .None import detection_utils
  from .samplers import InferenceSampler, 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: AspectRatioGroupedDataset, torch