|
| virtual | ~Module ()=default |
| |
| Tensor | forward (const Tensor &input) |
| | Runs this module's forward computation.
|
| |
| virtual std::optional< DeviceType > | compute_device () const |
| | The device this module computes on, so forward() can reject an input on another device before any kernel sees it (roadmap FND-8).
|
| |
| std::pair< Tensor, NodeId > | forward_traced (const Tensor &input, NodeId input_node, ComputationGraph &graph, Autograd &autograd) |
| | Runs forward() while also registering a ComputationGraph node (tagged with this module's op_type(), parented to input_node) and wiring an Autograd backward function that reuses this module's own backward() – the opt-in traced/explainable path, per Phase 2 Mission 0.
|
| |
| virtual Tensor | propagate_relevance (const Tensor &relevance_out, const LRPRuleConfig &config)=0 |
| | Computes this module's contribution to LRP relevance propagation.
|
| |
| virtual bool | supports_lrp_rule (LRPRule rule) const |
| | Whether propagate_relevance() implements rule (no silent fallback: callers such as ExplainerContext::relevance_pass() throw rather than run a module on a rule it does not implement).
|
| |
| virtual Tensor | backward (const Tensor &grad_output)=0 |
| | Computes the gradient w.r.t. this module's input, given the gradient w.r.t. its output. Must be called after forward() – uses state cached from that call.
|
| |
| virtual OpType | op_type () const =0 |
| | This module's operation-category tag, for ComputationGraph node tagging.
|
| |
| virtual std::vector< NamedParamRef > | named_parameters () |
| | This module's trainable parameters, each with its hierarchical name – the one place a module declares its parameters (roadmap FND-1).
|
| |
| virtual std::vector< ParamRef > | parameters () |
| | This module's trainable parameters and their gradients, for an optimizer to update uniformly across module types.
|
| |
| void | set_requires_grad (bool requires_grad, const std::string &prefix="") |
| | Freezes (false) or unfreezes (true) parameters by name (roadmap FND-2).
|
| |
| virtual void | set_training (bool training) |
| | Sets this module's training/eval mode. Defaults to training (matches every mainstream framework's Module default).
|
| |
| bool | is_training () const |
| | Whether this module is currently in training mode.
|
| |
Base class for every layer type (LinearModule, Conv2DModule, activations, ...).
- Note
forward()/forward_impl() is the NVI (non-virtual interface) idiom (oop_design/context_oop_design_patterns.md's Template Method section): the public entry point enforces preconditions every subclass gets for free; subclasses only implement the part that actually varies.
-
propagate_relevance is pure-virtual – charter non-negotiable #5. A module type without a defined LRP rule is a compile error, not a runtime "no default rule" exception (the Captum/Zennit failure mode this project exists to avoid).
-
A module does not build or own graph structure itself – ComputationGraph node registration and Autograd backward-function wiring are done generically by whichever caller opts into the traced path (Phase 2 Mission 0's Module::forward_traced), using backward()/op_type() below polymorphically. A module exposes plain tensor-in/tensor-out operations plus these two facts about itself; graph bookkeeping stays a separate concern (single responsibility).
| virtual Tensor pulsatrix::Module::backward |
( |
const Tensor & |
grad_output | ) |
|
|
pure virtual |
Computes the gradient w.r.t. this module's input, given the gradient w.r.t. its output. Must be called after forward() – uses state cached from that call.
- Parameters
-
| grad_output | Gradient w.r.t. this module's output. |
- Returns
- Gradient w.r.t. this module's input.
- Note
- Promoted to the base class in Phase 2 Mission 0 – every existing subclass (LinearModule/ReluModule/Conv2DModule) already implemented this exact signature independently; making it virtual lets graph-wiring code (Module::forward_traced) call it polymorphically through a Module* without knowing the concrete subclass, the same way propagate_relevance already works.
Implemented in pulsatrix::AggregatorModule, pulsatrix::AvgPool2DModule, pulsatrix::BatchNormModule, pulsatrix::ConjunctionModule, pulsatrix::Conv2DModule, pulsatrix::DisjunctionModule, pulsatrix::DropoutModule, pulsatrix::EmbeddingModule, pulsatrix::FlattenModule, pulsatrix::GroupNormModule, pulsatrix::GRUModule, pulsatrix::LayerNormModule, pulsatrix::LinearModule, pulsatrix::LSTMModule, pulsatrix::MambaModule, pulsatrix::MaxPool2DModule, pulsatrix::MultiHeadAttentionModule, pulsatrix::NegationModule, pulsatrix::ReluModule, pulsatrix::ResidualModule, pulsatrix::RetNetModule, pulsatrix::RMSNormModule, pulsatrix::RNNModule, pulsatrix::RoPEModule, pulsatrix::RWKVModule, pulsatrix::SequentialModule, pulsatrix::SoftmaxModule, pulsatrix::SwiGLUModule, and pulsatrix::TransformerBlock.
| virtual std::optional< DeviceType > pulsatrix::Module::compute_device |
( |
| ) |
const |
|
inlinevirtual |
The device this module computes on, so forward() can reject an input on another device before any kernel sees it (roadmap FND-8).
- Returns
- std::nullopt (the default) skips the check: a container whose layers check their own inputs, or a user module written before this existed. Every in-tree layer returns its device; EmbeddingModule doesn't, because it reads its indices through their own backend and so accepts them from any device.
Reimplemented in pulsatrix::AggregatorModule, pulsatrix::AvgPool2DModule, pulsatrix::BatchNormModule, pulsatrix::ConjunctionModule, pulsatrix::Conv2DModule, pulsatrix::DisjunctionModule, pulsatrix::DropoutModule, pulsatrix::FlattenModule, pulsatrix::GroupNormModule, pulsatrix::GRUModule, pulsatrix::LayerNormModule, pulsatrix::LinearModule, pulsatrix::LSTMModule, pulsatrix::MambaModule, pulsatrix::MaxPool2DModule, pulsatrix::MultiHeadAttentionModule, pulsatrix::NegationModule, pulsatrix::ReluModule, pulsatrix::ResidualModule, pulsatrix::RetNetModule, pulsatrix::RMSNormModule, pulsatrix::RNNModule, pulsatrix::RoPEModule, pulsatrix::RWKVModule, pulsatrix::SoftmaxModule, pulsatrix::SwiGLUModule, and pulsatrix::TransformerBlock.
| virtual std::vector< NamedParamRef > pulsatrix::Module::named_parameters |
( |
| ) |
|
|
inlinevirtual |
This module's trainable parameters, each with its hierarchical name – the one place a module declares its parameters (roadmap FND-1).
- Returns
- {name, {value, grad}} entries pointing directly at this module's own members, in a fixed order. Names are unique within the module tree. Default: empty (a parameterless module like ReluModule needs no override).
- Note
- Override this, not parameters(): saving, loading, freezing by name and optimizer parameter groups all key on these names.
Reimplemented in pulsatrix::BatchNormModule, pulsatrix::Conv2DModule, pulsatrix::EmbeddingModule, pulsatrix::GroupNormModule, pulsatrix::GRUModule, pulsatrix::LayerNormModule, pulsatrix::LinearModule, pulsatrix::LSTMModule, pulsatrix::MambaModule, pulsatrix::MultiHeadAttentionModule, pulsatrix::ResidualModule, pulsatrix::RetNetModule, pulsatrix::RMSNormModule, pulsatrix::RNNModule, pulsatrix::RWKVModule, pulsatrix::SequentialModule, pulsatrix::SwiGLUModule, and pulsatrix::TransformerBlock.