deepvis

Wrap any PyTorch, JAX (Flax linen, Flax NNX, Equinox, or a plain apply_fn(params, x)) or Keras 3 network — or open a saved file (ONNX, .keras, a torch.export program, a state_dict or .safetensors) — then focus on any part of it, monitor intermediate layers, unroll it into mathematics, play with its weights, activations and inputs, and see all of it in 3Blue1Brown style: an interactive dashboard with 2-D and volumetric 3-D views, and manim videos. Every color comes from manim's own palette.

deepvis in VS Code: Visualize, layers explained, the forward pass, 3-D tensors, neurons, weight edits, interventions, equations, drawing an input, live training

The 60-second tour inside VS Code (MP4, full-size GIF); a slower walkthrough: the VS Code introduction.

ResNet-18's tensors as 3-D volumes, each face painted with real activations

import deepvis as dv

net = dv.visualize(model, x)                # the one call: wrap, run on x, show inputs, every tensor, outputs
                                            # (browser, or inline in Jupyter) — and keep the wrapper:
net = dv.wrap(model, sample_input=x)        # torch / flax / nnx / equinox / (apply_fn, params) / keras
net = dv.open("model.onnx")                 # or a saved file: .onnx .keras .pt2 .pt .safetensors .npz
net.show(x)                                 # interactive dashboard (inline in Jupyter)
net.serve(x)                                # …live: draw inputs, edit weights, intervene, in the browser
print(net.equation())                       # h₁ = σ(W⁽¹⁾vec(x) + b⁽¹⁾) … ŷ = softmax(W⁽³⁾h₂ + b⁽³⁾)
net["fc1.weight"][:, 3] = 0                 # weight surgery — recorded, undoable, replayable
with net.intervene("relu1", dv.ablate([7])):  # activation-level knockouts
    y = net(x)
net.animate("volumes", x, path="tensors.mp4")  # a manim ThreeDScene of the network's tensors

dv.export_html(model, x, "model.html")      # one call → a self-contained interactive page
dv.export_svg(model, x, "model.svg")        # … or a static figure with the same expressive glyphs

It is general-purpose

The same calls work on everything below (all covered by the test suite): outputs match the native model, the graph includes functional ops (residual +, cat, softmax, .T, reshapes), and every layer can be traced, unrolled, edited and intervened on.

model what it exercises
torchvision ResNet-18, MobileNetV3 residual adds, BatchNorm, Hardswish, squeeze-excite mul
torchvision VisionTransformer, nn.TransformerEncoder attention (maps captured), class token, fused fast path
LSTM / GRU tuple outputs, recurrent layers
U-Net skip concatenations, transposed convolutions
two inputs → dict of outputs multi-input / multi-output graphs
weight tying, a module called twice shared parameters (… E⁽¹⁾ᵀ), call instances
Flax attention + BatchNorm, Equinox CNN, pure-JAX lax.scan RNN JAX flavors, running stats, loops
HuggingFace GPT-2, BERT, Llama, T5 HF layer classes recognized by name (GPT-2's Conv1D as an (in, out) Linear, LlamaRMSNorm, NewGELUActivation, rotary embeddings), fused SDPA attention (patterns recomputed: identical to output_attentions=True, causal / padding masks and grouped-query heads included), a fresh KV cache's cat(∅, k) elided, never-run modules hidden
torchvision ResNet-50, ViT-B/16, ConvNeXt-T size: 2–3 s exports, 4–6 MB self-contained pages (adaptive budgets, 8-bit quantized maps)
timm ResNet, ViT/DeiT, ConvNeXt, EfficientNet unbind-style q/k/v (multi-output ops get one node per output), hundreds of Identity / Dropout(0) placeholders (traced, hookable, not drawn), 3-D cls_token / pos_embed parameters
a module with no submodules (pure functional forward) traced into its ops rather than drawn as one box

Saved files, ONNX, Keras and torch.export

dv.open(path) (and deepvis open|export <file> on the command line) reads a model from wherever it was saved; dv.wrap and dv.visualize take the same paths.

file what you get
.onnx any exported network — PyTorch (both exporters), TensorFlow / Keras via tf2onnx, scikit-learn … — run in onnxruntime. Layers come from the exporter's module scopes (layer1.0.conv1, with their classes from the dynamo exporter's metadata); a decomposed attention or GELU folds back into one node; BatchNorm folded into a convolution and tensors the exporter stored once are traced back to their layers. Trace it, edit its weights (net.backend.save("edited.onnx")), make its page; interventions and gradients need the original model.
.keras / .h5 a Keras 3 model on the JAX, PyTorch or TensorFlow backend (the same as dv.wrap(keras_model, sample_input=x)): Sequential, functional and subclassed models, nested models as containers, a shared layer drawn per call, functional ops (keras.ops.relu on a symbolic tensor) as nodes, a layer's own activation= in its explanation and equations; weights edited in place, interventions on any layer.
.pt2 a torch.export program: its module tree and classes come back from the export's metadata — the same graph as the module it came from, still a live PyTorch module (interventions, gradients). dv.wrap(exported_program) works too.
.pt .pth .bin .ckpt torch.load(weights_only=True): a state_dict (or a checkpoint holding one) opens as a weights-only view. A file with a whole pickled module runs code when loaded, so it needs trusted=True (--trust).
.safetensors, .npz a weights-only view, read lazily: a 7B checkpoint opens in seconds, bfloat16 included.

A weights-only view draws one node per module path, its kind guessed from the tensors it holds (a 4-D weight is a convolution, running_mean means BatchNorm, in_proj_weight attention …), with every tensor's values, statistics and histograms. There is no code to trace, so layers are linked in name order — alphabetical .safetensors files are put back in computation order (embeddings, then per block norm → attention → norm → MLP, then the head) — and the page says so.

Inputs can be a dict too: a tokenizer's output ({"input_ids": …, "attention_mask": …}) is bound to the model's forward arguments by name.

Huge models

A model built on PyTorch's meta device has its architecture and shapes but no numbers and no memory, so any size draws in seconds: the page shows every layer, shape, parameter count, equation and explanation (marked shapes only; tracing needs real weights).

with torch.device("meta"):
    model = AutoModelForCausalLM.from_config(AutoConfig.from_pretrained("meta-llama/Llama-3.1-70B"))
dv.wrap(model, sample_input=torch.zeros(1, 8, dtype=torch.long, device="meta")).export_html("70b.html")
deepvis export hf:mistralai/Mixtral-8x7B-v0.1 --meta -o mixtral.html   # config only: ~5 s, 46.7B parameters
deepvis summary torchvision:vit_h_14 --meta

A 7B Llama (1,223 layers drawn) makes its page in 0.5 s and a 70B one (3,047) in 4 s; pages ship each distinct glyph once, values that every layer reads (rotary embeddings, masks) are drawn as one faint line rather than routed through every row, and live pages compress their updates.

Compatibility: the model zoo

61 of 61 architectures — from Hugging Face, JAX, Keras, ONNX, custom, timm, torchvision — wrap, trace to the native model's output (to 1e-4) and make a page in the test suite: the full table.

The neuron view of a trained MLP: the selected neuron's incoming weights form a ring detector

Install

pip install deepvis                 # the core needs only numpy
pip install "deepvis[torch]"        # or pick extras: [torch] [jax] [keras] [onnx] [widget] [figures] [anim] [sympy] [all]

From a checkout, for development:

conda create -n deepvis python=3.12 && conda activate deepvis
pip install -e ".[all,dev]"

Notes:

In VS Code

The deepvis extension — deepvis by batuoz on the VS Code Marketplace (ext install batuoz.deepvis) — shows the page in a panel beside your code:

Your unsaved edits are what runs, and saving re-makes the page. A failure puts a squiggle on its line with the fix.

To build it from a checkout instead: cd vscode && npm install && npm run package && code --install-extension deepvis-0.3.0.vsix.

The same runner works from a terminal: python -m deepvis.capture page.html train.py --line 40 --model net --inputs x writes the page for net on x as they are right after line 40, then stops the script.

A tour

The tour goes through every feature with code and pictures: wrap and focus, monitor, unroll into mathematics, manipulate weights, intervene on activations, export (HTML, SVG, PNG, PDF), notebooks, W&B and TensorBoard, live pages, language models and the logit lens, inside attention, attribution, comparing checkpoints, datasets, diffusion, training from the page, and manim animations.

When something goes wrong

Errors say what happened and what to do, in terms of your model and inputs — the model's own traceback stays attached underneath:

deepvis.errors.RunError: the model raised RuntimeError when run on the inputs: mat1 and mat2 shapes cannot be
multiplied (3x7 and 5x8)
  → fix: a Linear layer expects 5 features in the last dimension but got 7 (inputs: (3, 7)). Reshape the input,
    or check the first layer's in_features.

Covered: the class instead of an instance, None / dict / empty inputs, wrong feature counts, channels, dimensions, dtypes, token ids beyond the vocabulary, missing forward arguments, flax variables and JAX shape mismatches, misspelled options and views (with did you mean), unwritable paths, busy ports, unknown model names in the CLI, denoisers with the wrong signature, and — for scripts run from the VS Code extension — syntax errors, missing packages, timeouts and out-of-memory kills, pinned to the failing line. Harmless mismatches just work: numpy arrays and plain lists become tensors, inputs move to the model's device, missing output folders are created. Requests that can't apply (e.g. start="attention" for a model without attention, labels of the wrong length) raise a DeepvisWarning and the page is still made. All errors subclass deepvis.DeepvisError and the matching built-in (ValueError, TypeError, …).

Examples

examples/ has runnable scripts (outputs go to examples/out/): a trained MLP (01), CNN pruning (02), transformer attention and patching (03), Flax linen (04), NNX (05), Equinox (06), plain JAX (07), a weight-surgery tour (08), monitoring during training (09), the live playground on a trained classifier (10), the animations (11), a zoo of real architectures (12), exporting pages and figures (13), a live dashboard that follows a training loop, in PyTorch or Flax (14), a CNN you train with a button on its page (15), a diffusion model inside and out (16), and a Flax CNN trained from its page with optax (17).

Gallery: python docs/build_gallery.py builds one page per showcase (MLP, attribution, attention, LSTM, mixture of experts, graph network, before/after, training replay, diffusion, ViT), with thumbnails, an index and the API reference, into docs/site/. The site workflow publishes it at https://batuoz.com/deepvis/.

Design

src/deepvis/
  core/        graph IR (module tree + dataflow DAG), canonical layer kinds & weight roles, selectors, stats
  backends/    torch_backend.py (dispatch tracer, fx, hooks) · jax/ (jaxpr engine + linen/nnx/equinox/pure adapters)
  manipulate/  edit ops, serializable edits, history, ParamRef / neuron selections, interventions
  monitor/     Trace, Monitor, TrainingLog (metrics + per-layer learning dynamics)
  equations/   expression tree (LaTeX + Unicode), per-kind rules, unrolling modes
  viz/         expressive glyphs (glyphs.py), static SVG diagrams, dashboard payload, layered DAG layout,
               HTML/CSS/JS app, 3-D renderer, live server (edits, interventions, training updates)
  anim/        manim data builders, mobjects, scenes, renderer, LaTeX→Pango fallback
  cli.py       `deepvis export` / `deepvis summary`
  diffusion.py DDPM / DDIM sampling that records xₜ, x̂₀, ε̂ for the Diffusion tab

Colors are manim's palette (deepvis.theme, exact values from manim's config): a black canvas with GREY_E/GREY_D surfaces and GREY_A/GREY_B/GREY_C text; weights and signed activations use a RED_A … RED_E · GREY_E · BLUE_E … BLUE_A diverging map (3b1b's red-negative / blue-positive convention); magnitudes use the BLUE ramp; YELLOW_C marks selection. Layer families take manim hues (dense BLUE_C, conv TEAL_C, pooling TEAL_E, attention GOLD_C, embedding MAROON_C, recurrent PINK, norm PURPLE_C, nonlinearity GREEN_C); every node and block also prints its kind, so color is never the only cue. The dashboard's 3-D views use a small dependency-free orthographic renderer (volume3d.js): each face is an affine image of a texture, so voxels stay crisp and hover reads exact values.

Limitations

Tests

pytest                     # ~340 tests: core, torch, jax (linen/nnx/equinox/pure), Keras, ONNX files,
                           # torch.export, weights-only files, 5-framework parity, the model zoo, HuggingFace
                           # models, meta-device pages, equations (conv scalars checked exactly), gradient
                           # flow, functional-op hooks, glyphs + HTML/SVG/PNG/PDF export (strict-XML checked),
                           # dashboard payload + live playground, the notebook widget, dataset profiles (vs
                           # NumPy), W&B / TensorBoard, training updates, CLI, headless-browser (graph,
                           # glyphs, 3-D volumes, KaTeX, live training, Dataset tab, widget channel), manim
                           # renders, capture / notebook kernels, attribution, heads, compare, RNN / MoE views
pytest -m "not anim and not browser and not zoo_slow"   # skip the slow ones
pytest -m zoo                          # the model zoo: ~60 architectures (incl. ONNX files, Keras) wrap, trace, export
KERAS_BACKEND=torch pytest -m keras    # Keras tests run on the backend KERAS_BACKEND names (default: jax if installed)

References