Influence function model
This module implements several implementations of InfluenceFunctionModel utilizing PyTorch.
TorchInfluenceFunctionModel(model, loss)
¶
Bases: InfluenceFunctionModel[Tensor, DataLoader]
, ABC
Abstract base class for influence computation related to torch models
Source code in src/pydvl/influence/torch/influence_function_model.py
is_fitted
abstractmethod
property
¶
Override this, to expose the fitting status of the instance.
fit(data)
abstractmethod
¶
Override this method to fit the influence function model to training data, e.g. pre-compute hessian matrix or matrix decompositions
PARAMETER | DESCRIPTION |
---|---|
data |
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
The fitted instance |
Source code in src/pydvl/influence/base_influence_function_model.py
influences(x_test, y_test, x=None, y=None, mode=InfluenceMode.Up)
¶
Compute the approximation of
for the case of up-weighting influence, resp.
for the perturbation type influence case.
PARAMETER | DESCRIPTION |
---|---|
x_test |
model input to use in the gradient computations of \(H^{-1}\nabla_{theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
y_test |
label tensor to compute gradients
TYPE:
|
x |
optional model input to use in the gradient computations \(\nabla_{theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{theta}\ell(y, f_{\theta}(x))\), if None, use \(x=x_{\text{test}}\) |
y |
optional label tensor to compute gradients |
mode |
enum value of [InfluenceType][pydvl.influence.base_influence_model.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/torch/influence_function_model.py
influence_factors(x, y)
¶
Compute approximation of
where the gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
x |
model input to use in the gradient computations
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise inverse Hessian matrix vector products |
Source code in src/pydvl/influence/torch/influence_function_model.py
influences_from_factors(z_test_factors, x, y, mode=InfluenceMode.Up)
¶
Computation of
for the case of up-weighting influence, resp.
for the perturbation type influence case. The gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
z_test_factors |
pre-computed tensor, approximating \(H^{-1}\nabla_{\theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
x |
model input to use in the gradient computations \(\nabla_{\theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{\theta}\ell(y, f_{\theta}(x))\)
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
mode |
enum value of [InfluenceType][pydvl.influence.twice_differentiable.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/torch/influence_function_model.py
DirectInfluence(model, loss, hessian_regularization=0.0)
¶
Bases: TorchInfluenceFunctionModel
Given a model and training data, it finds x such that \(Hx = b\), with \(H\) being the model hessian.
PARAMETER | DESCRIPTION |
---|---|
model |
instance of torch.nn.Module.
TYPE:
|
hessian_regularization |
Regularization of the hessian.
TYPE:
|
Source code in src/pydvl/influence/torch/influence_function_model.py
influence_factors(x, y)
¶
Compute approximation of
where the gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
x |
model input to use in the gradient computations
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise inverse Hessian matrix vector products |
Source code in src/pydvl/influence/torch/influence_function_model.py
influences_from_factors(z_test_factors, x, y, mode=InfluenceMode.Up)
¶
Computation of
for the case of up-weighting influence, resp.
for the perturbation type influence case. The gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
z_test_factors |
pre-computed tensor, approximating \(H^{-1}\nabla_{\theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
x |
model input to use in the gradient computations \(\nabla_{\theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{\theta}\ell(y, f_{\theta}(x))\)
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
mode |
enum value of [InfluenceType][pydvl.influence.twice_differentiable.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/torch/influence_function_model.py
fit(data)
¶
Compute the hessian matrix based on a provided dataloader
PARAMETER | DESCRIPTION |
---|---|
data |
Instance of [torch.utils.data.Dataloader][]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
DirectInfluence
|
The fitted instance |
Source code in src/pydvl/influence/torch/influence_function_model.py
influences(x_test, y_test, x=None, y=None, mode=InfluenceMode.Up)
¶
Compute approximation of
for the case of up-weighting influence, resp.
for the perturbation type influence case. The action of \(H^{-1}\) is achieved via a direct solver using torch.linalg.solve.
PARAMETER | DESCRIPTION |
---|---|
x_test |
model input to use in the gradient computations of \(H^{-1}\nabla_{\theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
y_test |
label tensor to compute gradients
TYPE:
|
x |
optional model input to use in the gradient computations \(\nabla_{\theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{\theta}\ell(y, f_{\theta}(x))\), if None, use \(x=x_{\text{test}}\) |
y |
optional label tensor to compute gradients |
mode |
enum value of [InfluenceType][pydvl.influence.base_influence_model.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
[torch.nn.Tensor][] representing the element-wise scalar products for the provided batch. |
Source code in src/pydvl/influence/torch/influence_function_model.py
CgInfluence(model, loss, hessian_regularization=0.0, x0=None, rtol=1e-07, atol=1e-07, maxiter=None, progress=False)
¶
Bases: TorchInfluenceFunctionModel
Given a model and training data, it uses conjugate gradient to calculate the inverse of the Hessian Vector Product. More precisely, it finds x such that \(Hx = b\), with \(H\) being the model hessian. For more info, see Conjugate Gradient.
PARAMETER | DESCRIPTION |
---|---|
model |
Instance of torch.nn.Module.
TYPE:
|
loss |
A callable that takes the model's output and target as input and returns the scalar loss. |
hessian_regularization |
Regularization of the hessian.
TYPE:
|
x0 |
Initial guess for hvp. If None, defaults to b. |
rtol |
Maximum relative tolerance of result.
TYPE:
|
atol |
Absolute tolerance of result.
TYPE:
|
maxiter |
Maximum number of iterations. If None, defaults to 10*len(b). |
progress |
If True, display progress bars.
TYPE:
|
Source code in src/pydvl/influence/torch/influence_function_model.py
influence_factors(x, y)
¶
Compute approximation of
where the gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
x |
model input to use in the gradient computations
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise inverse Hessian matrix vector products |
Source code in src/pydvl/influence/torch/influence_function_model.py
influences_from_factors(z_test_factors, x, y, mode=InfluenceMode.Up)
¶
Computation of
for the case of up-weighting influence, resp.
for the perturbation type influence case. The gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
z_test_factors |
pre-computed tensor, approximating \(H^{-1}\nabla_{\theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
x |
model input to use in the gradient computations \(\nabla_{\theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{\theta}\ell(y, f_{\theta}(x))\)
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
mode |
enum value of [InfluenceType][pydvl.influence.twice_differentiable.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/torch/influence_function_model.py
influences(x_test, y_test, x=None, y=None, mode=InfluenceMode.Up)
¶
Compute approximation of
for the case of up-weighting influence, resp.
for the perturbation type influence case. The approximate action of \(H^{-1}\) is achieved via the [conjugate gradient method] (https://en.wikipedia.org/wiki/Conjugate_gradient_method).
PARAMETER | DESCRIPTION |
---|---|
x_test |
model input to use in the gradient computations of \(H^{-1}\nabla_{\theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
y_test |
label tensor to compute gradients
TYPE:
|
x |
optional model input to use in the gradient computations \(\nabla_{\theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{\theta}\ell(y, f_{\theta}(x))\), if None, use \(x=x_{\text{test}}\) |
y |
optional label tensor to compute gradients |
mode |
enum value of [InfluenceType][pydvl.influence.base_influence_model.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
[torch.nn.Tensor][] representing the element-wise scalar products for the provided batch. |
Source code in src/pydvl/influence/torch/influence_function_model.py
LissaInfluence(model, loss, hessian_regularization=0.0, maxiter=1000, dampen=0.0, scale=10.0, h0=None, rtol=0.0001, progress=False)
¶
Bases: TorchInfluenceFunctionModel
Uses LISSA, Linear time Stochastic Second-Order Algorithm, to iteratively approximate the inverse Hessian. More precisely, it finds x s.t. \(Hx = b\), with \(H\) being the model's second derivative wrt. the parameters. This is done with the update
where \(I\) is the identity matrix, \(d\) is a dampening term and \(s\) a scaling factor that are applied to help convergence. For details, see Linear time Stochastic Second-Order Approximation (LiSSA)
PARAMETER | DESCRIPTION |
---|---|
model |
instance of torch.nn.Module.
TYPE:
|
hessian_regularization |
Regularization of the hessian.
TYPE:
|
maxiter |
Maximum number of iterations.
TYPE:
|
dampen |
Dampening factor, defaults to 0 for no dampening.
TYPE:
|
scale |
Scaling factor, defaults to 10.
TYPE:
|
h0 |
Initial guess for hvp. |
rtol |
tolerance to use for early stopping
TYPE:
|
progress |
If True, display progress bars.
TYPE:
|
Source code in src/pydvl/influence/torch/influence_function_model.py
influence_factors(x, y)
¶
Compute approximation of
where the gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
x |
model input to use in the gradient computations
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise inverse Hessian matrix vector products |
Source code in src/pydvl/influence/torch/influence_function_model.py
influences(x_test, y_test, x=None, y=None, mode=InfluenceMode.Up)
¶
Compute the approximation of
for the case of up-weighting influence, resp.
for the perturbation type influence case.
PARAMETER | DESCRIPTION |
---|---|
x_test |
model input to use in the gradient computations of \(H^{-1}\nabla_{theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
y_test |
label tensor to compute gradients
TYPE:
|
x |
optional model input to use in the gradient computations \(\nabla_{theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{theta}\ell(y, f_{\theta}(x))\), if None, use \(x=x_{\text{test}}\) |
y |
optional label tensor to compute gradients |
mode |
enum value of [InfluenceType][pydvl.influence.base_influence_model.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/torch/influence_function_model.py
influences_from_factors(z_test_factors, x, y, mode=InfluenceMode.Up)
¶
Computation of
for the case of up-weighting influence, resp.
for the perturbation type influence case. The gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
z_test_factors |
pre-computed tensor, approximating \(H^{-1}\nabla_{\theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
x |
model input to use in the gradient computations \(\nabla_{\theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{\theta}\ell(y, f_{\theta}(x))\)
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
mode |
enum value of [InfluenceType][pydvl.influence.twice_differentiable.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/torch/influence_function_model.py
ArnoldiInfluence(model, loss, hessian_regularization=0.0, rank_estimate=10, krylov_dimension=None, tol=1e-06, max_iter=None, eigen_computation_on_gpu=False)
¶
Bases: TorchInfluenceFunctionModel
Solves the linear system Hx = b, where H is the Hessian of the model's loss function and b is the given right-hand side vector. It employs the [implicitly restarted Arnoldi method] (https://en.wikipedia.org/wiki/Arnoldi_iteration) for computing a partial eigen decomposition, which is used fo the inversion i.e.
where \(D\) is a diagonal matrix with the top (in absolute value) rank_estimate
eigenvalues of the Hessian
and \(V\) contains the corresponding eigenvectors.
For more information, see Arnoldi.
PARAMETER | DESCRIPTION |
---|---|
model |
Instance of torch.nn.Module. The Hessian will be calculated with respect to this model's parameters.
|
hessian_regularization |
Optional regularization parameter added to the Hessian-vector product for numerical stability.
TYPE:
|
rank_estimate |
The number of eigenvalues and corresponding eigenvectors to compute. Represents the desired rank of the Hessian approximation.
TYPE:
|
krylov_dimension |
The number of Krylov vectors to use for the Lanczos method. Defaults to min(model's number of parameters, max(2 times rank_estimate + 1, 20)). |
tol |
The stopping criteria for the Lanczos algorithm.
Ignored if
TYPE:
|
max_iter |
The maximum number of iterations for the Lanczos method.
Ignored if |
eigen_computation_on_gpu |
If True, tries to execute the eigen pair approximation on the model's device via a cupy implementation. Ensure the model size or rank_estimate is appropriate for device memory. If False, the eigen pair approximation is executed on the CPU by the scipy wrapper to ARPACK.
TYPE:
|
Source code in src/pydvl/influence/torch/influence_function_model.py
influence_factors(x, y)
¶
Compute approximation of
where the gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
x |
model input to use in the gradient computations
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise inverse Hessian matrix vector products |
Source code in src/pydvl/influence/torch/influence_function_model.py
influences(x_test, y_test, x=None, y=None, mode=InfluenceMode.Up)
¶
Compute the approximation of
for the case of up-weighting influence, resp.
for the perturbation type influence case.
PARAMETER | DESCRIPTION |
---|---|
x_test |
model input to use in the gradient computations of \(H^{-1}\nabla_{theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
y_test |
label tensor to compute gradients
TYPE:
|
x |
optional model input to use in the gradient computations \(\nabla_{theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{theta}\ell(y, f_{\theta}(x))\), if None, use \(x=x_{\text{test}}\) |
y |
optional label tensor to compute gradients |
mode |
enum value of [InfluenceType][pydvl.influence.base_influence_model.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/torch/influence_function_model.py
influences_from_factors(z_test_factors, x, y, mode=InfluenceMode.Up)
¶
Computation of
for the case of up-weighting influence, resp.
for the perturbation type influence case. The gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
z_test_factors |
pre-computed tensor, approximating \(H^{-1}\nabla_{\theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
x |
model input to use in the gradient computations \(\nabla_{\theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{\theta}\ell(y, f_{\theta}(x))\)
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
mode |
enum value of [InfluenceType][pydvl.influence.twice_differentiable.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/torch/influence_function_model.py
fit(data)
¶
Fitting corresponds to the computation of the low rank decomposition
of the Hessian defined by the provided data loader.
PARAMETER | DESCRIPTION |
---|---|
data |
Instance of [torch.utils.data.Dataloader][]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ArnoldiInfluence
|
The fitted instance |
Source code in src/pydvl/influence/torch/influence_function_model.py
EkfacInfluence(model, update_diagonal=False, hessian_regularization=0.0, progress=False)
¶
Bases: TorchInfluenceFunctionModel
Approximately solves the linear system Hx = b, where H is the Hessian of a model with the empirical categorical cross entropy as loss function and b is the given right-hand side vector. It employs the EK-FAC method [@george2018fast], which is based on the kronecker factorization of the Hessian first introduced in [@martens2015optimizing]. Contrary to the other influence function methods, this implementation can only be used for classification tasks with a cross entropy loss function. However, it is much faster than the other methods and can be used efficiently for very large datasets and models. For more information, see [Eigenvalue Corrected K-FAC][ekfac].
PARAMETER | DESCRIPTION |
---|---|
model |
Instance of torch.nn.Module.
TYPE:
|
update_diagonal |
If True, the diagonal values in the ekfac representation are refitted from the training data after calculating the KFAC blocks. This provides a more accurate approximation of the Hessian, but it is computationally more expensive.
TYPE:
|
hessian_regularization |
Regularization of the hessian.
TYPE:
|
progress |
If True, display progress bars.
TYPE:
|
Source code in src/pydvl/influence/torch/influence_function_model.py
influence_factors(x, y)
¶
Compute approximation of
where the gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
x |
model input to use in the gradient computations
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise inverse Hessian matrix vector products |
Source code in src/pydvl/influence/torch/influence_function_model.py
influences(x_test, y_test, x=None, y=None, mode=InfluenceMode.Up)
¶
Compute the approximation of
for the case of up-weighting influence, resp.
for the perturbation type influence case.
PARAMETER | DESCRIPTION |
---|---|
x_test |
model input to use in the gradient computations of \(H^{-1}\nabla_{theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
y_test |
label tensor to compute gradients
TYPE:
|
x |
optional model input to use in the gradient computations \(\nabla_{theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{theta}\ell(y, f_{\theta}(x))\), if None, use \(x=x_{\text{test}}\) |
y |
optional label tensor to compute gradients |
mode |
enum value of [InfluenceType][pydvl.influence.base_influence_model.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/torch/influence_function_model.py
influences_from_factors(z_test_factors, x, y, mode=InfluenceMode.Up)
¶
Computation of
for the case of up-weighting influence, resp.
for the perturbation type influence case. The gradient is meant to be per sample of the batch \((x, y)\).
PARAMETER | DESCRIPTION |
---|---|
z_test_factors |
pre-computed tensor, approximating \(H^{-1}\nabla_{\theta} \ell(y_{\text{test}}, f_{\theta}(x_{\text{test}}))\)
TYPE:
|
x |
model input to use in the gradient computations \(\nabla_{\theta}\ell(y, f_{\theta}(x))\), resp. \(\nabla_{x}\nabla_{\theta}\ell(y, f_{\theta}(x))\)
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
mode |
enum value of [InfluenceType][pydvl.influence.twice_differentiable.InfluenceType]
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/torch/influence_function_model.py
fit(data)
¶
Compute the KFAC blocks for each layer of the model, using the provided data. It then creates an EkfacRepresentation object that stores the KFAC blocks for each layer, their eigenvalue decomposition and diagonal values.
Source code in src/pydvl/influence/torch/influence_function_model.py
influences_by_layer(x_test, y_test, x=None, y=None, mode=InfluenceMode.Up)
¶
Compute the influence of the data on the test data for each layer of the model.
Args:
x_test: model input to use in the gradient computations of
$H^{-1}
abla_{ heta} \ell(y_{ ext{test}}, f_{ heta}(x_{ ext{test}}))$ y_test: label tensor to compute gradients x: optional model input to use in the gradient computations $ abla_{ heta}\ell(y, f_{ heta}(x))$, resp. $ abla_{x} abla_{ heta}\ell(y, f_{ heta}(x))$, if None, use \(x=x_{ ext{test}}\) y: optional label tensor to compute gradients mode: enum value of [InfluenceType] [pydvl.influence.base_influence_model.InfluenceType]
Returns:
A dictionary containing the influence of the data on the test data for each
layer of the model, with the layer name as key.
Source code in src/pydvl/influence/torch/influence_function_model.py
influence_factors_by_layer(x, y)
¶
Computes the approximation of
\[H^{-1}
abla_{ heta} \ell(y, f_{ heta}(x))]
for each layer of the model separately.
Args:
x: model input to use in the gradient computations
y: label tensor to compute gradients
Returns:
A dictionary containing the influence factors for each layer of the model,
with the layer name as key.
Source code in src/pydvl/influence/torch/influence_function_model.py
influences_from_factors_by_layer(z_test_factors, x, y, mode=InfluenceMode.Up)
¶
Computation of
\[ \langle z_{ ext{test_factors}},
abla_{ heta} \ell(y, f_{ heta}(x)) angle ]
for the case of up-weighting influence, resp.
\[ \langle z_{ ext{test_factors}},
abla_{x} abla_{ heta} \ell(y, f_{ heta}(x)) angle ]
for the perturbation type influence case for each layer of the model separately.
The gradients are meant to be per sample of the batch $(x, y)$.
Args:
z_test_factors: pre-computed tensor, approximating
$H^{-1}
abla_{ heta} \ell(y_{ ext{test}}, f_{ heta}(x_{ ext{test}}))$ x: model input to use in the gradient computations $ abla_{ heta}\ell(y, f_{ heta}(x))$, resp. $ abla_{x} abla_{ heta}\ell(y, f_{ heta}(x))$ y: label tensor to compute gradients mode: enum value of [InfluenceType] [pydvl.influence.twice_differentiable.InfluenceType]
Returns:
A dictionary containing the influence of the data on the test data for each
layer of the model, with the layer name as key.
Source code in src/pydvl/influence/torch/influence_function_model.py
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 |
|
explore_hessian_regularization(x, y, regularization_values)
¶
Efficiently computes the influence for input x and label y for each layer of the model, for different values of the hessian regularization parameter. This is done by computing the gradient of the loss function for the input x and label y only once and then solving the Hessian Vector Product for each regularization value. This is useful for finding the optimal regularization value and for exploring how robust the influence values are to changes in the regularization value.
PARAMETER | DESCRIPTION |
---|---|
x |
model input to use in the gradient computations
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
regularization_values |
list of regularization values to use |
RETURNS | DESCRIPTION |
---|---|
Dict[float, Dict[str, Tensor]]
|
A dictionary containing with keys being the regularization values and values |
Dict[float, Dict[str, Tensor]]
|
being dictionaries containing the influences for each layer of the model, |
Dict[float, Dict[str, Tensor]]
|
with the layer name as key. |