pulsatrix 1.1.0
Loading...
Searching...
No Matches
pulsatrix::ResidualIntervention Class Referenceabstract

A trainable edit of the residual stream after a transformer block (TRN-9: LoReFT), run by CausalLM::set_intervention(). Maps hidden states (N, L, hidden_size) to the same shape and, as a Module, trains and explains with the model. More...

#include <causal_lm.hpp>

Inheritance diagram for pulsatrix::ResidualIntervention:
Collaboration diagram for pulsatrix::ResidualIntervention:

Public Member Functions

virtual Tensor forward_at (const Tensor &hidden, int64_t start, int64_t prompt_length)=0
 The edit for hidden states covering positions [start, start + L) of a sequence whose prompt is prompt_length positions long. forward(x) is forward_at(x, 0, L). Cached generation calls it once on the prompt and then once per new token, each a later start.
 
- 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 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< NamedBufferRef > named_buffers ()
 This module's buffers: state a checkpoint must save that no optimizer updates.
 
virtual std::vector< NamedModuleRef > named_children ()
 This module's direct sub-modules, each under the prefix its parameters carry in named_parameters(), in the same order (TRN-7: how ApplyLora() finds a model's Linear layers). Default: none. NamedModules() walks the whole tree.
 
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.
 
virtual void release_activations ()
 Frees the tensors forward() kept for backward() and the relevance passes; containers release their children too. Inference that only needs the output calls it after each forward, so a deep model holds one layer's activations at a time (a 1024-token ESM-2 650M pass otherwise keeps over 10 GB of them).
 

Protected Member Functions

Tensor forward_impl (const Tensor &hidden) override
 The actual forward computation. Called by forward() after precondition checks.
 

Detailed Description

A trainable edit of the residual stream after a transformer block (TRN-9: LoReFT), run by CausalLM::set_intervention(). Maps hidden states (N, L, hidden_size) to the same shape and, as a Module, trains and explains with the model.

Member Function Documentation

◆ forward_at()

virtual Tensor pulsatrix::ResidualIntervention::forward_at ( const Tensor &  hidden,
int64_t  start,
int64_t  prompt_length 
)
pure virtual

The edit for hidden states covering positions [start, start + L) of a sequence whose prompt is prompt_length positions long. forward(x) is forward_at(x, 0, L). Cached generation calls it once on the prompt and then once per new token, each a later start.

Implemented in pulsatrix::HiddenStateTap, and pulsatrix::LoReFTIntervention.

◆ forward_impl()

Tensor pulsatrix::ResidualIntervention::forward_impl ( const Tensor &  input)
inlineoverrideprotectedvirtual

The actual forward computation. Called by forward() after precondition checks.

Implements pulsatrix::Module.


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