{"id":27373422,"url":"https://github.com/cambriantech/sentinel-ai","last_synced_at":"2026-05-16T17:36:23.968Z","repository":{"id":285179432,"uuid":"957307244","full_name":"CambrianTech/sentinel-ai","owner":"CambrianTech","description":"Sentinel-AI is a neuroscience-inspired transformer that dynamically prunes and regrows attention heads. Guided by controller feedback and entropy-based pruning, it self-optimizes through biologically informed cycles—compressing, adapting, and evolving its architecture over time.","archived":false,"fork":false,"pushed_at":"2025-04-20T15:16:28.000Z","size":9355,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-20T16:27:05.125Z","etag":null,"topics":["adaptive-transformers","colab-notebook","huggingface","model-pruning","neural-network-controller","pytorch","transformer-architecture","unet"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CambrianTech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-30T03:13:15.000Z","updated_at":"2025-04-10T01:05:51.000Z","dependencies_parsed_at":"2025-04-13T11:14:43.856Z","dependency_job_id":"871a0044-4ae8-4a7b-a820-a7ae39ea0343","html_url":"https://github.com/CambrianTech/sentinel-ai","commit_stats":null,"previous_names":["cambriantech/sentinel-ai"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CambrianTech/sentinel-ai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CambrianTech%2Fsentinel-ai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CambrianTech%2Fsentinel-ai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CambrianTech%2Fsentinel-ai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CambrianTech%2Fsentinel-ai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CambrianTech","download_url":"https://codeload.github.com/CambrianTech/sentinel-ai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CambrianTech%2Fsentinel-ai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280923455,"owners_count":26414237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adaptive-transformers","colab-notebook","huggingface","model-pruning","neural-network-controller","pytorch","transformer-architecture","unet"],"created_at":"2025-04-13T11:14:41.146Z","updated_at":"2026-05-16T17:36:23.961Z","avatar_url":"https://github.com/CambrianTech.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sentinel-AI\n\n**[Experiential Plasticity](https://github.com/CambrianTech/continuum/blob/main/docs/papers/EXPERIENTIAL-PLASTICITY.md) for transformers.** Train on domain data, prune what doesn't matter, retrain — the model emerges smaller, faster, and better at its job. Like biological synaptic pruning during brain development.\n\nThe architecture co-evolves with training: heads that contribute to the domain specialize, heads that don't are removed. The result is a model architecturally optimized for its target task — not just quantized, but structurally reshaped.\n\n**Published models:** [huggingface.co/continuum-ai](https://huggingface.co/continuum-ai)\n**Paper:** [Experiential Plasticity: Transformers That Grow Their Own Architecture From Experience](https://github.com/CambrianTech/continuum/blob/main/docs/papers/EXPERIENTIAL-PLASTICITY.md)\n**Part of:** [continuum](https://github.com/CambrianTech/continuum) — distributed AI on consumer hardware\n**Forge format:** [ForgeAlloy](https://github.com/CambrianTech/forge-alloy) — trustless AI compute contract (cryptographically verified pipelines)\n\n## Results\n\n### Qwen3.5 Domain-Specific Forging\n\nDomain-specific training amplifies the plasticity effect. Using [`forge_model.py`](scripts/forge_model.py) with LoRA + AMP mixed precision:\n\n| Model | Params | Domain | Training Data | Baseline PPL | Final PPL | Change | Device |\n|-------|--------|--------|--------------|-------------|-----------|--------|--------|\n| **[Qwen3.5-4B](https://huggingface.co/continuum-ai/qwen3.5-4b-code-forged)** | 3.4B | Code | [CodeFeedback](https://huggingface.co/datasets/m-a-p/CodeFeedback-Filtered-Instruction) (156K) | 3.04 | **2.31** | **+24.0%** | RTX 5090 |\n| **[Qwen3.5-27B](https://huggingface.co/continuum-ai/qwen3.5-27b-code-forged)** | 23.6B | Code | CodeFeedback (156K) | 3.07 | **2.96** | **+3.5%** | RTX 5090 |\n\n**+24% on 4B, +3.5% on 27B** — both better than baseline, both smaller. The 27B runs in 17GB (4-bit) instead of 28GB (fp16) while producing better code. Qwen3.5-27B benchmarks at Claude Sonnet 4.6 level ([source](https://x.com/TheAhmadOsman)) — now forged and improved, running on a MacBook Pro.\n\n```bash\n# Forge any model on any domain — memory tier auto-detected\npython scripts/forge_model.py Qwen/Qwen3.5-4B --domain code\npython scripts/forge_model.py Qwen/Qwen3.5-27B --domain code   # auto 4-bit on 32GB VRAM\n\n# Or use a ForgeAlloy recipe — typed, portable, cryptographically attestable\npython scripts/forge_model.py --alloy recipe.alloy.json\n```\n\n### Scaling Law\n\nImprovement from [experiential plasticity](https://github.com/CambrianTech/continuum/blob/main/docs/papers/EXPERIENTIAL-PLASTICITY.md) scales with model size. Larger models harbor more redundancy.\n\n| Model | Params | Baseline PPL | Final PPL | Change |\n|-------|--------|-------------|-----------|--------|\n| Qwen2.5-0.5B | 0.5B | 2.82 | 2.91 | −3.2% (too small) |\n| Qwen2.5-1.5B | 1.5B | 2.49 | 2.42 | +3.0% |\n| Qwen2.5-3B | 3.1B | 2.30 | 2.28 | +0.9% |\n| **Qwen2.5-7B** | **7.6B** | **2.46** | **2.17** | **+11.8%** |\n| **Qwen3.5-4B** | **3.4B** | **3.04** | **2.31** | **+24.0%** (code domain) |\n| **Qwen3.5-27B** | **23.6B** | **3.07** | **2.96** | **+3.5%** (code, 4-bit, 17GB) |\n\nDomain-specific training (Qwen3.5-4B on code) exceeds generic-text results (Qwen2.5-7B on wikitext) despite being a smaller model.\n\n### MoE Expert Pruning (§4.1.3.4)\n\nCalibration-aware expert activation count pruning. Profile which experts actually fire on a held-out corpus, remove the ones that don't. The surviving experts are the ones the model uses.\n\n| Model | Experts | Kept | PPL (base) | PPL (forged) | Δ | Size (Q4_K_M) |\n|-------|---------|------|-----------|-------------|---|--------------|\n| **[Mixtral 8x7B](https://huggingface.co/continuum-ai/mixtral-8x7b-instruct-compacted-conservative)** | 8 | 6 | 8.14 | **8.97** | +10.2% | **20 GB** |\n| **Mixtral 8x22B** | 8 | 6 | 7.81 | **~8.18** | +4.7% | **60 GB** |\n| [Qwen3-Coder-30B-A3B](https://huggingface.co/continuum-ai/qwen3-coder-30b-a3b-compacted-19b-256k) | 128 | 80 | — | — | — | — |\n\nSame methodology across independently-trained model families. The calibration corpus determines which experts survive — change the corpus, change the specialization. [Full methodology →](https://github.com/CambrianTech/continuum/blob/main/docs/papers/PLASTICITY-COMPACTION.md)\n\n### Continuous Defrag\n\nTraditional pruning masks heads but doesn't free memory. **[Continuous defrag](docs/CONTINUOUS-DEFRAG.md)** structurally removes dead heads between cycles — the model gets physically smaller, freeing VRAM for larger batch sizes. Each cycle trains faster than the last.\n\n```\nCycle 1: train (batch=1, 27B, 17.9GB) → prune → defrag → freed 1.7GB\nCycle 2: train (batch=2, 24.5B, 16.2GB) → prune → defrag → freed 1.7GB  ← 2x faster\nCycle 3: train (batch=3, 22B, 14.5GB)  → prune → defrag                  ← 2.8x faster\n```\n\n**40% faster total training** and a **33% smaller final model** (GGUF Q4: 10GB instead of 15GB for Qwen3.5-27B).\n\n### Self-Directed Plasticity\n\nThe [`AdaptivePlasticityController`](sentinel/plasticity/controller_ann/) observes the model and makes all decisions — pruning ratio, strategy, training budget, stopping criteria. No human hyperparameters.\n\nRecovery from iterative pruning follows a measurable [transfer function](https://github.com/CambrianTech/continuum/blob/main/docs/papers/EXPERIENTIAL-PLASTICITY.md#4-the-transfer-function): `1.45·exp(−0.18·cycle) − 0.03` — connecting transformer optimization to classical control theory.\n\n![Recovery Decay](paper/figures/recovery_decay_fit.png)\n\n## Quick Start: Forge Your Own Model\n\nThree commands. Any NVIDIA GPU with 8GB+ VRAM.\n\n```bash\n# 1. Clone and setup\ngit clone https://github.com/CambrianTech/sentinel-ai.git\ncd sentinel-ai\n./setup.sh                    # Creates venv, installs PyTorch + deps, detects CUDA/MPS\nsource .venv/bin/activate\n\n# 2. Forge (pick your model + domain)\npython scripts/forge_model.py Qwen/Qwen3.5-4B --domain code     # 8GB VRAM, ~30 min\npython scripts/forge_model.py Qwen/Qwen3.5-9B --domain code     # 18GB VRAM, ~45 min\npython scripts/forge_model.py Qwen/Qwen3.5-27B --domain code    # 32GB VRAM (4-bit auto), ~2 hr\n\n# 3. Publish to HuggingFace\npython publish_forged.py output/forged/qwen3.5-4b/ --domain code\n```\n\n**That's it.** The script auto-detects your GPU, picks the right memory tier, trains with LoRA + AMP, prunes attention heads, defrags, saves, and generates proof-of-quality code samples.\n\n### What Happens During Forging\n\n```\nLoad model → Baseline eval → [Train on domain data → Prune low-importance heads →\nDefrag (structurally remove) → Eval] × N cycles → Generate samples → Save\n```\n\n- **Memory tiers**: Tier A (≤40% VRAM, fp16), Tier B (≤70%, fp16+accum), Tier C (\u003e70%, 4-bit)\n- **Observable**: `status.json` updates every 10 steps + inference sample every 200 steps\n- **Early stopping**: `--early-stop 0.5` stops when improvement plateaus\n\n### Manual Setup (if setup.sh doesn't work)\n\n```bash\npython3 -m venv .venv\nsource .venv/bin/activate\npip install torch transformers datasets peft bitsandbytes safetensors accelerate\npip install huggingface_hub   # for publishing\n```\n\n## Run on MacBook M1/M2/M3 (No GPU Required)\n\nDon't have an NVIDIA GPU? Use our pre-forged models. Two commands:\n\n```bash\npip install mlx-lm\n```\n\n```python\nfrom mlx_lm import load, generate\n\n# Load Sonnet 4.6-level model (15GB, runs on 32GB MacBook)\nmodel, tokenizer = load(\"continuum-ai/qwen3.5-27b-code-forged-mlx-4bit\")\n\n# Generate code\nprint(generate(model, tokenizer, prompt=\"def merge_sort(arr):\", max_tokens=200))\n```\n\n**That's it.** 15GB download, ~9 tok/s on M1 32GB. The model writes working code with chain-of-thought reasoning.\n\n### End-to-End: Forge on GPU → Run on Mac\n\nIf you DO have an NVIDIA GPU and want to forge your own:\n\n```bash\n# On your GPU machine (RTX 3090, 4090, 5090, etc.)\ngit clone https://github.com/CambrianTech/sentinel-ai.git\ncd sentinel-ai \u0026\u0026 ./setup.sh \u0026\u0026 source .venv/bin/activate\n\n# Forge (auto-detects GPU, picks memory tier)\npython scripts/forge_model.py Qwen/Qwen3.5-4B --domain code\n\n# Publish to HuggingFace (creates your own model)\npython publish_forged.py output/forged/qwen3.5-4b/ --domain code\n\n# On your MacBook — convert to MLX 4-bit\npip install mlx-lm\npython -c \"from mlx_lm import convert; convert('YOUR_HF_USERNAME/qwen3.5-4b-code-forged', 'mlx-model', quantize=True, q_bits=4)\"\n\n# Run locally\npython -c \"from mlx_lm import load, generate; m,t = load('mlx-model'); print(generate(m,t,prompt='Write a web server:',max_tokens=300))\"\n```\n\n### Classic Experiments\n\n```bash\n# GPT2-medium — combined strategy (best on generic text)\npython scripts/run_neural_plasticity.py \\\n  --model_name gpt2-medium \\\n  --pruning_strategy combined \\\n  --pruning_level 0.3 \\\n  --training_steps 500 \\\n  --cycles 3\n\n# Self-directed — no hyperparameters, controller decides everything\npython experiments/experiment_self_directed.py --model_name gpt2-medium\n```\n\n### Notebooks\n\n| Notebook | Description |\n|----------|-------------|\n| [Neural Plasticity Evidence](paper/NEURAL-PLASTICITY-EVIDENCE.ipynb) | All experimental results with publication figures |\n| [Self-Directed Plasticity](paper/SELF-DIRECTED-PLASTICITY.ipynb) | V1→V2→PID controller evolution with transfer function analysis |\n| [Colab Demo](colab_notebooks/NeuralPlasticityDemo.ipynb) | Run on free Colab T4 GPU [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/CambrianTech/sentinel-ai/blob/main/colab_notebooks/NeuralPlasticityDemo.ipynb) |\n\n## The Model Compiler\n\nforge-alloy + sentinel-ai = a **compiler for neural networks**. You write a recipe (source code), the forge optimizes it for your hardware (target architecture), the benchmarks verify it (test suite), and the attestation proves it (build manifest).\n\n```\nRecipe → Profile → Search → Prune → Quantize → Evaluate → Publish\n         (PGO)    (optimizer)  (dead code    (codegen)   (test)   (ship)\n                                elimination)\n```\n\nThe search is FAST: size filter (instant) → quality estimate (instant) → quick eval (2 min) → full eval (40 min). Only the winning configuration gets the expensive evaluation. Domain specialization comes from the calibration corpus — `-march=coding` prunes experts that don't fire on code. Same source model, different domain, different optimized output.\n\n**Adapters make it extensible.** Every model family, pruning strategy, quantization format, and benchmark is an adapter. New model released? Write an adapter. New hardware target? Write a quant adapter. New training technique? Write a stage adapter. The community contributes adapters, the compiler integrates them. [Full architecture →](https://github.com/CambrianTech/forge-alloy/blob/main/docs/MODEL-COMPILER.md)\n\n## The Factory Pipeline\n\nSentinel-AI is the forge. The factory pipeline turns it into an\n**assembly line** for model production: drop a recipe alloy at the\nintake station, BigMama (or any single-GPU box) builds it through the\nfamily-adapter set, assays it against every benchmark it's eligible for,\nand parks the finished artifact in the shipping bay. **Continuum is the\nshipping department** — it reads `finished/`, applies its release gates,\nand publishes to HuggingFace. Sentinel never pushes to HF; that's a\ndeliberate architectural boundary.\n\n```\n                                       ┌──────────────────────────┐\n                                       │  .factory/line/          │\n                  drop alloy here  →   │    intake/               │  ← cp my-recipe.alloy.json here\n                                       │    assembly/  ← worker   │\n                                       │    finished/  ← shipping │  ← continuum reads here\n                                       │    rework/    ← QA flag  │\n                                       └────────────┬─────────────┘\n                                                    │\n                                                    ▼\n                                       FactoryWorker.process_one()\n                                                    │\n                                   ┌────────────────┴────────────────┐\n                                   ▼                                 ▼\n                          alloy_executor                       eval_runners\n                          .execute_alloy()                   (registry dispatch)\n                                   │                                 ▲\n                                   │                                 │\n                            family-adapter                  resolve_runner(name)\n                            dispatch (16 adapters)                   │\n                            → MoEUnfusedExpertsBase                  │\n                            → MixtralAdapter                         │\n                            → PhiMoEAdapter (inherits)               │\n                            → DeepSeekV2Adapter                      │\n                            → QwenVLAdapter                          │\n                            → ... 11 more                            │\n                                   │                                 │\n                                   ▼                                 │\n                            forged artifact  ──── assay (eval) ──→  9 real benchmark runners:\n                                   │                                 HumanEval, HumanEval+,\n                                   │                                 LCB v6, IFEval, BBH,\n                                   │                                 MATH-Hard, GPQA,\n                                   ▼                                 MMLU-Pro, MuSR\n                            mark_finished()                          (Open LLM Leaderboard v2 pack)\n                                   │\n                                   ▼\n                            .factory/line/finished/  ──→  CONTINUUM (shipping department)\n                                                          • reads result manifest\n                                                          • applies release gates\n                                                          • pushes to HF\n                                                          • posts model card\n```\n\n**Two-axis dispatch:**\n\n- **Axis 1 — `source.architecture` → FamilyAdapter.** Each model family\n  is one file in `scripts/adapters/` (16 adapters today). Adding a new\n  family is one new file plus one import line. Old families stay frozen\n  forever so older alloys reproduce bit-identically.\n- **Axis 2 — benchmark name → BenchmarkRunner.** Each benchmark is one\n  file in `scripts/eval_runners/` (9 real, 12 stubs). Adding a new\n  benchmark is one new file. The §4.1.4.1 anchor-reproduction discipline\n  gate routes through the same registry.\n\n**Sending BigMama a part to build:**\n\n```bash\ncp my-recipe.alloy.json /path/to/.factory/line/intake/\npython -m factory_queue --root /path/to/.factory --max-iters 1\n```\n\nThe worker picks the part off `intake/`, moves it to `assembly/`, runs\n`execute_alloy` (which dispatches to the right family adapter), executes\neach stage including `eval` (registry-dispatched), and on success moves\nthe alloy to `finished/` with a `.result.json` sidecar pointing at the\non-disk forged artifact and the eval results. On any failure the part\ngoes to `rework/` with a `.error.json` sidecar carrying the full\ntraceback — no silent defaults, no retries on broken state.\n\n**The filesystem IS the queue.** No DB, no service, no network\ncoordination. Multi-worker safety comes free if you ever need to scale\nbeyond a single GPU (atomic `intake → assembly` rename via `O_EXCL`).\nContinuum's shipping department picks parts off `finished/`, applies\nrelease gates, and publishes — separate from the assembly line, separate\nprocess, separate auth scope.\n\n## Papers\n\n- **[Experiential Plasticity](https://github.com/CambrianTech/continuum/blob/main/docs/papers/EXPERIENTIAL-PLASTICITY.md)** — Scaling law, transfer function, self-directed controller, domain forging, continuous defrag\n- **[Neural Plasticity in Transformers](https://github.com/CambrianTech/continuum/blob/main/docs/papers/SENTINEL-AI-NEURAL-PLASTICITY.md)** — Foundation paper: cross-architecture results, four-phase cycle, hypothetical training cost analysis\n- **[Plasticity Compaction](https://github.com/CambrianTech/continuum/blob/main/docs/papers/PLASTICITY-COMPACTION-MOE.md)** — MoE expert pruning (67GB → 14GB)\n\n## Architecture\n\n```\nsentinel-ai/\n├── scripts/\n│   ├── forge_model.py              # Domain-specific forging (Qwen3.5, LoRA, AMP)\n│   ├── defrag_model.py             # Post-processing structural pruning\n│   ├── defrag_inline.py            # Live in-place defrag during training\n│   └── run_neural_plasticity.py    # Classic experiment runner\n├── sentinel/\n│   ├── plasticity/                 # Plasticity loop, controllers, sleep cycle\n│   ├── pruning/                    # Pruning strategies (entropy, gradient, combined)\n│   └── models/                     # Adaptive transformer, head cloning\n├── docs/\n│   └── CONTINUOUS-DEFRAG.md        # Defrag architecture\n├── paper/                          # Notebooks and figures\n└── output/                         # Experiment results, forged models\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcambriantech%2Fsentinel-ai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcambriantech%2Fsentinel-ai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcambriantech%2Fsentinel-ai/lists"}