How lean-dojo/reprover works
• generation – for training and running the tactic generator (both with and without retrieval augmentation)
• retrieval – for training and running premise retrievers (including a BM25 baseline and transformer-based models)
• prover – for evaluating the final theorem proving pipeline (e.g., via best-first search tactics and proof search)
• scripts – containing utility scripts for data conversion, data statistics, downloading data, and integration tasks (e.g., converting checkpoints)
Main Components
a. Data & Preprocessing:
– A “common” code base (e.g., common.py) for shared functions.
– Scripts for downloading data and converting checkpoints.
b. Premise Retrieval Module:
– Located in the retrieval directory (with submodules for BM25 and transformer-based retrieval).
– Includes YAML configuration files (in retrieval/confs) to control training and evaluation.
– Tasks: indexing the corpus, training the retriever, and retrieving premises for a given proof state.
c. Tactic Generation Module:
– Found in the generation directory.
– Trains a ByT5 encoder-decoder model to generate tactics.
– Supports both standalone and retrieval-augmented versions (the latter combining retrieved premises with the proof state).
d. Proof Search / Evaluation:
– In the prover directory, where the search algorithms and evaluation functions (e.g., best-first search) integrate with the generation module.
– Interacts with external systems such as Lean (and optionally Lean Copilot) when running the final proof search.
e. Training & Logging Infrastructure:
– Leverages PyTorch Lightning and Weights & Biases (W&B) for logging.
– Uses configuration files for hyperparameter management.
Relationships and Interactions
a. The system starts with a proof state as an input.
b. The Retrieval Module (premise retriever) processes this proof state to compute embedding vectors and conduct a nearest neighbor search over a pre-indexed corpus (handled with retrieval/index.py).
c. The retrieved premises are then concatenated with the original proof state to form an enriched input.
d. This enriched input is passed to the Tactic Generation Module (in generation) to produce candidate tactics.
e. Finally, the Prover Module uses these generated tactics in a best-first search to interact with the Lean theorem prover, completing the evaluation loop.
f. During training, scripts, YAML configurations, and checkpoint converters ensure that training, evaluation, and deployment pipelines are seamlessly integrated.
Architectural Patterns / Design Principles
– Separation of Concerns: Clearly defined modules for retrieval, generation, and evaluation.
– Pipeline Architecture: Data flows from retrieval to generation to final proof search.
– Configurability: Use of YAML config files for both retrieval and generation allows tuning of hyperparameters.
– Modularity & Extensibility: The design supports both direct tactic generation and retrieval-augmented generation, along with seamless integration with external tools (Lean, W&B, Hugging Face).
Relevant Technologies and Frameworks
– Python (with PyTorch, PyTorch Lightning)
– Hugging Face Transformers (for model loading and inference)
– Weights & Biases for logging, along with standard CLI tools in Linux (wget, tar)
– Lean theorem prover integration for final evaluation.
– Additionally, configuration management via YAML files.
→ Proof State to Retrieval Module.
→ Retrieval Module outputs Passed along with Proof State to the Generation Module.
→ Tactic Generation outputs to the Prover Module.
– Label connectors (e.g., “embedding computation”, “concatenation”, “beam search generation”, “best-first search”).
– If desired, show how logging and experiment tracking (W&B) integrate with the training components.