A programming framework for agentic AI
Add preserve_checkpoint to preserve the checkpoint after del (#692)
Xueqing Liu3d1a28bfc04b
diff --git a/flaml/automl.py b/flaml/automl.pyindex b959437f0..381a61a0a 100644--- a/flaml/automl.py+++ b/flaml/automl.py@@ -627,6 +627,8 @@ class AutoML(BaseEstimator):keep_search_state: boolean, default=False | Whether to keep data neededfor model search after fit(). By default the state is deleted forspace saving.+ preserve_checkpoint: boolean, default=True | Whether to preserve the saved checkpoint+ on disk when deleting automl. By default the checkpoint is preserved.early_stop: boolean, default=False | Whether to stop early if thesearch is considered to converge.append_log: boolean, default=False | Whetehr to directly append the log@@ -726,6 +728,7 @@ class AutoML(BaseEstimator):settings["starting_points"] = settings.get("starting_points", "static")settings["n_concurrent_trials"] = settings.get("n_concurrent_trials", 1)settings["keep_search_state"] = settings.get("keep_search_state", False)+ settings["preserve_checkpoint"] = settings.get("preserve_checkpoint", True)settings["early_stop"] = settings.get("early_stop", False)settings["append_log"] = settings.get("append_log", False)settings["min_sample_size"] = settings.get("min_sample_size", MIN_SAMPLE_TRAIN)@@ -1576,6 +1579,7 @@ class AutoML(BaseEstimator):auto_augment=None,custom_hp=None,skip_transform=None,+ preserve_checkpoint=True,fit_kwargs_by_estimator=None,**fit_kwargs,):@@ -1704,10 +1708,19 @@ class AutoML(BaseEstimator):self._state.fit_kwargs = fit_kwargsself._state.custom_hp = custom_hp or self._settings.get("custom_hp")- self._skip_transform = self._settings.get("skip_transform") if skip_transform is None else skip_transform+ self._skip_transform = (+ self._settings.get("skip_transform")+ if skip_transform is None+ else skip_transform+ )self._state.fit_kwargs_by_estimator = (fit_kwargs_by_estimator or self._settings.get("fit_kwargs_by_estimator"))+ self.preserve_checkpoint = (+ self._settings.get("preserve_checkpoint")+ if preserve_checkpoint is None+ else preserve_checkpoint+ )self._validate_data(X_train, y_train, dataframe, label, groups=groups)logger.info("log file name {}".format(log_file_name))@@ -2123,6 +2136,7 @@ class AutoML(BaseEstimator):seed=None,n_concurrent_trials=None,keep_search_state=None,+ preserve_checkpoint=True,early_stop=None,append_log=None,auto_augment=None,@@ -2303,6 +2317,8 @@ class AutoML(BaseEstimator):keep_search_state: boolean, default=False | Whether to keep data neededfor model search after fit(). By default the state is deleted forspace saving.+ preserve_checkpoint: boolean, default=True | Whether to preserve the saved checkpoint+ on disk when deleting automl. By default the checkpoint is preserved.early_stop: boolean, default=False | Whether to stop early if thesearch is considered to converge.append_log: boolean, default=False | Whetehr to directly append the log@@ -2464,6 +2480,11 @@ class AutoML(BaseEstimator):if keep_search_state is Noneelse keep_search_state)+ self.preserve_checkpoint = (+ self._settings.get("preserve_checkpoint")+ if preserve_checkpoint is None+ else preserve_checkpoint+ )early_stop = (self._settings.get("early_stop") if early_stop is None else early_stop)@@ -2513,7 +2534,11 @@ class AutoML(BaseEstimator):self._state.fit_kwargs = fit_kwargscustom_hp = custom_hp or self._settings.get("custom_hp")- self._skip_transform = self._settings.get("skip_transform") if skip_transform is None else skip_transform+ self._skip_transform = (+ self._settings.get("skip_transform")+ if skip_transform is None+ else skip_transform+ )fit_kwargs_by_estimator = fit_kwargs_by_estimator or self._settings.get("fit_kwargs_by_estimator")@@ -3566,7 +3591,8 @@ class AutoML(BaseEstimator):and self._trained_estimatorand hasattr(self._trained_estimator, "cleanup")):- self._trained_estimator.cleanup()+ if self.preserve_checkpoint is False:+ self._trained_estimator.cleanup()del self._trained_estimatordef _select_estimator(self, estimator_list):diff --git a/test/nlp/test_autohf.py b/test/nlp/test_autohf.pyindex 6e59bcf2d..ee0ab693f 100644--- a/test/nlp/test_autohf.py+++ b/test/nlp/test_autohf.py@@ -13,6 +13,7 @@ def test_hf_data():automl = AutoML()automl_settings = get_automl_settings()+ automl_settings["preserve_checkpoint"] = Falsetry:automl.fit(@@ -68,6 +69,8 @@ def test_hf_data():automl.predict_proba(X_test)print(automl.classes_)+ del automl+if __name__ == "__main__":test_hf_data()