pydvl.influence.torch.base
¶
TorchBatch
dataclass
¶
Bases: Batch
A convenience class for handling batches of data. Validates, the alignment of the first dimension (batch dimension) of the input and target tensor
ATTRIBUTE | DESCRIPTION |
---|---|
x |
The input tensor that contains features or data points.
TYPE:
|
y |
The target tensor that contains labels corresponding to the inputs.
TYPE:
|
TorchGradientProvider
¶
Bases: GradientProvider[TorchBatch, Tensor]
Compute per-sample gradients of a function defined by a torch.nn.Module and a loss function using torch.func.
Consider a function
e.g. a two layer neural network \(f\) with a loss function, then this object should compute the expressions:
Source code in src/pydvl/influence/torch/base.py
grads
¶
grads(batch: TorchBatch) -> Dict[str, Tensor]
Computes and returns a dictionary mapping parameter names to their respective per-sample gradients. Given the example in the class docstring, this means
where the first dimension of the resulting tensors is always considered to be the batch dimension, so the shape of the resulting tensors are \((N, d_i)\), where \(N\) is the number of samples in the batch.
PARAMETER | DESCRIPTION |
---|---|
batch |
The batch of data for which to compute gradients.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Tensor]
|
A dictionary where keys are gradient identifiers and values are the gradients computed per sample. |
Source code in src/pydvl/influence/torch/base.py
mixed_grads
¶
mixed_grads(batch: TorchBatch) -> Dict[str, Tensor]
Computes and returns a dictionary mapping gradient names to their respective per-sample mixed gradients. In this context, mixed gradients refer to computing gradients with respect to the instance definition in addition to compute derivatives with respect to the input batch. Given the example in the class docstring, this means
where the first dimension of the resulting tensors is always considered to be the batch dimension and the last to be the non-batch input related derivatives. So the shape of the resulting tensors are \((N, n, d_i)\), where \(N\) is the number of samples in the batch.
PARAMETER | DESCRIPTION |
---|---|
batch |
The batch of data for which to compute mixed gradients.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Tensor]
|
A dictionary where keys are gradient identifiers and values are the mixed gradients computed per sample. |
Source code in src/pydvl/influence/torch/base.py
jacobian_prod
¶
jacobian_prod(batch: TorchBatch, g: Tensor) -> Tensor
Computes the matrix-Jacobian product for the provided batch and input tensor. Given the example in the class docstring, this means
where g must be a tensor of shape \((K, d_1+d_2)\), so the resulting tensor is of shape \((N, K)\).
PARAMETER | DESCRIPTION |
---|---|
batch |
The batch of data for which to compute the Jacobian.
TYPE:
|
g |
The tensor to be used in the matrix-Jacobian product calculation.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
The resulting tensor from the matrix-Jacobian product computation. |
Source code in src/pydvl/influence/torch/base.py
OperatorBilinearForm
¶
Bases: BilinearForm[Tensor, TorchBatch, TorchGradientProvider]
Base class for bilinear forms based on an instance of [TorchOperator][pydvl.influence.torch.operator.base.TorchOperator]. This means it computes weighted inner products of the form:
Source code in src/pydvl/influence/torch/base.py
grads_inner_prod
¶
grads_inner_prod(
left: BatchType,
right: Optional[BatchType],
gradient_provider: GradientProviderType,
) -> TensorType
Computes the gradient inner product of two batches of data, i.e.
where \(\nabla_{\omega}\ell(\omega, \cdot, \cdot)\) is represented by the
gradient_provider
and the expression must be understood sample-wise.
PARAMETER | DESCRIPTION |
---|---|
left |
The first batch for gradient and inner product computation
TYPE:
|
right |
The second batch for gradient and inner product computation,
optional; if not provided, the inner product will use the gradient
computed for
TYPE:
|
gradient_provider |
The gradient provider to compute the gradients.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
TensorType
|
A tensor representing the inner products of the per-sample gradients |
Source code in src/pydvl/influence/types.py
mixed_grads_inner_prod
¶
mixed_grads_inner_prod(
left: BatchType,
right: Optional[BatchType],
gradient_provider: GradientProviderType,
) -> TensorType
Computes the mixed gradient inner product of two batches of data, i.e.
where \(\nabla_{\omega}\ell(\omega, \cdot)\) and
\(\nabla_{\omega}\nabla_{x}\ell(\omega, \cdot)\) are represented by the
gradient_provider
. The expression must be understood sample-wise.
PARAMETER | DESCRIPTION |
---|---|
left |
The first batch for gradient and inner product computation
TYPE:
|
right |
The second batch for gradient and inner product computation
TYPE:
|
gradient_provider |
The gradient provider to compute the gradients.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
TensorType
|
A tensor representing the inner products of the mixed per-sample gradients |
Source code in src/pydvl/influence/types.py
inner_prod
¶
Computes the weighted inner product of two vectors, i.e.
PARAMETER | DESCRIPTION |
---|---|
left |
The first tensor in the inner product computation.
TYPE:
|
right |
The second tensor, optional; if not provided, the inner product will
use |
RETURNS | DESCRIPTION |
---|---|
Tensor
|
A tensor representing the inner product. |
Source code in src/pydvl/influence/torch/base.py
DictBilinearForm
¶
Bases: OperatorBilinearForm
Base class for bilinear forms based on an instance of [TorchOperator][pydvl.influence.torch.operator.base.TorchOperator]. This means it computes weighted inner products of the form:
Source code in src/pydvl/influence/torch/base.py
inner_prod
¶
Computes the weighted inner product of two vectors, i.e.
PARAMETER | DESCRIPTION |
---|---|
left |
The first tensor in the inner product computation.
TYPE:
|
right |
The second tensor, optional; if not provided, the inner product will
use |
RETURNS | DESCRIPTION |
---|---|
Tensor
|
A tensor representing the inner product. |
Source code in src/pydvl/influence/torch/base.py
grads_inner_prod
¶
grads_inner_prod(
left: TorchBatch,
right: Optional[TorchBatch],
gradient_provider: TorchGradientProvider,
) -> Tensor
Computes the gradient inner product of two batches of data, i.e.
where \(\nabla_{\omega}\ell(\omega, \cdot, \cdot)\) is represented by the
gradient_provider
and the expression must be understood sample-wise.
PARAMETER | DESCRIPTION |
---|---|
left |
The first batch for gradient and inner product computation
TYPE:
|
right |
The second batch for gradient and inner product computation,
optional; if not provided, the inner product will use the gradient
computed for
TYPE:
|
gradient_provider |
The gradient provider to compute the gradients.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
A tensor representing the inner products of the per-sample gradients |
Source code in src/pydvl/influence/torch/base.py
mixed_grads_inner_prod
¶
mixed_grads_inner_prod(
left: TorchBatch,
right: Optional[TorchBatch],
gradient_provider: TorchGradientProvider,
) -> Tensor
Computes the mixed gradient inner product of two batches of data, i.e.
where \(\nabla_{\omega}\ell(\omega, \cdot)\) and
\(\nabla_{\omega}\nabla_{x}\ell(\omega, \cdot)\) are represented by the
gradient_provider
. The expression must be understood sample-wise.
PARAMETER | DESCRIPTION |
---|---|
left |
The first batch for gradient and inner product computation
TYPE:
|
right |
The second batch for gradient and inner product computation
TYPE:
|
gradient_provider |
The gradient provider to compute the gradients.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
A tensor representing the inner products of the mixed per-sample gradients |
Source code in src/pydvl/influence/torch/base.py
LowRankBilinearForm
¶
Bases: OperatorBilinearForm
Specialized bilinear form for operators of the type
It computes the expressions
in an efficient way using torch.autograd functionality.
Source code in src/pydvl/influence/torch/base.py
inner_prod
¶
Computes the weighted inner product of two vectors, i.e.
PARAMETER | DESCRIPTION |
---|---|
left |
The first tensor in the inner product computation.
TYPE:
|
right |
The second tensor, optional; if not provided, the inner product will
use |
RETURNS | DESCRIPTION |
---|---|
Tensor
|
A tensor representing the inner product. |
Source code in src/pydvl/influence/torch/base.py
mixed_grads_inner_prod
¶
mixed_grads_inner_prod(
left: BatchType,
right: Optional[BatchType],
gradient_provider: GradientProviderType,
) -> TensorType
Computes the mixed gradient inner product of two batches of data, i.e.
where \(\nabla_{\omega}\ell(\omega, \cdot)\) and
\(\nabla_{\omega}\nabla_{x}\ell(\omega, \cdot)\) are represented by the
gradient_provider
. The expression must be understood sample-wise.
PARAMETER | DESCRIPTION |
---|---|
left |
The first batch for gradient and inner product computation
TYPE:
|
right |
The second batch for gradient and inner product computation
TYPE:
|
gradient_provider |
The gradient provider to compute the gradients.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
TensorType
|
A tensor representing the inner products of the mixed per-sample gradients |
Source code in src/pydvl/influence/types.py
grads_inner_prod
¶
grads_inner_prod(
left: TorchBatch,
right: Optional[TorchBatch],
gradient_provider: TorchGradientProvider,
) -> Tensor
Computes the gradient inner product of two batches of data, i.e.
where \(\nabla_{\omega}\ell(\omega, \cdot, \cdot)\) is represented by the
gradient_provider
and the expression must be understood sample-wise.
PARAMETER | DESCRIPTION |
---|---|
left |
The first batch for gradient and inner product computation
TYPE:
|
right |
The second batch for gradient and inner product computation,
optional; if not provided, the inner product will use the gradient
computed for
TYPE:
|
gradient_provider |
The gradient provider to compute the gradients.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tensor
|
A tensor representing the inner products of the per-sample gradients |
Source code in src/pydvl/influence/torch/base.py
TensorOperator
¶
Bases: Operator[Tensor, OperatorBilinearForm]
, ABC
Abstract base class for operators that can be applied to instances of torch.Tensor.
input_size
abstractmethod
property
¶
input_size: int
Abstract property to get the needed size for inputs to the operator instance
RETURNS | DESCRIPTION |
---|---|
int
|
An integer representing the input size. |
apply
¶
Applies the operator to a tensor.
PARAMETER | DESCRIPTION |
---|---|
tensor |
A tensor, whose tailing dimension must conform to the operator's input size
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
TensorType
|
A tensor representing the result of the operator application. |
Source code in src/pydvl/influence/types.py
TensorDictOperator
¶
Bases: TensorOperator
, ABC
Abstract base class for operators that can be applied to instances of
torch.Tensor and compatible dictionaries mapping strings to tensors.
Input dictionaries must conform to the structure defined by the property
input_dict_structure
. Useful for operators involving autograd functionality
to avoid intermediate flattening and concatenating of gradient inputs.
input_size
abstractmethod
property
¶
input_size: int
Abstract property to get the needed size for inputs to the operator instance
RETURNS | DESCRIPTION |
---|---|
int
|
An integer representing the input size. |
input_dict_structure
abstractmethod
property
¶
Implement this to expose the expected structure of the input tensor dict, i.e. a dictionary of shapes (excluding the first batch dimension), in order to validate the input tensor dicts.
apply
¶
Applies the operator to a tensor.
PARAMETER | DESCRIPTION |
---|---|
tensor |
A tensor, whose tailing dimension must conform to the operator's input size
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
TensorType
|
A tensor representing the result of the operator application. |
Source code in src/pydvl/influence/types.py
apply_to_dict
¶
Applies the operator to a dictionary of tensors, compatible to the structure
defined by the property input_dict_structure
.
PARAMETER | DESCRIPTION |
---|---|
mat |
dictionary of tensors, whose keys and shapes match the property
|
RETURNS | DESCRIPTION |
---|---|
Dict[str, Tensor]
|
A dictionary of tensors after applying the operator |
Source code in src/pydvl/influence/torch/base.py
TorchOperatorGradientComposition
¶
TorchOperatorGradientComposition(
op: TorchOperatorType, gp: TorchGradientProvider
)
Bases: OperatorGradientComposition[Tensor, TorchBatch, TorchOperatorType, TorchGradientProvider]
Representing a composable block that integrates an [TorchOperator][pydvl.influence.torch.operator.base.TorchOperator] and a [TorchPerSampleGradientProvider][pydvl.influence.torch.operator.gradient_provider.TorchPerSampleGradientProvider]
This block is designed to be flexible, handling different computational modes via an abstract operator and gradient provider.
Source code in src/pydvl/influence/torch/base.py
interactions
¶
interactions(
left_batch: BatchType, right_batch: Optional[BatchType], mode: InfluenceMode
)
Computes the interaction between the gradients on two batches of data based on the specified mode weighted by the operator action, i.e.
for the case InfluenceMode.Up
and
for the case InfluenceMode.Perturbation
.
PARAMETER | DESCRIPTION |
---|---|
left_batch |
The left data batch for gradient computation.
TYPE:
|
right_batch |
The right data batch for gradient computation.
TYPE:
|
mode |
An instance of InfluenceMode determining the type of influence computation.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
The result of the influence computation as dictated by the mode. |
Source code in src/pydvl/influence/types.py
transformed_grads
¶
Computes the gradients of a data batch, transformed by the operator application , i.e. the expressions
PARAMETER | DESCRIPTION |
---|---|
batch |
The data batch for gradient computation.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
A tensor representing the application of the operator to the gradients. |
Source code in src/pydvl/influence/types.py
interactions_from_transformed_grads
¶
interactions_from_transformed_grads(
left_factors: TensorType, right_batch: BatchType, mode: InfluenceMode
)
Computes the interaction between the transformed gradients on two batches of data using pre-computed factors and a batch of data, based on the specified mode. This means
for the case InfluenceMode.Up
and
for the case InfluenceMode.Perturbation
.
PARAMETER | DESCRIPTION |
---|---|
left_factors |
Pre-computed tensor factors from a left batch.
TYPE:
|
right_batch |
The right data batch for influence computation.
TYPE:
|
mode |
An instance of InfluenceMode determining the type of influence computation.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
The result of the interaction computation using the provided factors and batch gradients. |
Source code in src/pydvl/influence/types.py
TorchBlockMapper
¶
TorchBlockMapper(
composable_block_dict: OrderedDict[str, TorchOperatorGradientComposition]
)
Bases: BlockMapper[Tensor, TorchBatch, TorchOperatorGradientComposition[TorchOperatorType]]
Class for mapping operations across multiple compositional blocks represented by instances of TorchOperatorGradientComposition.
This class takes a dictionary of compositional blocks and applies their methods to batches or tensors, and aggregates the results.
Source code in src/pydvl/influence/torch/base.py
transformed_grads
¶
transformed_grads(batch: BatchType) -> OrderedDict[str, TensorType]
Computes and returns the transformed gradients for a batch in dictionary with the keys defined by the block names.
PARAMETER | DESCRIPTION |
---|---|
batch |
The batch of data for which to compute transformed gradients.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
OrderedDict[str, TensorType]
|
An ordered dictionary of transformed gradients by block. |
Source code in src/pydvl/influence/types.py
interactions
¶
interactions(
left_batch: BatchType, right_batch: BatchType, mode: InfluenceMode
) -> OrderedDict[str, TensorType]
Computes interactions between two batches, aggregated by block, based on a specified mode.
PARAMETER | DESCRIPTION |
---|---|
left_batch |
The left batch for interaction computation.
TYPE:
|
right_batch |
The right batch for interaction computation.
TYPE:
|
mode |
The mode determining the type of interactions.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
OrderedDict[str, TensorType]
|
An ordered dictionary of gradient interactions by block. |
Source code in src/pydvl/influence/types.py
interactions_from_transformed_grads
¶
interactions_from_transformed_grads(
left_factors: OrderedDict[str, TensorType],
right_batch: BatchType,
mode: InfluenceMode,
) -> OrderedDict[str, TensorType]
Computes interactions from transformed gradients and a right batch, aggregated by block and based on a mode.
PARAMETER | DESCRIPTION |
---|---|
left_factors |
Pre-computed factors as a tensor or an ordered dictionary of
tensors by block. If the input is a tensor, it is split into blocks
according to the ordering in the
TYPE:
|
right_batch |
The right batch for interaction computation.
TYPE:
|
mode |
The mode determining the type of interactions.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
OrderedDict[str, TensorType]
|
An ordered dictionary of interactions from transformed gradients by block. |
Source code in src/pydvl/influence/types.py
generate_transformed_grads
¶
generate_transformed_grads(
batch: BatchType,
) -> Generator[TensorType, None, None]
Generator that yields transformed gradients for a given batch, processed by each block.
PARAMETER | DESCRIPTION |
---|---|
batch |
The batch of data for which to generate transformed gradients.
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
TensorType
|
Transformed gradients for each block. |
Source code in src/pydvl/influence/types.py
generate_interactions
¶
generate_interactions(
left_batch: BatchType, right_batch: Optional[BatchType], mode: InfluenceMode
) -> Generator[TensorType, None, None]
Generator that yields gradient interactions between two batches, processed by each block based on a mode.
PARAMETER | DESCRIPTION |
---|---|
left_batch |
The left batch for interaction computation.
TYPE:
|
right_batch |
The right batch for interaction computation.
TYPE:
|
mode |
The mode determining the type of interactions.
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
TensorType
|
Gradient interactions for each block.
TYPE::
|
Source code in src/pydvl/influence/types.py
generate_interactions_from_transformed_grads
¶
generate_interactions_from_transformed_grads(
left_factors: Union[TensorType, OrderedDict[str, TensorType]],
right_batch: BatchType,
mode: InfluenceMode,
) -> Generator[TensorType, None, None]
Generator that yields interactions computed from pre-computed factors and a right batch, processed by each block based on a mode.
PARAMETER | DESCRIPTION |
---|---|
left_factors |
Pre-computed factors as a tensor or an ordered dictionary of tensors by block.
TYPE:
|
right_batch |
The right batch for interaction computation.
TYPE:
|
mode |
The mode determining the type of interactions.
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
TensorType
|
Interactions for each block.
TYPE::
|
Source code in src/pydvl/influence/types.py
TorchComposableInfluence
¶
TorchComposableInfluence(
model: Module,
block_structure: Union[
BlockMode, OrderedDict[str, List[str]]
] = BlockMode.FULL,
regularization: Optional[Union[float, Dict[str, Optional[float]]]] = None,
)
Bases: ComposableInfluence[Tensor, TorchBatch, DataLoader, TorchBlockMapper[TorchOperatorType]]
, ModelInfoMixin
, ABC
Abstract base class, that allow for block-wise computation of influence quantities with the torch framework. Inherit from this base class for specific influence algorithms.
Source code in src/pydvl/influence/torch/base.py
is_thread_safe
abstractmethod
property
¶
is_thread_safe: bool
Whether the influence computation is thread safe
fit
¶
fit(data: DataLoaderType) -> InfluenceFunctionModel
Fitting to provided data, by internally creating a block mapper instance from it. Args: data: iterable of tensors
RETURNS | DESCRIPTION |
---|---|
InfluenceFunctionModel
|
Fitted instance |
Source code in src/pydvl/influence/base_influence_function_model.py
fit_required
staticmethod
¶
Decorator to enforce the fitted check
Source code in src/pydvl/influence/base_influence_function_model.py
influence_factors
¶
Computes the approximation of
where the gradient is meant to be per sample of the batch \((x, y)\). For all input tensors it is assumed, that the first dimension is the batch dimension.
PARAMETER | DESCRIPTION |
---|---|
x |
model input to use in the gradient computations
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
TensorType
|
Tensor representing the element-wise inverse Hessian matrix vector products |
Source code in src/pydvl/influence/base_influence_function_model.py
influences
¶
influences(
x_test: TensorType,
y_test: TensorType,
x: Optional[TensorType] = None,
y: Optional[TensorType] = None,
mode: InfluenceMode = InfluenceMode.Up,
) -> TensorType
Computes 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_{test}, f_{\theta}(x_{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_{test}\)
TYPE:
|
y |
optional label tensor to compute gradients
TYPE:
|
mode |
enum value of InfluenceMode
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
TensorType
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/base_influence_function_model.py
influences_from_factors
¶
influences_from_factors(
z_test_factors: TensorType,
x: TensorType,
y: TensorType,
mode: InfluenceMode = InfluenceMode.Up,
) -> TensorType
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 array, 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))\), if None, use \(x=x_{\text{test}}\)
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
mode |
enum value of InfluenceMode
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
TensorType
|
Tensor representing the element-wise scalar products for the provided batch |
Source code in src/pydvl/influence/base_influence_function_model.py
influences_by_block
¶
influences_by_block(
x_test: TensorType,
y_test: TensorType,
x: Optional[TensorType] = None,
y: Optional[TensorType] = None,
mode: InfluenceMode = InfluenceMode.Up,
) -> OrderedDict[str, TensorType]
Compute the block-wise influence values for the provided data, i.e. an 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 the approximation of \(H^{-1}\nabla_{theta} \ell(y_{test}, f_{\theta}(x_{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_{test}\)
TYPE:
|
y |
optional label tensor to compute gradients
TYPE:
|
mode |
enum value of InfluenceMode
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
OrderedDict[str, TensorType]
|
Ordered dictionary of tensors representing the element-wise scalar products |
OrderedDict[str, TensorType]
|
for the provided batch per block. |
Source code in src/pydvl/influence/base_influence_function_model.py
influence_factors_by_block
¶
influence_factors_by_block(
x: TensorType, y: TensorType
) -> OrderedDict[str, TensorType]
Compute the block-wise 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 |
---|---|
OrderedDict[str, TensorType]
|
Ordered dictionary of tensors representing the element-wise |
OrderedDict[str, TensorType]
|
approximate inverse Hessian matrix vector products per block. |
Source code in src/pydvl/influence/base_influence_function_model.py
influences_from_factors_by_block
¶
influences_from_factors_by_block(
z_test_factors: OrderedDict[str, TensorType],
x: TensorType,
y: TensorType,
mode: InfluenceMode = InfluenceMode.Up,
) -> OrderedDict[str, TensorType]
Block-wise 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 array, 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))\), if None, use \(x=x_{\text{test}}\)
TYPE:
|
y |
label tensor to compute gradients
TYPE:
|
mode |
enum value of InfluenceMode
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
OrderedDict[str, TensorType]
|
Ordered dictionary of tensors representing the element-wise scalar products |
OrderedDict[str, TensorType]
|
for the provided batch per block |