{
  "name": "AI For Engineers, Part 3: Inside the LLM Engine — Matrices, Attention & Weights",
  "badge": "AI FOR ENGINEERS · PART 03 / 09",
  "children": [
    {
      "name": "Ch. 01: From Part 2 Audits to the Five LLM Engine Pillars",
      "children": [
        {
          "name": "Core Principle: Every numeric drift and phantom citation in Part 2 traces directly to Transformer matrix math and sampling."
        },
        {
          "name": "Why Unverified Drafts Hallucinated",
          "children": [
            {
              "name": "Pump draft shifted LOG-104 seal-housing peak (84.2°C → 94.2°C across SPEC-201's 85.0°C limit) and fabricated SPEC-992."
            },
            {
              "name": "Rule / Formula: verify_document.py @ τ = 0.0 → Quarantine Drift"
            }
          ]
        },
        {
          "name": "Neural Manifolds & 2017 Attention",
          "children": [
            {
              "name": "Affine weight projections, Pre-Norm residual highways, and Q, K, V attention circuits replace sequential recurrence."
            },
            {
              "name": "Rule / Formula: X → Affine + Nonlinearity + Causal Attention"
            }
          ]
        },
        {
          "name": "Decoder Layers, HBM & KV Caches",
          "children": [
            {
              "name": "RoPE, SwiGLU MLPs, compute-bound prefill, memory-bound decode, GQA, and FlashAttention govern context window physics."
            },
            {
              "name": "Rule / Formula: Prefill = Compute-Bound | Decode = HBM-Bound"
            }
          ]
        },
        {
          "name": "Sampling, Quantization & Weights",
          "children": [
            {
              "name": "Temperature scaling shapes inference logits, while Pre-Training, SFT (full or LoRA), and Preference/RL alignment update weights."
            },
            {
              "name": "Rule / Formula: Training Updates W | Inference Freezes W"
            }
          ]
        }
      ]
    },
    {
      "name": "Ch. 02: Affine Projections, Fixed Width & Nonlinear Manifolds",
      "children": [
        {
          "name": "Core Principle: Without nonlinear activations, a hundred linear matrices algebraically collapse into one single matrix."
        },
        {
          "name": "Activation Tensor X (B × T × d_model)",
          "children": [
            {
              "name": "Sequence length T varies with prompt tokens, while hidden width d_model (e.g., 4,096) remains fixed across all layers."
            },
            {
              "name": "Rule / Formula: Shape(X) = [Batch B, Tokens T, Width d_model]"
            }
          ]
        },
        {
          "name": "Weights W and Bias Vector b",
          "children": [
            {
              "name": "Each linear projection maps d_in features to d_out features using learned weight parameters W and additive bias b."
            },
            {
              "name": "Rule / Formula: Z = X × W + b   (W in R^(d_in × d_out))"
            }
          ]
        },
        {
          "name": "Why Linear Stacks Collapse Without σ",
          "children": [
            {
              "name": "Without ReLU, GELU, or SwiGLU activations, stacked matrices reduce to one linear transform and cannot separate curved data."
            },
            {
              "name": "Rule / Formula: W₂ × (W₁ × X) = W_eff × X  vs  σ(X × W₁) × W₂"
            }
          ]
        }
      ]
    },
    {
      "name": "Ch. 03: Pre-Norm Residual Highways & RMSNorm Stability",
      "children": [
        {
          "name": "Core Principle: Additive residual skip highways preserve an identity gradient path across eighty to one hundred layers."
        },
        {
          "name": "Repeated Matrix Products Diverge",
          "children": [
            {
              "name": "Multiplying 100 unnormalized matrices drives singular values to 0 or ∞, halting parameter updates in early layers."
            },
            {
              "name": "Rule / Formula: ∏ W_l → 0 (Vanishing) or ∞ (Exploding)"
            }
          ]
        },
        {
          "name": "Additive Pre-Norm Residual Stream",
          "children": [
            {
              "name": "Attention and MLP sub-layers read normalized states from a shared stream and add bounded delta updates back into x."
            },
            {
              "name": "Rule / Formula: x_next = x + F(RMSNorm(x))  |  ∂x_next/∂x = I + ∂F/∂x"
            }
          ]
        },
        {
          "name": "Root Mean Square Gain Stabilization",
          "children": [
            {
              "name": "Divides vector x by its root-mean-square norm times learned scale γ, skipping mean subtraction to reduce memory ops."
            },
            {
              "name": "Rule / Formula: RMSNorm(x) = (x / √(mean(x²) + ε)) * γ"
            }
          ]
        }
      ]
    },
    {
      "name": "Ch. 04: Superposition & Hypothesis: How Weights Blur 84.2°C → 94.2°C",
      "children": [
        {
          "name": "Core Principle: Weights store lossy superposed feature directions—never treat parametric memory as a relational database."
        },
        {
          "name": "Packing Millions of Features in R^d",
          "children": [
            {
              "name": "A 4,096-wide vector holds exponentially many nearly perpendicular directions, letting layers store >> 4,096 concepts."
            },
            {
              "name": "Rule / Formula: m >> d Directions with |dot(v_i, v_j)| < ε"
            }
          ]
        },
        {
          "name": "Shared Neurons & Cross-Talk Noise",
          "children": [
            {
              "name": "Single neurons activate on unrelated syntax and physics features; overlapping projections create non-zero interference."
            },
            {
              "name": "Rule / Formula: x_reconstructed = W^T W x = x + Interference"
            }
          ]
        },
        {
          "name": "How Priors Can Pull 84.2°C → 94.2°C",
          "children": [
            {
              "name": "Illustrates how lossy parametric priors can pull prompt numbers toward common values unless CSV scripts verify LOG-104."
            },
            {
              "name": "Rule / Formula: LOG-104 CSV = 84.2°C ≠ Superposed Prior 94.2°C"
            }
          ]
        }
      ]
    },
    {
      "name": "Ch. 05: Why Fixed-State Recurrence Failed & 2017 Attention",
      "children": [
        {
          "name": "Core Principle: Vaswani et al. (2017) replaced O(N) sequential recurrence with O(1) path-length all-to-all token routing."
        },
        {
          "name": "Serial O(N) Steps & Information Loss",
          "children": [
            {
              "name": "State h_t waits for h_(t−1), blocking parallel GPU training and compressing distant document specs into one lossy vector."
            },
            {
              "name": "Rule / Formula: h_t = f(h_(t−1), x_t)  →  Path Length O(N)"
            }
          ]
        },
        {
          "name": "Attention Is All You Need Blueprint",
          "children": [
            {
              "name": "Replaced recurrence with direct all-pairs attention: N = 6 layers, d_model = 512, d_ff = 2048, and 8 heads of width 64."
            },
            {
              "name": "Rule / Formula: Direct Token Routing  →  Path Length O(1)"
            }
          ]
        },
        {
          "name": "Dropping the Bidirectional Encoder",
          "children": [
            {
              "name": "Frontier LLMs retain only the masked autoregressive Decoder stack so one unified architecture reads prompts and generates."
            },
            {
              "name": "Rule / Formula: Encoder-Decoder (2017) → Causal Decoder Stack"
            }
          ]
        }
      ]
    },
    {
      "name": "Ch. 06: Scaled Dot-Product Q, K, V Math & Causal Masking",
      "children": [
        {
          "name": "Core Principle: Dividing Q·K^T by √d_k prevents softmax gradient saturation while causal masks block future tokens."
        },
        {
          "name": "Scaled Dot-Product Attention",
          "children": [
            {
              "name": "Queries match Keys via dot products to compute normalized routing weights that blend Value payload vectors across context."
            },
            {
              "name": "Rule / Formula: Attention(Q,K,V) = softmax((Q·K^T + M) / √d_k) · V"
            }
          ]
        },
        {
          "name": "Preventing Softmax Saturation",
          "children": [
            {
              "name": "Unit-variance Q and K of width d_k = 64 yield dot-product variance 64; scaling by 1/√64 = 1/8 restores unit variance."
            },
            {
              "name": "Rule / Formula: Var(q · k) = d_k  →  Var((q · k)/√d_k) = 1"
            }
          ]
        },
        {
          "name": "Upper-Triangular Future Blocking",
          "children": [
            {
              "name": "Mask matrix M sets entries j > i to −∞ before softmax, producing exact 0.0 weights on ungenerated future tokens."
            },
            {
              "name": "Rule / Formula: M_(i,j) = 0 (j ≤ i)  |  M_(i,j) = −∞ (j > i)"
            }
          ]
        }
      ]
    },
    {
      "name": "Ch. 07: Multi-Head Routing & Why Induction Heads Invent SPEC-992",
      "children": [
        {
          "name": "Core Principle: Induction heads complete structural citation patterns even when no matching source file exists."
        },
        {
          "name": "Parallel Subspace Projections",
          "children": [
            {
              "name": "W_Q, W_K, and W_V split d_model into H heads (d_head = d_model/H); W_O merges routed head outputs back to the stream."
            },
            {
              "name": "Rule / Formula: MHA(X) = Concat(head₁, …, head_H) × W_O"
            }
          ]
        },
        {
          "name": "Two-Layer Pattern Completion",
          "children": [
            {
              "name": "Layer-1 head indexes previous-token transitions; Layer-2 head matches the current prefix and predicts matching structure."
            },
            {
              "name": "Rule / Formula: [SPEC-][201] … [Seal Limit: SPEC-] → [992]"
            }
          ]
        },
        {
          "name": "Stopping Phantom Citations",
          "children": [
            {
              "name": "Pair Part 2's Unknowns Contract in the prompt with verify_document.py file-existence checks against the evidence folder."
            },
            {
              "name": "Rule / Formula: Cite Existing ID or Output UNKNOWN + Script Audit"
            }
          ]
        }
      ]
    },
    {
      "name": "Ch. 08: Tokens, Embeddings, RoPE & SwiGLU Memory Layers",
      "children": [
        {
          "name": "Core Principle: Subword tokens, RoPE relative angles, and SwiGLU MLP banks hold nearly two-thirds of dense LLM weights."
        },
        {
          "name": "Subword IDs & Learned Matrix E",
          "children": [
            {
              "name": "Tokenizer maps text/digits to IDs in V ≈ 128k (~0.75 words/token); row E[id] initializes the contextual residual vector."
            },
            {
              "name": "Rule / Formula: Text → Token IDs [0..V−1] → x₀ = E[id]"
            }
          ]
        },
        {
          "name": "Relative Distance via 2D Rotation",
          "children": [
            {
              "name": "Rotates Q at index m and K at index n in complex 2D planes so their inner product depends directly on offset (m − n)."
            },
            {
              "name": "Rule / Formula: dot(R_m q, R_n k) = g(q, k, m − n)"
            }
          ]
        },
        {
          "name": "Where Two-Thirds of Weights Reside",
          "children": [
            {
              "name": "Gated projections W_gate and W_up detect multi-token features gathered by attention; W_down writes attributes back."
            },
            {
              "name": "Rule / Formula: SwiGLU(x) = (Swish(x·W_gate) * (x·W_up)) · W_down"
            }
          ]
        }
      ]
    },
    {
      "name": "Ch. 09: GPU HBM Bandwidth vs Compute: Prefill vs Decode",
      "children": [
        {
          "name": "Core Principle: Prompt prefill saturates GPU compute cores in parallel; token-by-token decode stalls on HBM weight reads."
        },
        {
          "name": "Compute FLOPs vs HBM Byte Traffic",
          "children": [
            {
              "name": "GPU tensor cores compute orders of magnitude faster than off-chip HBM buses can stream gigabytes of model weights."
            },
            {
              "name": "Rule / Formula: Intensity = FLOPs / Bytes Moved (HBM ↔ SRAM)"
            }
          ]
        },
        {
          "name": "Parallel Matrix-Matrix (Compute-Bound)",
          "children": [
            {
              "name": "Processes all T prompt tokens at once; every weight fetched into SRAM multiplies across T vectors simultaneously."
            },
            {
              "name": "Rule / Formula: [T × d] × [d × d]  →  High Weight Reuse (TTFT)"
            }
          ]
        },
        {
          "name": "Serial Matrix-Vector (Bandwidth-Bound)",
          "children": [
            {
              "name": "Each generated token depends on the prior output, streaming all active weights from HBM for just 1 token vector."
            },
            {
              "name": "Rule / Formula: [1 × d] × [d × d]  →  1 Weight Read per Token"
            }
          ]
        }
      ]
    },
    {
      "name": "Ch. 10: KV Cache, GQA, FlashAttention & Context Window Drift",
      "children": [
        {
          "name": "Core Principle: GQA and FlashAttention tame KV memory traffic, while bounded context curbs empirical middle-context recall drops."
        },
        {
          "name": "Trading Compute for VRAM Capacity",
          "children": [
            {
              "name": "Caching prior K and V tensors makes decode steps O(N) instead of O(N²), but VRAM and HBM reads grow with context N."
            },
            {
              "name": "Rule / Formula: KV Bytes = 2 × L × n_kv × d_head × N × bytes"
            }
          ]
        },
        {
          "name": "GQA Shares K, V Across Query Groups",
          "children": [
            {
              "name": "Sharing 1 Key-Value head across 8 Query heads slashes KV Cache footprint and decode HBM traffic by 8×."
            },
            {
              "name": "Rule / Formula: MHA (n_kv = n_q)  →  GQA (n_kv = n_q / 8)"
            }
          ]
        },
        {
          "name": "SRAM Tiling & Online Softmax",
          "children": [
            {
              "name": "Computes exact attention inside fast on-chip SRAM blocks so the N × N score matrix never writes to slow HBM."
            },
            {
              "name": "Rule / Formula: Attention Memory: O(N²) HBM → O(N) Linear"
            }
          ]
        },
        {
          "name": "KV Reuse vs. Empirical Recall Drop",
          "children": [
            {
              "name": "KV caching is exact math, yet empirical benchmarks show middle-context distractor logs lower recall unless staged specs bound input."
            },
            {
              "name": "Rule / Formula: Exact KV Math ≠ Uniform Long-Context Recall"
            }
          ]
        }
      ]
    },
    {
      "name": "Ch. 11: Temperature Sampling (τ → 0) & Low-Bit Quantization",
      "children": [
        {
          "name": "Core Principle: Zero temperature enforces greedy argmax decoding, while MoE and FP8/NVFP4 slash HBM weight streaming."
        },
        {
          "name": "Why verify_document.py Uses τ = 0.0",
          "children": [
            {
              "name": "Positive τ scales logits pre-softmax, while τ = 0 invokes greedy argmax(z) for near-deterministic audits on pinned snapshots."
            },
            {
              "name": "Rule / Formula: τ > 0: softmax(z / τ)  |  τ → 0⁺ ⇒ argmax(z)"
            }
          ]
        },
        {
          "name": "Argmax ≠ Guaranteed Ground Truth",
          "children": [
            {
              "name": "Greedy argmax stays repeatable up to GPU kernel/batch tie-breaks, yet still picks ungrounded top logits without CSV checks."
            },
            {
              "name": "Rule / Formula: τ = 0.0 Entailment + Exact CSV/File Verification"
            }
          ]
        },
        {
          "name": "Top-k Experts & FP8 / NVFP4 Blocks",
          "children": [
            {
              "name": "Sparse MoE activates only top-k MLP experts per token, while 8-bit FP8 and 4-bit NVFP4 compress HBM weight transfers."
            },
            {
              "name": "Rule / Formula: BF16 (16-bit) → FP8 / NVFP4 (Up to 4× Less HBM)"
            }
          ]
        }
      ]
    },
    {
      "name": "Ch. 12: Three Weight Stages, Optional LoRA & Part 4",
      "children": [
        {
          "name": "Core Principle: Pre-training, full or LoRA SFT, and preference or RL alignment shape weights; Part 4 compares frontier stacks."
        },
        {
          "name": "Self-Supervised Next-Token Loss",
          "children": [
            {
              "name": "Updates all base weights via Cross-Entropy loss (−log P(y_true)), matrix backprop (∇W = X^T·ΔY), and AdamW states."
            },
            {
              "name": "Rule / Formula: Loss = −log P(y_true)  |  AdamW Updates All W₀"
            }
          ]
        },
        {
          "name": "Full SFT or Low-Rank Adapters",
          "children": [
            {
              "name": "Updates full checkpoints or optional LoRA adapters B × A (often <1% of weights) on curated instruction pairs."
            },
            {
              "name": "Rule / Formula: W_adapted = W₀ + B × A   (r << d_model)"
            }
          ]
        },
        {
          "name": "Offline DPO vs. Online RLHF / RLVR",
          "children": [
            {
              "name": "Aligns policy weights via offline Direct Preference Optimization or online RLHF and verifiable-reward RL."
            },
            {
              "name": "Rule / Formula: Offline DPO (Pairs) | Online RLHF / RLVR"
            }
          ]
        },
        {
          "name": "Big 4 Frontier Ecosystems Overview",
          "children": [
            {
              "name": "Dr. Ada & Dr. Alan compare OpenAI, Anthropic, Google AI, and xAI architectures, context windows, Skills, and Agents."
            },
            {
              "name": "Rule / Formula: Part 03 LLM Engine → Part 04 Frontier Comparison"
            }
          ]
        }
      ]
    }
  ]
}
