code: def _compute_jacobian_sample_wise_grads_per_batch(
      influence_inst: Union["TracInCP", "InfluenceFunctionBase"],
      inputs: Tuple[Any, ...],
      targets: Optional[Tensor] = None,
      loss_fn: Optional[Union[Module, Callable]] = None,
      reduction_type: Optional[str] = "none",
  ) -> Tuple[Tensor, ...]:
      """
      `TracInCP`, `InfluenceFunction`, and `ArnoldiInfluenceFunction` all compute
      jacobians, depending on their `sample_wise_grads_per_batch` attribute. this helper
      wraps that logic.
      """
  
      if influence_inst.sample_wise_grads_per_batch:
          return _compute_jacobian_wrt_params_with_sample_wise_trick(
              influence_inst.model,
              inputs,
              targets,
              loss_fn,
              reduction_type,
              influence_inst.layer_modules,
          )
      return _compute_jacobian_wrt_params(
          influence_inst.model,
          inputs,
          targets,
          loss_fn,
          influence_inst.layer_modules,
      )
  
imports: import warnings
  from functools import reduce
  from typing import Any, Callable, Iterable, List, NamedTuple, Optional, Tuple, TYPE_CHECKING, Union
  import torch
  import torch.nn
  from captum._utils.common import _get_module_from_name, _parse_version
  from captum._utils.gradient import _compute_jacobian_wrt_params, _compute_jacobian_wrt_params_with_sample_wise_trick
  from captum._utils.progress import progress
  from torch import Tensor
  from torch.nn import Module
  from torch.utils.data import DataLoader, Dataset
label_desc: Use image node_id 25 for calling a global function with example usage: _compute_jacobian_sample_wise_grads_per_batch(influence_inst, inputs, targets, loss_fn, reduction_type) and returns: _compute_jacobian_wrt_params, _compute_jacobian_wrt_params_with_sample_wise_trick