whatisgithub

What is torchlean?

lean-dojo/torchlean — explained in plain English

Analysis updated 2026-05-18

55LeanAudience · researcherComplexity · 5/5LicenseSetup · hard

In one sentence

A Lean 4 framework for building neural networks and mathematically proving properties about how they behave.

Mindmap

mindmap
  root((TorchLean))
    What it does
      Formal verification
      Neural network specification
      Built in Lean 4
    Tech stack
      Lean 4
      PyTorch
      CUDA
      Lake
    Capabilities
      Typed tensors
      Certificate checkers
      Graph IR
    Use cases
      Verify model behavior
      Train models in Lean
      Import export PyTorch
    Audience
      ML researchers
      Formal methods researchers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Formally verify mathematical properties of a neural network's behavior.

USE CASE 2

Build and train neural network models with typed tensors inside Lean 4.

USE CASE 3

Import or export models between TorchLean and PyTorch.

USE CASE 4

Use certificate checkers to confirm a model satisfies specific proven guarantees.

What is it built with?

Lean 4PyTorchCUDALake

How does it compare?

lean-dojo/torchleanjzshischolar/pyleanermathtensor/ai4math-putnam2025
Stars551413
LanguageLeanLeanLean
Setup difficultyhardhardmoderate
Complexity5/54/54/5
Audienceresearcherresearcherresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · hard Time to first run · 1day+

Requires the pinned Lean 4 toolchain and the Lake build tool, deep familiarity with Lean helps significantly.

Use freely for any purpose, including commercial use, as long as you keep the copyright and license notice.

So what is it?

TorchLean is a framework built in Lean 4, a programming language designed for writing mathematical proofs that a computer can check for correctness, and it applies that idea to neural networks. Instead of just building and running neural networks the usual way, TorchLean lets researchers write, run, inspect, and mathematically verify neural network programs, so claims about how a model behaves can be checked with the same rigor as a mathematical proof rather than only tested through examples. The framework provides typed tensors, which are the multi-dimensional arrays of numbers neural networks are built from, along with APIs for building models, a shared internal representation of a model's computation graph, support for running models and computing gradients during training, and tools for checking certificates, meaning formal evidence that a specific property about a model holds true. It also handles the boundary between this proof-focused code and lower-level runtime and CUDA graphics card execution, and includes examples spanning both typical machine learning use cases and scientific computing applications. Getting started involves cloning the repository and using Lake, the build tool for Lean projects, to build the project and run a small example, such as training a simple multi-layer perceptron on the CPU for a set number of steps. The README notes the project is pinned to a specific Lean 4 toolchain version. Other Lean projects can depend on TorchLean directly through Lake by pointing to its Git repository or a local path, and most downstream code is expected to start from a documented public entry point module. The repository is organized into folders covering the public interface, mathematical specifications, the runtime and training code, the internal graph representation, formal proofs, finite-precision number handling, learning theory, and verification tooling, along with the source for its documentation website. A companion academic paper describes the project in more detail, and TorchLean is released under the MIT license, a permissive open source license.

Copy-paste prompts

Prompt 1
Walk me through cloning and building TorchLean and running the first example.
Prompt 2
Explain what it means to formally verify a neural network with TorchLean.
Prompt 3
Help me understand how TorchLean's typed tensors differ from regular PyTorch tensors.
Prompt 4
How would I depend on TorchLean from my own Lean 4 project?

Frequently asked questions

What is torchlean?

A Lean 4 framework for building neural networks and mathematically proving properties about how they behave.

What language is torchlean written in?

Mainly Lean. The stack also includes Lean 4, PyTorch, CUDA.

What license does torchlean use?

Use freely for any purpose, including commercial use, as long as you keep the copyright and license notice.

How hard is torchlean to set up?

Setup difficulty is rated hard, with roughly 1day+ to a first successful run.

Who is torchlean for?

Mainly researcher.

Open on GitHub → Ask about another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.