ai-model-xray / README.md
CognitiveEngineering's picture
Deploy AI Model X-Ray - structural health scanner
451cf40 verified
|
Raw
History Blame Contribute Delete
2.08 kB

A newer version of the Gradio SDK is available: 6.20.0

Upgrade
metadata
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

Built by Cognitive Engineering πŸ‡¨πŸ‡­