Interpretability for LeelaChessZero networks.
Project description
lczerolens 🔍
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
- Encode Boards:
- Load Models:
- Move Prediction:
- Run Models on GPU:
- Evaluate Models on Puzzles:
- Convert Official Weights:
- Visualise Heatmaps:
- Probe Concepts:
Tutorials
- Walkthrough:
- Framework-Agnostic Interpretability:
- More to come...
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.
- Lczerolens Demo: Showcase some of the features of the library.
- Lczerolens Backends Demo: Make the conversion of lc0 models to
onnxeasy. - Lczerolens Puzzles Leaderboard: Coming soon...
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15dc5c365c930fae4cf081c9bfb55e4c7866b167dac1042476eadda1d8065723
|
|
| MD5 |
5a091a8f52bf6cd4c557e12c52de439a
|
|
| BLAKE2b-256 |
e5ebaf95a99921b51e8ab6c7328c5f2616bd9f8e6e5270d2430b44a11a9d73e4
|
Provenance
The following attestation bundles were made for lczerolens-0.4.0.tar.gz:
Publisher:
publish.yml on Xmaster6y/lczerolens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lczerolens-0.4.0.tar.gz -
Subject digest:
15dc5c365c930fae4cf081c9bfb55e4c7866b167dac1042476eadda1d8065723 - Sigstore transparency entry: 1400076972
- Sigstore integration time:
-
Permalink:
Xmaster6y/lczerolens@8b7f336c11b7df73f79fb78d65c9e23094527c90 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/Xmaster6y
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8b7f336c11b7df73f79fb78d65c9e23094527c90 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdb25f16299a12e64d372783be9c69ca7504f2b391648b79c9f3904438ddb855
|
|
| MD5 |
6ce7d20422ba1abafdd70dde153ed3dc
|
|
| BLAKE2b-256 |
d2eedb338078fcd040561d4c471c7cd695647d85023d00036bb40119f16bb3f5
|
Provenance
The following attestation bundles were made for lczerolens-0.4.0-py3-none-any.whl:
Publisher:
publish.yml on Xmaster6y/lczerolens
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lczerolens-0.4.0-py3-none-any.whl -
Subject digest:
fdb25f16299a12e64d372783be9c69ca7504f2b391648b79c9f3904438ddb855 - Sigstore transparency entry: 1400077023
- Sigstore integration time:
-
Permalink:
Xmaster6y/lczerolens@8b7f336c11b7df73f79fb78d65c9e23094527c90 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/Xmaster6y
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8b7f336c11b7df73f79fb78d65c9e23094527c90 -
Trigger Event:
release
-
Statement type: