pulsatrix
Loading...
Searching...
No Matches
softmax_module.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <optional>
9
10namespace pulsatrix {
11
20class SoftmaxModule : public Module {
21public:
28 explicit SoftmaxModule(DeviceBackend* backend);
29
40 [[nodiscard]] Tensor backward(const Tensor& grad_output) override;
41
43 [[nodiscard]] OpType op_type() const override { return OpType::Activation; }
44
70 [[nodiscard]] Tensor propagate_relevance(const Tensor& relevance_out, const LRPRuleConfig& config) override;
71
72
74 [[nodiscard]] std::optional<DeviceType> compute_device() const override { return backend_->device(); }
75
76protected:
83 [[nodiscard]] Tensor forward_impl(const Tensor& input) override;
84
85private:
86 DeviceBackend* backend_;
87 Tensor last_input_;
88 Tensor last_output_;
89};
90
91} // namespace pulsatrix
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:219
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:58
Softmax over the tensor's last dimension, applied independently to every "row" (every fixed combinati...
Definition softmax_module.hpp:20
SoftmaxModule(DeviceBackend *backend)
Constructs a softmax module.
OpType op_type() const override
Activation per charter's closed OpType set (same category as ReluModule).
Definition softmax_module.hpp:43
Tensor forward_impl(const Tensor &input) override
Numerically stable softmax over the last axis, per row (subtract the row max before exponentiating – ...
std::optional< DeviceType > compute_device() const override
Where this layer computes, so forward() rejects an input on another device (FND-8).
Definition softmax_module.hpp:74
Tensor propagate_relevance(const Tensor &relevance_out, const LRPRuleConfig &config) override
AttnLRP's softmax relevance rule (Achtibat et al. 2024, Eq. 13 – Deep Taylor Decomposition),...
Tensor backward(const Tensor &grad_output) override
Computes the gradient w.r.t. this module's input.
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
Configuration for LRP relevance propagation: which rule a module applies and its hyperparameters....
Definition lrp_rule_config.hpp:57