code: def _batched_generator(
      inputs: TensorOrTupleOfTensorsGeneric,
      additional_forward_args: Any = None,
      target_ind: TargetType = None,
      internal_batch_size: Union[None, int] = None,
  ) -> Iterator[Tuple[Tuple[Tensor, ...], Any, TargetType]]:
      """
      Returns a generator which returns corresponding chunks of size internal_batch_size
      for both inputs and additional_forward_args. If batch size is None,
      generator only includes original inputs and additional args.
      """
      assert internal_batch_size is None or (
          isinstance(internal_batch_size, int)
          and internal_batch_size > 0
      ), "Batch size must be greater than 0."
      inputs = _format_tensor_into_tuples(inputs)
      additional_forward_args = _format_additional_forward_args(
          additional_forward_args
      )
      num_examples = inputs[0].shape[0]
      # TODO Reconsider this check if _batched_generator is used for non gradient-based
      # attribution algorithms
      if not (inputs[0] * 1).requires_grad:
          warnings.warn(
              """It looks like that the attribution for a gradient-based method is
              computed in a `torch.no_grad` block or perhaps the inputs have no
              requires_grad."""
          )
      if internal_batch_size is None:
          yield inputs, additional_forward_args, target_ind
      else:
          for current_total in range(
              0, num_examples, internal_batch_size
          ):
              with torch.autograd.set_grad_enabled(True):
                  inputs_splice = _tuple_splice_range(
                      inputs,
                      current_total,
                      current_total + internal_batch_size,
                  )
              yield inputs_splice, _tuple_splice_range(
                  additional_forward_args,
                  current_total,
                  current_total + internal_batch_size,
              ), target_ind[
                  current_total : current_total + internal_batch_size
              ] if isinstance(
                  target_ind, list
              ) or (
                  isinstance(target_ind, torch.Tensor)
                  and target_ind.numel() > 1
              ) else target_ind
  
file_path: captum/captum/attr/_utils/batching.py
imports: import typing
  import warnings
  from typing import Any, Callable, Iterator, Tuple, Union
  import torch
  from captum._utils.common import _format_additional_forward_args, _format_output, _format_tensor_into_tuples, _reduce_list
  from captum._utils.typing import TargetType, TensorOrTupleOfTensorsGeneric, TupleOrTensorOrBoolGeneric
  from captum.attr._utils.approximation_methods import approximation_parameters
  from torch import Tensor
label_desc: Use image node_id 5 for calling a global function with example usage: _batched_generator(inputs, additional_forward_args, target_ind, internal_batch_size) without return types