LeanInfer provides tactic suggestions by running LLMs through Lean's foreign function interface (FFI).
![LeanInfer](https://private-user-images.githubusercontent.com/5431913/266791084-f87ec407-29a5-4468-b2fb-a2f6e9105ae9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE5MjQ0ODcsIm5iZiI6MTcyMTkyNDE4NywicGF0aCI6Ii81NDMxOTEzLzI2Njc5MTA4NC1mODdlYzQwNy0yOWE1LTQ0NjgtYjJmYi1hMmY2ZTkxMDVhZTkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjVUMTYxNjI3WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjI2MDk4OTYxMTU2YmRjN2I4MDVhNjBkMjdjMWQ2Njg1MDIyMTJlYzkwMTg2ODM5NzY3ZGUwZTBhNjc3MzRhZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.wwXUXUYGkljNsagQPLm6CkY-CK2eH0vZKizJuY6nTbk)
It is in an early stage of development. In the long term, we aim to integrate Lean and machine learning by providing a general and efficient way to run the inference of neural networks in Lean. The network can be of arbitrary model architectures and trained using arbitrary deep learning frameworks. After training, it is converted into the ONNX format, which can be run as a shared library using ONNX Runtime and integrated into Lean through FFI.
- Supported platforms: Linux and macOS (:warning: maybe also Windows, but untested)
- Clang (:warning: GCC not supported)
- Lean 4
- ONNX Runtime for optimized inference in C++
- Edit
lakefile.lean
to add the dependencyrequire LeanInfer from git "https://github.com/lean-dojo/LeanInfer.git"
and package configuration optionmoreLinkArgs := #["-lonnxruntime", "-lstdc++"]
(see this example). Runlake update
for the changes to take effect. - Download the model (LeanDojo's tactic generator in ONNX format) into the root of the repo. If you have Git LFS, this can be done by
git lfs install && git clone https://huggingface.co/kaiyuy/onnx-leandojo-lean4-tacgen-byt5-small
. Otherwise, see here. - Add the ONNX Runtime source directory (the directory that contains
onnxruntime_cxx_api.h
) to the environment variableCPATH
. Add the ONNX Runtime library directory (the directory that containslibonnxruntime.so
orlibonnxruntime.dylib
) toLD_LIBRARY_PATH
(Linux),DYLD_LIBRARY_PATH
(macOS), andLIBRARY_PATH
(all platforms). If you are using Lean in VSCode, also add these environment variables to theLean4: Server Env
setting in VSCode. - If your default C++ compiler is not Clang (e.g., in most Linux systems), add LLVM's libc++ directory (the directory that contains
libc++.so
) toLD_LIBRARY_PATH
(Linux),DYLD_LIBRARY_PATH
(macOS), andLIBRARY_PATH
. If you are using Lean in VSCode, also add it toLean4: Server Env
. - Run
lake script run LeanInfer/check
and fix problems (if any). Finally, runlake build
.
If you have problems building the project, our Dockerfile may be helpful as a reference. Note that it doesn't need Step 4 because the base Ubuntu image has no compiler pre-installed.
After import LeanInfer
, you can use the tactic suggest_tactics
(see the image above and this example).
- For general questions and discussions, please use GitHub Discussions.
- To report a potential bug, please open an issue. In the issue, please include your OS information and the exact steps to reproduce the error. The more details you provide, the better we will be able to help you.
- llmstep is another tool providing tactic suggestions using LLMs. We use their frontend for displaying tactics but a different mechanism for running the model.
@misc{leaninfer,
author = {Song, Peiyang and Yang, Kaiyu and Anandkumar, Anima},
title = {LeanInfer: Neural Network Inference in Lean 4},
year = {2023},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/lean-dojo/LeanInfer}},
}
The C++ code in this project is formatted using ClangFormat. To format the code, run
clang-format --style Google -i ffi.cpp