We rewrote an ML Framework* in Lean, (and yes it is faster*)
The authors rewrote tinygrad, a machine learning framework, using the Lean programming language. The rewrite reportedly improves performance, though the article notes asterisks on both the scope and speed claims.
Background
- TinyGrad is a minimalist deep learning framework (like a tiny PyTorch) used for education and research. It was originally written in Python and C.
- Lean is a programming language and proof assistant used for formal verification — writing code where you can mathematically prove it is correct.
- The article describes rewriting TinyGrad’s core operations (a tensor library) in Lean, then extracting efficient C code from it via Lean’s "compile" feature. This is novel because Lean is normally used for proofs, not for high-performance ML kernels.
- The asterisks in the title hint at the article’s honest framing: the rewrite is faster in some benchmarks but not all, and the real contribution is showing that formally verified code can be competitive with hand-tuned C.