Skip to content

Vishal-sys-code/variational-linear-attention

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

691 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Variational Linear Attention (VLA)

A Next-Generation Sequence Model

Vishal S. Pandey1  •  Gopal Singh2

1DeepBrain Labs     2Metriqual


Abstract: Standard Linear Attention models achieve $\mathcal{O}(N)$ computational complexity by approximating the Softmax kernel. However, they suffer universally from "attention dilution" due to fixed retention and struggle with targeted historical recall (e.g., Associative Retrieval). Variational Linear Attention (VLA) reformulates the linear attention mechanism entirely through the lens of a probabilistic graphical model, introducing a mathematically optimal, data-dependent dynamic penalty mechanism ($M_t$). By explicitly learning to forget irrelevant tokens via stable rank-1 Sherman-Morrison inverse tracking, VLA naturally maintains pristine long-range dependencies without sequence degradation.


Key Innovations

  1. Dynamic Penalty Matrix ($M_t$): Unlike standard exponential decay sequences, VLA learns to construct a dynamic, dense penalty matrix over time, strongly suppressing irrelevant information natively based on changing contextual input.
  2. Strict Numerical Stability: VLA leverages the Sherman-Morrison Rank-1 Update to actively maintain the exact inverse of the penalty matrix ($A_t = M_t^{-1}$) throughout the sequence. This guarantees that updating memory stays linear in time $\mathcal{O}(N d^2)$ while entirely dodging $\mathcal{O}(d^3)$ explosive inversions.
  3. Optimally Recovered Memory ($\alpha^*$): VLA analytically solves an online optimization problem at every forward step, mathematically guaranteeing the coefficient scaling $\alpha_t = A_t s_t$ perfectly minimizes reconstruction errors.

Theoretical Backbone (The Sherman-Morrison Update)

Maintaining numerical stability over infinitely long contexts requires flawless inversion updating. When the penalty matrix is perturbed by a new context vector ($u_t$), we stably update the structural inverse using our $\epsilon$-bounded stabilizer logic:

$$A_t = A_{t-1} - \frac{A_{t-1} u_t u_t^\top A_{t-1}}{1 + u_t^\top A_{t-1} u_t}$$

This ensures extreme numerical preservation (maintaining stable unity eigenvalues natively over 10M+ tokens without catastrophic failure), bypassing completely the issues dominating baseline standard state-space and linear transformer models.


Performance & Benchmarks

Our empirical evaluations across both Synthetic capabilities and symbolic reasoning scales showcase VLA operating natively at a State-of-the-Art capacity.

  • Synthetic Retrieval: Hits perfect exact match accuracy on 10,000+ length associative and delayed recall tasks, where standard Linear Transformers drop to baseline 0% due to capacity erasure.
  • Symbolic Reasoning & LRA: Exhibits powerful dominance against leading Linear-Time variants in memory-intensive logic flows specifically evaluated on ListOps, CLUTRR, and CommonsenseQA.

Experimental Visualizations & Ablations

1. Phase D Ablation Studies
Ablation Summaries
Comparing learning drivers vs fixed bounds
2. Penalty Matrix Heatmap ($M_t$)
Dynamic Penalty Matrix
Visualizing targeted exponential decay
3. Recursive Eigenvalue Stability
Numerical Stability
$\epsilon$-bounded rank-1 inversion preservation
4. LRA & Symbolic Task Overviews
LRA Accuracies
Performance spanning 10K+ contexts

VLA v3 Advanced Benchmarks & Stability

Latest empirical results from notebooks/07-vlav3-benchmark-fixed.ipynb

1. Linear O(T) Scaling Behavior
Scaling Behavior
VLA maintains strict linear-time step updates regardless of sequence length.
2. Inversion Stability Tracking
KV Norms Stability
KV state ratio (LA/VLA) is ~113x. VLA dynamically bounds exploding states.
3. MQAR Capacity Curve
MQAR Capacity Curve
VLA hits 100% accuracy on complex associative recall while standard models crash to ~7%.
4. MQAR Long-Context Accuracy
MQAR Acc vs Seq Len
VLA sustains 98.2% accuracy across 512 context lengths compared to Softmax failing at ~15%.

Detailed breakdown and interactive visualization tracking are available directly in our Documentation Portal.


Repository Structure

We enforce a strict, isolated architecture separating the pure math primitives from the actual PyTorch NN modules for maximal legibility:

variational-linear-attention/
├── src/
│   ├── modules/       # High-level PyTorch Neural Network definitions (VLA blocks)
│   ├── maths/         # Core isolated primitive functions (Sherman-Morrison, Woodbury)
│   └── data/          # Synthetic and benchmark data ingestion pipelines
├── benchmarks/        # LRA and complex timing suites
├── experiments/       # Ablation studies and convergence scripts
├── tests/             # Strict CI tests capturing numeric drift regressions
└── website/           # Docusaurus documentation (Math, APIs, Diagrams)

Getting Started

1. Installation Environment

Create a clean Conda environment and install torch natively:

conda create -n vla-env python=3.10
conda activate vla-env
pip install -r requirements.txt

2. Running the Sub-Tests

DeepBrain Labs enforces absolute numerical precision matching theoretical limits. To verify stability and gradients in your local CUDA configuration:

pytest tests/ -v

VLA v3 (Research Implementation Notes)

The repository now includes a dedicated VLAv3 implementation in src/models/attention/vla_v3.py, aligned with the stabilized formulation from the v3 notebook:

  1. Positive feature map: Q,K = ELU(·)+1 for non-negative linear attention features.
  2. Learned penalty direction: u_t = normalize(W_u k_t^{raw}) with full gradient flow.
  3. Stable inverse recursion: Sherman–Morrison updates for A_t with periodic diagonal nudging.
  4. Bounded fast-weight dynamics: normalized (k_t, α_t) outer-product updates to control Jacobian spectrum.
  5. Calibrated readout: z·q denominator normalization at decode time.

This is intended as the canonical code path for v3 ablations and reproducible MQAR-oriented experiments.

Comprehensive Benchmarks (from Notebook 07)

The VLAv3 architecture undergoes rigorous stress-testing against standard Softmax, Linear Attention, and DeltaNet in notebooks/07-vlav3-benchmark-fixed.ipynb.

  • Scaling Benchmark: Proves VLA runs in $\mathcal{O}(T)$ constant time per token, avoiding the $\mathcal{O}(T^2)$ slowdown of Softmax.
  • Stability Tracking: Tracks the internal hidden states ($S_t$). Standard Linear Attention explodes to $1633.9$ norms, while VLA bounds this dynamically to $14.5$ ($113\times$ reduction).
  • Copy Task & Basic Learning: Confirms VLA possesses pristine gradient flow to solve deterministic recall in $<2000$ steps.
  • MQAR Capacity Curve: VLA dominates high-density memory retrieval ($24$ pairs, seq len $73$) with $1.000$ accuracy, completely destroying Softmax ($0.074$), Linear ($0.075$), and DeltaNet ($0.010$).
  • Long-Context MQAR: Sustains retrieval capacity out to $512+$ context lengths with $0.982$ accuracy.

If you want to reproduce the paper-style v3 figures and data, run the full workflow in notebooks/07-vlav3-benchmark-fixed.ipynb and compare against the saved artifacts in the notebooks/vlav3_benchmarks/ directory.

3. Local Documentation Server

Want to read the interactive math and architectural deep dives? Boot the local Docusaurus server:

cd website
npm install
npm start

Citation & Open Source

This repository represents the official implementation payload for the Variational Linear Attention framework initiated by the Research Engineering Core at DeepBrain Labs. Check out the issue tracker for upcoming feature releases or integration requests.

Paper -> Work in Progress

About

Variational Linear Attention

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors