CoolFace
Modelpublic

inv0krr/leworld-memory-architecture

sourceHugging Faceupdated 5mo agoView on Hugging Face
2likes
Model Card

LeWorld Memory Architecture ๐Ÿง โšก

A CPU-inspired hierarchical neural architecture where 3 Small LeWorld Models (SLMs) compete to find the most useful memory for 1 Big LeWorld Model (BLM) to predict the next world state.

Architecture

ComponentParametersRole
Artificial Memory21KBit-level storage (64K words ร— 32 bits) + learned bit encoder/decoder
SLM-0745KState โ†’ memory address range
SLM-1745KState โ†’ memory address range
SLM-2745KState โ†’ memory address range
BLM11.2MSLM selector [1,0,1] + next-state predictor + info requester
Total13.5M

Key Ideas

  1. 1.CPU-Style Memory: Actual bit-level storage (64K ร— 32-bit words), accessed by address ranges โ€” just like RAM
  2. 2.Product-Key Addressing: SLMs output addresses by predicting high byte (256 choices) + low byte (256 choices) = 65K addresses with only 512 logits
  3. 3.Binary SLM Routing: BLM selects which SLMs to trust via Straight-Through Sigmoid โ†’ hard [1,0,1] in forward, differentiable in backward
  4. 4.Active Information Request: BLM generates "what do I need next?" queries that modulate SLM memory search at the next timestep
  5. 5.3-Phase Training: Pre-train โ†’ Joint end-to-end โ†’ Info-request refinement with paired-branch reward

Data Flow

                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚    ARTIFICIAL MEMORY         โ”‚
                    โ”‚  [0][1][0][1]...[1][0][1][0] โ”‚
                    โ”‚   64K words ร— 32 bits each   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€-โ”€โ”˜
                               โ”‚ READ(addr_range)
           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚   SLM-0     โ”‚   โ”‚    SLM-1       โ”‚   โ”‚     SLM-2       โ”‚
    โ”‚  (745K)     โ”‚   โ”‚   (745K)       โ”‚   โ”‚    (745K)       โ”‚
    โ”‚ past_state  โ”‚   โ”‚ past_state     โ”‚   โ”‚ past_state      โ”‚
    โ”‚ curr_state  โ”‚   โ”‚ curr_state     โ”‚   โ”‚ curr_state      โ”‚
    โ”‚ character.  โ”‚   โ”‚ character.     โ”‚   โ”‚ character.      โ”‚
    โ”‚  โ†’ addr     โ”‚   โ”‚  โ†’ addr        โ”‚   โ”‚  โ†’ addr         โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚                   โ”‚                     โ”‚
           โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ  BLM (11.2M)  โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                    mask = [1, 0, 1]
                    โ†’ next_state prediction
                    โ†’ "what info do I need next?"

Files

FileDescription
leworld_architecture.pyAll model definitions: Memory, SLM, BLM, full system (~990 lines)
leworld_training.py3-phase training pipeline, data generation, evaluation (~820 lines)
PLAN.mdComplete design document with literature references

Quick Start

python
from leworld_architecture import LeWorldSystem, MemoryConfig, SLMConfig, BLMConfig
from leworld_training import run_training, TrainingConfig

# Build system
system = LeWorldSystem(MemoryConfig(), SLMConfig(), BLMConfig())

# Train (3 phases: pre-train โ†’ joint โ†’ refine)
metrics = run_training(system, TrainingConfig())

Literature Foundation

PaperWhat we borrowed
Gumbel-SoftmaxStraight-Through sigmoid for binary routing
Switch TransformersGate-value scaling, load balance loss
Product Key MemoryAddress decomposition into sub-keys
LM2LSTM-style memory gates
NAMMBinary memory eviction
ProactAgentPaired-branch reward for retrieval decisions
MambaExplicit state maintenance

Verified Results (demo run)

Phase 1: SLM loss 12.87 โ†’ 7.13, BLM loss 0.39 โ†’ 0.33
Phase 2: Routing becomes diverse โ€” SLM usage: [0.72, 0.79, 0.67]
Phase 3: Info-request improves predictions by 19.5 loss units vs baseline

Final: MSE=0.36, Routing entropy=0.70
Per-step MSE: [0.64, 0.44, 0.31, 0.23, 0.19]  โ† improves over time
Routing patterns: [1,0,1] โ†’ [0,1,1] โ†’ [1,1,1] โ†’ [1,1,0] โ†’ [0,1,0]