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.
HFAgent is the go-to agent when you have local GPU resources and want end-to-end control over the training process. It wraps an SFTTrainer to fine-tune any HuggingFace causal language model on your traced Lean repositories, automatically detects whether LoRA adapters are in use, and then loads the resulting checkpoint into an HFProver for tactic-by-tactic or whole-proof theorem proving — all through the unified BaseAgent interface.
Class Definition
HFAgent extends BaseAgent. It does not build Lean dependencies during tracing (_get_build_deps() returns False), and it initialises an HFProver from the SFTTrainer’s output directory when prove() is called.
Constructor
A configured
lean_dojo_v2.trainer.SFTTrainer instance. The agent reads
trainer.output_dir to know where to find the fine-tuned checkpoint, and
checks trainer.lora_config to decide whether to load LoRA weights.Path to the JSON file used for
DynamicDatabase persistence. Shared with the
base class.Training hyperparameters such as learning rate, batch size, and EWC lambda.
Defaults to a
TrainingConfig with sensible out-of-the-box values. Pass a
customised instance to override individual fields.Prover runtime settings including
timeout, num_sampled_tactics,
num_workers, and use_vllm. Defaults to a ProverConfig with sensible
out-of-the-box values.Behaviour
| Method | Detail |
|---|---|
_get_build_deps() | Always returns False. Lean dependency trees are not traced, keeping setup fast. |
_setup_prover() | Constructs HFProver(ckpt_path=self.output_dir, use_lora=self.use_lora). |
use_lora | Set to True automatically when trainer.lora_config is not None. |
self.output_dir is taken directly from trainer.output_dir, so the
checkpoint path used during proving always matches the directory written by
the trainer. No manual path wiring is required.Example
Full-parameter SFT
The following example is adapted fromexamples/sft.py. It fine-tunes DeepSeek-Prover-V2-7B with full-parameter SFT on a sample Lean 4 repository and then runs the prover on all sorry theorems:
SFT with LoRA
The following example is adapted fromexamples/lora.py. It fine-tunes DeepSeek-Prover-V2-7B with LoRA adapters, which reduces GPU memory requirements significantly:
Whole-proof generation
Passwhole_proof=True to prove() to ask the model to emit a complete proof block in one forward pass rather than searching tactic-by-tactic:
Multiple Repositories
HFAgent supports progressive training over several repositories. Repositories are sorted by difficulty before training, and the same SFTTrainer checkpoint directory is reused across repos: