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

Average pooling, rank-4 (N, channels, H, W), matching Conv2DModule's convention. Stride fixed equal to kernel size (non-overlapping windows), no padding, no dilation – same minimal-cut discipline as MaxPool2DModule/Conv2DModule. More...

#include <avg_pool2d_module.hpp>

Inheritance diagram for pulsatrix::AvgPool2DModule:
Collaboration diagram for pulsatrix::AvgPool2DModule:

Public Member Functions

 AvgPool2DModule (int64_t kernel_h, int64_t kernel_w, DeviceBackend *backend, float eps=1e-6f)
 Constructs an average-pool layer.
 
Tensor backward (const Tensor &grad_output) override
 Computes the gradient w.r.t. this module's input – uniform 1/K per input position in each window (the true derivative of a mean, independent of activation value).
 
OpType op_type () const override
 Pooling per charter's closed OpType set.
 
Tensor propagate_relevance (const Tensor &relevance_out, const LRPRuleConfig &config) override
 Epsilon/z-rule LRP relevance propagation, weight = 1/K (Bach et al. 2015).
 
std::optional< DeviceType > compute_device () const override
 Where this layer computes, so forward() rejects an input on another device (FND-8).
 
- Public Member Functions inherited from pulsatrix::Module
virtual ~Module ()=default
 
Tensor forward (const Tensor &input)
 Runs this module's forward computation.
 
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 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 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.
 

Protected Member Functions

Tensor forward_impl (const Tensor &input) override
 The actual forward computation – per-window mean.
 

Detailed Description

Average pooling, rank-4 (N, channels, H, W), matching Conv2DModule's convention. Stride fixed equal to kernel size (non-overlapping windows), no padding, no dilation – same minimal-cut discipline as MaxPool2DModule/Conv2DModule.

Note
propagate_relevance is the epsilon/z-rule (Bach et al. 2015's generalized-linear- layer treatment of pooling, the same family LinearModule/Conv2DModule already use): average pooling is y = (1/K) * sum(x_i), i.e. a Linear layer with K uniform 1/K weights and no bias. z = sum(x_i/K) + eps*sign(z), R_i = (x_i * (1/K) / z) * R_out – proportional to each input's own activation, not a uniform 1/K split (that would be the gradient distribution, a weaker rule deliberately not used here). backward() is the real, undetached training gradient (uniform 1/K per input, independent of activation value – the correct derivative of a mean).

Constructor & Destructor Documentation

◆ AvgPool2DModule()

pulsatrix::AvgPool2DModule::AvgPool2DModule ( int64_t  kernel_h,
int64_t  kernel_w,
DeviceBackend *  backend,
float  eps = 1e-6f 
)

Constructs an average-pool layer.

Parameters
kernel_hWindow height. Also the vertical stride (non-overlapping).
kernel_wWindow width. Also the horizontal stride (non-overlapping).
backendBackend to allocate/compute through. Not owned; must outlive this module.
epsStabilizer added inside the LRP z-rule's denominator. Defaults to 1e-6, matching every other epsilon-rule module in this codebase.
Exceptions
std::invalid_argumentif kernel_h <= 0 or kernel_w <= 0 – external boundary, per cpp_tdd/context_tdd_adversarial_boundary_testing.md.

Member Function Documentation

◆ backward()

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

Computes the gradient w.r.t. this module's input – uniform 1/K per input position in each window (the true derivative of a mean, independent of activation value).

Parameters
grad_outputGradient w.r.t. this module's output. Must match the shape of the most recent forward() call's output.
Returns
Gradient w.r.t. this module's input.
Exceptions
std::logic_errorif forward() has never been called.
std::invalid_argumentif grad_output's shape doesn't match the cached forward output shape.
Note
Device-generic: runs on Cpu, Cuda or Hip tensors (GPU-native-kernels Mission 4).

Implements pulsatrix::Module.

◆ compute_device()

std::optional< DeviceType > pulsatrix::AvgPool2DModule::compute_device ( ) const
inlineoverridevirtual

Where this layer computes, so forward() rejects an input on another device (FND-8).

Reimplemented from pulsatrix::Module.

◆ forward_impl()

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

The actual forward computation – per-window mean.

Exceptions
std::invalid_argumentif input isn't rank-4 (N, C, H, W), or the kernel is larger than the input (kernel_h > H or kernel_w > W).
Note
Device-generic: runs on Cpu, Cuda or Hip tensors (GPU-native-kernels Mission 4).

Implements pulsatrix::Module.

◆ op_type()

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

Pooling per charter's closed OpType set.

Implements pulsatrix::Module.

◆ propagate_relevance()

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

Epsilon/z-rule LRP relevance propagation, weight = 1/K (Bach et al. 2015).

Parameters
relevance_outRelevance at this module's output. Must match the shape of the most recent forward() call's output.
configSelects epsilon.
Returns
Relevance at this module's input, proportional to each input's own cached activation within its window.
Exceptions
std::logic_errorif forward() has never been called.
std::invalid_argumentif relevance_out's shape doesn't match the cached forward output shape.

Implements pulsatrix::Module.


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