Skip to main content

circuit-tracer

This library implements tools for finding circuits using features from (cross-layer) MLP transcoders, as originally introduced by Ameisen et al. (2025) and Lindsey et al. (2025).

Our library performs three main tasks.

  1. Given a model with pre-trained transcoders, it finds the circuit / attribution graph; i.e., it computes the direct effect that each non-zero transcoder feature, transcoder error node, and input token has on each other non-zero transcoder feature and output logit.
  2. Given an attribution graph, it visualizes this graph and allows you to annotate these features.
  3. Enables interventions on a model's transcoder features using the insights gained from the attribution graph; i.e. you can set features to arbitrary values, and observe how model output changes.

Getting Started

One quick way to start is to try our tutorial notebook!

You can also find circuits and visualize them in one of three ways:

  1. Use circuit-tracer on Neuronpedia - no installation required! Just click on + New Graph to create your own, or use the drop-down menu to select an existing graph.
  2. Run circuit-tracer via a Python script or Jupyter notebook. Start with our tutorial notebook. This will work on Colab with the GPU resources provided for free by default - just click on the Colab badge! Check out the Demos section below for more tutorials. You can also run these demo notebooks locally, with your own compute.
  3. Run circuit-tracer via the command-line interface. This can only be done with your own compute. For more on how to do that, see Command-Line Interface.

Working with Gemma-2 (2B) is possible with relatively limited GPU resources; Colab GPUs have 15GB of RAM. More GPU RAM will allow you to do less offloading, and to use a larger batch size.

Currently, intervening on models with respect to the transcoder features you discover in your graphs is possible both when using circuit-tracer in a script or notebook, or on Neuronpedia for Gemma-2 (2B). To perform interventions on Neuronpedia, ensure at least one node is pinned, then click "Steer" in the subgraph.

Installation

To install this library, clone it and run the command pip install . in its directory.

Demos

We include some demos showing how to use our library in the demos folder. The main demo is demos/circuit_tracing_tutorial.ipynb, which replicates two of the findings from this paper using Gemma 2 (2B). All demos except for the Llama demo can be run on Colab.

We also make two simple demos of attribution and intervention available, for those who want to learn more about how to use the library:

We finally provide demos that dig deeper into specific, pre-computed and pre-annotated attribution graphs, performing interventions to demonstrate the correctness of the annotated graph:

We also provide a number of annotated attribution graphs for both models, which can be found at the top of their two demo notebooks.

Usage

Available Transcoders

On HuggingFace

The following transcoders are available for use with circuit-tracer; this means that the transcoder weights and features are both available (so features will load properly when you run the visualization server). You can use the HuggingFace repo name (e.g. mntss/gemma-scope-transcoders) as the transcoders argument of ReplacementModel.from_pretrained, or as the argument of --transcoder_set in the CLI.

Locally Saved Transcoders

Locally saved transcoders can be loaded by using ReplacementModel.from_pretrained and including the full root path (not relative path) as the transcoders argument (e.g. /path/to/local_transcoders/). To enable feature visualizations in this case, you must direct the visualization server to the local feature data by setting the optional features_dir argument in serve to the same directory; for example:

serve(data_dir=graph_path, port=port, features_dir='/path/to/local_transcoders/')

Choosing a Backend

By default, circuit-tracer creates a ReplacementModel that inherits from the TransformerLens HookedTransformer class. However, TransformerLens does not support all HuggingFace models; it only supports those implemented in TransformerLens.

Creating a ReplacementModel with backend='nnsight' will create an nnsight-backed ReplacementModel that inherits from its TransformersModel class; this supports most HuggingFace models. That is, you can create an nnsight ReplacementModel using ReplacementModel.from_pretrained(model_name, backend='nnsight'). Note, however, that the nnsight backend is still experimental: it is slower and less memory-efficient, and may not provide all of the functionality of the TransformerLens version.

Caching

In order to use the lazy_decoder and lazy_encoder options on transcoders, they must be stored in circuit-tracer-compatible format. While many transcoders have been uploaded in that format to HuggingFace, this requires large amounts of storage. circuit-tracer now supports instead creating a local cache of models, by calling e.g.

from circuit_tracer.utils.caching import save_transcoders_to_cache

hf_ref = "mwhanna/gemma-scope-2-27b-pt/transcoder_all/width_262k_l0_small"
cache_dir = "~/.cache/"
save_transcoders_to_cache(hf_ref, cache_dir=cache_dir)

You can also empty the cache using circuit_tracer.utils.caching.empty_cache.

Command-Line Interface

The unified CLI performs the complete 3-step process for finding and visualizing circuits:

3-Step Process

  1. Attribution: Runs the attribution algorithm to find the circuit/attribution graph, computing direct effects between transcoder features, error nodes, tokens, and output logits.
  2. Graph File Creation: Prunes the attribution graph to remove low-effect nodes and edges, then converts it to JSON format suitable for visualization.
  3. Local Server: Starts a local web server to visualize and interact with the graph in your browser.

Basic Usage

To find a circuit, create the graph files, and start up a local server, use the command:

circuit-tracer attribute --prompt [prompt] --transcoder_set [transcoder_set] --slug [slug] --graph_file_dir [directory] --slug [slug] --graph_file_dir [graph_file_dir] --server

It will tell you where the server is serving (something like localhost:[port]). If you run this command on a remote machine, make sure to enable port forwarding, so you can see the graphs locally!

Mandatory Arguments

Attribution

  • --prompt (-p): The input prompt to analyze
  • --transcoder_set (-t): The set of transcoders to use for attribution. Options:
    • HuggingFace repository ID (e.g., mntss/gemma-scope-transcoders, username/repo-name@revision)
    • Convenience shortcuts: gemma (GemmaScope transcoders) or llama (ReLU transcoders)
    • Path to locally saved transcoders: /path/to/local_transcoders/

Graph File Creation

These are required if you want to run a local web server for visualization:

  • --slug: A name/identifier for your analysis run
  • --graph_file_dir: Directory path where JSON graph files will be saved

You can also save the raw attribution graph (to be loaded and used in Python later):

  • --graph_output_path (-o): Path to save the raw attribution graph (.pt file)

You must set --slug and --graph_file_dir, or --graph_output_path, or both! Otherwise the CLI will output nothing.

Local Server

  • --server: Start a local web server for graph visualization

Optional Arguments

Attribution Parameters:

  • --model (-m): Model architecture (auto-inferred for gemma and llama presets)
  • --max_n_logits (default: 10): Maximum number of logit nodes to attribute from
  • --desired_logit_prob (default: 0.95): Cumulative probability threshold for top logits
  • --batch_size (default: 256): Batch size for backward passes
  • --max_feature_nodes: Maximum number of feature nodes (defaults to 7500)
  • --dtype: Datatype in which to load the model / transcoders (allowed: float32/fp32, float16/fp16, bfloat16/bf16)
  • --offload: Memory optimization option (cpu, disk, or None)
  • --verbose: Display detailed progress information

Graph Pruning Parameters:

  • --node_threshold (default: 0.8): Keeps minimum nodes with cumulative influence ≥ threshold
  • --edge_threshold (default: 0.98): Keeps minimum edges with cumulative influence ≥ threshold

Server Parameters:

  • --port (default: 8041): Port for the local server
  • --features_dir (default: None): Path to the directory containing feature files for local server, if using local transcoders

Examples

Complete workflow with visualization:

circuit-tracer attribute \
  --prompt "The International Advanced Security Group (IAS" \
  --transcoder_set gemma \
  --slug gemma-demo \
  --graph_file_dir ./graph_files \
  --server

Attribution only (save raw graph):

circuit-tracer attribute \
  --prompt "The capital of France is" \
  --transcoder_set llama \
  --graph_output_path france_capital.pt

Graph Annotation

When using the --server option, your browser will open to a local visualization interface. The interface is the same as in the original papers (frontend available here).

  • Select a node: Click on a node.
  • Pin / unpin a node to subgraph pane: Ctrl+click/Command+click the node.
  • Annotate a node: Click on the "Edit" button on the right side of the window while a node is selected to edit its annotation.
  • Group nodes: Hold G and click on nodes to group them together into a supernode. Hold G and click on the x next to a supernode to ungroup all of them.
  • Annotate supernode / node group: click on the label below the supernode to edit the supernode annotation.

Cite

You can cite this library as follows:

@misc{circuit-tracer,
  author = {Hanna, Michael and Piotrowski, Mateusz and Lindsey, Jack and Ameisen, Emmanuel},
  title = {circuit-tracer},
  howpublished = {\url{https://github.com/decoderesearch/circuit-tracer}},
  note = {The first two authors contributed equally and are listed alphabetically.},
  year = {2025}
}

or cite the paper here.

Metadata

Release files for circuit-tracer 0.5.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for circuit-tracer 0.5.4
File Size Uploaded Provenance Actions
circuit_tracer-0.5.4.tar.gz 2.3 MB With provenance Details for circuit_tracer-0.5.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for circuit-tracer 0.5.4
File Interpreter ABI Platform Actions
circuit_tracer-0.5.4-py3-none-any.whl Python 3 none any Details for circuit_tracer-0.5.4-py3-none-any.whl

Total release size: 2.5 MB

Release files / circuit_tracer-0.5.4.tar.gz

Download URL circuit_tracer-0.5.4.tar.gz
Size 2.3 MB
Tags Source
SHA-256 checksum
How to use checksums
b3f4b80c7c72d160b14faa63b50de307582dcf249ceea93eead213ca3e69821d
BLAKE2b-256 checksum
How to use checksums
cfcc9d2be7ce9664f8d76fc45d1c0118c9df116314562e55a6322a3fe21efcd9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / circuit_tracer-0.5.4-py3-none-any.whl

Download URL circuit_tracer-0.5.4-py3-none-any.whl
Size 160.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92d21a21e60fcfe7865a8f76b2f0886b41a28e5441104805c85c8959212cbd05
BLAKE2b-256 checksum
How to use checksums
9469a64c59c5721b1f94247914b5ce8c55b14894c2dbc027d156c64d768e4cdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for circuit-tracer 0.5.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for circuit_tracer-0.5.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page