pulsatrix
Loading...
Searching...
No Matches
pulsatrix::SequentialModule Class Reference

Composes layers_[0..n-1] in forward() order; backward()/propagate_relevance() chain layers_[n-1..0] in reverse – correct reverse-mode composition order. More...

#include <sequential_module.hpp>

Inheritance diagram for pulsatrix::SequentialModule:
Collaboration diagram for pulsatrix::SequentialModule:

Public Member Functions

 SequentialModule (std::vector< Module * > layers)
 Constructs a container over an ordered sequence of layers.
 
Tensor backward (const Tensor &grad_output) override
 Chains backward() across layers_ in reverse order.
 
OpType op_type () const override
 Composite per charter's closed OpType set – a container wrapping several ops is genuinely not any single existing category.
 
Tensor propagate_relevance (const Tensor &relevance_out, const LRPRuleConfig &config) override
 Chains propagate_relevance() across layers_ in reverse order.
 
bool supports_lrp_rule (LRPRule rule) const override
 A rule is supported iff every contained layer supports it (the config is forwarded to all).
 
std::vector< NamedParamRef > named_parameters () override
 Every contained layer's named_parameters(), prefixed with its index (0.weight).
 
void set_training (bool training) override
 Sets this container's own training flag and cascades to every contained layer.
 
const std::vector< Module * > & layers () const
 The contained layers, in forward-execution order.
 
- Public Member Functions inherited from pulsatrix::Module
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 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).
 
bool is_training () const
 Whether this module is currently in training mode.
 

Protected Member Functions

Tensor forward_impl (const Tensor &input) override
 Chains forward() across layers_ in order.
 

Detailed Description

Composes layers_[0..n-1] in forward() order; backward()/propagate_relevance() chain layers_[n-1..0] in reverse – correct reverse-mode composition order.

Note
layers_ is not owned – "not owned; must outlive this object", the same convention as every DeviceBackend* member in this codebase. A caller constructing a SequentialModule keeps its constituent modules alive independently.
propagate_relevance needs no new LRP theory – pure delegation to each contained layer's own already-cited rule. Conservation holds end-to-end because composing conserving functions conserves; this is verified numerically by an LRPConservationTest TEST_P case, not just asserted in prose.
set_training() overrides the (now virtual, since this mission) base method: sets its own flag and cascades to every contained layer – correct even when accessed through a Module* base pointer, not just SequentialModule's own concrete type.

Constructor & Destructor Documentation

◆ SequentialModule()

pulsatrix::SequentialModule::SequentialModule ( std::vector< Module * >  layers)
explicit

Constructs a container over an ordered sequence of layers.

Parameters
layersLayers in forward-execution order. Not owned; must outlive this object.
Exceptions
std::invalid_argumentif layers is empty, or any entry is nullptr – both external boundaries (a caller-constructed vector, e.g. from Phase 5's Python bindings, could be empty or contain a null entry with no upstream validation).

Member Function Documentation

◆ backward()

Tensor pulsatrix::SequentialModule::backward ( const Tensor &  grad_output)
overridevirtual

Chains backward() across layers_ in reverse order.

Parameters
grad_outputGradient w.r.t. this container's output. Must match the shape of the most recent forward() call's output (validated by the last layer's own backward(), not by SequentialModule itself).
Returns
Gradient w.r.t. this container's input.
Exceptions
std::logic_errorif forward() has never been called.

Implements pulsatrix::Module.

◆ forward_impl()

Tensor pulsatrix::SequentialModule::forward_impl ( const Tensor &  input)
overrideprotectedvirtual

Chains forward() across layers_ in order.

Exceptions
Whateverthe first layer whose own forward() rejects input throws – SequentialModule adds no extra validation of its own beyond delegation.

Implements pulsatrix::Module.

◆ layers()

const std::vector< Module * > & pulsatrix::SequentialModule::layers ( ) const
inline

The contained layers, in forward-execution order.

◆ named_parameters()

std::vector< NamedParamRef > pulsatrix::SequentialModule::named_parameters ( )
overridevirtual

Every contained layer's named_parameters(), prefixed with its index (0.weight).

Reimplemented from pulsatrix::Module.

◆ op_type()

OpType pulsatrix::SequentialModule::op_type ( ) const
inlineoverridevirtual

Composite per charter's closed OpType set – a container wrapping several ops is genuinely not any single existing category.

Implements pulsatrix::Module.

◆ propagate_relevance()

Tensor pulsatrix::SequentialModule::propagate_relevance ( const Tensor &  relevance_out,
const LRPRuleConfig &  config 
)
overridevirtual

Chains propagate_relevance() across layers_ in reverse order.

Parameters
relevance_outRelevance at this container's output. Must match the shape of the most recent forward() call's output (validated by the last layer's own propagate_relevance(), not by SequentialModule itself).
configForwarded unchanged to every contained layer's own rule.
Returns
Relevance at this container's input.
Exceptions
std::logic_errorif forward() has never been called.

Implements pulsatrix::Module.

◆ set_training()

void pulsatrix::SequentialModule::set_training ( bool  training)
overridevirtual

Sets this container's own training flag and cascades to every contained layer.

Parameters
trainingNew training/eval mode.

Reimplemented from pulsatrix::Module.

◆ supports_lrp_rule()

bool pulsatrix::SequentialModule::supports_lrp_rule ( LRPRule  rule) const
inlineoverridevirtual

A rule is supported iff every contained layer supports it (the config is forwarded to all).

Reimplemented from pulsatrix::Module.


The documentation for this class was generated from the following file: