Skip to main content

Transformer token flow visualizer

Project description

Token-Trace

A tool and UI to construct prompt-centric views of SAE feature attributions.

Main functionality:

  • We use this tool to identify which SAE features have the most 'attribution' towards decreasing the model loss.
  • In combination with Neuronpedia, we can identify what each SAE feature represents; this then gives us a rough idea of what computation the model is performing.

This tool is a first step towards discovering information flow between the features / layers of a transformer

Quickstart

Installation

pip install token-trace

Example Usage

from token_trace import compute_node_attribution

text = "When John and Mary went to the shops, John gave the bag to Mary"

df: pd.DataFrame = compute_node_attribution(
    model_name = "gpt2",
    text
)

Each row of df describes one node corresponding to an SAE feature or error term.

Visualizing SAE attribution statistics in frontend.

We use Streamlit to create a UI. Start the app as follows:

streamlit run app/token_trace_app.py

Methodology

Under the hood, we use attribution patching to compute indirect effect of the loss with respect to SAE features. The method is adapted heavily from Sparse Feature Circuits.

Development

We use PDM to manage dependencies. Set up a development environment as follows:

pdm install # creates a .venv
source .venv/bin/activate

Once in the virtual environment, make sure to also install the pre-commit hooks

pre-commit install

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

token_trace-0.3.2.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

token_trace-0.3.2-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file token_trace-0.3.2.tar.gz.

File metadata

  • Download URL: token_trace-0.3.2.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.15.1 CPython/3.10.12 Linux/6.5.0-1018-azure

File hashes

Hashes for token_trace-0.3.2.tar.gz
Algorithm Hash digest
SHA256 26541081e149d1cae5589e6fe86b906396f842d4e63e1ee52bd081eee6237ada
MD5 502e6f7b46ddd1d153a6396d99b796e8
BLAKE2b-256 ca1762155df0a456daccda6f59009529dbff4d89ee3f0cce17e0843b5f30a6b4

See more details on using hashes here.

File details

Details for the file token_trace-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: token_trace-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.15.1 CPython/3.10.12 Linux/6.5.0-1018-azure

File hashes

Hashes for token_trace-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e381f43c66a59584142960d2e70add71081bb4029842991a7f7ddb4f607d18b8
MD5 d44202e6ffe7ee8abe5aee35590bdb08
BLAKE2b-256 5282c0d33e0ec9b5d7695449d5cff3d26a9f1901721308779420461c8364b535

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page