Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 1.92 KB

README.md

File metadata and controls

34 lines (27 loc) · 1.92 KB

Python binding

This optional package lets torchlean.compile and torchlean.verify call the Lean IR checker inside Python. It also returns Lean's op table (_torchlean.op_table, the JSON that verify ir --op-table writes), which the Python captures read. PyTorch or JAX runs and differentiates the model itself.

Use a virtual environment with CPython 3.14 or newer and a shared Python library. Nerodia does not support free-threaded Python. The binding uses Lean 4.36.0 and TorchLean's CPU runtime from this checkout. From the TorchLean checkout, with that environment activated:

python -m pip install "setuptools>=82" setuptools-lean wheel
TORCHLEAN_PACKAGE_ROOT="$PWD/bindings/python" PYTHON3="$(command -v python)" \
  scripts/lake.sh build +TorchLeanPython:nerodiaExt
TORCHLEAN_PACKAGE_ROOT="$PWD/bindings/python" PYTHON3="$(command -v python)" \
  scripts/lake.sh env python -m pip install --no-build-isolation "$PWD/bindings/python"

The wrapper keeps both the extension build and the packaging step in the CPU build profile and holds the checkout lock while they run.

Keep using import torchlean from the checkout, with python/ on PYTHONPATH or after python -m pip install -e python. It picks up the installed _torchlean extension, and a checker= argument or TORCHLEAN_VERIFY selects the command-line checker instead. Without the extension, the package runs the verify executable. With it, the extension's errors reach the caller, with no fallback to the executable.

Both interfaces return the same reports, including failures and unsupported requests. The binding adds no proof that the frontend translation or the native kernels are correct. Nerodia is an experimental dependency and stays out of TorchLean's main Lake package.

The package builds from this checkout and its parent source, and is not a standalone source distribution. A built wheel contains the extension and the Lean runtime libraries it bundles.