Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

210 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Universal System 1 Engine (Universal S1)

Python 3.10+ PyTorch 2.2+ Tests Inference Latency Curriculum Milestone Architecture Roadmap v2.x Sponsor Research License: MIT

Modular, ultra-high-throughput Python/PyTorch library implementing an amortized reflex agent (System 1) trained via pure Recurrent Proximal Policy Optimization (PPO), Curvature-Gated Actor Surgery (GradVac/PCGrad), Unlimited Lossless Self-Imitation Learning (SIL), and Contrastive Online DPO.

Unlike deliberative "System 2" frameworks (LLMs with Chain-of-Thought, Monte Carlo Tree Search, or $A^*$ search), this agent operates by amortized muscle-memory reflex: executing a single deterministic forward pass with sub-millisecond latency on CPU (act_fast() <= 0.8 ms, measured at ~0.23 ms), navigating combinatorial state spaces of over 232 billion permutations (Rubik's Cube Depth 10 to 14) with zero test-time search.


⚑ Key Architectural Capabilities

  1. Sub-Millisecond Reflex Latency on Bare CPU:
    • agent.act_fast() executes in 0.230 ms (P50) and 0.249 ms (P95) on standard CPU (~3.5x below the strict 0.8 ms budget).
    • Zero test-time tree search ($O(1)$ recurrent forward pass).
  2. Deep Combinatorial Mastery (Rubik's Cube up to Depth 14):
    • Traverses a permutation manifold of over 232,248,000,000 states without heuristic search tables.
    • 100% solve rate on Depths D1–D4 with mathematically optimal move paths (1.0 to 3.9 average moves).
    • 93% on D5, 79% on D6, 57% on D7, 39% on D8, 15% on D9, 13% on D10, 3% on D11, and verified zero-shot generalization up to Depth 14.
  3. Definitive Architecture: SymGradVac-PureCritic:
    • Isolated Value Head: Critic operates under 100% pure on-policy PPO ($V^\pi(s)$), completely shielded from memory bias to protect generalized Bellman advantage calculations.
    • Curvature-Gated Actor Surgery: Actor parameters (FrontEnd, Trunk, PolicyHead) undergo symmetric projection via adaptive EMA curvature gating ($\hat{\alpha}_b$, Wang et al., ICLR 2021), smoothly rotating gradients under conflicting memory directions while strictly preserving gradient norms.
  4. Unlimited Lossless Buffer & Zero Failure Storage:
    • Stores over 250,000+ winning trajectories and success slices with zero memory degradation via 21.7x lossless compression, occupying $&lt;700\text{ MB}$ of RAM.
    • Contrastive DPO operates on-policy by contrasting stored victories against active negative rollout chunks under demand ($O(1)$ batch sampling), discarding failure episodes immediately.
  5. Tri-Compass Spatial Invariance:
    • Decoupled 3D spatial orientation representation providing rotational invariance across all 24 spatial cube orientations.
  6. Massive Multi-Vectorized Throughput (>20,000 FPS):
    • Vectorized headless C++/Rust Gym simulation running across 128 parallel environments, scaling training past 430M+ steps on commodity multi-core hardware.
  7. Interactive Mission Control HUD Deck (python -m system1_engine.hud):
    • Real-time dark-mode web control center at http://localhost:8050.
    • Live 3D WebGL Rubik's cube viewport + 2D net projection, live MJPEG video stream, real-time latency P50/P99 sliding charts, automated checkpoint scanner, and dynamic parameter tuning.
  8. Production ONNX Runtime & WebAssembly Parity:
    • Automatic zero-overhead ONNX model export (web/models/s1_rubiks_atomic.onnx) with bitwise parity for client-side in-browser WebAssembly execution.
  9. Pure, Unbloated Implementation:
    • Zero dependency on heavy high-level RL frameworks (no Stable-Baselines3, no Ray/RLlib). 100% pure PyTorch, Gymnasium, and NumPy.

πŸ“ Unified Tensor Flow Architecture

[ Vector Observation: s_t ] (324-dim One-Hot Facelets)
   β”‚
   β”œβ”€β–Ί [ Tri-Compass Encoder ] ──► z_rot  ∈ ℝ^32   (Rotational Invariance)
   β”œβ”€β–Ί [ VectorFrontEnd ]      ──► z_s    ∈ ℝ^256  (Facelet State Features)
   β”œβ”€β–Ί [ DeltaEncoder (Ξ”s) ]   ──► z_Ξ”    ∈ ℝ^32   (Temporal Dynamics)
   β”œβ”€β–Ί [ ActionEncoder (a_prev) ] β–Ί z_a   ∈ ℝ^16   (Action Feedback)
   └─► [ RewardEncoder (r_prev) ] β–Ί z_r   ∈ ℝ^1    (Scalar Feedback)
                                        β”‚
                         (Concatenation)β–Ό
                               z_in ∈ ℝ^337
                                        β”‚
                               [ LayerNorm(337) ]
                                        β”‚
                                        β–Ό
                   ╔══════════════════════════════════════════╗
                   β•‘      System 1 Lean Recurrent Trunk       β•‘
                   β•‘      - nn.GRU (337 -> 256)               β•‘
                   β•‘      - 2x LayerNorm + ResMLP Blocks      β•‘
                   β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
                                        β”‚
                                        β–Ό
                               h_t ∈ ℝ^256 (Latent Memory)
                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”
                               β–Ό                 β–Ό
                       [ Policy Head ]    [ Value Critic Head ]
                       12 Atomic Actions      Value V(s_t)
                       (U, U', D, D'...)     State Expectation

πŸ“ˆ Empirical Benchmarks (D1 to D10 Frontier)

100 paired evaluation episodes per depth comparing Pure Reflex $O(1)$ vs. Hybrid Re-rank Top-2 ($V(s')$):

Depth Permutation Combinatorial States Pure Reflex Win Rate Hybrid Re-rank Win Rate Average Move Count
D01 12 100.0% 100.0% 1.0 (Optimal)
D02 ~243 100.0% 100.0% 2.0 (Optimal)
D03 ~3,240 100.0% 100.0% 2.9 (Optimal)
D04 ~43,200 100.0% 100.0% 3.9 (Optimal)
D05 ~575,000 86.0% 88.0% 7.2 moves
D06 ~7,600,000 74.0% 84.0% 11.4 moves
D07 ~100,000,000 48.0% 60.0% 18.7 moves
D08 ~1,330,000,000 32.0% 36.0% 25.4 moves
D09 ~17,600,000,000 12.0% 32.0% 29.3 moves
D10 ~232,248,000,000 7.0% 12.0% 🌟 37.0 moves

Inference Latency Breakdown (CPU)

  • Pure Reflex ($O(1)$ forward pass): 0.230 ms (P50) | 0.249 ms (P95)
  • Hybrid Value Re-rank (conditional Top-2 tensor batch): 0.742 ms (P50) | 0.781 ms (P95)

πŸ—‚οΈ Directory Structure

system_one/
β”œβ”€β”€ system1_engine/                 # Core engine package
β”‚   β”œβ”€β”€ core/                       # Latent representation & amortized reflex
β”‚   β”‚   β”œβ”€β”€ agent.py                # UniversalS1Agent (act_fast, value_rerank, confidence)
β”‚   β”‚   β”œβ”€β”€ trunk.py                # System1Trunk & LeanRecurrentTrunk (nn.GRU + ResMLP)
β”‚   β”‚   β”œβ”€β”€ encoders.py             # VectorFrontEnd, TriCompassEncoder, ImpalaFrontEnd
β”‚   β”‚   β”œβ”€β”€ heads.py                # CategoricalPolicyHead, GaussianHead, ValueHead
β”‚   β”‚   └── onnx_exporter.py        # Automated ONNX export with WebAssembly parity
β”‚   β”œβ”€β”€ env/                        # State ingestion & environment adapters
β”‚   β”‚   β”œβ”€β”€ wrapper.py              # UniversalS1Wrapper (Ξ”s, temporal buffering, simulation)
β”‚   β”‚   └── adapters/               # Multi-level adapters (Gym, Vectorized, ViZDoom)
β”‚   β”‚       β”œβ”€β”€ rubiks.py           # RubiksCubeEnv, VectorizedRubiksEnv, RubiksCubeCore
β”‚   β”‚       β”œβ”€β”€ mountain_car.py     # Energy-shaped continuous/discrete adapter
β”‚   β”‚       β”œβ”€β”€ frozenlake.py       # Discrete curriculum wrapper
β”‚   β”‚       └── native_adapter.py   # Lock-step headless native engine (>10k FPS)
β”‚   β”œβ”€β”€ training/                   # Recurrent Reinforcement Learning & Imitation
β”‚   β”‚   β”œβ”€β”€ ppo.py                  # RecurrentPPOTrainer with Teacher-Assisted SIL Lookahead
β”‚   β”‚   β”œβ”€β”€ buffer.py               # RecurrentRolloutBuffer (chunked BPTT)
β”‚   β”‚   └── sterility.py            # Latent Sterility Memory & Cycle Pruning
β”‚   β”œβ”€β”€ transfer/                   # Knowledge transfer & Continual Learning
β”‚   β”‚   └── manager.py              # KnowledgeTransferManager (Warm-Start & Net2Net)
β”‚   β”œβ”€β”€ telemetry/                  # High-frequency real-time observability
β”‚   β”‚   β”œβ”€β”€ tracker.py              # LiveStatsTracker with O(1) circular ring buffers
β”‚   β”‚   └── server.py               # TelemetryServer (HTTP/SSE live streaming on port 8050)
β”‚   β”œβ”€β”€ hud/                        # Interactive Visual Mission Control Deck
β”‚   β”‚   β”œβ”€β”€ __main__.py             # Entry point (python -m system1_engine.hud)
β”‚   β”‚   β”œβ”€β”€ server.py               # Web server (HTTP, SSE, REST, MJPEG stream)
β”‚   β”‚   β”œβ”€β”€ runner.py               # HUDProcessRunner (isolated subprocess lifecycle)
β”‚   β”‚   β”œβ”€β”€ worker.py               # High-throughput training/evaluation worker
β”‚   β”‚   └── dashboard.html          # Reactive dark-mode mission control UI
β”‚   └── cli.py                      # Production CLI interface
β”œβ”€β”€ web/                            # Client-side web demo assets & ONNX models
β”‚   └── models/                     # Auto-synchronized ONNX runtime weights
β”œβ”€β”€ tests/                          # Automated test suite (210 unit & integration tests)
β”‚   β”œβ”€β”€ test_action_chunking.py     # Action chunking & teacher lookahead tests
β”‚   β”œβ”€β”€ test_value_rerank.py        # Value re-ranking top-k tests
β”‚   β”œβ”€β”€ test_tri_compass.py         # Tri-Compass rotational invariance tests
β”‚   β”œβ”€β”€ test_rubiks.py              # Cube simulation & core permutation tests
β”‚   β”œβ”€β”€ test_hud.py                 # HUD server & worker lifecycle tests
β”‚   └── ...                         # Complete 210-test suite
β”œβ”€β”€ docs/                           # Architectural specs & v2.x evolution roadmaps
β”‚   β”œβ”€β”€ LOOKAHEAD_INTUITION_SCAR_ARCHITECTURE.md
β”‚   └── ROADMAP_MOS_SCACHE_V2_INTEGRATION.md
β”œβ”€β”€ MANUAL_DE_USO.md                # Exhaustive operational manual (Portuguese)
└── README.md                       # Main architecture & quickstart guide

πŸš€ Quickstart Guide

1. Installation

Clone the repository and install dependencies in a virtual environment:

git clone https://github.com/byte-od/system_one.git
cd system_one

python3 -m venv .venv
source .venv/bin/activate
pip install -e .

2. Launch the Interactive Mission Control HUD

Launch the browser-based control deck on http://localhost:8050:

python -m system1_engine.hud

Open your browser at http://127.0.0.1:8050 to start, monitor, and inspect training runs with live 3D cube visualizations, real-time latency curves, and dynamic checkpoint management.

3. Run Benchmark via CLI

Evaluate sub-millisecond CPU reflex latency:

python -m system1_engine.cli --mode benchmark --steps 1000

4. Train with Recurrent PPO + Teacher SIL

Train directly on the Rubik's Cube with 128 parallel vectorized environments:

python -u -m system1_engine.hud.worker --config '{
  "mode": "train",
  "env": "RubiksCube-v0",
  "num_envs": 128,
  "trunk": "lean",
  "tri_compass": true,
  "action_chunk_size": 1,
  "steps": 300000000,
  "teacher_sil_envs": 16,
  "value_rerank": true,
  "value_rerank_top_k": 2,
  "value_rerank_threshold": 0.85,
  "save": "s1_rubiks_v6.pt"
}'

πŸ§ͺ Automated Test Suite

The engine includes a comprehensive suite of 210 automated unit and integration tests:

pytest tests/ -v

All 210 tests validate:

  • Dimensional contracts across all tensor adapters ($\mathbb{R}^{324} \to \mathbb{R}^{337} \to \mathbb{R}^{256}$).
  • Sub-millisecond CPU latency guarantees ($\le 0.8\text{ ms}$).
  • Value Re-ranking $O(1)$ state preservation and immediate solves.
  • Tri-Compass rotational invariance.
  • Asymmetric Teacher-Assisted SIL rollouts and lookahead convergence.
  • Multi-process HUD server lifecycle, REST APIs, and SSE stream health.

❀️ Sponsor Open Research & Compute

Universal System 1, Mixture of Scars (MoS), and SCache O(1) are developed as open-source MIT research by Julio Cesar Reis Filho (Byte-OD Research & System One Architecture Lab).

Sponsorships directly fund dedicated GPU/CPU compute for System 1 + 72B MoS speculative reflex fusion, continual SCache β†’ MoS consolidation experiments, and open public checkpoints (v1.4 β†’ v2.x Roadmap):

πŸ‘‰ Sponsor via GitHub Sponsors (github.com/sponsors/byte-od)


πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages