LeanDojo as REPL for online RL #159
-
Hi, I think LeanDojo is a very impressive project, and I'm interested in using LeanDojo as an RL environment (as advertised, I suppose). I noticed that initializing the environment is somewhat costly. The code snippet below took about 30s+ to initialize each theorem. I read in this issue that 1-2 minutes is quite normal. I was wondering what the recommendation is for using LeanDojo in an online RL setup given that this start-up time for each training sample is somewhat prohibitive. I have several questions:
I am looking into these questions myself by checking papers that cite LeanDojo and trying profiling on enter/exit functions to determine where the bottlenecks are, but I would greatly appreciate any guidance! Thanks for open sourcing this project and thanks in advance for any help! import json
from time import perf_counter
import numpy as np
from tqdm import tqdm
from dotenv import load_dotenv
load_dotenv() # load GH token env var
from lean_dojo import Dojo, Theorem, LeanGitRepo
with open("data/leandojo_benchmark_4/novel_premises/train.json") as f:
thm_dicts = json.load(f)
samples = 30
np.random.seed(42)
idxs = np.random.choice(range(len(thm_dicts)), samples, replace=False)
entry_times = []
exit_times = []
for idx in tqdm(idxs, total=samples):
thm_dict = thm_dicts[idx]
thm = Theorem(
repo=LeanGitRepo(url=thm_dict["url"], commit=thm_dict["commit"]),
file_path=thm_dict["file_path"],
full_name=thm_dict["full_name"]
)
start = perf_counter()
with Dojo(thm) as (dojo, initial_state):
entry_times.append(perf_counter() - start)
start = perf_counter()
exit_times.append(perf_counter() - start)
with open("outputs/entry_exit_times.json", 'w') as f:
json.dump({"idxs": list(idxs), "entry": entry_times, "exit": exit_times}, f, indent=2)
print("wrote to outputs/entry_exit_times.json") |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
I've looked into this a bit, and in my case the start time was due to the native "container" copying gigabytes of data several times. I have a hack that cuts this time out. (doragera#3) I think I deleted too much, and that version only works if you've processed the repo with the normal LeanDojo first. Sorry, I should clean it up someday. |
Beta Was this translation helpful? Give feedback.
-
Your code looks reasonable to me. If a theorem is in a big file and has a lot of stuff before it, the startup time is naturally going to be slow. Other than this reason, it might be worth some profiling to identify the performance bottleneck. |
Beta Was this translation helpful? Give feedback.
-
I finally get some time to work on this. This is the draft PR. I'll make a few further improvements and merge it into |
Beta Was this translation helpful? Give feedback.
-
Released! https://github.com/lean-dojo/LeanDojo/releases/tag/v2.0.0 |
Beta Was this translation helpful? Give feedback.
Released! https://github.com/lean-dojo/LeanDojo/releases/tag/v2.0.0