class_docstr: A shuffler to shuffle items and create batches.
  
  This class is used internally by :class:`ItemSampler` to shuffle items and
  create batches. It is not supposed to be used directly. The intention of
  this class is to avoid time-consuming iteration over :class:`ItemSet`. As
  an optimization, it slices from the :class:`ItemSet` via indexing first,
  then shuffle and create batches.
  
  Parameters
  ----------
  item_set : ItemSet
      Data to be iterated.
  shuffle : bool
      Option to shuffle before batching.
  batch_size : int
      The size of each batch.
  drop_last : bool
      Option to drop the last batch if it's not full.
  buffer_size : int
      The size of the buffer to store items sliced from the :class:`ItemSet`
      or :class:`ItemSetDict`.
  distributed : bool
      Option to apply on :class:`DistributedItemSampler`.
  drop_uneven_inputs : bool
      Option to make sure the numbers of batches for each replica are the
      same. Applies only when `distributed` is True.
  world_size : int
      The number of model replicas that will be created during Distributed
      Data Parallel (DDP) training. It should be the same as the real world
      size, otherwise it could cause errors. Applies only when `distributed`
      is True.
  rank : int
      The rank of the current replica. Applies only when `distributed` is
      True.
docstr: Collate a batch from the buffer. For internal use only.
docstr_tok: ["Collate","a","batch","from","the","buffer",".","For","internal","use","only","."]
code: def _collate_batch(self, buffer, indices, offsets=None):
      """Collate a batch from the buffer. For internal use only."""
      if isinstance(buffer, torch.Tensor):
          # For item set that's initialized with integer or single tensor,
          # `buffer` is a tensor.
          return torch.index_select(buffer, dim=0, index=indices)
      elif isinstance(buffer, list) and isinstance(buffer[0], DGLGraph):
          # For item set that's initialized with a list of
          # DGLGraphs, `buffer` is a list of DGLGraphs.
          return dgl_batch([buffer[idx] for idx in indices])
      elif isinstance(buffer, tuple):
          # For item set that's initialized with a tuple of items,
          # `buffer` is a tuple of tensors.
          return tuple(item[indices] for item in buffer)
      elif isinstance(buffer, Mapping):
          # For item set that's initialized with a dict of items,
          # `buffer` is a dict of tensors/lists/tuples.
          keys = list(buffer.keys())
          key_indices = (
              torch.searchsorted(offsets, indices, right=True) - 1
          )
          batch = {}
          for j, key in enumerate(keys):
              mask = (key_indices == j).nonzero().squeeze(1)
              if len(mask) == 0:
                  continue
              batch[key] = self._collate_batch(
                  buffer[key], indices[mask] - offsets[j]
              )
          return batch
      raise TypeError(
          f"Unsupported buffer type {type(buffer).__name__}."
      )
  
imports: from collections.abc import Mapping
  from functools import partial
  from typing import Callable, Iterator, Optional, Union
  import numpy
  import torch
  import torch.distributed
  from torch.utils.data import default_collate
  from torchdata.datapipes.iter import IterableWrapper, IterDataPipe
  from ..base import dgl_warning
  from ..batch import batch
  from ..heterograph import DGLGraph
  from .internal import calculate_range
  from .itemset import ItemSet, ItemSetDict
  from .minibatch import MiniBatch
label_desc: Use image node_id 2 for calling the ItemShufflerAndBatcher obj's underlying member method code with example usage: obj._collate_batch(buffer, indices, offsets) and returns: torch, dgl_batch, tuple, batch