def get_hvp(
    loss: torch.Tensor, params: Sequence[torch.Tensor], vectors: Sequence[torch.Tensor]
) -> Tuple[torch.Tensor, ...]:
    """
    Get a Hessian-Vector Product (HVP) `Hv` for each Hessian `H` of the `loss`
    with respect to the one of the parameter tensors in `params` and the corresponding
    vector `v` in `vectors`.

    # Parameters

    loss : `torch.Tensor`
        The loss calculated from the output of the model.
    params : `Sequence[torch.Tensor]`
        Tunable and used parameters in the model that we will calculate the gradient and hessian
        with respect to.
    vectors : `Sequence[torch.Tensor]`
        The list of vectors for calculating the HVP.
    """
    # Sanity check before performing element-wise multiplication
    assert len(params) == len(vectors)
    assert all(p.size() == v.size() for p, v in zip(params, vectors))
    grads = autograd.grad(loss, params, create_graph=True, retain_graph=True)
    hvp = autograd.grad(grads, params, grad_outputs=vectors)
    return hvp
Get a Hessian-Vector Product (HVP) `Hv` for each Hessian `H` of the `loss`
with respect to the one of the parameter tensors in `params` and the corresponding
vector `v` in `vectors`.

# Parameters

loss : `torch.Tensor`
The loss calculated from the output of the model.
params : `Sequence[torch.Tensor]`
Tunable and used parameters in the model that we will calculate the gradient and hessian
with respect to.
vectors : `Sequence[torch.Tensor]`
The list of vectors for calculating the HVP.
allennlp/interpret/influence_interpreters/simple_influence.py