Documentation Index
Fetch the complete documentation index at: https://mintlify.com/lean-dojo/LeanDojo-v2/llms.txt
Use this file to discover all available pages before exploring further.
HFProver brings locally fine-tuned language models into the LeanDojo v2 proof search pipeline. It loads any HuggingFace causal language model — whether a full checkpoint saved by SFTTrainer or a LoRA adapter saved alongside the base weights — and wraps it in the BaseProver search loop. At each step the prover builds a structured chat prompt from the current goal state, samples five candidate tactics, filters out illegal ones like sorry, and randomly selects a valid candidate to pass back to the search engine.
Class
lean_dojo_v2.prover.
Constructor
ckpt_path onto the target device and sets the model to evaluation mode. Construction is blocking — the model is fully loaded before the constructor returns.
Path to the saved model checkpoint directory. This should be the output directory of a
SFTTrainer or GRPOTrainer run and must contain the tokenizer files alongside the model weights.When
True, loads the checkpoint using peft.AutoPeftModelForCausalLM, which expects adapter files (adapter_config.json, adapter_model.safetensors, etc.) alongside the base model reference. When False, uses transformers.AutoModelForCausalLM for a standard full-weight checkpoint.Device placement string.
"auto" resolves to cuda if a GPU is available, otherwise falls back to cpu. Any string accepted by torch.device() is valid (e.g. "cuda:1", "mps").Methods
next_tactic
BaseProver.search() on every DFS step.
Prompt format — the goal state is embedded in a three-section chat template:
max_new_tokens=64, num_return_sequences=5, temperature=0.7, top_p=0.9.
After decoding, each candidate is trimmed to its first line and first <;> clause, and any candidate equal to "sorry" is discarded. One tactic is chosen uniformly at random from the remaining valid candidates.
The Pantograph
GoalState at the current DFS node. Its string representation is used directly as the {goal_str} in the prompt.Index of the active goal within
state.goals that the prover should address.A tactic string such as
"simp", "exact h", or "omega", or None if the model is not yet initialized (the theorem attribute has not been set by search()).generate_whole_proof
theorem in a single inference pass without running the DFS search loop.
Prompt format — uses the same ### System / ### User / ### Assistant template as next_tactic, but the user message is the full theorem_statement string and the system instruction asks for a complete proof body.
Generation parameters — max_new_tokens=512, num_return_sequences=1, temperature=0.7, top_p=0.9. The <;> combinator is stripped from the output before returning.
The
Theorem object to prove. Its __str__ representation (theorem_statement) is used as the model input.The decoded proof body string, with leading/trailing whitespace and
<;> combinator tokens removed.Example: Proof Search
The following example is adapted directly fromexamples/theorem_proving/generate_tactics.py:
Example: Whole-Proof Generation
Notes
next_tactic() returns None if self.theorem has not been set. When calling search(), theorem is set automatically. If you call next_tactic() directly (outside of search()), ensure you set prover.theorem first.See Also
- BaseProver — search loop and abstract interface
- ExternalProver — HF Inference API alternative
- RetrievalProver — RAG-based tactic generator