Whole-model LRP: runs the forward pass, seeds relevance at the chosen output(s), and propagates it to the input through every module's own propagate_relevance() rule.
More...
#include <lrp.hpp>
|
| | LRP (LRPRuleConfig config=LRPRuleConfig{}) |
| | Uniform rule: every module applies config.
|
| |
| | LRP (LRPComposite composite, std::string name="custom") |
| | Per-layer rules from a composite; name is reported as "composite:<name>".
|
| |
| Attribution | explain (ExplainerContext &ctx, const Tensor &input, int64_t target_index, DeviceBackend *backend) const |
| | Explains target_index for every row, OutputValue seed.
|
| |
| Attribution | explain (ExplainerContext &ctx, const Tensor &input, const LRPTarget &target, DeviceBackend *backend) const |
| | Explains the given target(s) / contrast(s).
|
| |
| Tensor | seed_relevance (ExplainerContext &ctx, const Tensor &input, const LRPTarget &target, DeviceBackend *backend, float *relevance_out_sum=nullptr) const |
| | The first half of explain(): runs the forward pass and builds the relevance it seeds at the output, shape (N, num_classes). With rule_configs(), this lets a caller run the relevance pass itself, for example in pieces (ExplainerContext::relevance_pass_through).
|
| |
| std::vector< LRPRuleConfig > | rule_configs (const ExplainerContext &ctx) const |
| | The rule each of ctx's modules applies, in forward order, as explain() uses them.
|
| |
| const LRPRuleConfig & | config () const |
| | The uniform config (default-constructed when this LRP uses a composite).
|
| |
| const LRPComposite & | composite () const |
| | The composite, or an empty function for a uniform-rule LRP.
|
| |
Whole-model LRP: runs the forward pass, seeds relevance at the chosen output(s), and propagates it to the input through every module's own propagate_relevance() rule.
- Note
- The per-layer rules are the ones each Module implements (see each module's propagate_relevance() doc); either one
config is passed to all of them, or an LRPComposite chooses one per module. A module asked for a rule it does not implement throws (ExplainerContext::relevance_pass) – there is no silent fallback to epsilon. With LRPRuleConfig::epsilon_bias_in_denominator set, bias terms absorb relevance, and the AttnLRP softmax / attention rules do not conserve exactly, so sum(values) matches the seeded total only for conservative stacks. The Attribution's metadata reports both sums.
-
Device-generic: the seed is assembled on the host (one device->host copy of the network output when seeding with output values) and uploaded through
backend, which must be the backend the network's output lives on.
◆ LRP() [1/2]
Uniform rule: every module applies config.
◆ LRP() [2/2]
| pulsatrix::LRP::LRP |
( |
LRPComposite |
composite, |
|
|
std::string |
name = "custom" |
|
) |
| |
|
inlineexplicit |
Per-layer rules from a composite; name is reported as "composite:<name>".
- Exceptions
-
| std::invalid_argument | if composite is empty. |
◆ capabilities()
◆ composite()
The composite, or an empty function for a uniform-rule LRP.
◆ config()
The uniform config (default-constructed when this LRP uses a composite).
◆ epsilon_alpha2_beta1()
| static LRP pulsatrix::LRP::epsilon_alpha2_beta1 |
( |
float |
epsilon = 1e-6f | ) |
|
|
inlinestatic |
◆ epsilon_gamma_box()
| static LRP pulsatrix::LRP::epsilon_gamma_box |
( |
float |
low, |
|
|
float |
high, |
|
|
float |
gamma = 0.25f, |
|
|
float |
epsilon = 1e-6f |
|
) |
| |
|
inlinestatic |
◆ epsilon_plus()
| static LRP pulsatrix::LRP::epsilon_plus |
( |
float |
epsilon = 1e-6f | ) |
|
|
inlinestatic |
◆ explain() [1/2]
Explains the given target(s) / contrast(s).
- Returns
- Attribution{"lrp", relevance (input's shape), metadata}: rule (the uniform rule's name, or "composite:<name>"), rules (each module's rule, comma-separated, forward order), epsilon (the uniform config's), seed, targets, contrasts, relevance_out_sum, relevance_in_sum.
- Exceptions
-
| std::invalid_argument | if the network output isn't rank-2, a target/contrast list has neither 1 nor N entries, an index is out of range, or a row's contrast equals its target (that seed is all zeros and explains nothing), a module does not implement its rule, or a rule's parameters are invalid. |
| std::logic_error | if the context's last forward pass was patched (relevance_pass()). |
◆ explain() [2/2]
Explains target_index for every row, OutputValue seed.
◆ rule_configs()
The rule each of ctx's modules applies, in forward order, as explain() uses them.
◆ seed_relevance()
The first half of explain(): runs the forward pass and builds the relevance it seeds at the output, shape (N, num_classes). With rule_configs(), this lets a caller run the relevance pass itself, for example in pieces (ExplainerContext::relevance_pass_through).
- Parameters
-
| relevance_out_sum | If not null, set to the seed's total. |
- Exceptions
-
| std::invalid_argument | as explain() does for the output and the target. |
The documentation for this class was generated from the following file: