Skip to content

Latest commit

 

History

2,407 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BRIAN — Biologically Realistic Information Architecture Network

146.9M trainable-param bowtie trunk · ~980M frozen cortex experts · exploring integrated information (Φ).

tests python torch license cortex-fusion formal-gate

BRIAN is a research prototype that bets on topology, Φ-coupled plasticity, and closed-loop embodiment instead of raw parameter count. The core question: does a strategically-wired 146.9M-param trunk outgeneralize a flat 100M transformer on OOD tasks?

Current verdict: 🟡 inconclusive — best variant B4 achieves 2.87 gap_ratio (53% better than flat-transformer baseline at 6.12), but matched-compute comparison is still pending. The apparatus to run it landed as H59: architectures/control-100m (a param-matched vanilla control arm trained by the same pipeline, data, and recipe) plus eval protocol v2 — trunk-only evaluation on every surface, a held-out train-distribution gap denominator (gap_v2), a PG-19 second OOD axis, and per-sequence NLLs gated by brian ood compare's Welch's-t test.


What it does

BRIAN combines five mechanisms into a single differentiable training loop:

Pillar What it is Verified
11-stage bowtie + re-entry loops Two re-entry paths enforce non-zero integrated information Φ ✅ H1
Differentiable Φ objective Gaussian-MI MIP pushes gradients toward integrated states ✅ H2–H3
Sheaf H¹ contradiction detection Narrative memory detects and resolves conflicting beliefs ✅ H4–H5
Embodied survival loop GridWorld 10×10 with homeostatic drive shapes qualia and policy ✅ H6.5
Multi-cortex fusion 3 frozen LM experts distil into the bowtie trunk via KL + NT-gated α ✅ H16–H21

Full architecture spec and tensor shapes: docs/architecture.md.


Implemented Mechanics

BRIAN currently composes 18 named mechanisms drawn from neuroscience, dynamical systems, and information geometry. Every entry below is:

  • a first-class DSL primitive — wires into any .neuro arch through a single block (nfo: { … }, grid_positions: { … }, …);
  • ReZero-disciplined — a zero-init read-out / alpha_init=0 makes the first forward bit-identical to a vanilla transformer, so additions never regress the baseline at step 0;
  • hypothesis-backed — every mechanism cites an entry in hypothesis/ with a formal claim, code refs, test refs, and (where available) a Lean theorem.

🌀 Topology & Geometric Substrate

Neural Field Oscillator — H15 · H16 · H17 · H18

$$ \dot\varphi_i = \omega_i + \sum_j \kappa_{ij}, A_j,\sin(\varphi_j - \varphi_i), \qquad \dot A_i = \mu, A_i - \tfrac14,(A_i^2 - A_\star^2), A_i $$ $$ \Phi_\kappa(t) = \sum_{(i,j),\in, E_{\mathrm{cut}}} \kappa_{ij}, A_i(t), A_j(t), \qquad y = h + \alpha,\mathrm{ReadOut}!\bigl(g\odot A\odot \cos(\varphi-\psi)\bigr) $$

A Kuramoto graph (binding-by-synchrony) coupled to a Swift–Hohenberg cubic-quintic amplitude flow with Lyapunov $V(A)=\tfrac18(A^2-A_+^2)^2$. The topological coherence functional $\Phi_\kappa$ is a closed-form lower bound on integrated information (H15) and a unit-interval information-preserving gate (H16). Read-out is ReZero so the block earns capacity only under LM gradient pressure (H18). Source: neuroslm/modules/neural_field_oscillator.py · lib/blocks/neural_field_oscillator.neuro · docs/NEURAL_FIELD_OSCILLATOR.md

Hyperbolic (Poincaré-Disc) Attention

$$ g^c_x = \lambda_c(x)^2, g^E,\quad \lambda_c(x) = \frac{2}{1 - c,|x|^2}, \qquad d_c(x,y) = \tfrac{2}{\sqrt{c}},\operatorname{artanh}!\bigl(\sqrt{c},|{-x \oplus_c y}|\bigr) $$ $$ \text{logit}_{ij} = -\frac{d_c(Q_i, K_j)}{\sqrt{d_{\mathrm{head}}}} $$

Query/key vectors are mapped into the Poincaré ball $\mathbb{D}^n_c$ via the exponential map at the origin; attention logits are negative geodesic distances instead of inner products. The exponential volume growth of the ball is the canonical embedding for tree-structured data (ASTs, dependency parses, scope chains). Source: neuroslm/modules/hyperbolic_attention.py · docs/features/hyperbolic_attention.md

Multi-Scale Grid-Cell Positions — HPB Phase 2

$$ \mathbf{g}_k(t) = \bigl[\cos(2\pi t / T_k),; \sin(2\pi t / T_k)\bigr], \qquad T_k = T_0\cdot \varphi^{,k},\quad \varphi = 1.618\ldots,\quad k = 0,\dots,K-1 $$

$K$ position scales at the golden ratio — the Sargolini/Stensola entorhinal-cortex grid module spacing. The $2K$ raw features project to d_model via a zero-init head, so the first forward is bit-identical to RoPE-only baseline; the dormant code path activates as the projection lifts off zero. Provable length-OOD extrapolation. Source: neuroslm/modules/grid_positions.py · DSL: grid_positions: { n_scales, scale_ratio, base_period }

RoPE on the Tonnetz Torus

$$ \mathbf{p}_t = R!\left(\tfrac{2\pi t}{P}\right)!\mathbf{p}_{t-1}, \qquad \mathbf{q}_t,, \mathbf{k}_t ;\leftarrow; \mathbf{q}_t\odot e^{i\theta_t},; \mathbf{k}_t\odot e^{i\theta_t} $$

Period-$P$ rotational embedding over the music-theoretic Tonnetz lattice — gives a closed cyclic prior under tonnetz_period chord-progression structure. Stacked with standard RoPE. Source: neuroslm/modules/positional.py · DSL: rope_base, tonnetz_period

🧠 Memory & Predictive Coding

Episodic kNN Memory — HPB Phase 5

$$ \hat v_t = \sum_{j,\in, \mathrm{kNN}(q_t, M)} \mathrm{softmax}!\bigl(\langle q_t, k_j\rangle/\tau\bigr), v_j, \qquad y_t = h_t + \alpha\cdot \hat v_t $$

A 4096-slot key/value store written either uniformly or surprise-gated (top-quantile of $\mathrm{nll}{\mathrm{local}} - \mathrm{nll}{\mathrm{global}}$). Read at every layer via kNN; $\alpha_{\mathrm{init}} = 0$ (ReZero). Memorizing-Transformers / RETRO style. Source: neuroslm/modules/episodic_memory.py · DSL: episodic_memory: { slots, k, alpha_init, write_gate }

Multi-Scale Predictive Coding Cascade (MSPCC) — HPB Phase 3

$$ \mathcal{L}_{\mathrm{MSPCC}} = \sum_{\ell=1}^{L-1} \lambda_\ell\cdot \mathrm{KL}!\bigl(q_\phi(z_{\ell+1}\mid h_\ell),|, p_\theta(z_{\ell+1})\bigr), \qquad \lambda_\ell = w_0\cdot \gamma^{(L-1)-\ell} $$

Applies an MDRV–VBB free-energy at every adjacent layer pair; the deepest (bowtie waist) pair dominates via geometric weight decay $\gamma$. Composes additively with the single-waist VBB. Source: neuroslm/modules/predictive_coding_residual.py · docs/features/predictive_coding_residual.md · DSL: mspcc: { base_weight, layer_weight_decay }

Local-Context Surprise Head — HPB Phase 5 (Mismatch Negativity)

$$ s_t = \mathrm{nll}_{\mathrm{local}}(x_t \mid x_{t-W:t}) - \mathrm{nll}_{\mathrm{global}}(x_t \mid x_{<t}) $$

A second tied LM head over a $W$-token local window; the per-token surplus surprise $s_t$ is exposed on every train forward and feeds the episodic write-gate. Sliding-window MMN analogue from EEG literature. Source: neuroslm/modules/surprise_head.py · DSL: surprise_head: { dim, local_window }

Predictive-Coding Residual

$$ \hat h_{\ell+1} = f_\ell(h_\ell),\qquad \varepsilon_\ell = h_{\ell+1} - \hat h_{\ell+1},\qquad \mathcal{L}_{\mathrm{PC}} = \sum_\ell |\varepsilon_\ell|^2 $$

Each layer predicts the next layer's activations from its own; only the prediction error propagates as a residual. Implements Rao–Ballard hierarchical predictive coding. Source: neuroslm/modules/predictive_coding_residual.py · docs/features/predictive_coding_residual.md

🔁 Distillation & Multi-Cortex Fusion

cortex_pre_head_norm — H16

$$ z_{\mathrm{trunk}} = W_{\mathrm{tied}}\cdot \mathrm{LayerNorm}(h_{\mathrm{trunk}}) $$

A LayerNorm before the tied LM head suppresses GPT-2's rogue dimension (std $\approx 24$, $82\times$ the median). Without it the init CE is 21.3 nats — above the uniform-distribution ceiling of 10.82; with it: 10.6 nats. Source: neuroslm/cortex/multi_cortex_lm_head.py

Per-Position Abstain Logit — H21

$$ \tilde z_{t,v} = \begin{cases} z_{t,v} & v \in \mathrm{vocab}_{\mathrm{cortex}} \[2pt] \max_{v'\in\mathrm{vocab}_{\mathrm{cortex}}} z_{t,v'} - \ln V_{\mathrm{trunk}} & \text{otherwise} \end{cases} $$

Unmapped vocab slots get an abstain logit instead of a flat $-10^4$. Dropped standalone-cortex CE from 17.37 → 4.03 nats, unblocking the entire fusion pathway. Source: neuroslm/cortex/cortex_lm_head.py

NT-Gated $\alpha$ Fusion

$$ \alpha_{\mathrm{eff}} = \sigma!\bigl(W_{\mathrm{NT}}\cdot \mathrm{EMA}(\ell_{\mathrm{cortex}} - \ell_{\mathrm{trunk}})\bigr), \qquad z = z_{\mathrm{trunk}} + \alpha_{\mathrm{eff}}\cdot (z_{\mathrm{cortex}} - z_{\mathrm{trunk}}) $$

An EMA-smoothed neurotransmitter signal collapses $\alpha_{\mathrm{eff}} \to 0$ once the trunk surpasses the cortex, and resumes contribution if the trunk regresses. Auto-retiring teacher. Source: neuroslm/cortex/nt_alpha_gate.py

KL Distillation (Temperature-Scaled)

$$ \mathcal{L}_{\mathrm{KL}} = T^2 \cdot \mathrm{KL}!\bigl(\mathrm{softmax}(z_{\mathrm{cortex}}/T).\mathrm{detach};\big|;\mathrm{softmax}(z_{\mathrm{trunk}}/T)\bigr), \quad \lambda_t = \lambda_{\max}\cdot \mathrm{clip}!\bigl((\ell_{\mathrm{cortex}} - \ell_{\mathrm{trunk}}) / \tau,, 0, 1\bigr) $$

Gap-ramped: $\lambda_t$ saturates at $\lambda_{\max} = 1.0$ when the trunk lags and shuts off when it leads. Pairs with the NT gate above. Source: neuroslm/cortex/distillation.py

📐 Generalisation & Training Geometry (GIF stack)

GIF-1/2/3 — Adaptive Gap-Ratio Ramp — H7

$$ r_t = \frac{\mathrm{ppl}_{\mathrm{OOD}}(t)}{\mathrm{ppl}_{\mathrm{train}}(t)},\qquad \beta_t = \beta_{\min} + (\beta_{\max} - \beta_{\min})\cdot \sigma(\kappa,(r_t - r_\star)) $$

The VBB $\beta$, isotropy strength, and OOD-probe weight all ramp from a single gap-ratio signal $r_t$ → closed loop on generalisation gap rather than wall-clock schedule. Source: neuroslm/gif/adaptive_ramp.py · DSL: vbb_kl_floor_gamma, loss_var_window

GIF-4 — Gap-Driven Label Smoothing — H8

$$ \varepsilon_t = \varepsilon_0 + (\varepsilon_{\max} - \varepsilon_0) \cdot \mathrm{clip}!\bigl((r_t - 1) / (r^\star - 1),, 0, 1\bigr) $$

Label smoothing magnitude is itself gap-driven — increases as OOD/train diverges, shrinks as they re-align. Source: neuroslm/gif/label_smoothing.py · DSL: label_smoothing

GIF-5 — Attention-Head Diversity — H9

$$ \mathcal{L}_{\mathrm{div}} = \frac{1}{H(H-1)}\sum_{i\ne j} \bigl|,P_i^\top P_j - \tfrac{1}{T}\mathbf{1}\mathbf{1}^\top\bigr|_F^2 $$

Penalises pairwise alignment of attention probabilities $P_i$ across heads → forces encoder-side diversity, measurably cuts redundancy. Source: neuroslm/gif/head_diversity.py

GIF-6 — Cosine LM Head — H10

$$ z_{t,v} = \tau\cdot \frac{\langle h_t,, W_v\rangle}{|h_t|\cdot |W_v|} $$

Cosine similarity (with learnable temperature $\tau$) instead of raw dot-product → eliminates the norm-mediated confidence asymmetry that biases LM heads toward high-norm trunk states. Source: neuroslm/modules/cosine_head.py · DSL: cosine_head: true

GIF-7 — Homeostatic Gradient Equilibrium

$$ g_\ell \mathrel{:=} g_\ell \big/ \bigl(c + \mathrm{var}_{\mathrm{batch}}(\mathcal{L})\bigr), \qquad \mathrm{var}_{\mathrm{batch}}(\mathcal{L}) \ge \mathrm{var}_{\min} $$

Divisive normalisation of layer-wise gradients by the rolling batch-loss variance — keeps SNR constant across the trunk and prevents bowtie-waist collapse. Source: neuroslm/gif/gradient_equilibrium.py · DSL: divisive_grad_c, loss_var_min_mult

Hyperbolic Bowtie Waist (HPB Phase 4)

$$ \mathrm{KL}_{\mathbb{D}^n_c}(q|p) = \mathrm{KL}_{\mathbb{R}^n}(q|p) + \log\det J_{\exp_0^c}(\mu_q) $$

Wraps the VBB posterior on the Poincaré ball of curvature $c$. The Jacobian log-det correction strictly upper-bounds the Euclidean KL for any $|\mu_q| > 0$$\sigma$-collapse becomes geometrically harder. Source: neuroslm/gif/hyperbolic_bowtie.py · DSL: vbb_curvature

ImprovementGate (Welch's $t$) — H5

$$ t = \frac{\bar x_A - \bar x_B}{\sqrt{s_A^2/n_A + s_B^2/n_B}},\quad \mathrm{df} = \frac{(s_A^2/n_A + s_B^2/n_B)^2}{(s_A^2/n_A)^2/(n_A-1) + (s_B^2/n_B)^2/(n_B-1)} $$

Every architecture mutation and DNA patch is gated by a two-sided Welch's $t$-test ($p < \alpha$) computed on the OOD-PPL pre/post window — no structural change lands without significance. Numerically pinned to scipy within $1!\times!10^{-6}$. Source: neuroslm/verification/improvement_gate.py · tests/verification/test_improvement_gate.py

✨ Φ / Integrated Information

Φ-MIP Gaussian Objective — H1 · H2

$$ \Phi^{\mathrm{MIP}}(X) = \min_{(A,B),\in,\mathrm{cuts}(X)} I(A;B), \qquad \mathcal{L}_\Phi = -\tanh(\Phi^{\mathrm{MIP}} / 3)\cdot 3 $$

Differentiable lower bound on integrated information via the Gaussian-MI estimator over the minimum information partition; the bounded $-\tanh$ scalarisation gives a non-vanishing gradient that pushes the trunk toward integrated states. Source: neuroslm/iit/phi_mip.py

Sheaf $H^1$ Contradiction Detection — H4

$$ H^1(\mathcal{F}) = \ker\delta^1 / \mathrm{im},\delta^0, \qquad \text{contradiction} ;\iff; H^1 \ne 0 $$

Narrative memory is encoded as a cellular sheaf $\mathcal{F}$ over the proposition graph; non-zero first cohomology means two stalks contradict ("likes coffee" vs "hates coffee") and triggers a SUPERSEDES edge. Belief revision = killing $H^1$. Source: neuroslm/sheaf/contradiction.py · tests/test_narrative_memory.py

Personality Vector

$$ \pi = \mathrm{EMA}!\bigl(\mathrm{Embed}(\text{identity-tokens})\bigr) \in \mathbb{R}^{5} $$

A frozen embedding learned during embodied training that survives weight reload — verified across checkpoints (H6). Used as a stable identity vector for self-reference rate and cognitive-closure metrics. Source: collectors/personality.py


Neural Flow Graph — current architecture

The NFG is generated from arch.neuro → Hypergraph IR → PyTorch. Re-render with:

brian compile nfg --current          # → .neuro/nfg.png
brian compile nfg --current --heat heatmap.json   # → .neuro/nfg.heat.png

The .neuro DSL

Architecture is specified declaratively in .neuro files — math-first ODEs and modulation rules that compile to byte-equivalent PyTorch:

export population amygdala {
    count: 32,
    ode: "dV/dt = (-V + x) / tau",
    timescale: 0.005
}

modulation dopamine -> pfc {
    effect: "multiplicative", gain: 0.6,
    equation: "y = output * (c * gain)"
}

The compiler (neuroslm/compiler/module_bundler.py, ribosome.py) produces modules with source maps and byte-identity round-trip verification. 1305 tests in tests/dsl/ guard codegen correctness.

Full reference: docs/dsl.md.


NGL — the Neuro-Genetic Language (algorithm discovery)

The .neuro DSLs describe architectures — what tensors flow where. They deliberately have no persistent state or control flow, so they cannot describe an ML algorithm: an optimizer update rule, a learning rule, a gradient/flow modulation. NGL (neuroslm/genetic/) fills that gap. It is a typed register machine — a scalar bank and a tensor bank, plus instructions drawn from a registry of total-semantics ops — in which an ML algorithm is a short, evolvable program. Because state registers persist across steps and the op set includes a conditional, NGL is Turing-complete in the linear-register-machine sense: the substrate AutoML-Zero and the Lion optimizer discovery searched.

SGD, Momentum, RMSProp, Adam and Lion are each written as an NGL program and reproduce their PyTorch reference bit-for-bit — proof the language spans the update-rule grammar. On top of that sits a CPU discovery harness that searches the program space with a Pareto GA (mutation + crossover + novelty in the program's semantic-embedding space), scoring each candidate by training a tiny model on a synthetic task:

brian discover optimizer --task parity --generations 20 --out run.json
brian discover flow      --generations 12 --out flow.json   # + effective-information objective

The optimizer search rediscovers-and-tunes scaled gradient descent from a cold start, and — given the adaptive family in reach — selects per-coordinate gradient normalization on a task where plain SGD provably plateaus. This is the machinery behind the neuroscience-inspired-SLM goal: search for the topology and modulation that beat scaling, cheaply on CPU, before spending a GPU.

NGL also compiles an architecture into itself — every mechanic, including attention. An nn_lang forward graph lowers to an NGL program (composite ops like linear/rmsnorm/swiglu delegate to nn_ops; scalar-config ops like attention carry their n_heads/… as instruction config), byte-equivalent to the compiled module — so a whole TransformerBlock is discovery-, simplification- and evolution-ready:

brian discover simplify --layer-file block.layer   # arch → NGL → shorter equivalent
brian discover trunk    --generations 12 --save my_gain   # evolve + persist a modulation
brian discover optimizer --novelty 0.3             # hunt NOVEL update rules
brian modulation list                              # manage modulations/*.neuro
brian modulation merge my_gain other --name combo  # compose gains g2(g1(h))

The simplifier builds an expression DAG and applies value-preserving algebraic rewrites to a fixpoint (dead-code elimination, (a+b)−b → a, constant folding, like-term combination), every rewrite globally probe-verified against shape-correct random params. The trunk auto-evolve searches an NGL neuromodulation on the residual stream, scoring candidates by validation perplexity jointly with a neuroanatomic-realism prior (divisive normalization, multiplicative gain, homeostatic saturation) — improving language modelling while staying biologically plausible. Discovered modulations persist as modulations/*.neuro and can be listed, merged, or thrown away from brian.

The competitor is a GPU outcome. The CPU engine discovers candidate mechanics, update rules and modulations and proves them on tiny models — but a param-matched GPT-2 competitor comes only from GPU exploration and extensive GPU training (brian deploy). --save carries a discovered gain law from the CPU search to the trunk.

Design: docs/dsl_subsystem_roadmap.md §NGL. Results: docs/findings.md H31, H32, H33.


Multi-Cortex Fusion

Three frozen causal-LM experts sit above the bowtie trunk and fuse logits at the LM head:

Domain Expert Params Tokenizer bridge
General smollm2_360m ~360M cross-vocab retokenise
Code microsoft/CodeGPT-small-py ~125M direct (shared BPE)
Reasoning Qwen/Qwen2.5-0.5B ~500M cross-vocab retokenise

|--------|--------|--------|-----------------| | General | smollm2_360m | ~360M | cross-vocab retokenise | | Code | microsoft/CodeGPT-small-py | ~125M | direct (shared BPE) | | Reasoning | Qwen/Qwen2.5-0.5B | ~500M | cross-vocab retokenise |

Three interlocking mechanisms govern the fusion:

  1. cortex_pre_head_norm — LayerNorm before the tied head suppresses GPT-2's rogue dimension (std ≈ 24, 82× median). Without it, CE at step 0 = 21.3 nats (above the uniform-distribution ceiling of 10.82). With it: 10.6 nats.

  2. Per-position abstain logit (H21) — Unmapped vocab slots are filled with max(mapped_logits) − ln(V_trunk) instead of a flat −1e4. This single fix dropped standalone-cortex CE from 17.37 → 4.03 nats and unlocked the entire multi-cortex pathway:

    Metric broken (vast 40923107) fixed (vast 40925851) Δ
    train PPL @ 2,000 steps 1444 102.9 -93%
    OOD PPL (WikiText-103-v1) 4655 295.9 -94%
    α_eff 0.000 (collapsed) 0.500 (stable) fusion alive
    cortex_loss_ema ~0.001 ~0.5 fusion alive
  3. NT-mediated α gating — Once the trunk surpasses the cortex, an EMA inhibitory signal drives α_eff → 0 so cortex experts retire automatically. The reverse also holds: cortex contribution resumes if the trunk regresses.

KL distillation runs in parallel: L_KL = T² · KL(cortex.detach()/T ‖ trunk/T) with a gap-ramped λ that saturates at 1.0 when the trunk lags and shuts off when it leads.


Evidence

Layer A — Mechanism Verification ✅

4955 unit tests across tests/ confirm every mechanism computes as specified:

Hypothesis Result
H1 — Φ > 0 for coupled outputs ✅ Gaussian-MI MIP verified
H2 — Φ gradient is real ✅ ‖∂L/∂θ‖ increases measurably
H3 — BDNF grows high-Φ paths preferentially ✅ kernel rank expands on hot paths
H4 — Sheaf H¹ detects contradictions ✅ "likes coffee" vs "hates coffee" → SUPERSEDES edge
H5 — Causal generalization from narratives ✅ P(Joy|Gift) > 0.8 from 10 examples
H6 — Personality survives weight reload ✅ identity vector stable across checkpoints
H16 — cortex_pre_head_norm kills init loss ✅ CE: 21.3 → 10.6 nats
H19 — ImprovementGate (Welch's t) ✅ p-values within 1e-6 of scipy; mutation blocked without significance
H21 — Per-position abstain unblocks fusion ✅ -93% train-PPL / -94% OOD-PPL vs broken precursor

Run all: py -3 -m pytest tests/ -v (~~10 mins on CPU).

Layer B — OOD Generalization 🟡

Evaluated on WikiText-103-v1 held-out set. gap_ratio = OOD_ppl / train_ppl (lower is better):

Protocol note (H59, eval v2): rows below predate protocol v2. New runs additionally report gap_v2 = wikitext_ppl / traindist_ppl — both sides produced by the same trunk-only eval code on a held-out slice of the training distribution, so training-side regularisation (flooding, label smoothing) can no longer distort the denominator — plus a PG-19 second OOD axis, and per-sequence NLLs so arm-vs-arm comparisons run through brian ood compare (Welch's t) instead of eyeballed ppl deltas.

Variant Params Steps train_ppl OOD_ppl gap_ratio Log
Flat Transformer (Baseline) 106.9M 80,000 66.0 404.0 6.12 -
BRIAN B1 (trunk + recursive) 108.2M 5,000 216.5 1372.8 6.34 -
BRIAN B2 (trunk + ReZero) 107.8M 7,000 258.8 1351.5 5.22 -
BRIAN B3 (PCT trunk) 69.2M 4,000 400.9 1806.6 4.51 -
BRIAN (abstain-fix + multi-cortex, B4) 889.6M 2,000 102.9 295.9 2.87 (log not available)

B4 is the first variant under 3.0 gap_ratio — a 53% improvement over the flat baseline — achieved at 40x fewer steps. Absolute OOD PPL (295.9) still trails the baseline (404.0), but the baseline ran 80,000 steps. Matched-compute comparison is the immediate next experiment.

⚠️ gap_ratio drifts upward within B4 (2.05 → 2.87 from step 500 → 2,000). The 10k follow-up run will distinguish plateau from accelerating overfit. See docs/findings.md#H21.

Latest Logs

Best Run Overall (OOD / Combined Score):

[`logs/20260616/gpt2/140627_500_10000.log`](logs/20260616/gpt2/140627_500_10000.log)

[mid-ood] step 9500: wikitext ppl=87.0 gap_ratio=4.37 (train_ppl=19.9) (50 seq, 6430 tok)

Most Recent Run (Last Checkpoint):

[`logs/discover/20260709T132733Z_experts.log`](logs/discover/20260709T132733Z_experts.log)

[expert-discovery] round 1/30 Qwen/Qwen2.5-0.5B: best_ce=3.3029 Δ=0.0012 evaluated=1009 (saved expert_qwen2_5_0_5b_step1) [expert:smollm2_360m] round 2: baseline_ce=2.6459 (final: sens=0.04544 improve=-0.002228 (scale_up) tight) [expert-discovery] round 2/30 HuggingFaceTB/SmolLM2-360M: best_ce=2.6455 Δ=0.0004 evaluated=380 (saved expert_smollm2_360m_step2)


Quick Start

python -m venv .venv
# Windows:
.\.venv\Scripts\Activate.ps1
# Linux/Mac:
source .venv/bin/activate

pip install -r requirements.txt
# Install torch separately to match your accelerator:
pip install torch --index-url https://download.pytorch.org/whl/cu121

# CPU sanity run (~~27M params)
brian train --preset=tiny --steps=2000

# A100 full run (~~240M params, bf16)
brian train --preset=xl --steps=100000 --device=cuda

# Resume latest checkpoint
python -m neuroslm.train --resume latest

# Flat transformer ablation at matched params
python -m neuroslm.train --preset xl --baseline

# Interactive generation
python -m neuroslm.generate --prompt "Once upon a time"

Full Colab workflow (clone → ablation → training → benchmarks): colab_run.ipynb.


Parameter Presets

Preset Params Accelerator VRAM Notes
tiny ~~27M CPU sanity / CI
small ~~93M CPU local dev
medium ~~389M T4 16 GB
large ~~100M T4 15 GB
xl ~~240M A100 40 GB standard research run
xxl ~~10B 4×A100 320 GB

Add --baseline for a parameter-matched flat transformer ablation.


Configuration (brian.toml)

Single source of truth for the active architecture:

[current]
arch = "architectures/rcc_bowtie"   # active architecture
dna  = ""                            # .dna path for evolutionary training

[nfg]
output = ".neuro/nfg.png"
format = "png"                       # png | svg | pdf | dot
engine = "dot"

Override per-run with env vars: BRIAN_ARCH, BRIAN_DNA, BRIAN_NFG_OUTPUT. Contract locked by 27 tests in tests/test_project_config.py.


Real-Time Architecture Evolution

BRIAN can mutate its own architecture during training. Mutations are gated by ImprovementGate (Welch's t-test) — no structural change lands without statistically significant fitness gain:

from neuroslm.utils import EvolutionaryTrainingContext

with EvolutionaryTrainingContext("dna/base.dna", "checkpoints/") as ctx:
    harness = BRIANHarness(ctx.arch_path, resume_from=ctx.resume_step)
    for step in range(ctx.resume_step, 10000):
        loss = harness.train_step(batch)
        if step % 1000 == 0:
            harness.checkpoint_mutations()   # emits step_XXXXX.patch.dna
  • RAID-5 protected DNA (triple redundancy)
  • Incremental patches only — not full model state
  • Hot paths (ρ > 0.7) grow via BDNF; cold paths (ρ < 0.1) prune
  • Fault-tolerant: patch stack replayed from any checkpoint

Loss Composition

Term Source Weight
lm_loss mesolimbic-gain-modulated cross-entropy 1.0
phi_loss −tanh(Φ/3)·3 from MIP estimator 0.02 × maturation
world_loss predicted vs target world embedding (MSE) 0.3 × maturation
pred_coding_loss per-layer next-layer prediction 0.1 × maturation
cortex_kl_loss T²·KL(cortex.detach()/T ‖ trunk/T) λ_t (gap-ramped, max 1.0)
motor, CPC, RSSM, novel aux embodied + optional modules 0.05–0.1 × maturation
topo_loss (H24) α·(Q_h − Q*)² + γ·ε_ortho from topo_charge diagnostic α, γ (default 0 = diagnostic-only)
noether_loss (H25) λ·(H_final − H_initial)² leapfrog Noether residual λ (default 0 = diagnostic-only)
josephson_loss (H26) −(1/L)Σ K̄_h·R_ℓ inter-layer Josephson phase coupling λ_J (default 0 = diagnostic-only)

The maturation gate _aux_w_scale ∈ [0.001, 1.0] suppresses all aux losses until step 5000 (or lm_loss < 7.5), so the LM gradient dominates during early training.

The topo_loss row (Phase 1 of the 3-mechanism THSD program) is enabled in arch.neuro by default as diagnostic-only (α = γ = 0): per-head Berg-Lüscher discrete windings Q_h and inter-layer orientation decorrelation ε_ortho are logged every step but zero is added to the loss. See docs/findings.md H24 + neuroslm/mechanisms/topo_charge.py. Activating the soft penalty (α > 0 or γ > 0) is a follow-up experiment.

The noether_loss row (Phase 2 of the THSD program) is enabled in arch.neuro by default as diagnostic-only (λ = 0): noether_H_diff = |H_final − H_initial| is logged every step but zero is added to the loss. The Liouville symplectic residual block runs one leapfrog step on the final hidden state; det(J) = 1 is guaranteed by the triangular-shear structure of the Stoermer-Verlet integrator. See docs/findings.md H25 + neuroslm/mechanisms/liouville_symplectic.py.

The josephson_loss row (Phase 3 of the THSD program) is enabled in arch.neuro by default as diagnostic-only (λ_J = 0): the Josephson order parameter R_ℓ is logged every step but zero is added to the loss. Each attention head carries a per-(head, layer, token) phase φ with intra-layer Kuramoto sync (η) and inter-layer Josephson coupling (K_h). At zero init all scalars are zero, so step-0 loss is bit-identical to vanilla (torch.equal). See docs/findings.md H26 + neuroslm/mechanisms/kjpla.py.


Introspection

model.intelligence_metrics.snapshot()   # Φ, identity drift, causal density, self-reference rate
model.consciousness_metrics.per_tick()  # γ (binding), θ (memory), α (idling), coherence, ignition
model.narrative_stack.query_rules()     # discovered causal patterns with support counts
model.personality_vector               # tensor(5) — stable across checkpoints

Tests

py -3 -m pytest tests/                                              # full suite (4955 tests, ~~10 mins)
py -3 -m pytest tests/test_phi.py -v                               # H1–H3: integrated information
py -3 -m pytest tests/test_narrative_memory.py -v                  # H4–H5: memory & causation
py -3 -m pytest tests/test_cognitive_closure.py -v                 # H6–H6.5: identity & embodiment
py -3 -m pytest tests/training/test_cortex_pre_head_norm.py -v     # H16: catastrophic-loss fix
py -3 -m pytest tests/training/test_cortex_distillation_and_gating.py -v  # H17–H18: KL + NT gating
py -3 -m pytest tests/verification/test_improvement_gate.py -v     # H19: Welch's t admission gate
py -3 -m pytest tests/dsl/ -v                                       # 1305 DSL codegen + byte-equivalence

Checkpoints

Pushed to moritzroessler/BRIAN on HuggingFace Hub every 2000 steps. Configure in architectures/*/config.neuro:

checkpoint {
    push_backend: "hf"
    hf_repo_id: "moritzroessler/BRIAN"
    hf_token_env: "HF_TOKEN"
    save_every: 2000
    push_every: 2000
    push_optimizer: false    # strips Adam state, ~2/3 size saving
}

Skip LFS on laptops (recommended):

git lfs install --local --skip-smudge   # fetch stubs only
git lfs pull --include="lfs_checkpoints/neuroslm_xl_adamw_mix_800.pt"  # pull one when needed

Docs

Document Contents
docs/findings.md Hypothesis ledger H1–H18: test files, result JSONs, raw logs. Source of truth for what's proven vs open.
docs/architecture.md Full spec: 11-stage forward pass, tensor shapes, equations, IIT 4.0 theory.
docs/formal_framework.md Normative math contract: sheaf ontology, H¹ guard, Φ guard, RAID-5 DNA, ImprovementGate spec, Lean roadmap.
docs/dsl.md .neuro syntax, macro system, compile pipeline, module bundling, source maps.
docs/technical_report.md Executive summary: proven claims, open questions, all 7 pillars.

Open research. Issues, stars, and PRs welcome.

About

BRIAN — brain-inspired language model exploring whether topology beats scale. 11-stage bowtie with re-entry loops, real differentiable Φ from IIT 4.0, sheaf-H¹ narrative memory, embodied survival in a 10×10 GridWorld, and multi-cortex fusion (frozen GPT-2 experts + trunk) gated by KL distillation and NT-mediated α. Architecture written in own DSL.

Topics

Resources

Contributing

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages