Skip to main content

Interpretability for LeelaChessZero networks.

Project description

logo

lczerolens 🔍

Documentation lczerolens license uv Ruff python versions

codecov ci-tests ci-tests-slow publish docs

Leela Chess Zero (lc0) Lens (lczerolens): a set of utilities to make interpretability easy and framework-agnostic (PyTorch): use it with tdhook, captum, zennit, or nnsight.

Getting Started

Installs

pip install lczerolens

Most examples below use models from Hugging Face Hub, so install the hf extra as well:

pip install "lczerolens[hf]"

Take the viz extra to render heatmaps and the backends extra to use the lc0 backends.

Run Models

Get the best move predicted by a model:

from lczerolens import LczeroBoard, LczeroModel

model = LczeroModel.from_hf("lczerolens/maia-1100")
board = LczeroBoard()

output = model(board)
best_move_idx = output["policy"].argmax()
print(board.decode_move(best_move_idx))

Framework-Agnostic Interpretability

Use lczerolens with your preferred PyTorch interpretability framework (tdhook, captum, zennit, nnsight). More examples in the framework-agnostic interpretability notebook.

from lczerolens import LczeroBoard, LczeroModel
from tdhook.attribution import Saliency
from tensordict import TensorDict

model = LczeroModel.from_hf("lczerolens/maia-1100")
board = LczeroBoard()

def best_logit_init_targets(td: TensorDict, _):
    policy = td["policy"]
    best_logit = policy.max(dim=-1).values
    return TensorDict(out=best_logit, batch_size=td.batch_size)

saliency_context = Saliency(init_attr_targets=best_logit_init_targets)
with saliency_context.prepare(model) as hooked_model:
    output = hooked_model(TensorDict(board=model.prepare_boards(board), batch_size=1))
    attr = output.get(("attr", "board"))

Features

Tutorials

Demo

Spaces

Some Hugging Face Spaces are available to try out the library. The demo (:red_circle: in construction) will showcase some of the features of the library and the backends demo makes the conversion of lc0 models to onnx easy.

Local Demo

Additionally, you can run the gradio demos locally. First you'll need to clone the spaces (after cloning the repo):

git clone https://huggingface.co/spaces/lczerolens/demo spaces/demo

And optionally the backends demo:

git clone https://huggingface.co/spaces/lczerolens/backends-demo spaces/backends-demo

And then launch the demo (running on port 8000):

just demo

To test the backends use:

just demo-backends

Full Documentation

See the full documentation.

Contribute

See the guidelines in CONTRIBUTING.md.

Citation

If you're using lczerolens in your research, please cite it using the following BibTeX entry:

@software{poupart_lczerolens_2026,
  author = {Poupart, Yoann},
  title = {LCZeroLens},
  version = {0.4.0},
  year = {2026},
  url = {https://github.com/Xmaster6y/lczerolens}
}

License

lczerolens 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

lczerolens-0.4.0.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

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

lczerolens-0.4.0-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file lczerolens-0.4.0.tar.gz.

File metadata

  • Download URL: lczerolens-0.4.0.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lczerolens-0.4.0.tar.gz
Algorithm Hash digest
SHA256 15dc5c365c930fae4cf081c9bfb55e4c7866b167dac1042476eadda1d8065723
MD5 5a091a8f52bf6cd4c557e12c52de439a
BLAKE2b-256 e5ebaf95a99921b51e8ab6c7328c5f2616bd9f8e6e5270d2430b44a11a9d73e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for lczerolens-0.4.0.tar.gz:

Publisher: publish.yml on Xmaster6y/lczerolens

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

File details

Details for the file lczerolens-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: lczerolens-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lczerolens-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fdb25f16299a12e64d372783be9c69ca7504f2b391648b79c9f3904438ddb855
MD5 6ce7d20422ba1abafdd70dde153ed3dc
BLAKE2b-256 d2eedb338078fcd040561d4c471c7cd695647d85023d00036bb40119f16bb3f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for lczerolens-0.4.0-py3-none-any.whl:

Publisher: publish.yml on Xmaster6y/lczerolens

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