Closed GeorgeXiaojie closed 3 months ago
Hi @GeorgeXiaojie,
I don't see fit()
being called in the code you shared, if it isn't, the model does not exist and there is not much to actually save. Can you try the following:
from darts.models import RegressionEnsembleModel, LightGBMModel, XGBModel
from darts.datasets import AirPassengersDataset
ts = AirPassengersDataset().load()
model = RegressionEnsembleModel(
forecasting_models = [
LightGBMModel(
lags=3,
output_chunk_length=1,
random_state=2022,
),
XGBModel(
lags=3,
output_chunk_length=1,
random_state=2022
)],
regression_train_n_points = 10
)
model.fit(ts)
# works
model.predict(3)
model.save("model.pt")
model_loaded = RegressionEnsembleModel.load("model.pt")
# works as well
model_loaded.predict(3)
Hi @GeorgeXiaojie,
I don't see
fit()
being called in the code you shared, if it isn't, the model does not exist and there is not much to actually save. Can you try the following:from darts.models import RegressionEnsembleModel, LightGBMModel, XGBModel from darts.datasets import AirPassengersDataset ts = AirPassengersDataset().load() model = RegressionEnsembleModel( forecasting_models = [ LightGBMModel( lags=3, output_chunk_length=1, random_state=2022, ), XGBModel( lags=3, output_chunk_length=1, random_state=2022 )], regression_train_n_points = 10 ) model.fit(ts) # works model.predict(3) model.save("model.pt") model_loaded = RegressionEnsembleModel.load("model.pt") # works as well model_loaded.predict(3)
Thank you for your reply. There is a model.fit and I've followed up on the issue.
RegressionEnsembleModel is OK using the predictive models LightGBMModel and XGBModel.
However, RegressionEnsembleModel using TiDEModel and NLinearModel is not working.
Oh thanks for the clarification, managed to reproduce the problem.
It seems like the torch models weights are not being loaded properly, we will investigate this further.
Hi! @madtoinou @GeorgeXiaojie
I found out that the problem comes from the save
and load
method used by the ensemble model.
Since ensemble model uses the save
of the ForecastingModel
class, it is not possible to save the .ckpt file of torch model like the save
method in TorchForecastingModel
. In this case, even torch model does not load the .ckpt file, it's model._fit_called
attribute remains to be True, which may cause AttributeError: 'NoneType' object has no attribute 'set_predict_parameters'
.
We may need to figure out a way to save the .ckpt file of the torch model in the ensemble model.
Hi! @madtoinou @GeorgeXiaojie
I found out that the problem comes from the
save
andload
method used by the ensemble model.Since ensemble model uses the
save
of theForecastingModel
class, it is not possible to save the .ckpt file of torch model like thesave
method inTorchForecastingModel
. In this case, even torch model does not load the .ckpt file, it'smodel._fit_called
attribute remains to be True, which may causeAttributeError: 'NoneType' object has no attribute 'set_predict_parameters'
.We may need to figure out a way to save the .ckpt file of the torch model in the ensemble model.
Thanks, looking forward to providing a solution. I've tried before to save the model directly using pickle.dump to save the model directly and then load the model using pickle.load, but I still can't get rid of the problem.
Describe the bug A clear and concise description of what the bug is.
scene1:as below, RegressionEnsembleModel train and predict works
train:
predict:
scene2:as bellow, RegressionEnsembleModel train works, but predict doesn't work, and raises an exception: AttributeError: 'NoneType' object has no attribute 'set_predict_parameters'
train:
predict:
I debugged into the code below and found that self.model is indeed None, I'm not sure if it's because of a bug?
To Reproduce Steps to reproduce the behavior, preferably code snippet.
Expected behavior A clear and concise description of what you expected to happen.
System (please complete the following information):
Additional context Add any other context about the problem here.