lfxai.utils.influence module
This code is adapted from https://github.com/nimarb/pytorch_influence_functions/
- get_numpy_parameters(model)
Recovers the parameters of a pytorch model in numpy format
- hessian_vector_product(loss, model, v)
Multiplies the Hessians of the loss of a model with respect to its parameters by a vector v. Adapted from: https://github.com/kohpangwei/influence-release
This function uses a backproplike approach to compute the product between the Hessian and another vector efficiently, which even works for large Hessians with O(p) compelxity for p parameters.
- Parameters
loss – scalar/tensor, for example the output of the loss function
model – the model for which the Hessian of the loss is evaluated
v – list of torch tensors, rnn.parameters(), will be multiplied with the Hessian
- Returns
list of torch tensors, contains product of Hessian and v.
- Return type
return_grads
- stack_torch_tensors(input_tensors)
Takes a list of tensors and stacks them into one tensor