tdhook.attribution.lrp_helpers.rules#
LRP rules.
This code is adapted from the Zennit library (LGPL-3.0) and the LXT library (Clear BSD) Original sources: - chr5tphr/zennit - rachtibat/LRP-eXplains-Transformers
Classes#
Metaclass for defining Abstract Base Classes (ABCs). |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Base class for LRP rules implemented as custom autograd functions. |
|
Functions#
|
|
|
Module Contents#
- class tdhook.attribution.lrp_helpers.rules.ParamModifier(modify_fn=None, select_fn=None)[source]#
- Parameters:
modify_fn (Optional[Callable[[str, torch.nn.Parameter], torch.Tensor]])
select_fn (Optional[Callable[[str, torch.nn.Parameter], bool]])
- static from_modifiers(modifiers)[source]#
- Parameters:
modifiers (List[ParamModifier])
- class tdhook.attribution.lrp_helpers.rules.RemovableRuleHandle(rule, module)[source]#
- Parameters:
rule (Rule)
module (torch.nn.Module)
- class tdhook.attribution.lrp_helpers.rules.AbstractFunctionMeta(name, bases, attrs)[source]#
Bases:
abc.ABCMeta,torch.autograd.function.FunctionMetaMetaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed directly, and then acts as a mix-in class. You can also register unrelated concrete classes (even built-in classes) and unrelated ABCs as ‘virtual subclasses’ – these and their descendants will be considered subclasses of the registering ABC by the built-in issubclass() function, but the registering ABC won’t show up in their MRO (Method Resolution Order) nor will method implementations defined by the registering ABC be callable (not even via super()).
- class tdhook.attribution.lrp_helpers.rules.Rule[source]#
Bases:
torch.autograd.function.FunctionBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.EpsilonRule(epsilon=1e-06)[source]#
Bases:
RuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.UniformEpsilonRule(epsilon=1e-06)[source]#
Bases:
EpsilonRuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.PassRule[source]#
Bases:
RuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.IgnoreRule[source]#
Bases:
RuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.WSquareRule(stabilizer=1e-06)[source]#
Bases:
RuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.FlatRule(stabilizer=1e-06)[source]#
Bases:
WSquareRuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.UniformRule[source]#
Bases:
RuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.StopRule[source]#
Bases:
RuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.AlphaBetaRule(alpha=2.0, beta=1.0, stabilizer=1e-06)[source]#
Bases:
RuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.SoftmaxEpsilonRule(epsilon=1e-06)[source]#
Bases:
EpsilonRuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.LayerNormRule[source]#
Bases:
RuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.PseudoIdentityRule(stabilizer=1e-06)[source]#
Bases:
RuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.AHQKVRule[source]#
Bases:
RuleBase class for LRP rules implemented as custom autograd functions.
Subclasses override forward() and backward() to define how relevance is propagated through a wrapped module. Instances are registered onto modules by temporarily replacing module.forward with Function.apply(…).
- class tdhook.attribution.lrp_helpers.rules.BaseRuleMapper(stabilizer=1e-06, rule_mapper=None)[source]#
- Parameters:
rule_mapper (Optional[Callable[[str, torch.nn.Module], Rule | None]])
- class tdhook.attribution.lrp_helpers.rules.EpsilonPlus(epsilon=1e-06, stabilizer=1e-06, rule_mapper=None)[source]#
Bases:
BaseRuleMapper- Parameters:
rule_mapper (Optional[Callable[[str, torch.nn.Module], Rule | None]])