Skip to content

A programming framework for agentic AI

Set use_ray to True for logging to databricks (#414)

Xueqing Liu47d2295fb7c9
diff --git a/flaml/automl.py b/flaml/automl.py
index 9426f944c..834ba8f6d 100644
--- a/flaml/automl.py
+++ b/flaml/automl.py
@@ -333,6 +333,10 @@ class AutoMLState:
and self.resources_per_trial.get("gpu", 0) > 0
):
+ if _is_nlp_task(self.task):
+ use_ray = self.fit_kwargs.get("use_ray")
+ self.fit_kwargs["use_ray"] = True
+
def _trainable_function_wrapper(config: dict):
return_estimator, train_time = train_estimator(
@@ -364,6 +368,13 @@ class AutoMLState:
)
result = list(analysis.results.values())[0]
estimator, train_time = result["estimator"], result["train_time"]
+
+ if _is_nlp_task(self.task):
+ if use_ray is None:
+ del self.fit_kwargs["use_ray"]
+ else:
+ self.fit_kwargs["use_ray"] = use_ray
+ estimator.use_ray = False
else:
if _is_nlp_task(self.task):
use_ray = self.fit_kwargs.get("use_ray")
diff --git a/flaml/model.py b/flaml/model.py
index 763b36892..e5cf2c7b8 100644
--- a/flaml/model.py
+++ b/flaml/model.py
@@ -715,7 +715,8 @@ class TransformersEstimator(BaseEstimator):
test_dataset, _ = self._init_model_for_predict(X)
predictions = self._trainer.predict(test_dataset)
- self._trainer = None
+ if self.use_ray is True:
+ self._trainer = None
return predictions.predictions
def predict(self, X):
@@ -728,7 +729,8 @@ class TransformersEstimator(BaseEstimator):
max_length=training_args.generation_max_length,
num_beams=training_args.generation_num_beams,
)
- self._trainer = None
+ if self.use_ray is True:
+ self._trainer = None
if self._task == SEQCLASSIFICATION:
return np.argmax(predictions.predictions, axis=1)
elif self._task == SEQREGRESSION: