Pools a rank-4 (N, C, H, W) input to (N, C, out_h, out_w), as AdaptiveAvgPool2d((out_h,
out_w)): ResNet's global pooling is (1, 1), VGG's is (7, 7).
More...
#include <adaptive_avg_pool2d_module.hpp>
|
| | AdaptiveAvgPool2DModule (int64_t out_h, int64_t out_w, DeviceBackend *backend, float eps=1e-6f) |
| |
| Tensor | backward (const Tensor &grad_output) override |
| | 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.
|
| |
| Tensor | propagate_relevance (const Tensor &relevance_out, const LRPRuleConfig &config) override |
| | AvgPool2DModule's z-rule over each window.
|
| |
| OpType | op_type () const override |
| | This module's operation-category tag, for ComputationGraph node tagging.
|
| |
| std::optional< DeviceType > | compute_device () const override |
| | The device this module computes on, so forward() can reject an input on another device before any kernel sees it (roadmap FND-8).
|
| |
| int64_t | out_h () const |
| |
| int64_t | out_w () const |
| |
| 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< 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).
|
| |
Pools a rank-4 (N, C, H, W) input to (N, C, out_h, out_w), as AdaptiveAvgPool2d((out_h,
out_w)): ResNet's global pooling is (1, 1), VGG's is (7, 7).
- Note
- Only sizes that divide evenly are supported (H divisible by out_h, W by out_w): the windows are then the non-overlapping
(H / out_h, W / out_w) of AvgPool2DModule, with its backward and its LRP z-rule. PyTorch's uneven windows (overlapping, of different sizes) are refused rather than approximated.
◆ AdaptiveAvgPool2DModule()
| pulsatrix::AdaptiveAvgPool2DModule::AdaptiveAvgPool2DModule |
( |
int64_t |
out_h, |
|
|
int64_t |
out_w, |
|
|
DeviceBackend * |
backend, |
|
|
float |
eps = 1e-6f |
|
) |
| |
- Exceptions
-
| std::invalid_argument | if out_h or out_w < 1. |
◆ backward()
| Tensor pulsatrix::AdaptiveAvgPool2DModule::backward |
( |
const Tensor & |
grad_output | ) |
|
|
overridevirtual |
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.
Implements pulsatrix::Module.
◆ compute_device()
| std::optional< DeviceType > pulsatrix::AdaptiveAvgPool2DModule::compute_device |
( |
| ) |
const |
|
inlineoverridevirtual |
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 from pulsatrix::Module.
◆ forward_impl()
| Tensor pulsatrix::AdaptiveAvgPool2DModule::forward_impl |
( |
const Tensor & |
input | ) |
|
|
overrideprotectedvirtual |
- Exceptions
-
| std::invalid_argument | unless the input is rank 4 with H and W divisible by the output size. |
Implements pulsatrix::Module.
◆ op_type()
| OpType pulsatrix::AdaptiveAvgPool2DModule::op_type |
( |
| ) |
const |
|
inlineoverridevirtual |
This module's operation-category tag, for ComputationGraph node tagging.
- Returns
- This module's OpType (see op_type.hpp's closed set).
- Note
- Added in Phase 2 Mission 0 alongside backward() – lets graph-wiring code tag nodes generically through a Module* rather than switching on concrete subclass.
Implements pulsatrix::Module.
◆ out_h()
| int64_t pulsatrix::AdaptiveAvgPool2DModule::out_h |
( |
| ) |
const |
|
inline |
◆ out_w()
| int64_t pulsatrix::AdaptiveAvgPool2DModule::out_w |
( |
| ) |
const |
|
inline |
◆ propagate_relevance()
| Tensor pulsatrix::AdaptiveAvgPool2DModule::propagate_relevance |
( |
const Tensor & |
relevance_out, |
|
|
const LRPRuleConfig & |
config |
|
) |
| |
|
overridevirtual |
The documentation for this class was generated from the following file: