Latent dynamics instrumentation

Interactive latent trajectory explorer for transformer forward passes.

Mottled instruments latent dynamics — how the residual stream moves, turns, and settles as a prompt flows through the layers of a transformer. It is not a neuron inspector or an attribution dashboard: hidden-state evolution is drawn as animated trajectories over a projected density terrain, with a logit-lens readout at every state.

Launch viewer View source on GitHub
prompt → forward pass → capture residual stream → project → estimate manifold → animate trajectory
Explorer — A/B scene streamlit run ui.py
The Mottled explorer: an A/B prompt scene on the density terrain, with the layer scrubber and the token inspector
The Streamlit explorer with an A/B overlay — “The capital of France is” against “The capital of Germany is” — marbles at layer 12, inspector showing the final token’s predictions and representation-space neighbors.
Web viewer — WebGL viewer/?file=samples/scene-abc.mtj
The dependency-free WebGL viewer rendering a three-run sample scene
The dependency-free WebGL viewer on the committed three-run sample scene: one shared terrain, per-run visibility toggles, the comparison table, and the layer scrubber.
Capabilities

Six instruments, one trajectory.

01

Residual-stream capture

Forward hooks record the residual stream after every block, with logit-lens logits, entropy, and top-k predictions attached to each state.

02

Density terrain

Hidden states are projected to a low-dimensional plane and animated over a density terrain, with a layer scrubber and per-state representation-space neighbors.

03

Trajectory comparison

A/B and multi-prompt runs share one joint projection and are measured with Hausdorff distance, dynamic time warping, and shared-prefix divergence.

04

Causal interventions

Perturb-and-replay rewrites the residual stream at a chosen layer, and a divergence readout reports where the counterfactual branch separates.

05

SAE features

Pretrained sparse autoencoders are applied to every captured state, alongside an exact per-block attention-versus-MLP residual decomposition.

06

The .mtj format

Trajectories and scenes freeze into the versioned .mtj interchange format, rendered by a dependency-free WebGL viewer with no build step.

Architecture

Producers emit one. Viewers consume one.

StateTrajectory is the center of the project — the interchange format everything else plugs into. Neither side knows about the other: a new substrate only needs to emit a trajectory, and the entire stack works unchanged.

Producers
transformers capturehooks on every block
Mambastate-space — no attention at all
in-browser forward passWebGPU, no server
future: diffusion · recordings
Interchange
StateTrajectoryin memory
.mtjon disk · JSON manifest + raw buffers
Viewers
Python / Streamlitui.py
web viewerWebGL2, zero dependencies
notebooksplain Plotly figures
Quickstart

Two commands to a trajectory.

ExplorerPython 3
pip install -r requirements.txt
streamlit run ui.py

Every capture is a real model; gpt2 is the default because it is the smallest honest one. The web viewer can also run a model in the browser.

Web viewerany static server
python -m http.server
# → open http://localhost:8000/viewer/

Drag a .mtj file in, or pass ?file=samples/scene-abc.mtj. The sample scene runs here.