pydvl.influence.base_influence_function_model
¶
ComposableInfluence
¶
Bases: InfluenceFunctionModel
, Generic[TensorType, BatchType, DataLoaderType, BlockMapperType]
, ABC
Generic abstract base class, that allow for block-wise computation of influence quantities. Inherit from this base class for specific influence algorithms and tensor frameworks.
is_thread_safe
abstractmethod
property
¶
is_thread_safe: bool
Whether the influence computation is thread safe
n_parameters
abstractmethod
property
¶
Number of trainable parameters of the underlying model
_concat
abstractmethod
¶
_create_batch
abstractmethod
staticmethod
¶
Implement this method to provide the creation of a subtype of Batch for a specific framework
Source code in src/pydvl/influence/base_influence_function_model.py
_create_block_mapper
abstractmethod
¶
Override this method to create a block mapper instance, that can be used to compute block-wise influence quantities.
PARAMETER | DESCRIPTION |
---|---|
data
|
iterable of tensors
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
BlockMapperType
|
BlockMapper instance |
Source code in src/pydvl/influence/base_influence_function_model.py
_flatten_trailing_dim
abstractmethod
¶
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
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
¶
influences(
x_test: TensorType,
y_test: TensorType,
x: Optional[TensorType] = None,
y: Optional[TensorType] = None,
mode: 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_by_block
¶
influences_by_block(
x_test: TensorType,
y_test: TensorType,
x: Optional[TensorType] = None,
y: Optional[TensorType] = None,
mode: 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
influences_from_factors
¶
influences_from_factors(
z_test_factors: TensorType,
x: TensorType,
y: TensorType,
mode: 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_from_factors_by_block
¶
influences_from_factors_by_block(
z_test_factors: OrderedDict[str, TensorType],
x: TensorType,
y: TensorType,
mode: 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 |
Source code in src/pydvl/influence/base_influence_function_model.py
InfluenceFunctionModel
¶
Bases: Generic[TensorType, DataLoaderType]
, ABC
Generic abstract base class for computing influence related quantities. For a specific influence algorithm and tensor framework, inherit from this base class
is_fitted
abstractmethod
property
¶
Override this, to expose the fitting status of the instance.
is_thread_safe
abstractmethod
property
¶
is_thread_safe: bool
Whether the influence computation is thread safe
n_parameters
abstractmethod
property
¶
Number of trainable parameters of the underlying model
_influence_factors
abstractmethod
¶
Override this method to implement the 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 |
---|---|
TensorType
|
Tensor representing the element-wise inverse Hessian matrix vector products |
Source code in src/pydvl/influence/base_influence_function_model.py
_influences
abstractmethod
¶
_influences(
x_test: TensorType,
y_test: TensorType,
x: Optional[TensorType] = None,
y: Optional[TensorType] = None,
mode: InfluenceMode = Up,
) -> TensorType
Override this method to implement 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
fit
abstractmethod
¶
fit(data: DataLoaderType) -> InfluenceFunctionModel
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 |
---|---|
InfluenceFunctionModel
|
The 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 = 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
abstractmethod
¶
influences_from_factors(
z_test_factors: TensorType,
x: TensorType,
y: TensorType,
mode: InfluenceMode = Up,
) -> TensorType
Override this method to implement the 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 |