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 collections import defaultdict
  from typing import Any, Callable, cast, Dict, List, Optional, Sequence, Tuple, Union
  import torch
  from captum._utils.common import _reduce_list, _run_forward, _sort_key_list, _verify_select_neuron
  from captum._utils.sample_gradient import SampleGradientWrapper
  from captum._utils.typing import Literal, ModuleOrModuleList, TargetType, TensorOrTupleOfTensorsGeneric
  from torch import device, Tensor
  from torch.nn import Module
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