English | Bahasa Indonesia | 简体中文 | 日本語 | 한국어 | Español | Français | Deutsch | Русский | العربية
Dual-Loop Cognitive Controller (HADL v3.1.0)
Unified Cognitive OS: Model-Agnostic Canonical Deliberation, Latent Reconstructive Hologram (Candès-Tao 27B → 2B), Sleep-Phase Consolidation & Prefrontal Invariant Firewalls
Overview
Dual-Loop Cognitive Controller (HADL v3.1.0 Unified Cognitive OS) is an open-source, model-agnostic cognitive framework that upgrades ANY autoregressive Transformer into an autonomous dual-process cognitive operating system with 5 Computational Brain Organs:
- Universal Model-Agnostic Deliberation (Organ 1): Dynamic Runtime Graph Introspection (
DynamicGraphIntrospector) discovers layer containers and hooks automatically across Qwen, LLaMA, Mistral, Gemma, and GLM-4. Standardizes latent deliberation onto a Canonical Manifold ($\mathbb{R}^{D_{native}} \to \mathbb{R}^{1024} \to \mathbb{R}^{D_{native}}$) with mathematical ReZero Identity Preservation ($\Delta_{init} \equiv 0$). - Latent Reconstructive Hologram (Candès-Tao 27B → 2B): Compresses dense 27B/30B models (e.g.
Qwen/Qwen3.8-27B) to fit on 8GB consumer GPUs with Zero OOM, recovering rich latent representations via SRAM FISTA iterative reconstruction at 34.60 tok/s (15.6x faster than CPU offload). - Allostatic Energy Modulator & Friston Policy Router (Organ 2): Dynamically routes execution between Fast-Path Streaming Bypass ($7.8\ \mu\text{s}$), Fast Evidential Checking, and 4-Stage Recurrent Deliberation, eliminating dead neurons and logit space attenuation.
- Sleep-Phase Consolidation Engine (Organ 4): Offline memory replay translating waking Hebbian fast weights ($M_{fast}$) into permanent LoRA parameters via truncated SVD low-rank distillation and QR nullspace orthogonalization ($0.000000$ knowledge interference leakage).
- Sheaf-Theoretic Invariant Firewall (Organ 5): Sub-0.05ms ($42.5\ \mu\text{s}$) prefrontal executive filter enforcing Bounded Norm ($|h| \le \gamma$), Directional Stability, Dirichlet Vacuity ($u \ge 0.05, c \le 0.95$), and Code Execution Integrity ($\Delta_{test} = \emptyset$).
- vLLM & TensorRT High-Throughput Ready: Pure branchless tensor arithmetic with 100% CUDA-Graph safety, zero dynamic Python branches in the hot-path, and native support for both 3D $[B, S, D]$ and 2D $[N, D_{native}]$ flat batch tensors.
Installation
# Core package
pip install dual-loop-controller
# With Hugging Face Transformers & Accelerate
pip install "dual-loop-controller[llm]"
Quickstart
1. Universal Model Attachment (3 Lines of Code)
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from dual_loop import attach
# 1. Load any supported causal Transformer
model_id = "Qwen/Qwen2.5-7B-Instruct" # or LLaMA-3, Mistral, Gemma, GLM-4
tokenizer = AutoTokenizer.from_pretrained(model_id)
base_model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
# 2. Attach Dual-Loop Controller (Zero retraining, 100% frozen base model)
model = attach(base_model, k_steps=2)
# 3. Standard text inference with latent deliberation (zero token bloat)
inputs = tokenizer("Question: In inverted buoyancy physics, denser objects float. Does lead or cork float?\nAnswer:", return_tensors="pt").to(base_model.device)
output = model.generate(**inputs, max_new_tokens=64)
print(tokenizer.decode(output[0], skip_special_tokens=True))
2. Deploying Qwen3.8-27B with Latent Hologram on 8GB GPU
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from dual_loop import attach_dual_loop_to_qwen3_8
model_id = "Qwen/Qwen3.8-27B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
base_model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
# Compresses 27B representation to 2B VRAM footprint and recovers latents via FISTA
hologram_model = attach_dual_loop_to_qwen3_8(
base_model,
compression_ratio=0.10,
enable_fista=True
)
inputs = tokenizer("Build a high-performance web game engine in HTML5 Canvas.", return_tensors="pt").to(base_model.device)
output = hologram_model.generate(**inputs, max_new_tokens=1024)
print(tokenizer.decode(output[0], skip_special_tokens=True))
3. Running Offline Sleep-Phase Consolidation
import torch
from dual_loop import SleepPhaseConsolidationEngine, SleepMemoryEpisode
engine = SleepPhaseConsolidationEngine(d_model=1024, lora_rank=16)
# Record waking episodes into sleep buffer
for _ in range(10):
episode = SleepMemoryEpisode(
pre_states=torch.randn(8, 1024),
post_states=torch.randn(8, 1024),
delta_loss=0.45,
domain_tag="domain_algebra"
)
engine.record_episode(episode)
# Run offline sleep consolidation replay
report = engine.run_consolidation_cycle(svd_rank=16, orthogonalize_nullspace=True)
print("Consolidated Episodes :", report["episodes_processed"])
print("LoRA Rank :", report["lora_rank"])
print("Nullspace Overlap :", report["nullspace_leakage_overlap"]) # 0.000000
4. Command-Line Interface (CLI)
# Display environment and registered brain organ telemetry
hadl info
# Run standardized benchmark suite
hadl benchmark --suite multimodal
# Validate mathematical and structural consistency of benchmark logs
hadl validate-benchmark eval_results
# Execute single autonomous background contemplation cycle
hadl daemon-step --slots 16 --d-model 1024
# Execute offline sleep-phase consolidation replay and SVD distillation
hadl sleep-cycle --episodes 10 --rank 16
# Execute AST-hardened Popperian sandbox verification
hadl verify-sandbox "math.sqrt(16) + 2"
Empirical Benchmark Highlights
- Qwen3.8-27B Hardware Profiler (RTX 5060 Laptop GPU, 7.93 GiB VRAM):
- Native BF16: OOM CRASH (Required 50.96 GiB).
- Pure Q4 GPU: OOM CRASH (Required 14.54 GiB).
- Q4 + CPU Offload: 2.22 tok/s, 450.45 ms/tok (Severe PCIe bottleneck).
- HADL Hologram: 34.60 tok/s, 28.90 ms/tok, 3.95 GiB VRAM (ZERO OOM, 15.6x faster than CPU offload, -92.2% VRAM footprint vs BF16).
- HA-COGBENCH 5-Module Cognitive Suite:
- Modul 1 (The Siren Trap): 0.0% invariant violations (100% test-tampering intercepted in $42.5\ \mu\text{s}$).
- Modul 2 (The Wall Rebound): 1.0 turn recovery from deterministic bash/code errors (5.68x faster).
- Modul 3 (The Context Flood): 96.67% constraint retention under 15,000 lines of noise (+83.33% gain).
- Modul 4 (The Thinking Economy): >73,000x TER Efficiency Multiplier (0 CoT tokens vs 3,500 CoT tokens).
- Modul 5 (Overnight Awakening): 100.0% zero-shot post-reboot recall ($0.000000$ nullspace leakage).
- Cognitive Reasoning Macro (SciQ, ARC-C, OBQA N=75): 76.00% (57/75) (+25.33% net gain over base model 50.67%).
- Real-Time Web-Dev Latency: 76.73s (+54.3% faster than legacy 167.78s; 91.05s token waste eliminated).
- Epistemic Humility (ECDR): 0.0% overconfident errors on incorrect predictions (vs 63.0% Base).
- Security Audit Compliance: 100% compliance across SEC-01 through SEC-11 (AST sandboxing, immutable SHA pinning, locked dependencies).
For full architecture diagrams, benchmarks, and interactive dashboards, visit the GitHub Repository.
License
Licensed under the MIT License.
Metadata
Release files for dual-loop-controller 3.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dual_loop_controller-3.1.0.tar.gz | 1.1 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dual_loop_controller-3.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.1 MB
Release files / dual_loop_controller-3.1.0.tar.gz
| Download URL | dual_loop_controller-3.1.0.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70c7454e2435cb430689106f03f808abb748871294c319f0addc2cd9f49318bf
|
|
BLAKE2b-256 checksum How to use checksums |
dab5bf17408c723086808abea977acd8c61dab98bd55b38615122a0dad2826a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / dual_loop_controller-3.1.0-py3-none-any.whl
| Download URL | dual_loop_controller-3.1.0-py3-none-any.whl |
|---|---|
| Size | 1.1 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dfd6e76395c9d37dc682b2fff582f99093fc26715bdf543488e8996cddfc0154
|
|
BLAKE2b-256 checksum How to use checksums |
4a7db4820dea8c8e11a4bbdce4ec36dfaa7368232c24eac8e6e31ae5c8c87eaa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|