CellularFlow is a memory-augmented neural architecture designed as a continual-learning alternative to standard Transformers. By replacing dense Feed-Forward Networks (FFN/MLP) with Multi-Head Associative DNA Memory Banks and an Episodic Memory Slot Buffer, CellularFlow decouples factual knowledge storage from sequence reasoning.
It achieves state-of-the-art catastrophic forgetting mitigation (83.9% retention across sequential domains) and enables zero-backprop streaming learning during inference.
| Feature | Standard Transformer (LLaMA/GPT) | CellularFlow v4 |
|---|---|---|
| Parametric Architecture | Dense FFN / SwiGLU | Multi-Head Associative DNA Memory (CMCLayer) |
| Sequential Adaptation | Severe catastrophic forgetting (61.8% retention) | 83.9% retention via Selective Fine-Tuning (Mode 2) |
| Real-time Live Learning | β Impossible without retraining | β Mode 1: EMA streaming forward update (0 backprop) |
| Instant Fact Injection | β Requires finetuning or external RAG | β Mode 3: Episodic slot buffer with decay & consolidation |
| Sequence Attention | $O(T^2)$ quadratic compute | $O(T)$ FlashAttention + NTK-aware dynamic RoPE |
| Inference Efficiency | Full recompute or dense KV cache | Decoupled memory lookup + incremental KV-cache |
| Knowledge Inspectability | Diffuse, entangled weights | Discrete, addressable, and prunable memory slots |
CellularFlow fuses two computational pathways into a unified Hybrid CMC Layer:
Input Sequence: X (B, T, d)
β
ββββββββββββββββ΄βββββββββββββββ
βΌ βΌ
βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ
β Multi-Head DNA Memory β β Episodic Memory Slot β
β Associative Banks β β Buffer (Fast-Write) β
ββββββββββββββ¬βββββββββββββ ββββββββββββββ¬βββββββββββββ
β β
ββββββββββββββββ¬βββββββββββββββ
β (Gated Memory Enrichment)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Causal Multi-Head Self-Attention with RoPE (FlashAttn)β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βΌ
Output Sequence: Y (B, T, d)
CMCLayer)Each head ($H$) maintains learned key-value associative banks: $$\text{scores}_h = \frac{\text{Norm}(x_h) \cdot \text{Norm}(K_h)^T}{\tau_h} + \mathcal{N}(0, 0.1)$$ $$\text{weights}_h = \text{Softmax}(\text{Top-K}(\text{scores}_h))$$ $$\text{out}_h = \text{weights}_h \cdot V_h$$
inference_write=True): Updates DNA memory values on the fly during inference via Exponential Moving Average (EMA) with zero backward pass. Protected by Spherical Anisotropy Regularization to prevent vector collapse.set_mode("selective")): Freezes ~85% of the backbone (projections, embeddings, LayerNorms) and trains only the DNA banks. Retains foundational knowledge while rapidly absorbing new domains.inject_fact): Writes facts into slot-based episodic memory with temporal age decay (exp(-0.005 * age)) and consolidates top facts into DNA banks post-epoch.Requires Python $\ge$ 3.11 and PyTorch $\ge$ 2.4.0.
# Clone the repository
git clone https://github.com/celcilin/cellularflow.git
cd cellularflow
# Install dependencies using UV (recommended) or pip
pip install -e .
# For GPU acceleration (CUDA 12.4+):
pip install torch --index-url https://download.pytorch.org/whl/cu124
import torch
from cellularflow import CellularFlowLM, CellularFlowTrainer, BPEDataset
# 1. Initialize tokenizer & dataset
dataset = BPEDataset("Alice was beginning to get very tired of sitting by her sister...", context_len=256)
# 2. Instantiate CellularFlow LM
model = CellularFlowLM(
vocab_size = dataset.vocab,
dim = 512,
n_layers = 6,
n_heads = 8,
n_entries = 128,
context_len = 256,
use_episodic = True
)
# 3. Pretraining
trainer = CellularFlowTrainer(model, dataset, device="cuda" if torch.cuda.is_available() else "cpu")
trainer.pretrain(epochs=100, seed_dna=True)
# 4. Fast Generation (with KV-Cache)
prompt = "The journey into"
print(trainer.generate(prompt, max_new=100, temperature=0.8))
# 5. Continual Learning: Mode 3 Fact Injection
trainer.inject_fact("The hidden archives are kept inside Vault 42.")
# 6. Continual Learning: Mode 2 Selective Fine-Tuning (Backbone Frozen)
trainer.selective_finetune("Technical medical notes on neurology...", epochs=10)
# 7. Continual Learning: Mode 1 Live Streaming Learning (0 Backprop)
trainer.live_learn("Streaming log telemetry received in real time...")
CellularFlow includes an interactive glassmorphic web dashboard for real-time inference, fact injection, and memory inspection:
# Start the FastAPI server
uvicorn server.app:app --host 0.0.0.0 --port 8000
Open http://localhost:8000 in your browser to interactively generate text, inspect layer-wise episodic slot utilization, and test live fact injections.
# Interactive CLI Playground
python analysis.py --checkpoint checkpoint/CMC_BaseModel.pt --interactive
Evaluated on a standardized 62KB multi-domain corpus:
| Architecture | Parameters | Perplexity | Accuracy |
|---|---|---|---|
| GPT-mini (Vanilla Transformer) | 810K | 8.51 | 36.4% |
| CellularFlow v4 (Hybrid CMC) | 379K (2.1Γ fewer) | 2.54 (β70.3%) | 73.7% |
Trained sequentially across Literature, Science, History, Technical, and Poetry:
| Fine-Tuning Strategy | Overall Domain Retention |
|---|---|
| Full Fine-Tuning (All Weights) | 61.8% |
| Mode 2: Selective DNA Fine-Tuning | 83.9% (+22.1 pp) |
cellularflow/
βββ cellularflow/
β βββ core.py # CMCLayer, HybridCMCLayer, EpisodicMemory, CellularFlowLM
β βββ trainer.py # Pretraining, selective fine-tuning, live learning, mixed precision
β βββ extensions.py # Blockwise Attention, Compressed KV (CKV), MTP, Beaconing
β βββ corpus.py # Multi-domain benchmark corpora
β βββ swarm.py # DNASwarm evolutionary optimizer
βββ benchmarks/
β βββ evaluate_checkpoint.py# Evaluation harness for perplexity, accuracy, and memory norms
βββ server/
β βββ app.py # FastAPI server + WebSocket endpoint
βββ dashboard/
β βββ index.html # Web dashboard UI
β βββ app.js # Frontend WebSocket and API client
β βββ styles.css # Dark glassmorphic design system
βββ sft/
β βββ sft_dataset.py # ChatML templates and target loss masking
β βββ sft_trainer.py # Supervised fine-tuning curriculum engine
βββ scripts/
β βββ train_tokenizer.py # ByteLevelBPE tokenizer builder
β βββ test_extensions.py # Architecture extension verification
βββ analysis.py # CLI exploration & interactive REPL
βββ pyproject.toml # Project build & dependency definitions
βββ CONTRIBUTING.md # Contribution guidelines & developer standards
We welcome contributions from researchers, engineers, and developers worldwide! Please review CONTRIBUTING.md for instructions on setting up your environment, adhering to XLA/TPU graph rules, and submitting pull requests.
Celcilin C S
This project is licensed under the MIT License β see the LICENSE file for details.
1 commits
Python
61.8%
Jupyter Notebook
25.0%
CSS
4.0%
TeX
3.8%
HTML
3.4%
JavaScript
2.2%
CellularFlow is a memory-augmented neural architecture designed as a continual-learning alternative to standard Transformers. By replacing dense Feed-Forward Networks (FFN/MLP) with Multi-Head Associative DNA Memory Banks and an Episodic Memory Slot Buffer, CellularFlow decouples factual knowledge storage from sequence reasoning.
It achieves state-of-the-art catastrophic forgetting mitigation (83.9% retention across sequential domains) and enables zero-backprop streaming learning during inference.
| Feature | Standard Transformer (LLaMA/GPT) | CellularFlow v4 |
|---|---|---|
| Parametric Architecture | Dense FFN / SwiGLU | Multi-Head Associative DNA Memory (CMCLayer) |
| Sequential Adaptation | Severe catastrophic forgetting (61.8% retention) | 83.9% retention via Selective Fine-Tuning (Mode 2) |
| Real-time Live Learning | β Impossible without retraining | β Mode 1: EMA streaming forward update (0 backprop) |
| Instant Fact Injection | β Requires finetuning or external RAG | β Mode 3: Episodic slot buffer with decay & consolidation |
| Sequence Attention | $O(T^2)$ quadratic compute | $O(T)$ FlashAttention + NTK-aware dynamic RoPE |
| Inference Efficiency | Full recompute or dense KV cache | Decoupled memory lookup + incremental KV-cache |
| Knowledge Inspectability | Diffuse, entangled weights | Discrete, addressable, and prunable memory slots |
CellularFlow fuses two computational pathways into a unified Hybrid CMC Layer:
Input Sequence: X (B, T, d)
β
ββββββββββββββββ΄βββββββββββββββ
βΌ βΌ
βββββββββββββββββββββββββββ βββββββββββββββββββββββββββ
β Multi-Head DNA Memory β β Episodic Memory Slot β
β Associative Banks β β Buffer (Fast-Write) β
ββββββββββββββ¬βββββββββββββ ββββββββββββββ¬βββββββββββββ
β β
ββββββββββββββββ¬βββββββββββββββ
β (Gated Memory Enrichment)
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Causal Multi-Head Self-Attention with RoPE (FlashAttn)β
βββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββ
β
βΌ
Output Sequence: Y (B, T, d)
CMCLayer)Each head ($H$) maintains learned key-value associative banks: $$\text{scores}_h = \frac{\text{Norm}(x_h) \cdot \text{Norm}(K_h)^T}{\tau_h} + \mathcal{N}(0, 0.1)$$ $$\text{weights}_h = \text{Softmax}(\text{Top-K}(\text{scores}_h))$$ $$\text{out}_h = \text{weights}_h \cdot V_h$$
inference_write=True): Updates DNA memory values on the fly during inference via Exponential Moving Average (EMA) with zero backward pass. Protected by Spherical Anisotropy Regularization to prevent vector collapse.set_mode("selective")): Freezes ~85% of the backbone (projections, embeddings, LayerNorms) and trains only the DNA banks. Retains foundational knowledge while rapidly absorbing new domains.inject_fact): Writes facts into slot-based episodic memory with temporal age decay (exp(-0.005 * age)) and consolidates top facts into DNA banks post-epoch.Requires Python $\ge$ 3.11 and PyTorch $\ge$ 2.4.0.
# Clone the repository
git clone https://github.com/celcilin/cellularflow.git
cd cellularflow
# Install dependencies using UV (recommended) or pip
pip install -e .
# For GPU acceleration (CUDA 12.4+):
pip install torch --index-url https://download.pytorch.org/whl/cu124
import torch
from cellularflow import CellularFlowLM, CellularFlowTrainer, BPEDataset
# 1. Initialize tokenizer & dataset
dataset = BPEDataset("Alice was beginning to get very tired of sitting by her sister...", context_len=256)
# 2. Instantiate CellularFlow LM
model = CellularFlowLM(
vocab_size = dataset.vocab,
dim = 512,
n_layers = 6,
n_heads = 8,
n_entries = 128,
context_len = 256,
use_episodic = True
)
# 3. Pretraining
trainer = CellularFlowTrainer(model, dataset, device="cuda" if torch.cuda.is_available() else "cpu")
trainer.pretrain(epochs=100, seed_dna=True)
# 4. Fast Generation (with KV-Cache)
prompt = "The journey into"
print(trainer.generate(prompt, max_new=100, temperature=0.8))
# 5. Continual Learning: Mode 3 Fact Injection
trainer.inject_fact("The hidden archives are kept inside Vault 42.")
# 6. Continual Learning: Mode 2 Selective Fine-Tuning (Backbone Frozen)
trainer.selective_finetune("Technical medical notes on neurology...", epochs=10)
# 7. Continual Learning: Mode 1 Live Streaming Learning (0 Backprop)
trainer.live_learn("Streaming log telemetry received in real time...")
CellularFlow includes an interactive glassmorphic web dashboard for real-time inference, fact injection, and memory inspection:
# Start the FastAPI server
uvicorn server.app:app --host 0.0.0.0 --port 8000
Open http://localhost:8000 in your browser to interactively generate text, inspect layer-wise episodic slot utilization, and test live fact injections.
# Interactive CLI Playground
python analysis.py --checkpoint checkpoint/CMC_BaseModel.pt --interactive
Evaluated on a standardized 62KB multi-domain corpus:
| Architecture | Parameters | Perplexity | Accuracy |
|---|---|---|---|
| GPT-mini (Vanilla Transformer) | 810K | 8.51 | 36.4% |
| CellularFlow v4 (Hybrid CMC) | 379K (2.1Γ fewer) | 2.54 (β70.3%) | 73.7% |
Trained sequentially across Literature, Science, History, Technical, and Poetry:
| Fine-Tuning Strategy | Overall Domain Retention |
|---|---|
| Full Fine-Tuning (All Weights) | 61.8% |
| Mode 2: Selective DNA Fine-Tuning | 83.9% (+22.1 pp) |
cellularflow/
βββ cellularflow/
β βββ core.py # CMCLayer, HybridCMCLayer, EpisodicMemory, CellularFlowLM
β βββ trainer.py # Pretraining, selective fine-tuning, live learning, mixed precision
β βββ extensions.py # Blockwise Attention, Compressed KV (CKV), MTP, Beaconing
β βββ corpus.py # Multi-domain benchmark corpora
β βββ swarm.py # DNASwarm evolutionary optimizer
βββ benchmarks/
β βββ evaluate_checkpoint.py# Evaluation harness for perplexity, accuracy, and memory norms
βββ server/
β βββ app.py # FastAPI server + WebSocket endpoint
βββ dashboard/
β βββ index.html # Web dashboard UI
β βββ app.js # Frontend WebSocket and API client
β βββ styles.css # Dark glassmorphic design system
βββ sft/
β βββ sft_dataset.py # ChatML templates and target loss masking
β βββ sft_trainer.py # Supervised fine-tuning curriculum engine
βββ scripts/
β βββ train_tokenizer.py # ByteLevelBPE tokenizer builder
β βββ test_extensions.py # Architecture extension verification
βββ analysis.py # CLI exploration & interactive REPL
βββ pyproject.toml # Project build & dependency definitions
βββ CONTRIBUTING.md # Contribution guidelines & developer standards
We welcome contributions from researchers, engineers, and developers worldwide! Please review CONTRIBUTING.md for instructions on setting up your environment, adhering to XLA/TPU graph rules, and submitting pull requests.
Celcilin C S
This project is licensed under the MIT License β see the LICENSE file for details.
1 commits
Python
61.8%
Jupyter Notebook
25.0%
CSS
4.0%
TeX
3.8%
HTML
3.4%
JavaScript
2.2%