9#include <initializer_list>
124 void set_W_Q(std::initializer_list<float> values);
126 void set_W_K(std::initializer_list<float> values);
128 void set_W_V(std::initializer_list<float> values);
131 void set_W_Q(
const std::vector<float>& values);
133 void set_W_K(
const std::vector<float>& values);
135 void set_W_V(
const std::vector<float>& values);
138 [[nodiscard]]
const Tensor&
W_Q()
const {
return w_q_; }
140 [[nodiscard]]
const Tensor&
W_K()
const {
return w_k_; }
142 [[nodiscard]]
const Tensor&
W_V()
const {
return w_v_; }
153 [[nodiscard]]
float gamma()
const {
return gamma_; }
180 return {{
"w_q", {&w_q_, &w_q_grad_}}, {
"w_k", {&w_k_, &w_k_grad_}}, {
"w_v", {&w_v_, &w_v_grad_}}};
213 bool has_forwarded_ =
false;
Vendor-agnostic compute/memory backend. CPUBackend, CUDABackend (Phase 1.5), and HIPBackend (Phase 1....
Definition device_backend.hpp:219
virtual DeviceType device() const noexcept=0
Which device this backend's buffers reside on.
Base class for every layer type (LinearModule, Conv2DModule, activations, ...).
Definition module.hpp:58
Core RetNet retention block (Sun et al. 2023, arXiv:2307.08621), recurrent mode, input (N,...
Definition retnet_module.hpp:87
const Tensor & W_V_grad() const
Accumulated gradient w.r.t. W_V.
Definition retnet_module.hpp:149
RetNetModule(int64_t d_model, int64_t key_dim, float gamma, DeviceBackend *backend)
Constructs a retention layer with zero-initialized parameters.
Tensor forward_impl(const Tensor &input) override
The actual forward computation – per-timestep tied-weight retention recurrence.
Tensor backward(const Tensor &grad_output) override
Real backpropagation-through-time across the retention recurrence: accumulates all three parameter gr...
void set_W_V(std::initializer_list< float > values)
Overwrites the value projection weight (d_model, d_model) – test/initialization use only.
void set_W_Q(std::initializer_list< float > values)
Overwrites the query projection weight (d_model, key_dim) – test/initialization use only.
const Tensor & W_Q_grad() const
Accumulated gradient w.r.t. W_Q.
Definition retnet_module.hpp:145
float gamma() const
The fixed retention decay. A hyperparameter, not a parameter – it has no gradient and is absent from ...
Definition retnet_module.hpp:153
std::optional< DeviceType > compute_device() const override
Where this layer computes, so forward() rejects an input on another device (FND-8).
Definition retnet_module.hpp:185
void set_W_K(const std::vector< float > &values)
std::vector overload of set_W_K().
const Tensor & W_K_grad() const
Accumulated gradient w.r.t. W_K.
Definition retnet_module.hpp:147
void set_W_V(const std::vector< float > &values)
std::vector overload of set_W_V().
OpType op_type() const override
Recurrent per charter's closed OpType set – a compound accumulate-over-time operation,...
Definition retnet_module.hpp:121
std::vector< NamedParamRef > named_parameters() override
This module's trainable parameters, each with its hierarchical name – the one place a module declares...
Definition retnet_module.hpp:179
const Tensor & W_K() const
The key projection weight (d_model, key_dim).
Definition retnet_module.hpp:140
const Tensor & W_V() const
The value projection weight (d_model, d_model).
Definition retnet_module.hpp:142
void set_W_K(std::initializer_list< float > values)
Overwrites the key projection weight (d_model, key_dim) – test/initialization use only.
void set_W_Q(const std::vector< float > &values)
std::vector overload of set_W_Q() – for callers building values programmatically.
const Tensor & W_Q() const
The query projection weight (d_model, key_dim).
Definition retnet_module.hpp:138
Tensor propagate_relevance(const Tensor &relevance_out, const LRPRuleConfig &config) override
The original derived LRP rule (see the class-level note): unrolls the retention recurrence into Y = G...
N-dimensional tensor. Owns its data buffer exclusively; a DeviceBackend* is injected (not owned) – th...
Definition tensor.hpp:29
Abstract base every layer subclasses – NVI forward(), pure-virtual LRP contract.
Definition acquisition_functions.hpp:16
OpType
The op-type tag a Node carries. Charter Part 2 §3: nodes are tagged by a small closed set of op types...
Definition op_type.hpp:19
Configuration for LRP relevance propagation: which rule a module applies and its hyperparameters....
Definition lrp_rule_config.hpp:57