Skip to main content
logo

lczerolens 🔍

Documentation lczerolens license uv Ruff python versions

codecov ci-tests ci-tests-slow publish docs

Leela Chess Zero (lc0) Lens (lczerolens) makes lc0-family models portable and operable in PyTorch, then expresses their evaluator and search behavior as chess-domain evidence. It provides the model and chess-analysis boundary; interpretability methods remain external integrations. See the scope and compatibility policy.

Getting Started

Installs

pip install lczerolens

Loading or publishing models through Hugging Face Hub requires the hub extra:

pip install "lczerolens[hub]"

Tests

After just test-fixtures has fetched and checksummed the lc0 fixtures, just tests runs the complete fast, offline suite (unit and conformance tests) and produces the coverage report. just tests-unit and just tests-conformance select either tier for diagnosis. The native Lczero bindings are a test-only conformance oracle, installed through the conformance dependency group rather than exposed as library API. Notebook and release checks are opt-in with just tests-slow; the notebook suite executes every maintained .ipynb page. just tests-wheel builds and installs the wheel in a fresh virtual environment before running the maintained workflow. CI retains JUnit and coverage artifacts to make failures inspectable.

Evaluate a position

Get the best move predicted by a model:

import chess
from lczerolens import LczeroEvaluator, LczeroModel

model = LczeroModel.from_hf("lczerolens/maia-1100")
evaluator = LczeroEvaluator(model)
board = chess.Board()

evaluation = evaluator.evaluate(board)
print(evaluation.policy.best_move)
print(evaluation.policy["e2e4"].probability)

External Interpretability Integrations

Use lczerolens with your preferred PyTorch interpretability framework (tdhook, captum, zennit, or nnsight). These packages own their methods; they are not lczerolens abstractions or dependencies of its evaluator contract.

import chess
from lczerolens import LczeroEvaluator, LczeroKeys, LczeroModel
from tdhook.attribution import Saliency
from tensordict import TensorDict

model = LczeroModel.from_hf("lczerolens/maia-1100")
evaluator = LczeroEvaluator(model)
board = chess.Board()

def best_logit_init_targets(td: TensorDict, _):
    policy = td[LczeroKeys.NETWORK_POLICY_LOGITS]
    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(evaluator.model) as hooked_model:
    tensors = hooked_model(evaluator.prepare([board]))
    evaluation = evaluator.finish([board], tensors)[0]
    attr = tensors.get(("attr", "input", "planes"))

Define and grade a puzzle

Puzzle correctness comes from an authored solution tree rather than from model preference or chess terminality:

import chess
from lczerolens import Puzzle, PuzzleContinuation, PuzzleSolution

board = chess.Board("7k/8/5KQ1/8/8/8/8/8 w - - 0 1")
solution = PuzzleSolution((PuzzleContinuation("g6g7"),))
puzzle = Puzzle.from_board(board, solution)

attempt = puzzle.grade(["g6g7"])
print(attempt.status)  # PuzzleStatus.SOLVED

Solution trees can retain alternative accepted moves and authored opponent replies. Provider-specific dataset ingestion remains outside the core package.

Decision-analysis documentation

The maintained documentation covers the evaluator and position contract, exact facts and move/variation evidence, authored puzzles, constrained counterfactuals, typed search traces, and concrete decision comparisons. Start with the scope and compatibility policy, then follow the facts, search, and use cases guides.

Interpretability techniques remain external integrations rather than lczerolens APIs.

Maintained demos

The executable decision-analysis tutorial composes evaluator, search, exact line analysis, and counterfactual comparison against a deterministic fixture. Seven maintained feature and tutorial notebooks cover model loading and inputs, evaluation, chess evidence, search and replay, complete decision analysis, model comparison, and authored-puzzle analysis. Sphinx renders and executes them, and the integration tier executes the source notebooks directly. Historical notebooks built on removed APIs are not shipped.

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.

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.5.0.tar.gz (77.1 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.5.0-py3-none-any.whl (84.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lczerolens-0.5.0.tar.gz
  • Upload date:
  • Size: 77.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lczerolens-0.5.0.tar.gz
Algorithm Hash digest
SHA256 f358b107c513b9df736ad1a9fd6a5a77d62726e820abdaaf28292e1c11baf44d
MD5 33bc5e09ade73a78e459d8e32bb1344c
BLAKE2b-256 4240f2287a32764aa243bb623eff7a06d0da8f4a372caaa735cdb754dcf80ddb

See more details on using hashes here.

Provenance

The following attestation bundles were made for lczerolens-0.5.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.5.0-py3-none-any.whl.

File metadata

  • Download URL: lczerolens-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 84.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for lczerolens-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 039bc56961561242c7c2a3f8c66cb47ee670716c747713d9e5e8564517cff6de
MD5 5fb440933a923502ac9df620f74137f8
BLAKE2b-256 62ef97e1a1ba6210c3acb8f98c7dd66ee28f9ed00c276bf49dbeab0586a93f15

See more details on using hashes here.

Provenance

The following attestation bundles were made for lczerolens-0.5.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.

Release history Release notifications | RSS feed

0.5.1

2 files

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page