Restart training from a saved file #313
-
|
Dear Miles, I have been training a large number of models in parallel and have achieved some relatively good results. However, they did not quite meet my expectations and I am interested in further training. I am wondering if there is any feature that supports continuing training from a selected checkpoint. Thank you for your attention to my question. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 14 replies
-
|
You can use the However after exiting Python, it is not possible to restart, as the Julia runtime will be closed and relevant variables erased. Perhaps one could serialize the Julia variables ( Edit: note that PySR v1.x saves the search state to a file, so this point above doesn't apply. |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for your response. I tried loading the model from a file and setting the |
Beta Was this translation helpful? Give feedback.
-
|
Right: you can’t have a successful warm start without However you could try to save this object using the Serialization library in Julia: https://docs.julialang.org/en/v1/stdlib/Serialization/. You will need to access this with PyJulia, from julia import Serialization
Serialization.serialize(
"checkpoint.pt",
model.raw_julia_state_ # This is the trained model
)Then, in a new process: from pysr import PySRRegressor
model = PySRRegressor.from_file("hall_of_fame...pkl")
model.warm_start = True
from pysr.julia_helpers import init_julia
init_julia()
from julia import SymbolicRegression # Needed to load library (usually this is done by .fit())
from julia import Serialization
model.raw_julia_state_ = Serialization.deserialize("checkpoint.pt")Now it should be an identical model as before you closed Python. |
Beta Was this translation helpful? Give feedback.
-
|
Dear Miles, tttc3, and Zhyang, I am also training several large number of models in parallel and have achieved some relatively good results. model = PySRRegressor.from_file(str("file-name.pkl"), warm_start=True)combined with the option warm_start set to True, to start where the model was left off. However, it seems that the model does not start from it was left off. So I looked it up and reached this thread where is it prescribed to save the Julia state, by doing from julia import Serialization
Serialization.serialize(
"checkpoint.pt",
model.raw_julia_state_
)which I call after the model.fit() call. Then, I restart from the Julia state by loading the checkpoint.pt file along with the .pkl file doing model = PySRRegressor.from_file(str("file-namepkl"), warm_start=True)
from pysr.julia_helpers import init_julia
init_julia()
from julia import SymbolicRegression
from julia import Serialization
model.raw_julia_state_ = Serialization.deserialize("checkpoint.pt")
model.fit(X, y)However, this does not restart from the saved state as I thought it would. Is there anything I'm missing out ? Did @tttc3, or @zhyang-dev successfully restart from previous state ? Best, |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Right: you can’t have a successful warm start without
raw_julia_state_, and that is cleared from the state when the PySRRegressor is saved to a pickle file.However you could try to save this object using the Serialization library in Julia: https://docs.julialang.org/en/v1/stdlib/Serialization/. You will need to access this with PyJulia,
for example:
Then, in a new process: