llmstep: LLM proofstep suggestions in Lean

Sean Welleck, Rahul Saha

TL;DR

LLMSTEP is an open-source tool that integrates large language models (LLMs) directly into the Lean 4 proof assistant to provide real-time tactic suggestions. By bridging the gap between neural theorem provers and the interactive user environment, it allows researchers and mathematicians to receive verified, context-aware suggestions for their next proof steps across various hardware configurations.

What Problem Does This Paper Address?

Interactive Theorem Provers (ITPs) like Lean are powerful tools for formalizing mathematics and verifying software, but they have a notoriously steep learning curve. A major hurdle for users is "tactic selection"—knowing exactly which command (or tactic) will move a proof forward from a specific state.

While recent research has shown that LLMs are surprisingly good at predicting these tactics, most existing tools were either closed-source (like the now-disabled gpt-f), tied to specific proprietary APIs, or difficult to integrate into a standard workflow. There was a clear need for an extensible, open-source framework that works within the modern Lean 4 ecosystem and provides suggestions that are not just "plausible-looking text" but are actually verified by the proof assistant.

Methods

LLMSTEP consists of three main components that work in a loop:

  1. The Lean Tactic: A Lean 4 metaprogram that captures the current "proof state" (the goals and hypotheses) and sends it to a backend server. It also supports prefixed suggestions, where a user can type part of a tactic (e.g., llmstep "exact") to constrain the LLM's output.
  2. The Server: A Python-based backend that hosts the language model. The authors provide implementations for various environments, including standard CPU, CUDA-enabled GPUs, and high-performance inference via vLLM.
  3. The Verification Loop: Once the LLM generates suggestions, LLMSTEP doesn't just display them. It automatically runs each suggestion through the Lean compiler to check if it is:
  4. Complete: Finishes the proof.
  5. Valid: Compiles without error and moves the proof forward.
  6. Invalid: Results in a compilation error.

These suggestions are then color-coded and displayed in the VS Code Infoview, where a user can simply click one to insert it into their code.

Datasets

The authors used the following for training and evaluation:

  • Training: A Pythia 2.8b model was fine-tuned on (state, next-tactic) pairs extracted from the Lean Mathlib (the standard mathematical library for Lean) via the LeanDojo Benchmark 4 dataset.
  • Evaluation: The tool was benchmarked using mathlib4-test and miniF2F-test (a standard benchmark for formal Olympiad-level math problems).

Key Insights and Ideas

  • Verification is the Killer Feature: Unlike standard LLM chatbots that can "hallucinate" incorrect code, LLMSTEP uses the proof assistant as a ground-truth filter. By checking suggestions before the user even sees them, it eliminates the frustration of trying tactics that don't compile.
  • Prefixing as a UI Bridge: Allowing users to provide a prefix (like apply or simp) turns the LLM into a powerful "super-autocomplete," helping users find the specific lemma they need within a general tactic category.
  • Hardware Flexibility: The authors recognized that not every Lean user has a high-end GPU. By supporting ReProver (a smaller model) for CPU-only use and Pythia with vLLM for GPU users, they made the tool accessible to a wider range of researchers.

Key Results

  • Performance: The fine-tuned Pythia 2.8b model outperformed recent open-source models like ReProver (without retrieval) on the miniF2F-test set, achieving a 27.9% success rate compared to ReProver's 22.1%.
  • Latency: Speed is crucial for an interactive tool. Using vLLM on an NVIDIA GTX 1080Ti, LLMSTEP can generate 10 suggestions in just 0.25 seconds, making the experience feel near-instant.
  • CPU Viability: For users without GPUs, the ReProver model on a standard MacBook Pro (Intel Core i7) could still generate 10 suggestions in about 3.16 seconds, which is usable for interactive work.

Limitations and Future Work

  • Lack of Retrieval: Currently, the baseline model relies on its internal weights to remember lemmas. It does not yet incorporate "retrieval-augmented generation" (RAG) to search through the entire Mathlib for relevant theorems, which is a known way to improve performance.
  • Tactic-Level Granularity: The tool focuses on predicting the next step. The authors suggest that future work could involve "whole-proof" generation or more complex search algorithms integrated directly into the UI.
  • Model Evolution: While Pythia 2.8b is the current default, the authors emphasize that LLMSTEP is model-agnostic, meaning it can easily be updated as more powerful mathematical LLMs (like Llemma) are released.

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