--- title: AI Model X-Ray emoji: 🔬 colorFrom: blue colorTo: green sdk: gradio sdk_version: 5.33.0 app_file: app.py pinned: false license: apache-2.0 short_description: Which layers can you prune? Structural health scanner. tags: - backyard-ai - custom-ui --- # 🔬 AI Model X-Ray — Structural Health Scanner Which layers of your transformer are compressible? Which are fragile? Select a model or paste any HuggingFace model ID. The scanner extracts attention graphs, computes the spectral simplicial hierarchy per layer, and classifies each layer as **immune** (safe to prune), **buffer** (caution), or **critical** (do not touch). Based on the spectral principle λ₂(T(G)) ≤ λ₂(G), validated on 45,000+ graphs with zero violations. Formally verified in Lean 4. ## How it works For each layer we average every attention head's map over a small probe set (16 sentences for text models, 16 CIFAR-10 images for vision), flatten it to a signature, and join heads whose signatures correlate (Pearson r > 0.3). On that head-to-head graph `G` we compute: - **λ₂(G)** — algebraic connectivity of the head graph. - **T(G)** — the triangle graph (edges of `G` that share a triangle). - **λ₂(T(G))** and the coherence ratio **ρ = λ₂(T(G)) / λ₂(G)**. - **FI** — the fragility index: fraction of edges sitting in zero triangles. High ρ with zero FI means a layer is triangle-redundant — its head structure has slack and is safe to prune. Low ρ means the layer is structurally load-bearing. | Regime | Condition | Meaning | |---|---|---| | 🟢 Immune | ρ > 0.8, FI = 0 | safe to prune | | 🟡 Buffer | 0.5 ≤ ρ ≤ 0.8 | prune with caution | | 🔴 Critical | ρ < 0.5 | do not prune | Pre-loaded models (BERT, GPT-2, ViT) show **instantly** from a precomputed cache. Custom model IDs and DistilBERT trigger a live scan on ZeroGPU. 🎬 Demo: [YouTube link TBD] 🐙 See also: [Octopus AI](https://huggingface.co/spaces/build-small-hackathon/octopus-ai) Built by [Cognitive Engineering](https://cognitive-engineering.dev) 🇨🇭