Slim205/RL-Lean

Python

1

94 commits

updated Nov 20, 2025

See the code

README

RL-Lean

Reinforcement learning for formal-math reasoning with Lean 4. We train a conjecturer to propose useful theorem statements for a prover, then use those generated samples to improve the prover via SFT and RL.

Alt text

Why formal math + Lean?

Formal proofs are machine-checkable: the Lean compiler verifies every step, removing ambiguity compared to informal math. This also enables synthetic data generation—you don’t need to hand-annotate ground truth when the compiler can validate it.

Method overview

  • Goal. Train a conjecturer that proposes conjectures neither too easy nor too hard for the prover—i.e., maximally useful for training.
  • Approach. We use PPO with a reward shaped by pass rate, novelty/relatedness, and batch diversity.

Reward

We define a base term:

$$ R_{\text{base}} = \mathbf{1}!\left(0 < \text{Pass@16} \le 0.5\right) \cdot \mathbf{1}!\left(0.4 < \cos(\texttt{new}, \texttt{old}) < 0.9\right) \cdot \mathbf{1}!\left(\min \cos(\text{same batch}) < 0.9\right) $$

The $R_{\text{base}}$ term is designed to capture several key aspects :

  • Complexity : encourages statements that are non-trivial but not too difficult for the LLM.
  • Novelty avoids near-duplicate statements.
  • Relatedness : ensures a meaningful connection between the statement and its conjecturer.
  • Synthetic correctness : guarantees that statements are syntactically valid and pass the Lean compiler with by sorry.

Additionally, $R_{\text{base}}$ enforces batch-level diversity to prevent collapse.

Training pipeline

  1. Conjecturer RL: Train with PPO using the reward above.
  2. Data collection: Generate ~40k conjectures/proofs; deduplicate.
  3. Prover SFT: Start from DeepSeek-Prover-v1.5-SFT, run 1 epoch SFT on the collected data.
  4. Prover RL: Further fine-tune on LeanWorkbook using RL.

Results (MiniF2F)

ModelPass@1Pass@32
DeepSeek-Prover-v1.5-SFT30.7447.95
+ SFT on conjecturer data32.7949.18
+ SFT + RL (LeanWorkbook)39.7549.18

Takeaway: +9 absolute improvement in Pass@1 over the base.


Implementation notes

  • RL framework: VERL
  • SFT framework: Levanter
  • Lean compiler service: kimina-server
  • Base prover: DeepSeek-Prover-v1.5-SFT

Dataset & Models


Acknowledgements

Built on and inspired by: GodelLM, kimina-server, VERL, STP, Levanter, Lean Dojo ,and DeepSeek-Prover-v1.5. Thanks to the authors and maintainers of these projects.


For more details, please see the slides: [https://github.com/Slim205/RL-Lean/blob/master/Harvard%20Work.pdf]

Slim205/RL-Lean

Python

1

94 commits

updated Nov 20, 2025

See the code

README

RL-Lean

Reinforcement learning for formal-math reasoning with Lean 4. We train a conjecturer to propose useful theorem statements for a prover, then use those generated samples to improve the prover via SFT and RL.

Alt text

Why formal math + Lean?

Formal proofs are machine-checkable: the Lean compiler verifies every step, removing ambiguity compared to informal math. This also enables synthetic data generation—you don’t need to hand-annotate ground truth when the compiler can validate it.

Method overview

  • Goal. Train a conjecturer that proposes conjectures neither too easy nor too hard for the prover—i.e., maximally useful for training.
  • Approach. We use PPO with a reward shaped by pass rate, novelty/relatedness, and batch diversity.

Reward

We define a base term:

$$ R_{\text{base}} = \mathbf{1}!\left(0 < \text{Pass@16} \le 0.5\right) \cdot \mathbf{1}!\left(0.4 < \cos(\texttt{new}, \texttt{old}) < 0.9\right) \cdot \mathbf{1}!\left(\min \cos(\text{same batch}) < 0.9\right) $$

The $R_{\text{base}}$ term is designed to capture several key aspects :

  • Complexity : encourages statements that are non-trivial but not too difficult for the LLM.
  • Novelty avoids near-duplicate statements.
  • Relatedness : ensures a meaningful connection between the statement and its conjecturer.
  • Synthetic correctness : guarantees that statements are syntactically valid and pass the Lean compiler with by sorry.

Additionally, $R_{\text{base}}$ enforces batch-level diversity to prevent collapse.

Training pipeline

  1. Conjecturer RL: Train with PPO using the reward above.
  2. Data collection: Generate ~40k conjectures/proofs; deduplicate.
  3. Prover SFT: Start from DeepSeek-Prover-v1.5-SFT, run 1 epoch SFT on the collected data.
  4. Prover RL: Further fine-tune on LeanWorkbook using RL.

Results (MiniF2F)

ModelPass@1Pass@32
DeepSeek-Prover-v1.5-SFT30.7447.95
+ SFT on conjecturer data32.7949.18
+ SFT + RL (LeanWorkbook)39.7549.18

Takeaway: +9 absolute improvement in Pass@1 over the base.


Implementation notes

  • RL framework: VERL
  • SFT framework: Levanter
  • Lean compiler service: kimina-server
  • Base prover: DeepSeek-Prover-v1.5-SFT

Dataset & Models


Acknowledgements

Built on and inspired by: GodelLM, kimina-server, VERL, STP, Levanter, Lean Dojo ,and DeepSeek-Prover-v1.5. Thanks to the authors and maintainers of these projects.


For more details, please see the slides: [https://github.com/Slim205/RL-Lean/blob/master/Harvard%20Work.pdf]

Significant stargazers

SuperCowProducts

12 followers · starred Jun 2026