Skip to content
Part 6 of 20

Legacy V10.2 Configuration

Krrish Choudhary·March 23, 2026

Source: nct_v2/config.py Lines: 243

Purpose

The NCTv2Config dataclass is the V10.2 (transformer-adapted) configuration. It is included in the NCT standalone as a dependency for shared brain modules, specifically brain_embeddings.py, which was originally written for V10.2 and references this config type. The V11 model does not directly use NCTv2Config; instead, the V11BrainEmbedding wrapper extracts relevant dimensions from V11Config and passes them to the underlying brain embedding components.

This section is included for completeness. No new theorems or figures are needed, the config is a plain dataclass with dimension parameters.

Source Code

Python
243 lines
# ===========================================================================
# Legacy Config (dependency for brain modules)
# Source: nct_v2/config.py
# ===========================================================================

"""NCT V2 hyperparameter configuration."""



@dataclass
class NCTv2Config:
    # ── Architecture ──────────────────────────────────────────────────────
    d: int = 128                # Model dimension
    L: int = 6                  # Number of NCT-V2 layers
    H_E: int = 6                # Excitatory attention heads
    H_I: int = 2                # Inhibitory attention heads
    d_ff: int = 512             # FFN intermediate dimension (InhibitoryFFN)
    K: int = 2                  # Cortical columns per layer (V-CCE)
    P: int = 2                  # Oscillatory phases (UCAM)
    V: int = 50257              # Vocabulary size (GPT-2 BPE)
    max_seq_len: int = 64       # Maximum sequence length

    # ── Neuromodulation ───────────────────────────────────────────────────
    neuromod_global_hidden: int = 512   # Global neuromod MLP hidden dim (shared)
    neuromod_local_hidden: int = 64     # Local neuromod MLP hidden dim (per layer)

    # ── Attention KV Compression (Thm 74-75: GQA & MLA) ────────────────
    # Grouped Query Attention: share K/V across head groups for cache efficiency.
    # n_kv_groups_E: KV groups for excitatory heads (0 = H_E, standard MHA)
    # n_kv_groups_I: KV groups for inhibitory heads (0 = H_I, standard MHA)
    # Brain basis: cortical minicolumns share receptive fields (Mountcastle 1957);
    # excitatory vs inhibitory neurons have different receptive field widths.
    n_kv_groups_E: int = 0              # 0 = H_E (MHA). 2 = 3:1 sharing for H_E=6
    n_kv_groups_I: int = 0              # 0 = H_I (MHA). 1 = 2:1 sharing for H_I=2

    # ── Multi-head Latent Attention (Thm 75: Thalamic Latent KV) ─────
    # MLA compresses KV into a low-rank latent before decoding per-group K/V.
    # Brain basis: thalamic pulvinar compresses multi-modal information into
    # low-dimensional encoding before routing to cortex (Sherman 2007).
    # Cache stores latent + rope_key instead of full K + V → higher compression.
    # use_mla=True requires GQA groups to be set (uses n_kv_groups from GQA).
    use_mla: bool = False               # Enable MLA (overrides GQA KV path)
    d_kv_latent: int = 0                # 0 = d//4 (auto). Latent KV dimension
    d_rope_per_group: int = 0           # 0 = d_h//2 (auto). RoPE dim per KV group

    # ── Derived (set in __post_init__) ────────────────────────────────────
    H: int = field(init=False)          # Total heads (H_E + H_I)
    d_h: int = field(init=False)        # Head dimension (d // H)
    d_col: int = field(init=False)      # Column dimension (d // K)
    n_kv_groups: int = field(init=False) # Total KV groups (n_kv_groups_E + n_kv_groups_I)

    # ── Loss ──────────────────────────────────────────────────────────────
    lambda_pc: float = 0.1              # PC loss weight (only 2 terms in V2)

    # ── Module-specific ───────────────────────────────────────────────────
    tau_init: float = 1.0               # PC-HP threshold init
    pi_init: float = 0.0                # PC-HP precision init (softplus(0) ≈ 0.693)
    gate_sharpness: float = 10.0        # PC-HP sigmoid sharpness
    eta_init: float = 0.0               # GLH learning rate init (softplus(0) ≈ 0.693)
    glh_chunk_size: int = 64            # GLH parallel scan chunk size

    # ── V4.6 features ─────────────────────────────────────────────────────
    # Surprise-modulated decay: when PC-HP reports high surprise, the
    # ThalamicGLH adjusts retention (sign learned, or set via surprise_decay_init).
    # Biologically: norepinephrine modulates hippocampal plasticity.
    use_surprise_decay: bool = False    # Set True for V4.6+ models
    # Init for W_surprise_decay weights. Positive → high surprise = more retention
    # (novel/entity tokens kept longer, NE analog). Zero → let gradient decide.
    surprise_decay_init: float = 0.0   # V4.8: set to +0.1 for entity-retentive init
    # Learnable global decay bias per GLH layer.
    # decay_logit = W_decay(X) + decay_bias  →  a = sigmoid(decay_logit)
    # Init 0.0 → a=0.5 (V4.5 default, 50% retention per step — fast decay).
    # Init 3.35 → a=0.966 (high retention, lag32≈33% — matches attention baseline).
    # Init 1.0 → a=0.731 (V4.8: moderate baseline, learn selective retention).
    # The scalar is learned, so NTP gradient can decrease it if retention hurts.
    glh_decay_bias_init: float = 0.0    # V4.7: set to 3.35 for long-lag memory
    kwta_init: float = 0.5             # InhibitoryFFN initial sparsity fraction
    kwta_beta_init: float = 10.0        # k-WTA sharpness init
    kwta_beta_max: float = 30.0         # k-WTA max sharpness
    tau_cons_init: float = 1.0          # V-CCE consensus temperature init
    # ── V4.11 Sparsity Controls ───────────────────────────────────────────
    # V4.11 targets much sparser representations (brain: 1-5% active)
    # vcce_k_active: number of winning columns in VCCEWithWTA
    #   V4.10: 2 (max(2,K*0.5)) = 50% active  ← too dense for coreference
    #   V4.11: 1 (25% active) = genuine lateral inhibition commitment
    vcce_k_active: int = 2
    # ffn_sparsity_init: DendriticFFN initial active fraction
    #   V4.10: 0.5 (sigmoid(0) = 50% active)  ← too dense (LIS=0.69)
    #   V4.11: 0.2 (sigmoid(-1.39) = 20% active)  ← target LIS≈0.25
    ffn_sparsity_init: float = 0.5

    # ── V10.1 Multi-Scale GLH Decay ──────────────────────────────────────
    # RetNet/RWKV show 3.7% PPL improvement from per-channel vs single decay.
    # Neuroscience: cortex has temporal hierarchy (primary cortex ~10ms fast,
    # PFC ~200ms-2s slow). V10 currently forces ALL d_h channels to same init.
    # V10.1: each channel gets its own initial timescale via linspace.
    # glh_decay_multiscale=True: init decay_bias as vector(d_h) not scalar.
    # Range linspace(glh_decay_bias_low, glh_decay_bias_high, d_h):
    #   sigmoid(-2)=0.12 (fast, word-level)  …  sigmoid(4)=0.98 (slow, entity-level)
    #   Mean = 1.0 = same as V10 uniform init (non-regressive).
    # Zero new parameters for inference vs V10 (same count, different init shape).
    glh_decay_multiscale: bool = False    # V10.1: True for per-channel timescales
    glh_decay_bias_low: float = -2.0     # fastest channel: a_init≈0.12
    glh_decay_bias_high: float = 4.0     # slowest channel: a_init≈0.98

    # ── V6 Full Brain-Circuit Controls ────────────────────────────────────
    # Global Workspace Theory: broadcast hub across all layers (default True in V6)
    global_workspace_enabled: bool = False
    # Re-entrant processing: low-rank rank for A[l]@B[l] correction matrices
    reentrant_rank: int = 16
    # Norepinephrine gain: init for ne_scale (softplus(ne_gain_init) ≈ gain)
    #   -3.0 → softplus(-3)≈0.05 (nearly invisible at init, grows through training)
    ne_gain_init: float = -3.0
    # Serotonin timescale: per-layer time-constant gating (True in V6)
    sht_enabled: bool = False
    # SlowReplay weight: HPC→neocortex consolidation loss head weight
    replay_weight: float = 0.05
    # DopamineRPE: surprise-modulation scale for per-token PC weighting
    da_scale: float = 0.5
    # ACh inversion: handled by CrossFrequencyCoupledUCAM_V6 (structural — no config needed)

    # ── MoE (Theorem 77-79: Cortical Column Expert Routing) ────────────────
    # Brain: cortical columns specialize with depth (V1 general → IT specialized)
    # MoE replaces DendriticFFN in later layers with N expert DendriticFFNs
    # BG D1/D2 router selects top-k experts per token (DA-modulated)
    use_moe: bool = False               # Enable MoE in later layers
    moe_n_experts: int = 8              # Number of experts per MoE layer
    moe_k_min: int = 2                  # Minimum experts active per token
    moe_k_max: int = 4                  # Maximum experts active per token
    moe_start_frac: float = 0.5         # MoE starts at this fraction of total layers
                                        # 0.5 → layers L//2 to L-1 (later = more specialized)

    # ── Sliding Window Attention (Thm 76: Cortical Receptive Field) ─────
    # Each layer attends only to the last W tokens (local window).
    # Long-range context comes from ThalamicGLH recurrence, not attention.
    # Brain basis: cortical layers have limited receptive fields; long-range
    # comes from recurrent thalamo-cortical loops (Sherman 2007).
    # 0 = disabled (full causal attention). 128/256 typical for training.
    # Combines with GQA/MLA: cache only stores window of KV entries.
    sliding_window: int = 0                 # 0 = disabled. 128/256 typical.

    # ── SSM Parallel Scan (T_ssm_1/2/3: Hardware-Efficient Recurrence) ──
    # Replace ThalamicGLH's chunked scan with parallel prefix scan (Blelloch 1990).
    # Brain basis: thalamocortical relay (Sherman & Guillery 2006) decomposes into
    # d_h independent linear recurrences — each row of S evolves independently.
    # Works in float32 (no float64 needed), chunk-based hybrid (CHUNK=32).
    # NMDA and SilentTrace already use SSM scans unconditionally.
    use_ssm: bool = False                   # Enable SSM scan for ThalamicGLH
    use_hippo_init: bool = False            # HiPPO-LegS decay init (T_ssm_2)

    # ── Fused Kernel Dispatch (Prop 23-25f: Brain Module Fusion) ─────────
    # Enable fused kernels from nct_v2/kernels/ package. Replaces sequential
    # element-wise module chains with single fused operations. Also enables
    # parallel scan dispatch for NMDA/Silent/Thalamic scans, fused PWPC chain,
    # tiled FlashAttention+CFC, radix-select k-WTA, and WEAVER++ top-K.
    # Requires CUDA for Triton kernels; falls back to PyTorch on CPU/MPS.
    use_fused_kernels: bool = False         # Enable fused kernel dispatch

    # ── Training ──────────────────────────────────────────────────────────
    lr: float = 3e-4
    warmup_steps: int = 100
    weight_decay: float = 0.1
    batch_size: int = 4
    grad_clip: float = 1.0
    dropout: float = 0.1
    use_amp: bool = False               # Use automatic mixed precision (fp16 or bf16)

    def __post_init__(self):
        self.H = self.H_E + self.H_I
        self.d_h = self.d // self.H
        self.d_col = self.d // self.K
        # GQA: resolve sentinel 0 → MHA (backward compatible)
        if self.n_kv_groups_E == 0:
            self.n_kv_groups_E = self.H_E
        if self.n_kv_groups_I == 0:
            self.n_kv_groups_I = self.H_I
        self.n_kv_groups = self.n_kv_groups_E + self.n_kv_groups_I
        assert self.d % self.H == 0, (
            f"d ({self.d}) must be divisible by H ({self.H})"
        )
        assert self.d % self.K == 0, (
            f"d ({self.d}) must be divisible by K ({self.K})"
        )
        assert self.H_E % self.n_kv_groups_E == 0, (
            f"H_E ({self.H_E}) must be divisible by n_kv_groups_E ({self.n_kv_groups_E})"
        )
        assert self.H_I % self.n_kv_groups_I == 0, (
            f"H_I ({self.H_I}) must be divisible by n_kv_groups_I ({self.n_kv_groups_I})"
        )
        assert self.max_seq_len % self.glh_chunk_size == 0, (
            f"max_seq_len ({self.max_seq_len}) must be divisible by "
            f"glh_chunk_size ({self.glh_chunk_size})"
        )
        # MLA: resolve auto-sizing (0 sentinel → default fractions of d/d_h)
        if self.use_mla:
            if self.d_kv_latent == 0:
                self.d_kv_latent = self.d // 4
            if self.d_rope_per_group == 0:
                self.d_rope_per_group = self.d_h // 2
            assert self.d_rope_per_group <= self.d_h, (
                f"d_rope_per_group ({self.d_rope_per_group}) must be <= d_h ({self.d_h})"
            )


# ── Preset scale configurations ───────────────────────────────────────────────

def nano_config(**kwargs) -> NCTv2Config:
    """V2-Nano ~8.7M params — benchmark vs V1 and baseline."""
    defaults = dict(
        d=128, L=6, H_E=6, H_I=2,
        d_ff=512, K=2, P=2,
        V=50257, max_seq_len=64,
        neuromod_global_hidden=512, neuromod_local_hidden=64,
    )
    defaults.update(kwargs)
    return NCTv2Config(**defaults)


def small_config(**kwargs) -> NCTv2Config:
    """V2-Small ~93M params — proof of concept."""
    defaults = dict(
        d=512, L=12, H_E=6, H_I=2,
        d_ff=2048, K=4, P=4,
        V=50257, max_seq_len=256,
        neuromod_global_hidden=512, neuromod_local_hidden=64,
        glh_chunk_size=64,
    )
    defaults.update(kwargs)
    return NCTv2Config(**defaults)


def base_config(**kwargs) -> NCTv2Config:
    """V2-Base ~350M params — first real scale."""
    defaults = dict(
        d=1024, L=24, H_E=12, H_I=4,
        d_ff=4096, K=4, P=4,
        V=50257, max_seq_len=1024,
        neuromod_global_hidden=512, neuromod_local_hidden=64,
        glh_chunk_size=64,
        lr=1e-4, warmup_steps=5000, batch_size=16,
    )
    defaults.update(kwargs)
    return NCTv2Config(**defaults)