code: def apply_rand_augment(
      augmentations: List[_Augmentation],
      data: _DataNode,
      n: int,
      m: int,
      num_magnitude_bins: int = 31,
      seed: Optional[int] = None,
      **kwargs,
  ) -> _DataNode:
      """
      Applies the list of ``augmentations`` in RandAugment (https://arxiv.org/abs/1909.13719) fashion.
      Each sample is transformed with ``n`` operations in a sequence randomly selected from the
      ``augmentations`` list. Each operation uses ``m`` as the magnitude bin.
  
      Args
      ----
      augmentations : List[core._Augmentation]
          List of augmentations to be sampled and applied in RandAugment fashion.
      data : DataNode
          A batch of samples to be processed.
      n: int
          The number of randomly sampled operations to be applied to a sample.
      m: int
          A magnitude bin (strength) of each operation to be applied, it must be an integer
          within ``[0, num_magnitude_bins - 1]``.
      num_magnitude_bins: int
          The number of bins to divide the magnitude ranges into.
      seed: int
          Seed to be used to randomly sample operations (and to negate magnitudes).
      kwargs:
          Any extra parameters to be passed when calling `augmentations`.
          The signature of each augmentation is checked for any extra arguments and if
          the name of the argument matches one from the `kwargs`, the value is
          passed as an argument. For example, some augmentations from the default
          RandAugment suite accept ``shapes``, ``fill_value`` and ``interp_type``.
      Returns
      -------
      DataNode
          A batch of transformed samples.
      """
      if not isinstance(n, int) or n < 0:
          raise Exception(
              f"The number of operations to apply `n` must be a non-negative integer, got {n}."
          )
      if (
          not isinstance(num_magnitude_bins, int)
          or num_magnitude_bins < 1
      ):
          raise Exception(
              f"The `num_magnitude_bins` must be a positive integer, got {num_magnitude_bins}."
          )
      if not isinstance(m, int) or not 0 <= m < num_magnitude_bins:
          raise Exception(
              f"The magnitude bin `m` must be an integer from "
              f"`[0, {num_magnitude_bins - 1}]` range. Got {m}."
          )
      if n == 0:
          warnings.warn(
              "The `apply_rand_augment` was called with `n=0`, "
              "no augmentation will be applied.",
              Warning,
          )
          return data
      if len(augmentations) == 0:
          raise Exception(
              "The `augmentations` list cannot be empty, unless n=0. "
              "Got empty list in `apply_rand_augment` call."
          )
      shape = tuple() if n == 1 else (n,)
      op_idx = fn.random.uniform(
          values=list(range(len(augmentations))),
          seed=seed,
          shape=shape,
          dtype=types.INT32,
      )
      use_signed_magnitudes = any(
          aug.randomly_negate for aug in augmentations
      )
      mag_bin = (
          signed_bin(m, seed=seed, shape=shape)
          if use_signed_magnitudes
          else m
      )
      _forbid_unused_kwargs(augmentations, kwargs, "apply_rand_augment")
      for level_idx in range(n):
          level_mag_bin = (
              mag_bin
              if not use_signed_magnitudes or n == 1
              else mag_bin[level_idx]
          )
          op_kwargs = dict(
              data=data,
              magnitude_bin=level_mag_bin,
              num_magnitude_bins=num_magnitude_bins,
              **kwargs,
          )
          level_op_idx = op_idx if n == 1 else op_idx[level_idx]
          data = _pretty_select(
              augmentations,
              level_op_idx,
              op_kwargs,
              auto_aug_name="apply_rand_augment",
              ref_suite_name="get_rand_augment_suite",
          )
      return data
  
file_path: DALI/dali/python/nvidia/dali/auto_aug/rand_augment.py
imports: import warnings
  from typing import List, Optional, Tuple, Union
  from nvidia.dali import fn
  from nvidia.dali import types
  from nvidia.dali.auto_aug import augmentations
  from nvidia.dali.auto_aug.core import signed_bin, _Augmentation
  from nvidia.dali.auto_aug.core._args import forbid_unused_kwargs
  from nvidia.dali.auto_aug.core._utils import get_translations, pretty_select
  from nvidia.dali.data_node import DataNode
label_desc: Use image node_id 2 for calling a global function with example usage: apply_rand_augment(augmentations, data, n, m, num_magnitude_bins, seed) and returns: data, data