Skip to main content

Interpretability with tensordict and torch hooks.

Project description

logo

tdhook 🤖🪝

Documentation tdhook license uv Ruff python versions

codecov ci publish docs

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.

Features

Python Config

Using uv to manage python dependencies and run scripts.

Scripts

This project uses Just to manage scripts, refer to their instructions for installation.

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

tdhook-0.1.2.tar.gz (42.8 kB view details)

Uploaded Source

Built Distribution

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

tdhook-0.1.2-py3-none-any.whl (43.9 kB view details)

Uploaded Python 3

File details

Details for the file tdhook-0.1.2.tar.gz.

File metadata

  • Download URL: tdhook-0.1.2.tar.gz
  • Upload date:
  • Size: 42.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tdhook-0.1.2.tar.gz
Algorithm Hash digest
SHA256 caf211c20a0bc12ee7d24bc5e796072964b9b2513d1e8e8de3e828c4d7cb8206
MD5 40d76490e7ac31f29c5b52ab26ff56ab
BLAKE2b-256 e89cbb3e3268fd4d09480df32095980f35abdd3ada1a53628f1fca9148a0b4fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for tdhook-0.1.2.tar.gz:

Publisher: publish.yml on Xmaster6y/tdhook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tdhook-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: tdhook-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 43.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tdhook-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 87ed66e3ba82ce68f874a65ffdbeaf78fc3d2d437e4481995c73cec35e11a79d
MD5 9d2e722ae09113f55070e034a8f2e706
BLAKE2b-256 d1274b3b3fdd3e32e9eb0e22574a8e043654170c320239377951d4722ae45fe2

See more details on using hashes here.

Provenance

The following attestation bundles were made for tdhook-0.1.2-py3-none-any.whl:

Publisher: publish.yml on Xmaster6y/tdhook

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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