code: def compute_gradients(
      forward_fn: Callable,
      inputs: Union[Tensor, Tuple[Tensor, ...]],
      target_ind: TargetType = None,
      additional_forward_args: Any = None,
  ) -> Tuple[Tensor, ...]:
      r"""
      Computes gradients of the output with respect to inputs for an
      arbitrary forward function.
  
      Args:
  
          forward_fn: forward function. This can be for example model's
                      forward function.
          input:      Input at which gradients are evaluated,
                      will be passed to forward_fn.
          target_ind: Index of the target class for which gradients
                      must be computed (classification only).
          additional_forward_args: Additional input arguments that forward
                      function requires. It takes an empty tuple (no additional
                      arguments) if no additional arguments are required
      """
      with torch.autograd.set_grad_enabled(True):
          # runs forward pass
          outputs = _run_forward(
              forward_fn, inputs, target_ind, additional_forward_args
          )
          assert outputs[0].numel() == 1, (
              "Target not provided when necessary, cannot"
              " take gradient with respect to multiple outputs."
          )
          # torch.unbind(forward_out) is a list of scalar tensor tuples and
          # contains batch_size * #steps elements
          grads = torch.autograd.grad(torch.unbind(outputs), inputs)
      return grads
  
imports: import threading
  import typing
  import warnings
  from typing import Any, Callable, Dict, List, Tuple, Union, cast
  import torch
  from torch import Tensor, device
  from torch.nn import Module
  from captum.attr._utils.batching import _reduce_list, _sort_key_list
  from captum.attr._utils.common import _run_forward, _verify_select_column
  from captum.attr._utils.typing import Literal, TargetType, TensorOrTupleOfTensorsGeneric
label_desc: Use image node_id 3 for calling a global function with example usage: compute_gradients(forward_fn, inputs, target_ind, additional_forward_args) and returns: grads