Interpretability with tensordict and torch hooks.
Project description
tdhook 🤖🪝
Interpretability with tensordict and torch hooks.
Getting Started
Most methods should work with minimal configuration. Here's a basic example of running Integrated Gradients on a VGG16 model (full example available here):
from tdhook.attribution import IntegratedGradients
# Define attribution target (e.g., zebra class = 340)
def init_attr_targets(targets, _):
zebra_logit = targets["output"][..., 340]
return TensorDict(out=zebra_logit, batch_size=targets.batch_size)
# Compute attribution
with IntegratedGradients(init_attr_targets=init_attr_targets).prepare(model) as hooked_model:
td = TensorDict({
"input": image_tensor,
("baseline", "input"): torch.zeros_like(image_tensor) # required for integrated gradients
}).unsqueeze(0)
td = hooked_model(td) # Access attribution with td.get(("attr", "input"))
To dig deeper, see the documentation.
Skills
An agent skill is available for tdhook. It provides AI guidance for attribution, activation analysis, probing, steering, and weight-level interventions—including when to use each method and how to wire TensorDict keys.
Features
Config
This project uses uv to manage python dependencies and run scripts, as well as just to run commands.
Citation
If you're using tdhook in your research, please cite it using the following BibTeX entry:
@misc{poupart2025tdhooklightweightframeworkinterpretability,
title={TDHook: A Lightweight Framework for Interpretability},
author={Yoann Poupart},
year={2025},
eprint={2509.25475},
archivePrefix={arXiv},
primaryClass={cs.AI},
url={https://arxiv.org/abs/2509.25475},
}
License
tdhook is licensed under the MIT License. See LICENSE for details.
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
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 tdhook-0.1.3.tar.gz.
File metadata
- Download URL: tdhook-0.1.3.tar.gz
- Upload date:
- Size: 54.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6f485e3d9776c8e56aa983b98b3f5d9e38793bb75542ee8c8497da5c4d0e402
|
|
| MD5 |
c7e945ea638ecdb622d1f4e737c0138a
|
|
| BLAKE2b-256 |
889c686ac71e47d2f9a61be031e64f0d04866b418252055ddf90a3e24d6a10a5
|
Provenance
The following attestation bundles were made for tdhook-0.1.3.tar.gz:
Publisher:
publish.yml on Xmaster6y/tdhook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tdhook-0.1.3.tar.gz -
Subject digest:
e6f485e3d9776c8e56aa983b98b3f5d9e38793bb75542ee8c8497da5c4d0e402 - Sigstore transparency entry: 1320852680
- Sigstore integration time:
-
Permalink:
Xmaster6y/tdhook@e2e3692c095e923fa0e289af34449cb8f937477a -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Xmaster6y
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e2e3692c095e923fa0e289af34449cb8f937477a -
Trigger Event:
release
-
Statement type:
File details
Details for the file tdhook-0.1.3-py3-none-any.whl.
File metadata
- Download URL: tdhook-0.1.3-py3-none-any.whl
- Upload date:
- Size: 60.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b90e4fb5a6a9bdd8efbf424c1e13b5c3cd39799be435e012ec09b17b183002c
|
|
| MD5 |
ec16956f2a331bc24c31d8ad10f283be
|
|
| BLAKE2b-256 |
e143e7032140c3128c4faea8cc44adc13be2433ff0f2e6221a94be317360341d
|
Provenance
The following attestation bundles were made for tdhook-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on Xmaster6y/tdhook
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tdhook-0.1.3-py3-none-any.whl -
Subject digest:
6b90e4fb5a6a9bdd8efbf424c1e13b5c3cd39799be435e012ec09b17b183002c - Sigstore transparency entry: 1320852792
- Sigstore integration time:
-
Permalink:
Xmaster6y/tdhook@e2e3692c095e923fa0e289af34449cb8f937477a -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/Xmaster6y
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e2e3692c095e923fa0e289af34449cb8f937477a -
Trigger Event:
release
-
Statement type: