model-graph

See your model think — then run one yourself.

An open teaching tool for language models. Run a tiny model (135M–500M) right in your browser on WebGPU — watch it generate, or drive it through an agent state machine that turns one forward pass into a think → tool → observe loop. Every layer's activity — norms, heads, router flow, logit lens, attention, residual trajectories — streams live as it runs. OpenAI-compatible, testable, honest. The animation behind this card is the real visualization, on mock data.

What you see · live mock views

Logit-lens flips

Every layer's residual decoded as if the network stopped there. Dots mark where the prediction changes with depth — red where it settles on the token actually emitted. Settle depth ≈ per-token difficulty.

Residual trajectory

Each token's hidden state as a point in a fixed random 3D basis, connected in generation order — blue dotted trace is the full prompt context. Loops = repeated structure; outliers = attention sinks. Drag-rotate, per-layer minimap in the real app.

Attention sources

Select any token and see where it looked: top attention sources (mean over heads) drawn as arcs over the token strip, with per-token uncertainty (entropy + margin) riding on every frame.

Inside a transformer · step by step

token mixer channel mixer

go deeper: an intro to transformers, along the papers →

Run it as an agent · a state machine for tiny models

A 135M model can't reliably use tools on its own — a harness makes it. A finite state machine drives the model through an explicit loop, and you watch every decision live in your browser:

think decide call a tool observe answer

Real tools run in the page (calculator, unit-convert, clock) alongside clearly-labelled sandbox tools. When a tiny model flubs the format, the harness catches it — the failure is shown, not hidden. No GPU? A scripted demo runs the same machine with no download.

Why it fits your stack

OpenAI-compatible

Point any SDK or agent framework at http://localhost:8080/v1 — zero code change and every request is fully instrumented, recorded and replayable.

Tool calling + multimodal

Spec-compliant tool_calls round-trips (LFM2 pythonic + JSON parsing) and image content parts — vision-language chats are hooked like any other.

Testable internals

The curator records every run and gates CI: internals checks (finite norms, settle depth, uncertainty, attention focus) plus tool-reasoning suites — should-call / abstain / arguments / grounded chains.

Runs in the browser too

Curated models on WebGPU via transformers.js — no install. Run one as an agent → through a state-machine harness, or use the observable-ONNX export that graph-surgeries residual streams into declared outputs, so serverless runs still show real per-layer activity.

Engines at a glance

capabilityserverbrowserbrowser·observable
chat + top-k predictions
tool calling · multimodal
norm heatmaps · heads · lens · arcsresid
residual trajectory + context
curator recording

Run your own · 2 minutes

# clone & env (python 3.11+, torch with your accelerator) git clone https://github.com/QSchlegel/model-graph && cd model-graph python3 -m venv .venv && .venv/bin/pip install -r requirements.txt # full stack: OpenAI API + chat + dashboard + ws internals .venv/bin/python api_server.py --model LiquidAI/LFM2.5-1.2B-Instruct --device mps → http://localhost:8080 (chat at /chat · dashboard at /dashboard) # no GPU / no weights? the entire UI on a mock backend: .venv/bin/python api_server.py --mock # wire in any agent: client = OpenAI(base_url="http://localhost:8080/v1", api_key="x")
# test gates: pipeline sanity + behavioral suites over internals .venv/bin/python harness.py all --model-dir <folder> --fallback-hub LiquidAI/LFM2.5-1.2B-Instruct .venv/bin/python curator.py suite suites/smoke.json .venv/bin/python curator.py suite suites/tools.json # build the observable ONNX model for in-browser internals .venv/bin/python export_observable.py

Works with any HF causal LM — hybrid conv/SSM, MoE and vision-language models are first-class. Apple-silicon (mps), CUDA and CPU devices.

Contribute

Start here

product six-pager (PDF) · the vault (architecture & flow graphs, protocol, engines) · CONTRIBUTING · AGENTS.md keeps humans and AI agents honest about docs.

Good first contributions

suite cases & curator checks (no ML needed) → curated browser engines → dashboard views for attention/entropy → observable-export coverage → hooks for new architectures.

House rules

Honest pixels (never render unmeasured data) · every PR keeps the vault diagrams true · suites green before merge · MIT licensed.