Treescope

0.1.10 · active · verified Fri Apr 10

Treescope is an interactive HTML pretty-printer and N-dimensional array ("tensor") visualizer, designed for machine learning and neural networks research in IPython notebooks. It serves as a drop-in replacement for the standard IPython/Colab renderer, enhancing output with features like expandable/collapsible subtrees, embedded faceted visualizations of arbitrary-dimensional arrays, and color-coding for model structures. It supports inspecting data from libraries such as JAX, NumPy, PyTorch, Equinox, Flax NNX, and Penzai. Maintained by Google DeepMind, the current version is 0.1.10.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to enable Treescope as the default renderer in an IPython/Colab environment and visualize a complex, nested data structure containing both JAX and NumPy arrays. After `basic_interactive_setup()`, simply outputting a variable in a notebook cell will automatically trigger Treescope's rich, interactive HTML visualization.

import treescope
import jax
import jax.numpy as jnp
import numpy as np

# Enable Treescope as the default IPython renderer and auto-visualizers
treescope.basic_interactive_setup()

# Define a nested data structure with arrays
my_data = {
    "model_config": {
        "num_layers": 4,
        "hidden_size": 256,
        "activation": "relu"
    },
    "weights": {
        "layer_0": jnp.ones((16, 256)),
        "layer_1": jnp.zeros((256, 128))
    },
    "metadata": [
        "training_started",
        "epoch_1",
        {"loss": 0.123, "accuracy": 0.98, "grad_norm": np.array(0.005)}
    ]
}

# In an IPython notebook, simply outputting the variable will use Treescope:
my_data

# Or explicitly display it:
treescope.display(my_data)

view raw JSON →