Skip to main content

Universal mechanistic interpretability primitives for any PyTorch model

Project description

omnilens

Universal mechanistic interpretability for any PyTorch/HuggingFace model.

omnilens wraps native HuggingFace models with zero-overhead PyTorch hooks — no reimplementation, no weight copying. One API works across Llama, GPT-2, Mistral, Gemma, Qwen2, Phi-3, and any architecture with auto-detection.

Install

pip install omnilens

Quick start

from omnilens import TappedModel

model = TappedModel.from_pretrained("meta-llama/Llama-3.1-8B", torch_dtype="auto")
logits, cache = model.run_with_cache(text="The Eiffel Tower is in")
resid = cache["layers.15.residual.block_out"]   # (1, seq, 4096)
attn  = cache["layers.15.attention.weights"]    # (1, heads, seq, seq)

Features

  • Zero reimplementation — wraps the original HF model with native PyTorch hooks
  • Standardized naminglayers.{i}.attention.q, layers.{i}.residual.block_out, etc. across all architectures
  • run_with_cache — cache any combination of activations in one forward pass
  • run_with_hooks — intervene on activations with arbitrary functions
  • Logit lens — project intermediate residual states through the unembedding at every layer
  • Activation patching — sweep components and measure causal effect on output
  • SAE — sparse autoencoders with relu / topk / jumprelu / gated activations, full hook helpers
  • Transcoder — sparse MLP replacement with attach/detach context manager and cross-layer support
  • Probe — linear and MLP probes with layer sweep via {i} expansion
  • SteeringVector — construct from contrastive pairs, probes, or SAE features; apply with scale
  • Registry system — built-in YAML registries for 7 architectures, auto-detect for unknown models, inline dict override

Built-in architectures

Llama 2/3/3.1, Code Llama, Mistral, Gemma, Gemma 2, Qwen2, Phi-3, GPT-2

Documentation

See docs/guide.md for the full reference with examples for every feature.

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

omnilens-0.1.1.tar.gz (46.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

omnilens-0.1.1-py3-none-any.whl (50.7 kB view details)

Uploaded Python 3

File details

Details for the file omnilens-0.1.1.tar.gz.

File metadata

  • Download URL: omnilens-0.1.1.tar.gz
  • Upload date:
  • Size: 46.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for omnilens-0.1.1.tar.gz
Algorithm Hash digest
SHA256 308414ee0c81a27df78b8c9d69a190909a3e2bbd2f6d286b5ae78789548ebbc8
MD5 0be259915643ef2047e118b048386c34
BLAKE2b-256 245d0ca0e1b9841b00d3f6ac01177c906afdc300de13b2901366b1fc1035a57c

See more details on using hashes here.

File details

Details for the file omnilens-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: omnilens-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 50.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for omnilens-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c9bf4bd448d1acc2ac52ce7392af8514ac5baa534c611ffbe6daef05359cfb0
MD5 867d1e7c5e9de52c956642612f0593d5
BLAKE2b-256 74bd2f39e32563cd025b5535d5cbe5dddaa60382c01ac2d640c1cf525ea09649

See more details on using hashes here.

Supported by

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