Get StartedStablesince v0.9.2

Quickstart

Attach NeuronScope to any PyTorch model and record your first activation in under ten minutes.

Audience: New usersRead: 10 minEdit on GitHub

This page is the shortest useful path through NeuronScope: install the library, record a single activation from a real model, and read the resulting artifact. Every subsequent chapter builds on the primitives introduced here.

Install

A one-line install is enough for the quickstart. See Installation for the full matrix.

shellbash
$ pip install "neuronscope[torch]==0.9.2"
$ ns doctor
python 3.12 · neuronscope 0.9.2 · adapter torch ok

Record an activation

A recording has three inputs — a model, a prompt, and a probe — and one output: a sealed.nsz artifact. This program records the residual stream of a small BERT model on a single prompt.

quickstart.py·
·python
import neuronscope as ns
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("google-bert/bert-base-uncased")
tok   = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased")
prompt = ns.Prompt("The quick brown fox jumps over the lazy dog.")

probe = ns.probes.LayerActivations(layers="encoder.layer.*")

with ns.record(model=model, probe=probe, out="fox.nsz") as run:
    run.forward(**tok(prompt.text, return_tensors="pt"))

print(run.artifact.fingerprint)
# fp:experiment:5a7c...

Inspect the artifact

Artifacts are self-describing. ns inspect prints the input fingerprints, the recorded tensors, and a per-layer summary — enough to verify a recording without loading a framework.

shellbash
$ ns inspect fox.nsz
experiment fp:experiment:5a7c... model fp:model:b3c2... google-bert/bert-base-uncased prompt fp:prompt:8f10... probe LayerActivations (glob: encoder.layer.*) recorded 12 layers · 9 216 activations · 1.4 MB

Where to go next

  1. Read Fingerprinting — the primitive every other guarantee builds on.
  2. Try Compare two models — the first realistic recipe.
  3. Skim System architecture to see what the library is doing on your behalf.
Related