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>
|
| | 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).
|
| |
| 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.
|
| |
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).
◆ 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_h | Window height. Also the vertical stride (non-overlapping). |
| kernel_w | Window width. Also the horizontal stride (non-overlapping). |
| backend | Backend to allocate/compute through. Not owned; must outlive this module. |
| eps | Stabilizer added inside the LRP z-rule's denominator. Defaults to 1e-6, matching every other epsilon-rule module in this codebase. |
- Exceptions
-
| std::invalid_argument | if kernel_h <= 0 or kernel_w <= 0 – external boundary, per cpp_tdd/context_tdd_adversarial_boundary_testing.md. |
◆ 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_output | Gradient 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_error | if forward() has never been called. |
| std::invalid_argument | if 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 |
◆ forward_impl()
| Tensor pulsatrix::AvgPool2DModule::forward_impl |
( |
const Tensor & |
input | ) |
|
|
overrideprotectedvirtual |
The actual forward computation – per-window mean.
- Exceptions
-
| std::invalid_argument | if 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 |
◆ propagate_relevance()
Epsilon/z-rule LRP relevance propagation, weight = 1/K (Bach et al. 2015).
- Parameters
-
| relevance_out | Relevance at this module's output. Must match the shape of the most recent forward() call's output. |
| config | Selects epsilon. |
- Returns
- Relevance at this module's input, proportional to each input's own cached activation within its window.
- Exceptions
-
| std::logic_error | if forward() has never been called. |
| std::invalid_argument | if 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: