-
Notifications
You must be signed in to change notification settings - Fork 10
Version bump guide
Thomas Zhu edited this page Oct 29, 2025
·
10 revisions
This guide provides instructions for updating LeanHammer to a new Lean version.
We want to have a tag of LeanHammer for each release (candidate) of Lean. To do this, you need to bump all dependencies of LeanHammer.
LeanHammer has these components / dependencies that we manage:
- premise-selection
- Lean-auto @ hammer branch
- Duper @ hammer branch
- HammerCore (the HammerCore subdirectory of LeanHammer)
- Hammer (the root directory of LeanHammer)
- (To be added)
and these external dependencies:
- Batteries
- Aesop
We need to manually bump the Lean versions of the former set, and set the tags for the Lean versions in the latter set in lakefile files.
Example: Say we are updating to Lean v4.21.0. The steps are:
- In premise-selection
- Change all dependencies in lakefile.lean to use the
v4.21.0tag. premise-selection currently has no dependencies, so nothing has to be done. - Change lean-toolchain to
leanprover/lean4:v4.21.0. - Run
lake updateand thenlake build. - Fix any errors. (Usually there will be no errors).
- Run
lake test. It should run the PremiseSelectionTest.lean without errors. - Push the results to a branch/fork, and open and merge a bump PR.
- Create a tag
v4.21.0.
- Change all dependencies in lakefile.lean to use the
- In the hammer branch of lean-auto
- Change all dependencies in lakefile.lean to use the
v4.21.0tag. Lean-auto currently has no dependencies, so nothing has to be done. - Change lean-toolchain to
leanprover/lean4:v4.21.0. - Run
lake updateand thenlake build. - Fix any errors. (This is the most time-consuming step)
- Push the results to a branch/fork, and open and merge a bump PR.
- Change all dependencies in lakefile.lean to use the
- In the hammer branch of duper
- Change all dependencies in lakefile.lean to use the
v4.21.0tag. Currently, this is changing the tag for Batteries tov4.21.0. - Change lean-toolchain to
leanprover/lean4:v4.21.0. - Run
lake updateand thenlake build. - Fix any errors. (This is the most time-consuming step)
- Push the results to a branch/fork, and open and merge a bump PR.
- Change all dependencies in lakefile.lean to use the
- In the HammerCore subdirectory of LeanHammer
- Change all dependencies in lakefile.lean to use the
v4.21.0tag. Currently, this is changing the tag for Aesop tov4.21.0. - Change lean-toolchain to
leanprover/lean4:v4.21.0. - Run
lake updateand thenlake build. - Fix any errors. (This is the most time-consuming step)
- Change all dependencies in lakefile.lean to use the
- In the root directory of LeanHammer
- Change all dependencies in lakefile.lean to use the
v4.21.0tag. Currently, this is changing the tags for premise-selection and Qq tov4.21.0. - Change lean-toolchain to
leanprover/lean4:v4.21.0. - Run
lake updateand thenlake build. - Fix any errors.
- Push the results to a branch/fork, and open and merge a bump PR.
- Create a tag
v4.21.0.
- Change all dependencies in lakefile.lean to use the
You need access to a machine with 4 GPUs. The following paths assume access to the Babel HPC at CMU LTI; otherwise change the paths / SLURM configs accordingly.
There are two global paths that are used throughout the following guides:
-
data directory:
- Holds extracted mathlib & upstream premises from ntp-toolkit
- Default:
/data/user_data/thomaszh/mathlibon Babel
-
model path:
- Holds the trained model
- Default:
/data/user_data/thomaszh/models/all-distilroberta-v1-lr2e-4-bs256-nneg3-ml-ne2on Babel, where the final string depends on some hyperparameters
- Go to the hammer branch of https://github.com/cmu-l3/ntp-toolkit
- Edit both
configs/config_mathlib.jsonandconfigs/config_mathlib_full.json, and edit bothcommitandleanin either file to reflect the new version. - Run the command:
python scripts/extract_repos.py --config configs/config_mathlib_full.json --cwd "`pwd`"- This command does nothing except updating
lakefile.lean,lake-manifest.json, andlean-toolchainin ntp-toolkit. It is expected to throw an error; it doesn’t matter.
- This command does nothing except updating
- Ensure that
lake update && lake buildworks. If it doesn’t, fix the relevant errors (in TrainingData/ or scripts/) that result from the version bump. - Push the changes.
- In a compute cluster (perhaps your own laptop is also fine), on a clone of ntp-toolkit, checkout the hammer branch, pull the changes.
- (NB(Thomas): I have ntp-toolkit on babel at
/home/thomaszh/ntp-toolkit-hammer. In there there is also a scriptcheck_integrity.pyto check the extracted data; the TrainingDataWithPremises can tolerate some malformed data but the extracted Imports and Declarations need to be accurate.)
- (NB(Thomas): I have ntp-toolkit on babel at
- Run
extract.shto extract all Mathlib & upstream premises- The data directory is set to
$OUTPUT_DIRinntp-toolkit/extract.sh. You may changeOUTPUT_DIRto extract to a different location. - For SLURM (e.g. on Babel),
sbatch extract.shtakes a night to complete - There will be a
revisionfile in data directory storing the Lean version, and this file is read by the following scripts.
- The data directory is set to
- Follow the guide below to upload everything to Hugging Face and leanpremise.net.
- (In
.envin lean-premise-server, you can updateDATA_REVISIONonly without updatingMODEL_REVISION, since the model is not updated.)
- (In
- Clone LeanHammer-training
- Do the steps of data extraction.
- Train the model by running
train-4gpu.sh.- If the data directory is changed during extraction, set
DATA_DIRintrain-4gpu.shto point to the data directory. - The model path is set to
$OUTPUT_DIR/<model_name>/finalintrain-4gpu.sh, where<model_name>is a string likeall-distilroberta-v1-lr2e-4-bs256-nneg3-ml-ne2that depends on hyperparameters. You may changeOUTPUT_DIRto a different location. - For example, on babel,
sbatch train-4gpu.shtakes about 37 hours, using 4 GPUs and 2 epochs. You may experiment with hyperparameters and using 8 GPUs, etc. - If training is interrupted, simply run
train-4gpu.shagain which will automatically resume training from a periodic checkpoint. - Similar to data directory, there will be a
revisionfile in model path storing the Lean version, and this file is read by the following scripts.
- If the data directory is changed during extraction, set
- Follow the guide below to upload everything to Hugging Face and leanpremise.net.
Uploading model and data to Hugging Face and leanpremise.net server:
- In LeanHammer-training, run
scripts/upload.pyto upload everything to Hugging Face.- In the script, ensure
data_diris set to data directory andmodel_pathis set to model path. - This uploads the premises data and precomputed embeddings to a branch corresponding to the Lean version (e.g.
v4.21.0) in https://huggingface.co/datasets/l3lab/lean-premises. - This uploads the model to a branch corresponding to the Lean version (e.g.
v4.21.0) in https://huggingface.co/l3lab/all-distilroberta-v1-lr2e-4-bs256-nneg3-ml-ne2.- (If you are only running data extraction and not model training, then the model will just be re-uploaded; this is harmless)
- You may change these URLs in
scripts/upload.py, and make sure to also change them in the.envfile in lean-premise-server below. - TODO: update train.py to automatically run upload.py.
- In the script, ensure
- Go to lean-premise-server.
- Edit
DATA_REVISIONin.envto the Lean version used when extracting data.- (The server will pull the data from https://huggingface.co/datasets/l3lab/lean-premises/tree/DATA_REVISION.)
- If the model is retrained, edit
MODEL_REVISIONin.envto the Lean version of the training data used to train the model.- (The server will pull the model from https://huggingface.co/l3lab/all-distilroberta-v1-lr2e-4-bs256-nneg3-ml-ne2/tree/MODEL_REVISION.)
- Push the changes.
- SSH into the server hosting leanpremise.net. Run the following:
cd /opt/dlami/nvme/lean-premise-server # or path to lean-premise-server
git pull
docker compose down
docker compose -f docker-compose.yaml -f docker-compose.gpu.yaml up- Watch the logs and make sure the model is running. Go to http://leanpremise.net/max-new-premises to see if you can access the server (it should say a number like
2048). - Go to the test file PremiseSelectionTest.lean in premise-selection to ensure the server is working. You can also do this by running
lake test. - Bump premise-selection to the newest Lean version by updating its lean-toolchain and running lake build, ensuring everything compiles (fix any errors resulting from the bump). Tag the new commit (e.g.
v4.21.0).- (This can be done asynchronously with data/model updates. In practice, this can be done per LeanHammer tag.)