TorchLean is a Lean 4 framework for writing, running, inspecting, and verifying neural-network programs. It provides typed tensors and model APIs, a shared graph IR, runtime/autograd support, finite-precision semantics, certificate checkers, CUDA/runtime boundaries, and examples across modern ML and scientific ML.
The detailed story lives in the project site, guide, API docs, and paper. This README is the quick entry point: build the repo, run the first examples, find the docs, and cite the project.
git clone https://github.com/lean-dojo/TorchLean.git
cd TorchLean
lake build
lake exe torchlean mlp --cpu --steps 10TorchLean is pinned by lean-toolchain and currently builds with
leanprover/lean4:v4.29.0.
lake exe torchlean --help
lake exe verify --help
lake exe verify -- torchlean-ibpFor the maintained example surface:
lake build NN.Examples.Zoo- Project site: https://lean-dojo.github.io/TorchLean/
- Guide: https://lean-dojo.github.io/TorchLean/blueprint/
- API reference: https://lean-dojo.github.io/TorchLean/docs/
- Paper: TorchLean: Formalizing Neural Networks in Lean (arXiv:2602.22631)
Detailed tutorials, verification chapters, model walkthroughs, CUDA notes, and API-level reference material belong in the guide and generated docs rather than in this README.
TorchLean is a normal Lake package. You can depend on the Git repository directly:
require TorchLean from git "https://github.com/lean-dojo/TorchLean.git" @ "main"Then run:
lake update
lake exe cache get
lake buildMost downstream model and training files should start from the public facade:
import NN.API.PublicUse the broader umbrella when you want the maintained specification, IR, proof, verification, examples, and widget surface:
import NN.LibraryFor local development against a checkout, use a path dependency instead:
require TorchLean from "../TorchLean"Reservoir is not required for Git or path dependencies. It is only for package
discovery and versioned require lines once the repository is indexed.
NN/API: public facade for model, tensor, data, and training workflows.NN/Spec: mathematical tensor, layer, model, and dynamical-system definitions.NN/Runtime: executable autograd, optimizers, training loops, CUDA boundary, PyTorch import/export, and RL runtime support.NN/IRandNN/GraphSpec: graph IR, graph semantics, and typed architecture descriptions.NN/Proofs: tensor algebra, autograd correctness, analytic derivatives, runtime approximation, and bridge proofs.NN/Floats: finite-precision models, IEEE-style executable semantics, NeuralFloat formats, and error-bound infrastructure.NN/MLTheory: learning theory, robustness, CROWN/LiRPA, generative objectives, optimization theory, and related proof layers.NN/Verification: certificate checkers and CLI workflows.NN/Examples: quickstarts, model zoo commands, widgets, verification fixtures, and interoperability demos.blueprint/TorchLeanBlueprint/Guide: source for the public guide.home_page: project website sources.
For correctness claims, trust assumptions, and third-party tooling:
TRUST_BOUNDARIES.mdAI_USAGE.mdTHIRD_PARTY_NOTICES.mdCONTRIBUTING.md
Lean proofs, executable checkers, Lake builds, tests, and explicit trust-boundary documentation are the source of truth for what is proved, checked, or assumed.
For the current paper BibTeX, use the citation metadata on arXiv:
@misc{george2026torchleanformalizingneuralnetworks,
title={TorchLean: Formalizing Neural Networks in Lean},
author={Robert Joseph George and Jennifer Cruden and Xiangru Zhong and Huan Zhang and Anima Anandkumar},
year={2026},
eprint={2602.22631},
archivePrefix={arXiv},
primaryClass={cs.MS},
url={https://arxiv.org/abs/2602.22631},
}TorchLean is released under the MIT License. See LICENSE.
