code: def TrainDataLoader(
      dataset: Dataset,
      *,
      transform: Transformation = Identity(),
      batch_size: int,
      stack_fn: Callable,
      num_batches_per_epoch: Optional[int] = None,
      shuffle_buffer_length: Optional[int] = None,
  ):
      """
      Construct an iterator of batches for training purposes.
  
      This function wraps around ``DataLoader`` to offer training-specific
      behaviour and options, as follows:
  
          1. The provided dataset is iterated cyclically, so that one can go over
          it multiple times in a single epoch. 2. A transformation must be
          provided, that is lazily applied as the dataset is being iterated;
          this is useful e.g. to slice random instances of fixed length out of
          each time series in the dataset. 3. The resulting batches can be
          iterated in a pseudo-shuffled order.
  
      The returned object is a stateful iterator, whose length is either
      ``num_batches_per_epoch`` (if not ``None``) or infinite (otherwise).
  
      Parameters
      ----------
      dataset
          Data to iterate over.
      transform
          Transformation to be lazily applied as data is being iterated.
          The transformation is applied in "training mode" (``is_train=True``).
      batch_size
          Number of entries to include in a batch.
      stack_fn
          Function to use to stack data entries into batches.
          This can be used to set a specific array type or computing device
          the arrays should end up onto (CPU, GPU).
      num_batches_per_epoch
          Length of the iterator. If ``None``, then the iterator is endless.
      shuffle_buffer_length
          Size of the buffer used for shuffling. Default: None, in which case no
          shuffling occurs.
  
      Returns
      -------
      Iterator[DataBatch]
          An iterator of batches.
      """
      dataset: Dataset = Cyclic(dataset)
  
      if shuffle_buffer_length:
          dataset = PseudoShuffled(dataset, shuffle_buffer_length)
  
      transform += Batch(batch_size=batch_size) + AdhocTransform(
          stack_fn
      )
      transformed_dataset = transform.apply(dataset, is_train=True)
  
      batches = iter(transformed_dataset)
      return IterableSlice(batches, num_batches_per_epoch)
  
file_path: gluonts/src/gluonts/dataset/loader.py
imports: import logging
  from typing import Callable, Iterable, Optional
  import numpy
  from gluonts.dataset import DataBatch, Dataset
  from gluonts.itertools import Cyclic, IterableSlice, PseudoShuffled, batcher, rows_to_columns
  from gluonts.pydantic import BaseModel
  from gluonts.transform import AdhocTransform, Identity, SelectFields, Transformation, Valmap
label_desc: Use image node_id 2 for calling a global function with example usage: TrainDataLoader(dataset) and returns: IterableSlice