diff --git a/flaml/automl/automl.py b/flaml/automl/automl.py index d2d9f98956..47a82a5b2a 100644 --- a/flaml/automl/automl.py +++ b/flaml/automl/automl.py @@ -2521,8 +2521,8 @@ def _search(self): self._warn_threshold = 10 self._selected = None self.modelcount = 0 - if self._max_iter < 2 and self.estimator_list and self._state.retrain_final: - # when max_iter is 1, no need to search + if self._max_iter < 1 and self.estimator_list and self._state.retrain_final: + # when max_iter is 1, search is also necessary for test. Besides, it won't take a lot of time. self.modelcount = self._max_iter self._max_iter = 0 self._best_estimator = estimator = self.estimator_list[0] diff --git a/flaml/fabric/mlflow.py b/flaml/fabric/mlflow.py index 4cfb0e2cd2..e0ad4e870b 100644 --- a/flaml/fabric/mlflow.py +++ b/flaml/fabric/mlflow.py @@ -504,16 +504,22 @@ def log_automl(self, automl): self.adopt_children(automl) if self.manual_log: - best_mlflow_run_id = self.manual_run_ids[automl._best_iteration] + if len(self.manual_run_ids) == 0: + best_mlflow_run_id = self.parent_run_id or mlflow.active_run().info.run_id + else: + best_mlflow_run_id = self.manual_run_ids[automl._best_iteration] best_run_name = self.mlflow_client.get_run(best_mlflow_run_id).info.run_name automl.best_run_id = best_mlflow_run_id automl.best_run_name = best_run_name self.mlflow_client.set_tag(best_mlflow_run_id, "flaml.best_run", True) self.best_run_id = best_mlflow_run_id if self.parent_run_id is not None: - conf = automl._config_history[automl._best_iteration][1].copy() - if "ml" in conf.keys(): - conf = conf["ml"] + conf = {} + if automl._best_iteration in automl._config_history:### + conf = automl._config_history[automl._best_iteration][1].copy() + if "ml" in conf.keys(): + conf = conf["ml"] + mlflow.log_params(conf) mlflow.log_param("best_learner", automl._best_estimator)