Universal mechanistic interpretability primitives for any PyTorch model
Project description
omnilens
Universal mechanistic interpretability for any PyTorch model.
omnilens wraps native HuggingFace models with zero-overhead PyTorch hooks — no reimplementation, no weight copying. One API works across transformers, SSMs (Mamba), linear attention (RWKV), 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 naming —
layers.{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 — composable sparse autoencoders (relu / topk / jumprelu / gated / custom), hook helpers, load pretrained from SAELens
- 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
- Visualization —
.plot()on results, attention heatmaps (pip install omnilens[viz]) - Registry system — built-in YAML registries for 18 architectures, auto-detect for unknown models, inline dict override
Built-in architectures
Transformers: Llama 2/3/3.1, DeepSeek, Yi, Mistral, Gemma 1/2/3, Qwen 2/2.5/3, Phi-2, Phi-3, GPT-2, Pythia/GPT-NeoX, OPT, GPT-J, Falcon, BLOOM, StableLM
Non-transformers: Mamba (SSM), RWKV (linear attention)
Any model not listed above still works via raw module names or auto-detection.
Documentation
See docs/guide.md for the full reference with examples for every feature.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file omnilens-0.1.2.tar.gz.
File metadata
- Download URL: omnilens-0.1.2.tar.gz
- Upload date:
- Size: 46.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd592f9c5f9446044078b6b46a3ee599d7657639ed7761e0ef7fa1bf6b8bf347
|
|
| MD5 |
2314879a47220a968daf15a879c4594f
|
|
| BLAKE2b-256 |
4dd8fee54e46fc0e848ab5d1e33b6ba94fc587ecbb1cb920a1c174ffe23cd760
|
File details
Details for the file omnilens-0.1.2-py3-none-any.whl.
File metadata
- Download URL: omnilens-0.1.2-py3-none-any.whl
- Upload date:
- Size: 50.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c26ca4cde8319ee7d75c1474448d9182c6183d2cdff16032fe1572127e605404
|
|
| MD5 |
48fce5ca6bd2feb25da8bfe7f472abfb
|
|
| BLAKE2b-256 |
332cac7c63d70cb7ed3bf2b4b920cb3c5e30411c99e1ca30d07f737fa97990a9
|