pulsatrix 1.1.0
Loading...
Searching...
No Matches
activation_module.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <optional>
9
10#include "pulsatrix/module.hpp"
11
12namespace pulsatrix {
13
19class ActivationModule : public Module {
20public:
26
28 [[nodiscard]] Tensor backward(const Tensor& grad_output) override;
30 [[nodiscard]] Tensor propagate_relevance(const Tensor& relevance_out, const LRPRuleConfig& config) override;
31 [[nodiscard]] bool supports_lrp_rule(LRPRule) const override { return true; }
32 [[nodiscard]] OpType op_type() const override { return OpType::Activation; }
33 [[nodiscard]] std::optional<DeviceType> compute_device() const override { return backend_->device(); }
34 [[nodiscard]] ElementwiseOp op() const { return op_; }
35
36 void release_activations() override;
37
38protected:
39 [[nodiscard]] Tensor forward_impl(const Tensor& input) override;
40
41private:
42 ElementwiseOp op_;
43 DeviceBackend* backend_;
44 Tensor last_input_;
45 bool has_forwarded_ = false;
46};
47
48} // namespace pulsatrix
y = f(x), elementwise, for one of the backend's activations. No parameters.
Definition activation_module.hpp:19
std::optional< DeviceType > compute_device() const override
The device this module computes on, so forward() can reject an input on another device before any ker...
Definition activation_module.hpp:33
void release_activations() override
Frees the tensors forward() kept for backward() and the relevance passes; containers release their ch...
ElementwiseOp op() const
Definition activation_module.hpp:34
Tensor forward_impl(const Tensor &input) override
The actual forward computation. Called by forward() after precondition checks.
OpType op_type() const override
This module's operation-category tag, for ComputationGraph node tagging.
Definition activation_module.hpp:32
bool supports_lrp_rule(LRPRule) const override
Whether propagate_relevance() implements rule (no silent fallback: callers such as ExplainerContext::...
Definition activation_module.hpp:31
ActivationModule(ElementwiseOp op, DeviceBackend *backend)
Tensor propagate_relevance(const Tensor &relevance_out, const LRPRuleConfig &config) override
relevance_out, unchanged.
Tensor backward(const Tensor &grad_output) override
grad_output times f'(x) at the cached input.
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:248
virtual DeviceType device() const noexcept=0
Which device this backend's buffers reside on.
Base class for every layer type (LinearModule, Conv2DModule, activations, ...).
Definition module.hpp:78
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
Abstract base every layer subclasses – NVI forward(), pure-virtual LRP contract.
Definition acquisition_functions.hpp:16
OpType
The op-type tag a Node carries. Charter Part 2 §3: nodes are tagged by a small closed set of op types...
Definition op_type.hpp:19
LRPRule
The LRP rule family a module applies. Semantics follow Zennit 1.0.0 exactly (Anders et al....
Definition lrp_rule_config.hpp:21
ElementwiseOp
Unary elementwise operations supported by DeviceBackend::elementwise().
Definition device_backend.hpp:43
Configuration for LRP relevance propagation: which rule a module applies and its hyperparameters....
Definition lrp_rule_config.hpp:72