code: def _compute_dataset_func(
      inputs_dataset: Union[Tuple[Tensor, ...], DataLoader],
      model: Module,
      loss_fn: Optional[Union[Module, Callable]],
      reduction_type: str,
      layer_modules: Optional[List[Module]],
      f: Callable,
      show_progress: bool,
      **f_kwargs,
  ):
      """
      This function is used to compute higher-order functions of a given model's loss
      over a given dataset, using the model's current parameters. For example, that
      higher-order function `f` could be the Hessian, or a Hessian-vector product.
      This function uses the factory returned by `_flatten_forward_factory`, which given
      a batch, returns the loss for the batch as a function of flattened parameters.
      In particular, for each batch in `inputs_dataset`, this function uses the factory
      to obtain `flattened_forward`, which returns the loss for `model`, using the batch.
      `flattened_forward`, as well as the flattened parameters for `model`, are used by
      argument `f`, a higher-order function, to compute a batch-specific quantity.
      For example, `f` could compute the Hessian via `torch.autograd.functional.hessian`,
      or compute a Hessian-vector product via `torch.autograd.functional.hvp`. Additional
      arguments besides `flattened_forward` and the flattened parameters, i.e. the vector
      in Hessian-vector products, can be passed via named arguments.
      """
      # extract the parameters in a tuple
      params = tuple(
          model.parameters()
          if layer_modules is None
          else _extract_parameters_from_layers(layer_modules)
      )
  
      # construct functions that can flatten / unflatten tensors, and get
      # names of each param in `params`.
      # Both are needed for calling `_flatten_forward_factory`
      _unflatten_params = _unflatten_params_factory(
          tuple([param.shape for param in params])
      )
      param_names = _params_to_names(params, model)
  
      # prepare factory
      factory_given_batch = _flatten_forward_factory(
          model,
          loss_fn,
          reduction_type,
          _unflatten_params,
          param_names,
      )
  
      # the function returned by the factor is evaluated at a *flattened* version of
      # params, so need to create that
      flattened_params = _flatten_params(params)
  
      # define function of a single batch
      def batch_f(batch):
          flattened_forward = factory_given_batch(
              batch
          )  # accepts flattened params
          return f(flattened_forward, flattened_params, **f_kwargs)
  
      # sum up results of `batch_f`
      if show_progress:
          inputs_dataset = tqdm(
              inputs_dataset, desc="processing `hessian_dataset` batch"
          )
  
      return _dataset_fn(inputs_dataset, batch_f, add)
  
imports: import functools
  from abc import abstractmethod
  from operator import add
  from typing import Any, Callable, List, Optional, Tuple, Union
  import torch
  import torch.nn
  from captum._utils.gradient import _extract_parameters_from_layers
  from captum.influence._core.influence import DataInfluence
  from captum.influence._utils.common import _check_loss_fn, _compute_batch_loss_influence_function_base, _compute_jacobian_sample_wise_grads_per_batch, _dataset_fn, _flatten_params, _format_inputs_dataset, _functional_call, _get_k_most_influential_helper, _influence_batch_intermediate_quantities_influence_function, _influence_helper_intermediate_quantities_influence_function, _influence_route_to_helpers, _load_flexible_state_dict, _params_to_names, _progress_bar_constructor, _self_influence_helper_intermediate_quantities_influence_function, _set_active_parameters, _top_eigen, _unflatten_params_factory, KMostInfluentialResults
  from captum.log import log_usage
  from torch import Tensor
  from torch.nn import Module
  from torch.utils.data import DataLoader, Dataset
  from tqdm import tqdm
label_desc: Use image node_id 2 for calling a global function with example usage: _compute_dataset_func(inputs_dataset, model, loss_fn, reduction_type, layer_modules, f, show_progress) and returns: _dataset_fn, f