pydvl.influence.base_influence_function_model
¶
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
n_parameters
abstractmethod
property
¶
Number of trainable parameters of the underlying model
is_thread_safe
abstractmethod
property
¶
is_thread_safe: bool
Whether the influence computation is thread safe
is_fitted
abstractmethod
property
¶
Override this, to expose the fitting status of the instance.
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 = 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 = 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 |
Source code in src/pydvl/influence/base_influence_function_model.py
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.
n_parameters
abstractmethod
property
¶
Number of trainable parameters of the underlying model
is_thread_safe
abstractmethod
property
¶
is_thread_safe: bool
Whether the influence computation is thread safe
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
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
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 |
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 |