1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
//! Streaming linear attention models.
//!
//! This module provides [`StreamingAttentionModel`], a streaming machine learning
//! model that uses multi-head linear attention as its temporal feature extractor,
//! feeding into a Recursive Least Squares (RLS) readout layer. It integrates
//! with irithyll's [`StreamingLearner`](crate::learner::StreamingLearner) trait
//! and [`StreamingPreprocessor`](crate::pipeline::StreamingPreprocessor) trait.
//!
//! # Architecture
//!
//! ```text
//! input features ──→ [MultiHeadAttention] ──→ temporal features ──→ [RLS] ──→ prediction
//! (d_model) (recurrent state) (d_model) (1)
//! ```
//!
//! The attention layer processes each feature vector as a timestep, maintaining
//! per-head recurrent state that captures temporal dependencies via linear
//! attention mechanisms (RetNet, Hawk, GLA, DeltaNet, GatedDeltaNet, RWKV, mLSTM,
//! DeltaProduct, RWKV7, HGRN2).
//! The RLS readout learns a linear mapping from the attention output to the target.
//!
//! # Components
//!
//! - [`StreamingAttentionModel`] -- full model implementing `StreamingLearner`
//! - [`AttentionPreprocessor`] -- attention-only preprocessor implementing `StreamingPreprocessor`
//! - [`StreamingAttentionConfig`] / [`StreamingAttentionConfigBuilder`] -- validated configuration
//!
//! # Example
//!
//! ```ignore
//! use irithyll::attention::{StreamingAttentionModel, StreamingAttentionConfig, AttentionMode};
//! use irithyll::learner::StreamingLearner;
//!
//! let config = StreamingAttentionConfig::builder()
//! .d_model(8)
//! .n_heads(2)
//! .mode(AttentionMode::GLA)
//! .build()
//! .unwrap();
//!
//! let mut model = StreamingAttentionModel::new(config);
//! model.train(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0], 5.0);
//! let pred = model.predict(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]);
//! assert!(pred.is_finite());
//! ```
pub use ;
pub use AttentionPreprocessor;
pub use StreamingAttentionModel;
// Re-export core types
pub use ;
// ---------------------------------------------------------------------------
// Factory functions
// ---------------------------------------------------------------------------
/// Create a Gated Linear Attention model (SOTA streaming attention).
///
/// GLA uses data-dependent gating for adaptive forgetting, providing strong
/// performance across a wide range of sequence modeling tasks.
///
/// ```ignore
/// use irithyll::attention::gla;
/// use irithyll::learner::StreamingLearner;
///
/// let mut model = gla(8, 2);
/// model.train(&[1.0; 8], 0.5);
/// ```
/// Create a Gated DeltaNet model (NVIDIA, strongest retrieval).
///
/// GatedDeltaNet combines delta rule updates with gating for the strongest
/// associative recall performance among linear attention variants.
///
/// ```ignore
/// use irithyll::attention::delta_net;
/// use irithyll::learner::StreamingLearner;
///
/// let mut model = delta_net(8, 2);
/// model.train(&[1.0; 8], 0.5);
/// ```
/// Create a DeltaProduct model (strongest tunable linear attention).
///
/// DeltaProduct applies `n_compositions` sequential delta rule steps per token,
/// with spectrally bounded Householder transitions. Higher `n_compositions`
/// increases expressivity at the cost of per-token compute.
///
/// ```ignore
/// use irithyll::attention::delta_product;
/// use irithyll::learner::StreamingLearner;
///
/// let mut model = delta_product(8, 2, 3);
/// model.train(&[1.0; 8], 0.5);
/// ```
/// Create an RWKV-7 model (vector-gated delta rule with DPLR transitions).
///
/// RWKV-7 uses per-dimension vector decay, vector in-context learning rate,
/// and decoupled removal/replacement keys for state-of-the-art in-context
/// learning performance.
///
/// ```ignore
/// use irithyll::attention::rwkv7;
/// use irithyll::learner::StreamingLearner;
///
/// let mut model = rwkv7(8, 2);
/// model.train(&[1.0; 8], 0.5);
/// ```
/// Create an HGRN2 model (lower-bounded gated linear RNN with state expansion).
///
/// HGRN2 uses per-dimension forget gates with a lower bound ensuring minimum
/// memory retention. The outer-product state update provides expressivity
/// comparable to GLA, while the lower bound prevents catastrophic forgetting.
///
/// ```ignore
/// use irithyll::attention::hgrn2;
/// use irithyll::learner::StreamingLearner;
///
/// let mut model = hgrn2(8, 2, 0.9);
/// model.train(&[1.0; 8], 0.5);
/// ```
/// Create a Hawk model (lightest, vector state).
///
/// Hawk uses a single-head vector state (no KV matrices), making it the
/// most memory-efficient linear attention variant. Best for resource-constrained
/// environments.
///
/// ```ignore
/// use irithyll::attention::hawk;
/// use irithyll::learner::StreamingLearner;
///
/// let mut model = hawk(8);
/// model.train(&[1.0; 8], 0.5);
/// ```
/// Create a RetNet model (simplest, fixed decay).
///
/// RetNet uses exponential decay with a fixed gamma parameter. Simplest
/// linear attention variant -- good baseline with predictable behavior.
///
/// ```ignore
/// use irithyll::attention::ret_net;
/// use irithyll::learner::StreamingLearner;
///
/// let mut model = ret_net(8, 0.99);
/// model.train(&[1.0; 8], 0.5);
/// ```
/// Create a generic streaming attention model with any mode.
///
/// For full control over all hyperparameters, use
/// [`StreamingAttentionConfig::builder()`] directly.
///
/// ```ignore
/// use irithyll::attention::{streaming_attention, AttentionMode};
/// use irithyll::learner::StreamingLearner;
///
/// let mut model = streaming_attention(8, AttentionMode::MLSTM);
/// model.train(&[1.0; 8], 0.5);
/// ```
/// Create a Log-Linear Attention model (Han Guo et al., ICLR 2026).
///
/// Wraps any inner linear-attention rule with an O(log T) hierarchical
/// Fenwick state. The headline novelty of irithyll v10: bridges
/// linear-attention efficiency and softmax expressivity. State memory
/// is `max_levels * d_k * d_v * n_heads` per layer, padded to a
/// constant shape regardless of stream length (paper §3.4 stability
/// choice).
///
/// # Arguments
///
/// - `d_model` — model dimension.
/// - `n_heads` — number of attention heads.
/// - `inner` — inner linear-attention mode wrapped per token. Must NOT
/// itself be `AttentionMode::LogLinear`. Recommended: `GatedDeltaNet`
/// for strongest associative recall, `GLA` for stability.
/// - `max_levels` — Fenwick depth cap; 32 covers streams up to ~4 G
/// tokens.
///
/// # Paper reference
///
/// Han Guo, Songlin Yang, Tarushii Goel, Eric P. Xing, Tri Dao, Yoon
/// Kim. *Log-Linear Attention*. ICLR 2026. arXiv:2506.04761.
///
/// ```ignore
/// use irithyll::attention::{log_linear, AttentionMode};
/// use irithyll::learner::StreamingLearner;
///
/// let mut model = log_linear(
/// 8,
/// 2,
/// AttentionMode::GatedDeltaNet {
/// beta_scale: 1.0,
/// gate_mode_delta: irithyll::attention::GatedDeltaMode::Static,
/// },
/// 32,
/// );
/// model.train(&[1.0; 8], 0.5);
/// ```