Add dark-mode architecture diagram and update README (generate_architecture_diagram.py)
Browse files- generate_architecture_diagram.py +246 -0
generate_architecture_diagram.py
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
MarsNext Phobos-1 — Dark-Mode Technical Architecture Blueprint Generator
|
| 4 |
+
(`phobos-1/models/phobos_scratch_v1/generate_architecture_diagram.py`)
|
| 5 |
+
========================================================================
|
| 6 |
+
Generates a high-resolution 3-column dark-mode SVG & PNG architecture diagram
|
| 7 |
+
(`phobos-1/assets/phobos1_architecture_diagram.svg` and `.png`) illustrating:
|
| 8 |
+
- Column 1: End-to-End 8-Layer Cortical Stack (`L0-L4` Lower Cortex + `L5-L7` Upper Cortex,
|
| 9 |
+
`Engram` Memory at `L1`/`L5`, and Dual `t+1` LM + `t+2` MTP Output Heads)
|
| 10 |
+
- Column 2: Inside One `PhobosCorticalBlock` (`Causal QK-Conv + GQA + RoPE`, `Engram`,
|
| 11 |
+
`SigmoidHC` Highway Gate, and `Shared E00 + Cortical MoE` Parallel Split)
|
| 12 |
+
- Column 3: 2-Stage Spherical Cortical Router (`4` Domain Branches -> `Top-2 of 16` Specialist
|
| 13 |
+
Leaves) & Online SVD Spherical Mitosis (`Parent -> Child +δ / -δ`)
|
| 14 |
+
|
| 15 |
+
Strictly <= 290 lines (`RULE[user_global]`).
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
from __future__ import annotations
|
| 19 |
+
|
| 20 |
+
from pathlib import Path
|
| 21 |
+
from typing import List
|
| 22 |
+
|
| 23 |
+
_THIS_DIR = Path(__file__).resolve().parent
|
| 24 |
+
_ROOT_DIR = _THIS_DIR.parent.parent
|
| 25 |
+
ASSETS_DIR = _ROOT_DIR / "assets"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def build_architecture_svg() -> str:
|
| 29 |
+
"""Renders the 1600x860 dark-mode SVG architecture diagram for `MarsNext Phobos-1`."""
|
| 30 |
+
w, h = 1600, 860
|
| 31 |
+
s: List[str] = [
|
| 32 |
+
f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {w} {h}" width="{w}" height="{h}">',
|
| 33 |
+
"<defs>",
|
| 34 |
+
' <linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">',
|
| 35 |
+
' <stop offset="0%" stop-color="#0b0d12"/>',
|
| 36 |
+
' <stop offset="100%" stop-color="#07090d"/>',
|
| 37 |
+
" </linearGradient>",
|
| 38 |
+
' <linearGradient id="emeraldGrad" x1="0" y1="0" x2="1" y2="1">',
|
| 39 |
+
' <stop offset="0%" stop-color="#10b981" stop-opacity="0.24"/>',
|
| 40 |
+
' <stop offset="100%" stop-color="#064e3b" stop-opacity="0.32"/>',
|
| 41 |
+
" </linearGradient>",
|
| 42 |
+
' <linearGradient id="tealGrad" x1="0" y1="0" x2="1" y2="1">',
|
| 43 |
+
' <stop offset="0%" stop-color="#0d9488" stop-opacity="0.22"/>',
|
| 44 |
+
' <stop offset="100%" stop-color="#134e4a" stop-opacity="0.30"/>',
|
| 45 |
+
" </linearGradient>",
|
| 46 |
+
' <linearGradient id="purpleGrad" x1="0" y1="0" x2="1" y2="1">',
|
| 47 |
+
' <stop offset="0%" stop-color="#6366f1" stop-opacity="0.22"/>',
|
| 48 |
+
' <stop offset="100%" stop-color="#312e81" stop-opacity="0.30"/>',
|
| 49 |
+
" </linearGradient>",
|
| 50 |
+
' <linearGradient id="coralGrad" x1="0" y1="0" x2="1" y2="1">',
|
| 51 |
+
' <stop offset="0%" stop-color="#e07a5f" stop-opacity="0.24"/>',
|
| 52 |
+
' <stop offset="100%" stop-color="#7c2d12" stop-opacity="0.30"/>',
|
| 53 |
+
" </linearGradient>",
|
| 54 |
+
' <linearGradient id="amberGrad" x1="0" y1="0" x2="1" y2="1">',
|
| 55 |
+
' <stop offset="0%" stop-color="#f59e0b" stop-opacity="0.22"/>',
|
| 56 |
+
' <stop offset="100%" stop-color="#78350f" stop-opacity="0.30"/>',
|
| 57 |
+
" </linearGradient>",
|
| 58 |
+
' <marker id="arrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">',
|
| 59 |
+
' <path d="M 0 1 L 10 5 L 0 9 z" fill="#64748b"/>',
|
| 60 |
+
" </marker>",
|
| 61 |
+
' <marker id="arrowEm" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">',
|
| 62 |
+
' <path d="M 0 1 L 10 5 L 0 9 z" fill="#10b981"/>',
|
| 63 |
+
" </marker>",
|
| 64 |
+
' <marker id="arrowCoral" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">',
|
| 65 |
+
' <path d="M 0 1 L 10 5 L 0 9 z" fill="#e07a5f"/>',
|
| 66 |
+
" </marker>",
|
| 67 |
+
"</defs>",
|
| 68 |
+
f'<rect width="{w}" height="{h}" fill="url(#bg)"/>',
|
| 69 |
+
# Header Bar
|
| 70 |
+
'<text x="36" y="36" fill="#f8fafc" font-family="Inter, -apple-system, sans-serif" font-size="20" font-weight="700">MarsNext Phobos-1 — Hierarchical Cortical MoE & Dynamic SVD Mitosis Architecture</text>',
|
| 71 |
+
'<text x="36" y="58" fill="#94a3b8" font-family="Inter, -apple-system, sans-serif" font-size="13.5" font-weight="500">96,256,569 Total Params (215.84 MiB BF16) • 52,216,377 Active Params / Token (54.2%) • 8 Cortical Layers (d_model = 512, ctx = 2048)</text>',
|
| 72 |
+
f'<rect x="22" y="72" width="{w - 44}" height="{h - 92}" rx="14" fill="#0d1017" stroke="#1e2433" stroke-width="1.5"/>',
|
| 73 |
+
]
|
| 74 |
+
|
| 75 |
+
# =========================================================================
|
| 76 |
+
# COLUMN 1: MACRO 8-LAYER CORTICAL BACKBONE (x = 46..486)
|
| 77 |
+
# =========================================================================
|
| 78 |
+
s += [
|
| 79 |
+
'<rect x="44" y="92" width="445" height="726" rx="10" fill="#10141d" stroke="#1f2937" stroke-width="1.2"/>',
|
| 80 |
+
'<text x="64" y="122" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="16" font-weight="700">1. Macro Cortical Stack (8 Layers)</text>',
|
| 81 |
+
'<text x="64" y="142" fill="#64748b" font-family="Inter, sans-serif" font-size="12">End-to-End Token Flow: Input BPE → Lower/Upper Cortex → Dual Heads</text>',
|
| 82 |
+
# Input BPE Box
|
| 83 |
+
'<rect x="68" y="162" width="396" height="62" rx="8" fill="#151b26" stroke="#334155" stroke-width="1.2"/>',
|
| 84 |
+
'<text x="266" y="187" text-anchor="middle" fill="#f8fafc" font-family="Inter, sans-serif" font-size="14" font-weight="700">32,768 Byte-Level BPE Tokenizer + Tied Embedding</text>',
|
| 85 |
+
'<text x="266" y="208" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="12"><|bos|> <|user|> <|assistant|> <think> </think> • E ∈ R^(32768 × 512)</text>',
|
| 86 |
+
'<line x1="266" y1="224" x2="266" y2="250" stroke="#64748b" stroke-width="1.8" marker-end="url(#arrow)"/>',
|
| 87 |
+
# Lower Cortex L0-L4
|
| 88 |
+
'<rect x="68" y="254" width="396" height="156" rx="8" fill="url(#tealGrad)" stroke="#0d9488" stroke-width="1.4"/>',
|
| 89 |
+
'<text x="86" y="280" fill="#5eead4" font-family="Inter, sans-serif" font-size="14" font-weight="700">Lower Sensory & Syntax Cortex (Layers L0 – L4)</text>',
|
| 90 |
+
'<text x="86" y="300" fill="#cbd5e1" font-family="Inter, sans-serif" font-size="12">• 5x Cortical Blocks (GQA + Shared E00 + 4 Branches × 16 Leaves)</text>',
|
| 91 |
+
'<text x="86" y="320" fill="#cbd5e1" font-family="Inter, sans-serif" font-size="12">• Frozen during 60-Book Post-Training to lock syntax & factual base</text>',
|
| 92 |
+
'<rect x="86" y="334" width="360" height="60" rx="6" fill="#0f172a" stroke="#38bdf8" stroke-width="1.1"/>',
|
| 93 |
+
'<text x="266" y="357" text-anchor="middle" fill="#38bdf8" font-family="Inter, sans-serif" font-size="12.5" font-weight="700">DeepInferEngramMemory Injected at L1 & L5</text>',
|
| 94 |
+
'<text x="266" y="377" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11.5">Deterministic 2-gram & 3-gram XOR Hash Table (O(1) Fact Lookup)</text>',
|
| 95 |
+
'<line x1="266" y1="410" x2="266" y2="438" stroke="#10b981" stroke-width="1.8" marker-end="url(#arrowEm)"/>',
|
| 96 |
+
# Upper Cortex L5-L7
|
| 97 |
+
'<rect x="68" y="442" width="396" height="152" rx="8" fill="url(#emeraldGrad)" stroke="#10b981" stroke-width="1.6"/>',
|
| 98 |
+
'<text x="86" y="468" fill="#34d399" font-family="Inter, sans-serif" font-size="14" font-weight="700">Upper Executive Reasoning Cortex (Layers L5 – L7)</text>',
|
| 99 |
+
'<text x="86" y="489" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12">• 3x High-Level Abstract Reasoning & Code Synthesis Blocks</text>',
|
| 100 |
+
'<text x="86" y="509" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12">• Refined on 60 Textbooks (114,858 examples) + 50/50 Base Replay</text>',
|
| 101 |
+
'<text x="86" y="529" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12">• Protected by 0.35 × KL(P_base || P_post) Self-Distillation Anchor</text>',
|
| 102 |
+
'<text x="86" y="549" fill="#a7f3d0" font-family="Inter, sans-serif" font-size="11.5" font-weight="600">• Selectivity Mask (S_i): Freezes Fact Neurons, Trains Logic</text>',
|
| 103 |
+
'<line x1="200" y1="594" x2="165" y2="630" stroke="#10b981" stroke-width="1.8" marker-end="url(#arrowEm)"/>',
|
| 104 |
+
'<line x1="332" y1="594" x2="367" y2="630" stroke="#e07a5f" stroke-width="1.8" marker-end="url(#arrowCoral)"/>',
|
| 105 |
+
# Dual Output Heads
|
| 106 |
+
'<rect x="68" y="634" width="190" height="96" rx="8" fill="#132220" stroke="#10b981" stroke-width="1.4"/>',
|
| 107 |
+
'<text x="163" y="659" text-anchor="middle" fill="#34d399" font-family="Inter, sans-serif" font-size="13.5" font-weight="700">Causal LM Head (t + 1)</text>',
|
| 108 |
+
'<text x="163" y="679" text-anchor="middle" fill="#cbd5e1" font-family="Inter, sans-serif" font-size="11.5">RMSNorm + Tied W_emb^T</text>',
|
| 109 |
+
'<text x="163" y="698" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11">Direct Mode (mask <think>)</text>',
|
| 110 |
+
'<text x="163" y="714" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11">or System-2 <think> Mode</text>',
|
| 111 |
+
'<rect x="274" y="634" width="190" height="96" rx="8" fill="url(#coralGrad)" stroke="#e07a5f" stroke-width="1.4"/>',
|
| 112 |
+
'<text x="369" y="659" text-anchor="middle" fill="#f4a261" font-family="Inter, sans-serif" font-size="13.5" font-weight="700">DeepInfer MTP (t + 2)</text>',
|
| 113 |
+
'<text x="369" y="679" text-anchor="middle" fill="#cbd5e1" font-family="Inter, sans-serif" font-size="11.5">Multi-Token Lookahead Head</text>',
|
| 114 |
+
'<text x="369" y="698" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11">Predicts token (t+2) during</text>',
|
| 115 |
+
'<text x="369" y="714" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11">training for planning depth</text>',
|
| 116 |
+
# Bottom Telemetry Pill
|
| 117 |
+
'<rect x="68" y="746" width="396" height="52" rx="7" fill="#0b0e14" stroke="#1e293b" stroke-width="1"/>',
|
| 118 |
+
'<text x="266" y="768" text-anchor="middle" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12.5" font-weight="600">100% Curriculum: 33,977 Steps • 3.63M Sequences • 1.56B Tokens</text>',
|
| 119 |
+
'<text x="266" y="787" text-anchor="middle" fill="#10b981" font-family="Inter, sans-serif" font-size="12" font-weight="600">Val PPL: 14.03 → 5.36 | Held-Out Fact PPL: 1.98 | Gen-25: 80.0%</text>',
|
| 120 |
+
]
|
| 121 |
+
|
| 122 |
+
# =========================================================================
|
| 123 |
+
# COLUMN 2: INSIDE ONE PHOBOS CORTICAL BLOCK (x = 510..1030)
|
| 124 |
+
# =========================================================================
|
| 125 |
+
s += [
|
| 126 |
+
'<rect x="510" y="92" width="516" height="726" rx="10" fill="#10141d" stroke="#1f2937" stroke-width="1.2"/>',
|
| 127 |
+
'<text x="530" y="122" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="16" font-weight="700">2. Inside One PhobosCorticalBlock (Layer l)</text>',
|
| 128 |
+
'<text x="530" y="142" fill="#64748b" font-family="Inter, sans-serif" font-size="12">Hybrid Attention + Sigmoid Highway + Parallel Shared/Specialist MoE</text>',
|
| 129 |
+
# Block Input h^(l-1)
|
| 130 |
+
'<rect x="658" y="160" width="220" height="36" rx="6" fill="#161d2a" stroke="#475569" stroke-width="1.1"/>',
|
| 131 |
+
'<text x="768" y="183" text-anchor="middle" fill="#f1f5f9" font-family="Inter, sans-serif" font-size="13" font-weight="600">Hidden State h^(l-1) ∈ R^(B × T × 512)</text>',
|
| 132 |
+
'<line x1="768" y1="196" x2="768" y2="222" stroke="#64748b" stroke-width="1.8" marker-end="url(#arrow)"/>',
|
| 133 |
+
# Causal QK-Conv + GQA Attention
|
| 134 |
+
'<rect x="538" y="226" width="460" height="104" rx="8" fill="url(#purpleGrad)" stroke="#818cf8" stroke-width="1.4"/>',
|
| 135 |
+
'<text x="768" y="252" text-anchor="middle" fill="#a5b4fc" font-family="Inter, sans-serif" font-size="14" font-weight="700">RMSNorm → Causal QK-Conv (w=8) + Grouped-Query Attention</text>',
|
| 136 |
+
'<text x="768" y="274" text-anchor="middle" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12">• Depth-wise Causal Conv1D (kernel = 8) on Q & K for local n-gram sharpness</text>',
|
| 137 |
+
'<text x="768" y="294" text-anchor="middle" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12">• 8 Query Heads, 4 KV Heads (head_dim = 64) + 1D Rotary Embeddings (RoPE)</text>',
|
| 138 |
+
'<text x="768" y="314" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11.5">+ Residual Add + Optional DeepInferEngramMemory (at L1 & L5)</text>',
|
| 139 |
+
'<line x1="768" y1="330" x2="768" y2="356" stroke="#64748b" stroke-width="1.8" marker-end="url(#arrow)"/>',
|
| 140 |
+
# SigmoidHCBlockMixin Highway
|
| 141 |
+
'<rect x="578" y="360" width="380" height="50" rx="7" fill="#172030" stroke="#38bdf8" stroke-width="1.2"/>',
|
| 142 |
+
'<text x="768" y="382" text-anchor="middle" fill="#7dd3fc" font-family="Inter, sans-serif" font-size="13" font-weight="700">SigmoidHCBlockMixin Residual Highway Gate</text>',
|
| 143 |
+
'<text x="768" y="400" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11.5">u = h + σ(g_hc) ⊙ (h − h_in) • Stabilizes deep gradient flow</text>',
|
| 144 |
+
# Split into Shared E00 (Left) and Cortical Router (Right)
|
| 145 |
+
'<line x1="680" y1="410" x2="635" y2="454" stroke="#64748b" stroke-width="1.8" marker-end="url(#arrow)"/>',
|
| 146 |
+
'<line x1="856" y1="410" x2="900" y2="454" stroke="#10b981" stroke-width="1.8" marker-end="url(#arrowEm)"/>',
|
| 147 |
+
# Shared E00 Box (Left)
|
| 148 |
+
'<rect x="536" y="458" width="210" height="176" rx="8" fill="#161f2c" stroke="#64748b" stroke-width="1.4"/>',
|
| 149 |
+
'<text x="641" y="484" text-anchor="middle" fill="#f8fafc" font-family="Inter, sans-serif" font-size="13.5" font-weight="700">Always-Active Shared E00</text>',
|
| 150 |
+
'<text x="641" y="504" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="12">(Universal Trunk Expert)</text>',
|
| 151 |
+
'<rect x="554" y="520" width="174" height="54" rx="6" fill="#0f1520" stroke="#334155" stroke-width="1"/>',
|
| 152 |
+
'<text x="641" y="543" text-anchor="middle" fill="#cbd5e1" font-family="Inter, sans-serif" font-size="12" font-weight="600">SwiGLU MLP (d_ff = 1,024)</text>',
|
| 153 |
+
'<text x="641" y="562" text-anchor="middle" fill="#64748b" font-family="Inter, sans-serif" font-size="11">100% tokens pass through E00</text>',
|
| 154 |
+
'<text x="641" y="600" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11.5">Captures syntax, grammar &</text>',
|
| 155 |
+
'<text x="641" y="617" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11.5">cross-domain primitives</text>',
|
| 156 |
+
# Cortical Router Box (Right)
|
| 157 |
+
'<rect x="762" y="458" width="240" height="176" rx="8" fill="url(#emeraldGrad)" stroke="#10b981" stroke-width="1.6"/>',
|
| 158 |
+
'<text x="882" y="484" text-anchor="middle" fill="#34d399" font-family="Inter, sans-serif" font-size="13.5" font-weight="700">2-Stage Cortical MoE</text>',
|
| 159 |
+
'<text x="882" y="504" text-anchor="middle" fill="#a7f3d0" font-family="Inter, sans-serif" font-size="11.5">Spherical Cosine Router (τ = 0.14)</text>',
|
| 160 |
+
'<text x="882" y="526" text-anchor="middle" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12">1. Causal Context Pool (W = 16)</text>',
|
| 161 |
+
'<text x="882" y="546" text-anchor="middle" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12">2. Top-1 Branch (of 4 Lobes)</text>',
|
| 162 |
+
'<text x="882" y="566" text-anchor="middle" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12">3. Top-2 Specialist Leaves (of 16)</text>',
|
| 163 |
+
'<text x="882" y="592" text-anchor="middle" fill="#34d399" font-family="Inter, sans-serif" font-size="11.5" font-weight="700">2 × SwiGLU Leaves (d_ff = 256)</text>',
|
| 164 |
+
'<text x="882" y="614" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11">Only 2 of 16 leaves active/token!</text>',
|
| 165 |
+
# Merge into Block Output
|
| 166 |
+
'<line x1="641" y1="634" x2="725" y2="682" stroke="#64748b" stroke-width="1.8" marker-end="url(#arrow)"/>',
|
| 167 |
+
'<line x1="882" y1="634" x2="810" y2="682" stroke="#10b981" stroke-width="1.8" marker-end="url(#arrowEm)"/>',
|
| 168 |
+
'<rect x="578" y="686" width="380" height="54" rx="8" fill="#161d2a" stroke="#10b981" stroke-width="1.3"/>',
|
| 169 |
+
'<text x="768" y="710" text-anchor="middle" fill="#f8fafc" font-family="Inter, sans-serif" font-size="13.5" font-weight="700">Cortical Fusion: h^(l) = u + E00(u) + ∑ w_k · Leaf_k(u)</text>',
|
| 170 |
+
'<text x="768" y="729" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11.5">Combines universal trunk E00 with 2 domain-specialized leaf experts</text>',
|
| 171 |
+
# Bottom note
|
| 172 |
+
'<rect x="538" y="754" width="460" height="44" rx="7" fill="#0b0e14" stroke="#1e293b" stroke-width="1"/>',
|
| 173 |
+
'<text x="768" y="781" text-anchor="middle" fill="#cbd5e1" font-family="Inter, sans-serif" font-size="12">Routing Accuracy at Step 33,977: Branch = 75.5% (77.1% Peak) • Leaf = 66.3% (67.6% Peak)</text>',
|
| 174 |
+
]
|
| 175 |
+
|
| 176 |
+
# =========================================================================
|
| 177 |
+
# COLUMN 3: 4 CORTICAL LOBES & DYNAMIC SVD MITOSIS (x = 1050..1556)
|
| 178 |
+
# =========================================================================
|
| 179 |
+
s += [
|
| 180 |
+
'<rect x="1050" y="92" width="506" height="726" rx="10" fill="#10141d" stroke="#1f2937" stroke-width="1.2"/>',
|
| 181 |
+
'<text x="1070" y="122" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="16" font-weight="700">3. Cortical Lobes & Online SVD Mitosis</text>',
|
| 182 |
+
'<text x="1070" y="142" fill="#64748b" font-family="Inter, sans-serif" font-size="12">4 Functional Branches → 16 Specialist Leaves/Layer (44 Mitosis Splits)</text>',
|
| 183 |
+
]
|
| 184 |
+
|
| 185 |
+
# 4 Cortical Branches Grid
|
| 186 |
+
branches = [
|
| 187 |
+
("B0: Language & Dialogue", "narratives, dialogue, chat", "#38bdf8", 1072, 162),
|
| 188 |
+
("B1: Code & Software", "Python, SQL, JS, algorithms", "#10b981", 1308, 162),
|
| 189 |
+
("B2: Math & Formal Logic", "algebra, calculus, <think>", "#f59e0b", 1072, 236),
|
| 190 |
+
("B3: Natural Sciences", "biology, chemistry, physics", "#c084fc", 1308, 236),
|
| 191 |
+
]
|
| 192 |
+
for b_title, b_sub, b_col, bx, by in branches:
|
| 193 |
+
s += [
|
| 194 |
+
f'<rect x="{bx}" y="{by}" width="224" height="62" rx="7" fill="#141a26" stroke="{b_col}" stroke-width="1.3"/>',
|
| 195 |
+
f'<text x="{bx + 12}" y="{by + 25}" fill="{b_col}" font-family="Inter, sans-serif" font-size="13" font-weight="700">{b_title}</text>',
|
| 196 |
+
f'<text x="{bx + 12}" y="{by + 45}" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11">4 Leaves • {b_sub}</text>',
|
| 197 |
+
]
|
| 198 |
+
|
| 199 |
+
# Online SVD Spherical Mitosis Diagram Box
|
| 200 |
+
s += [
|
| 201 |
+
'<rect x="1072" y="318" width="460" height="290" rx="9" fill="url(#amberGrad)" stroke="#f59e0b" stroke-width="1.4"/>',
|
| 202 |
+
'<text x="1302" y="345" text-anchor="middle" fill="#fbbf24" font-family="Inter, sans-serif" font-size="14.5" font-weight="700">Online SVD Spherical Mitosis (8 → 16 Leaves / Layer)</text>',
|
| 203 |
+
'<text x="1302" y="365" text-anchor="middle" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="11.5">Triggered when a leaf specialist becomes overloaded (Load > 1.8× & High Grad Variance)</text>',
|
| 204 |
+
# Parent Leaf Box
|
| 205 |
+
'<rect x="1182" y="382" width="240" height="50" rx="7" fill="#171c28" stroke="#fbbf24" stroke-width="1.3"/>',
|
| 206 |
+
'<text x="1302" y="404" text-anchor="middle" fill="#fef3c7" font-family="Inter, sans-serif" font-size="12.5" font-weight="700">Overloaded Parent Leaf k</text>',
|
| 207 |
+
'<text x="1302" y="422" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11">W_down = U Σ V^T (Top Singular Vec u_1)</text>',
|
| 208 |
+
# Split arrows
|
| 209 |
+
'<line x1="1252" y1="432" x2="1182" y2="476" stroke="#fbbf24" stroke-width="1.8" marker-end="url(#arrow)"/>',
|
| 210 |
+
'<line x1="1352" y1="432" x2="1422" y2="476" stroke="#fbbf24" stroke-width="1.8" marker-end="url(#arrow)"/>',
|
| 211 |
+
# Child A & Child B
|
| 212 |
+
'<rect x="1092" y="480" width="190" height="64" rx="7" fill="#121824" stroke="#34d399" stroke-width="1.3"/>',
|
| 213 |
+
'<text x="1187" y="503" text-anchor="middle" fill="#34d399" font-family="Inter, sans-serif" font-size="12.5" font-weight="700">Child Leaf A (+δ u_1)</text>',
|
| 214 |
+
'<text x="1187" y="521" text-anchor="middle" fill="#cbd5e1" font-family="Inter, sans-serif" font-size="11">W_A = 0.5 · W + δ(u_1 v_1^T)</text>',
|
| 215 |
+
'<text x="1187" y="536" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="10.5">Specializes in Sub-Cluster +</text>',
|
| 216 |
+
'<rect x="1322" y="480" width="190" height="64" rx="7" fill="#121824" stroke="#38bdf8" stroke-width="1.3"/>',
|
| 217 |
+
'<text x="1417" y="503" text-anchor="middle" fill="#38bdf8" font-family="Inter, sans-serif" font-size="12.5" font-weight="700">Child Leaf B (−δ u_1)</text>',
|
| 218 |
+
'<text x="1417" y="521" text-anchor="middle" fill="#cbd5e1" font-family="Inter, sans-serif" font-size="11">W_B = 0.5 · W − δ(u_1 v_1^T)</text>',
|
| 219 |
+
'<text x="1417" y="536" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="10.5">Specializes in Sub-Cluster −</text>',
|
| 220 |
+
'<text x="1302" y="572" text-anchor="middle" fill="#fde68a" font-family="Inter, sans-serif" font-size="12" font-weight="600">Zero-Shock Identity: Child_A(x) + Child_B(x) == Parent(x)</text>',
|
| 221 |
+
'<text x="1302" y="592" text-anchor="middle" fill="#94a3b8" font-family="Inter, sans-serif" font-size="11.5">Grew from 64 initial leaves (8/layer) → 128 final leaves (16/layer)</text>',
|
| 222 |
+
# Parameter Efficiency Summary Box
|
| 223 |
+
'<rect x="1072" y="624" width="460" height="174" rx="9" fill="#131924" stroke="#10b981" stroke-width="1.4"/>',
|
| 224 |
+
'<text x="1092" y="652" fill="#34d399" font-family="Inter, sans-serif" font-size="14.5" font-weight="700">Parameter & Memory Budget Breakdown</text>',
|
| 225 |
+
'<text x="1092" y="678" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12.5">• Tied BPE Embedding + LM Head: 16.78M params (Active)</text>',
|
| 226 |
+
'<text x="1092" y="700" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12.5">• 8x GQA Attention + QK-Conv + Gates: 8.42M params (Active)</text>',
|
| 227 |
+
'<text x="1092" y="722" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12.5">• 8x Shared E00 Trunk (d_ff=1024): 12.58M params (Active)</text>',
|
| 228 |
+
'<text x="1092" y="744" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12.5">• 128x Specialist Leaves (16/layer): 50.33M total (6.29M Active/tok)</text>',
|
| 229 |
+
'<text x="1092" y="766" fill="#e2e8f0" font-family="Inter, sans-serif" font-size="12.5">• DeepInfer Engram (L1, L5) + MTP: 8.15M params</text>',
|
| 230 |
+
'<text x="1092" y="788" fill="#10b981" font-family="Inter, sans-serif" font-size="12.5" font-weight="700">Total = 96.26M Params (215.8 MiB) | Active = 52.22M / Token (54.2%)</text>',
|
| 231 |
+
]
|
| 232 |
+
|
| 233 |
+
s.append("</svg>")
|
| 234 |
+
return "\n".join(s)
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
def main() -> None:
|
| 238 |
+
ASSETS_DIR.mkdir(parents=True, exist_ok=True)
|
| 239 |
+
svg_str = build_architecture_svg()
|
| 240 |
+
svg_path = ASSETS_DIR / "phobos1_architecture_diagram.svg"
|
| 241 |
+
svg_path.write_text(svg_str, encoding="utf-8")
|
| 242 |
+
print(f"[Generated Architecture SVG] {svg_path} ({len(svg_str):,} bytes)", flush=True)
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
if __name__ == "__main__":
|
| 246 |
+
main()
|