The Loci-S4D Architecture
A state-space language model designed to handle extreme sequence lengths with constant state memory $\mathcal{O}(1)$ during inference and linear computational scaling $\mathcal{O}(N)$ during training.
Continuous State-Space Base (HiPPO & S4D)
At its core, LociS4DLm models continuous dynamics over sequential input streams using dynamic continuous linear recurrences. Standard SSMs project sequence history into a continuous latent space state vector $h_t$.
HiPPO Matrix Initialization
System dynamics are initialized using continuous High-order Polynomial Projection Operators (HiPPO), structuring continuous time memories to optimally approximate historical context over sliding time windows.
Complex Frequency Discretization
The continuous transition matrix $A_{\text{sys}}$ is parameterized in complex frequency space and discretized via step-size $\delta$ with learnable decay rates $\alpha$ and natural frequencies $\omega$:
The Multi-Center "Loci" Mechanism
Standard SSMs suffer from uniform exponential decay, which causes older context to gradually blur into a single homogenized vector. Loci-S4D solves information blur by establishing localized memory focus windows ("loci") across the total sequence horizon ($L_{\text{max}}$).
1. Halton Sequence Base-2
The architecture computes quasi-random, maximally spaced center positions $\tau_k \in [0, L_{\text{max}}]$ across the sequence horizon using a low-discrepancy Halton sequence base-2 distribution.
2. Cumulative Contribution Indexing
Rather than relying strictly on unweighted token counts, a specialized gating network continuously tracks cumulative sequence mass ($\sum \text{gate}_t$) as tokens flow through the layer.
3. Gaussian Focus Windows
Transition weights are dynamically modulated based on the proximity of the cumulative contribution index to the Halton centers $\tau_k$ using a Gaussian window parameter $\sigma$:
This dual mechanism allows Loci-S4D to retain distinct, high-fidelity memory "loci" at varying historical distances, enabling targeted retrieval across long context spans without uniform exponential blurring.
Layer & Block Architecture
Each block in the model stack contains a dual-path pipeline designed to combine continuous local dynamics with long-range anchored memory retention.
Dual-Path Feature Pipeline
By combining FullS4DBlock (for global linear recurrence) and FullMultiBlock (for anchored memory centers), the model simultaneously maintains high-frequency sequential awareness and long-range structural dependencies.
GatedState Integration
Complex state representations are projected back into model dimensionality via adaptive non-linear gating functions (Softsign/Sigmoid), stabilizing state magnitude across deep network stacks.
Training & Execution Strategy
Loci-S4D achieves computational efficiency through specialized GPU kernel routines during training and a streamlined state-passing algorithm for auto-regressive generation.
Channel-Parallel Linear Recurrence
Instead of associative parallel scans, sequence processing runs via step-by-step linear loops inside Triton kernels. High GPU utilization is achieved by reshaping dimensions to $(B \cdot D_s/2, T, 2)$, distributing time-stepping across $B \cdot D_s/2$ parallel execution warps.
Chunked Gradient Checkpointing
For long sequences exceeding chunk limits (e.g. 128 tokens), the model utilizes sequential state passing (_forward_chunked) paired with gradient checkpointing to bound VRAM consumption.
$\mathcal{O}(1)$ Auto-Regressive Generation
During inference, the model operates recursively token-by-token. It carries forward only the compact state tensor $h_{\text{prev}}$ and cumulative contribution indices without allocation or growth of a Key-Value (KV) cache.
Architectural Complexity Comparison
Comparison of LociS4DLm against Standard Transformers and traditional State Space Models across asymptotic complexities and memory behavior:
| Architecture Model | Training Time | Training VRAM | Inference Memory | Long Context Retention |
|---|---|---|---|---|
| Standard Transformer (Attention) | $\mathcal{O}(N^2)$ | $\mathcal{O}(N^2)$ | $\mathcal{O}(N)$ (KV-Cache) | Exact Attention (High Memory) |
| Standard SSM (S4 / Mamba) | $\mathcal{O}(N)$ | $\mathcal{O}(N)$ | $\mathcal{O}(1)$ Constant | Uniform Decay (Information Blur) |
| Loci-S4D (LociS4DLm) | $\mathcal{O}(N)$ / Channel Parallel | $\mathcal{O}(1)$ Chunk Checkpoint | $\mathcal{O}(1)$ Constant State | Anchored Loci (Blur Resistant) |
Reference Implementation Pseudo-Structure
import torch
import torch.nn as nn
class LociS4DBlock(nn.Module):
def __init__(self, d_model, l_max, num_loci=8):
super().__init__()
self.s4d_branch = FullS4DBlock(d_model)
self.multi_branch = FullMultiBlock(d_model, l_max, num_loci)
self.gated_state = GatedState(d_model)
self.norm = nn.LayerNorm(d_model)
self.ffn = FFNWithGELU(d_model)
def forward(self, x, h_prev=None, cum_contrib=None):
# Residual Path 1: Recurrence & Loci Anchoring
residual = x
x_norm = self.norm(x)
s4d_out = self.s4d_branch(x_norm)
loci_out = self.multi_branch(x_norm, cum_contrib)
h_integrated = self.gated_state(s4d_out, loci_out)
x = residual + h_integrated
# Residual Path 2: Feed-Forward Network
x = x + self.ffn(self.norm(x))
return x, h_integrated