Open Goicu opened 2 years ago
Thanks for the report. As a workaround, can you try with cloudpickle?
Thanks for the tip Yard1. But still don't work.
With cloudpickle:
from ray.cloudpickle import cloudpickle
cloudpickle.pickle.dump(trained_model, f)
Error:
AttributeError: Can't pickle local object 'MaximumIterationStopper.__init__.<locals>.<lambda>'
from ray import cloudpickle or import cloudpickle
cloudpickle.dump(trained_model, f)
Error:
TypeError: cannot pickle 'weakref' object
Why do you need to save the TuneSearchCV object in the first place? What's the use case? Doesn't the model by itself suffice?
You are complete right. Actually what I want is to save the refit trained model. But I do not know how either.
You can obtain the best model by calling TuneSearchCV.best_estimator_
after fitting had completed. You can then save it following instructions for the framework you are using.
Thanks again Yard1.
With TuneSearchCV.best_estimator_
I couldn't save it either because I am using a KerasClassifier estimator.
I understand the porpoise of the CV like it is said here: https://stackoverflow.com/questions/55814197/kerasclassifier-object-has-no-attribute-save
But I suppose that the TuneSearchCV has the refit param for this porpoise and with this as I am in research and not in production this will save me the task of retrain the model with the bestparams founds in the search.
But perhaps this was not contemplated.
The refit param merely specifies that the best estimator will be returned in its trained form. However, using bestparams and refitting the estimator yourself is also a solution.
I try with pickle, joblib and dill.
With pickle I had this error:
AttributeError: Can't pickle local object 'MaximumIterationStopper.__init__.<locals>.<lambda>'
With joblib I had this error:
raise PicklingError(_pickle.PicklingError: Can't pickle <function MaximumIterationStopper.__init__.<locals>.<lambda> at 0x7f3093158790>: it's not found as ray.tune.stopper.MaximumIterationStopper.__init__.<locals>.<lambda>
With dill I had this error:
TypeError: cannot pickle 'tensorflow.python._pywrap_tf_session.TF_Operation' object
I don't have defined any lambda function in my code. I suppose that the lambda function is inside the keras or tensorflow libraries.