code: def _parameter_arnoldi(
      hvp: Callable,
      b: Tuple[Tensor, ...],
      n: int,
      tol: float,
      projection_device: torch.device,
      show_progress: bool,
  ) -> Tuple[List[Tuple[Tensor, ...]], Tensor]:
      r"""
      Given `hvp`, a function which computes the Hessian-vector product of an arbitrary
      vector `v` with an implicitly-defined Hessian matrix `A`, performs the Arnoldi
      iteration for `A` for `n` iterations.  (We use `A`, not `H` to refer to the
      Hessian, unlike elsewhere, because `H` is already used in the below explanation
      of the Arnoldi iteration.)
  
      For more details on the Arnoldi iteration, please see Trefethen and Bau, Chp 33.
      Running Arnoldi iteration for n iterations gives a basis for the Krylov subspace
      spanned by :math`\{b, Ab,..., A^{n-1}b\}`, as well as a `n+1` by `n` matrix
      :math`H_n` which is upper Hessenberg (all entries below the diagonal, except those
      adjoining it, are 0), whose first n rows represent the restriction of `A` to the
      Krylov subspace, using the basis. Here, `b` is an arbitrary initialization basis
      vector. The basis is assembled into a `D` by `n+1` matrix, where the last
      column is a "correction factor", i.e. not part of the basis, denoted
      :math`Q_{n+1}`. Letting :math`Q_n` denote the matrix with the first n columns of
      :math`Q_{n+1}`, the following equality is satisfied: :math`A=Q_{n+1} H_n Q_n'`.
  
      In this implementation, `v` is not actually a vector, but instead a tuple of
      tensors, because `hvp` being a Hessian-vector product, `v` lies in parameter-space,
      which Pytorch represents as tuples of tensors. This implementation avoids
      flattening `v` to a 1D tensor, which leads to scalability gains.
  
      Args:
          hvp (Callable): A callable that accepts an arbitrary tuple of tensors
                  `v`, which represents a parameter, and returns
                  `Av`, i.e. the multiplication of `v` with an implicitly defined matrix
                  `A` of compatible dimension, which in practice is a Hessian-vector
                  product.
          b (tensor): The Arnoldi iteration requires an initialization basis to
                  construct the basis, typically randomly chosen. This is that basis,
                  and is a tuple of tensors. We assume that the device of `b` is the same
                  as the required device of input `v` to `hvp`. For example, if `hvp`
                  computes HVP using a model that is on the GPU, then `b` should also be
                  on the GPU.
          n (int): The number of iterations to run the iteration for.
          tol (float, optional): After many iterations, the already-obtained
                  basis vectors may already approximately span the Krylov subspace,
                  in which case the addition of additional basis vectors involves
                  normalizing a vector with a small norm. These vectors are not
                  necessary to include in the basis and furthermore, their small norm
                  leads to numerical issues. Therefore we stop the Arnoldi iteration
                  when the addition of additional vectors involves normalizing a
                  vector with norm below a certain threshold. This argument specifies
                  that threshold.
                  Default: 1e-4
          projection_device (torch.device) The returned quantities (which will be used
                  to define a projection of parameter-gradients, hence the name) are
                  potentially memory intensive, because they represent a basis of a
                  subspace in the space of parameters, which are potentially
                  high-dimensional. Therefore we need to be careful of out-of-memory
                  GPU errors. This argument represents the device where the returned
                  quantities should be stored, and its choice requires balancing
                  speed with GPU memory.
          show_progress (bool): If true, the progress of the iteration (i.e. number of
                  basis vectors already determined) will be displayed. It will try to
                  use tqdm if available for advanced features (e.g. time estimation).
                  Otherwise, it will fallback to a simple output of progress.
  
      Returns:
          qs (list of tuple of tensors): A list of tuple of tensors, whose first `n`
                  elements contain a basis for the Krylov subspace.
          H (tensor): A tensor with shape `(n+1, n)` whose first `n` rows represent
                  the restriction of `A` to the Krylov subspace.
      """
      # because the HVP is the computational bottleneck, we always do HVP on
      # the same device as the model, which is assumed to be the device `b` is on
      computation_device = next(iter(b)).device
  
      # all entries of `b` have the same dtype, and so can be used to determine dtype
      # of `H`
      H = torch.zeros(n + 1, n, dtype=next(iter(b)).dtype).to(
          device=projection_device
      )
      qs = [
          _parameter_to(
              _parameter_multiply(b, 1.0 / _parameter_dot(b, b) ** 0.5),
              device=projection_device,
          )
      ]
  
      iterates = range(1, n + 1)
      if show_progress:
          iterates = tqdm(
              iterates, desc="Running Arnoldi Iteration for step"
          )
  
      for k in iterates:
          v = _parameter_to(
              hvp(_parameter_to(qs[k - 1], device=computation_device)),
              device=projection_device,
          )
  
          for i in range(k):
              H[i, k - 1] = _parameter_dot(qs[i], v)
              v = _parameter_add(
                  v, _parameter_multiply(qs[i], -H[i, k - 1])
              )
          H[k, k - 1] = _parameter_dot(v, v) ** 0.5
  
          if H[k, k - 1] < tol:
              break
          qs.append(_parameter_multiply(v, 1.0 / H[k, k - 1]))
  
      return qs[:k], H[:k, : k - 1]
  
imports: import functools
  from typing import Any, Callable, List, Optional, Tuple, Union
  import torch
  from captum._utils.gradient import _extract_parameters_from_layers
  from captum.influence._utils.common import _compute_batch_loss_influence_function_base, _compute_jacobian_sample_wise_grads_per_batch, _dataset_fn, _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, _parameter_add, _parameter_dot, _parameter_linear_combination, _parameter_multiply, _parameter_to, _params_to_names, _progress_bar_constructor, _self_influence_helper_intermediate_quantities_influence_function, _top_eigen, 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
  from .influence_function import _get_dataset_embeddings_intermediate_quantities_influence_function, InfluenceFunctionBase, IntermediateQuantitiesInfluenceFunction
label_desc: Use image node_id 1 for calling a global function with example usage: _parameter_arnoldi(hvp, b, n, tol, projection_device, show_progress) and returns: qs,  H