LLMSTEP: LLM proofstep suggestions in Lean

Sean Welleck, Rahul Saha

Abstract

We present LLMSTEP, a tool for integrating a language model into the Lean proof assistant. LLMSTEP is a Lean 4 tactic that sends a user's proof state to a server hosting a language model. The language model generates suggestions, which are checked in Lean and displayed to a user in their development environment. We provide a baseline language model, along with code for fine-tuning and evaluation to support further development. We provide server implementations that run on CPU, a CUDA GPU, or a Google Colab notebook, as a step towards fast, effective language model suggestions for any user.

Introduction

Interactive Theorem Provers (ITPs) like Lean 4 are essential for formalizing mathematics and verifying software, yet they present a steep learning curve. A primary challenge for users is "tactic selection"—identifying the specific command required to advance a proof from a given state. While Large Language Models (LLMs) have demonstrated proficiency in predicting these tactics, existing solutions often suffer from being closed-source, tied to proprietary APIs, or difficult to integrate into standard workflows. LLMSTEP addresses these issues by providing an open-source, extensible framework that delivers verified, real-time tactic suggestions directly within the Lean 4 environment.

System Architecture

LLMSTEP operates through a seamless loop between the user's development environment and a backend inference server. The system consists of three primary components:

  1. The Lean Tactic: A metaprogram within Lean 4 that captures the current proof state (goals and hypotheses) and transmits it to the backend. It supports "prefixed suggestions," allowing users to guide the LLM by typing the start of a tactic (e.g., llmstep "exact").
  2. The Server: A Python-based backend hosting the LLM. To ensure accessibility, the authors provide implementations for various hardware, including standard CPUs, CUDA-enabled GPUs, and high-performance inference via vLLM.
  3. The Verification Loop: Crucially, LLMSTEP does not merely display raw LLM output. It automatically executes each suggestion within the Lean compiler to verify its validity. Suggestions are categorized as complete (finishing the proof), valid (advancing the proof), or invalid (compilation error).
The LLMSTEP system architecture illustrates the flow from a proof state to verified suggestions.

User Experience and Verification

The integration into the VS Code Infoview allows users to interact with suggestions intuitively. Verified suggestions are color-coded, providing immediate visual feedback on which tactics are likely to succeed. This "ground-truth" filtering eliminates the common LLM issue of hallucination, ensuring that users only spend time on tactics that are mathematically sound and syntactically correct.

An example of LLMSTEP suggestions in the Lean Infoview, showing verified tactics for a set theory proof.

The prefixing feature further enhances the UI by acting as a "super-autocomplete." By providing a hint like apply or simp, users can leverage the LLM to find specific lemmas within a broader tactic category, bridging the gap between general intent and specific formal syntax.

Evaluation and Results

The baseline model, a Pythia 2.8b model fine-tuned on the LeanDojo Benchmark 4 dataset, was evaluated against the miniF2F-test set. It achieved a success rate of 27.9%, notably outperforming the ReProver model (22.1%) in a similar configuration.

Latency is a critical factor for interactive tools. LLMSTEP demonstrates impressive performance across hardware tiers:

  • GPU Performance: Using vLLM on an NVIDIA GTX 1080Ti, the system generates 10 suggestions in approximately 0.25 seconds.
  • CPU Accessibility: On a standard MacBook Pro (Intel Core i7), the ReProver model generates 10 suggestions in roughly 3.16 seconds, maintaining usability for researchers without dedicated high-end hardware.

Limitations and Future Directions

While LLMSTEP provides a robust foundation, several areas for improvement remain. The current baseline model relies on internal weights rather than retrieval-augmented generation (RAG), which could further improve performance by searching the extensive Mathlib library. Additionally, while the tool currently focuses on next-step suggestions, future iterations could explore whole-proof generation or more complex search algorithms integrated directly into the user interface. By remaining model-agnostic, LLMSTEP is well-positioned to incorporate future advancements in mathematical language modeling.

Summary updated

BibTeX
@inproceedings{welleck2023llmstep,
  author = {Sean Welleck and Rahul Saha},
  title = {{LLMSTEP: LLM proofstep suggestions in Lean}},
  booktitle = {MATH-AI @ NeurIPS},
  year = {2023},
  url = {https://openreview.net/forum?id=ODOJuAM4Qj},
}

Loading related content...

Figure