# modelmap **Repository Path**: limoncc/modelmap ## Basic Information - **Project Name**: modelmap - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-08-31 - **Last Updated**: 2026-08-31 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # modelmap Paste a Hugging Face model id. Get a living map of the network — explorable down to every projection, animated so you can watch a token flow from embedding to logits — and the answer to the question you re-ask every week: **will it fit on my GPU?** **No weights are ever downloaded.** modelmap fetches `config.json` (~2 KB), instantiates the model on PyTorch's meta device, runs a hooked fake forward pass to capture real execution order and tensor shapes, and serves the result as a compact hierarchical graph. An 8B or 671B model costs the same few seconds; the graph ships as ~10 KB gzipped. **Live demo:** https://modelmap.cc (free-tier Cloud Run: cached models are instant; the first uncached model on a cold instance takes ~30 s). Try **⚡ live**: open [TinyLLama-v0](https://modelmap.cc/m/Maykeye/TinyLLama-v0), press ⚡ live, type a prompt — real next-token probabilities, per-head attention and a logit lens, computed in *your* browser (9 MB download; the server still never touches weights). Design doc: [docs/design.html](docs/design.html) · API (REST · Python · CLI · MCP): [docs/API.md](docs/API.md) · Deployment: [DEPLOY.md](DEPLOY.md) · Extending: [EXTENDING.md](EXTENDING.md) ## Run it ```bash # one-off, nothing to install (pins the CPU torch wheel instead of the 2.5 GB CUDA one) uvx --index https://download.pytorch.org/whl/cpu modelmap # opens http://127.0.0.1:7860 # from a checkout uv sync && (cd web && npm install && npm run build) uv run modelmap # serve + open browser uv run modelmap ./my-finetune # …opening a local checkpoint (dir, .safetensors or .gguf) uv run modelmap serve --warm # pre-extract the gallery in the background uv run modelmap dump Qwen/Qwen3-8B -f md # graph as JSON / CSV / Markdown / DOT uv run modelmap cost Qwen/Qwen3-8B-GGUF:Q4_K_M # headline numbers for a quantized variant uv run modelmap plan Qwen/Qwen3-8B --gpus 2 --gpu-memory 24 --pp 2 -T 32768 # does it fit? uv run modelmap diff Qwen/Qwen2.5-7B Qwen/Qwen3-8B uv run modelmap mcp # MCP server for Claude Code / Cursor (pip install 'modelmap[mcp]') # container (non-root, read-only rootfs, capabilities dropped) docker compose up --build ``` `uvx modelmap` needs the package on PyPI (`uv publish`); until then install from GitHub: `uvx --index https://download.pytorch.org/whl/cpu --from modelmap@git+https://github.com/lizhaoliu/modelmap modelmap` (add `[mcp]` → `modelmap[mcp]@git+…` for the MCP server). CI also attaches a wheel to each GitHub release. ## What you get - **Explore mode** — a zoomable, collapsible map of the module tree. Repeated layers collapse into stacks (`decoder block ×36`, `experts ×128`) so a 235B MoE opens as ~10 nodes — including interleaved designs (DeepSeek-V4's alternating attention layers collapse into `×43 — 2 repeated designs`). Click any node for class, params (absolute + share), dtype, weight shapes with inline dim labels (`[151936 vocab × 4096 hidden]`), traced I/O shapes (`[1 batch × 7 seq × 4096 hidden]`), and a parameter treemap of its children, the module's own attributes (`in_features`, `eps`, kernel…) and a link to its defining source line. A **cost lens** (`params · compute · memory · kv · vram`) re-encodes the map with analytic MACs, activation and KV-cache bytes and active-params-per-token for MoE, all re-derived live from a what-if bar (sequence length, batch, dtype). Breadcrumb trail, semantic colors, light/dark, shareable URLs that reproduce the exact view, keyboard-first (`?` lists shortcuts). - **Flow mode** — the animation is the default impression: the landing page opens on a running mini-replay, a first visit to any model starts its own replay (once; never under reduced motion), edges drift while it runs, edge thickness encodes the tensor flowing through, and the camera follows the pulse (pan to take over). It replays the traced forward pass: an amber pulse travels the graph in real execution order while a HUD narrates each step with true shapes and a plain-language caption. Repeat stacks compress with a `layer 12 / 36` counter (~12 s for a full 8B replay). Expand a block and the pulse walks its internals. **Micro-views** show a beat's inner choreography — a block's norm → attention → ⊕ → norm → MLP → ⊕, attention's Q/K/V → scores → softmax → merge, a gated MLP, an MoE router — all filled from the model's own config and trace. - **Compare** — `/compare/A...B` (or “compare…” in the top bar): two models aligned by path, then by role, with linked pan/zoom/expansion/selection; unchanged modules dim, changed ones outline amber, additions/removals get `+`/`−`; a two-column diff inspector and a summary strip (params, layers, heads, KV heads, hidden, ffn, vocab, context, compute/token, KV/token). Base vs fine-tune reports no structural change; Qwen2.5-7B vs Qwen3-8B calls out q/k norms, dropped biases, ffn, layers. - **⚡ Live mode** — for small models (llama-family / gpt2, single-file safetensors ≤ 700 MB) the browser downloads the weights and runs *real inference* on your CPU in a Web Worker — a hand-written TS engine (RMSNorm/rotary/GQA/SwiGLU and the GPT-2 stack, KV cache, two BPE tokenizer families read straight from tokenizer.json). Type a prompt: true next-token probabilities, a per-head **attention heatmap** (layer slider, head picker, or click an attention block on the map), a **logit lens** showing the prediction sharpen layer by layer, and streamed generation that ripples through the map. TinyLLama-v0 (9 MB, ~4 ms/token) is the instant default; SmolLM2-135M and distilgpt2 also run. The engine is pinned to real `transformers`/`tokenizers` outputs by fixture tests (logits 2e-4, attention 2e-5, greedy token-for-token, byte-identical tokenization). - **Take it with you** — `export ▾` saves a PNG/SVG of the current view, a Markdown summary, a CSV module table (params, shapes, dtype, cost columns), the JSON document or Graphviz DOT; copies a link to the exact view, an `