Skip to content

Commit 2b31565

Browse files
authored
fix microsoft#871: call check_spark only when necessary (microsoft#872)
Co-authored-by: Li Jiang <[email protected]>
1 parent 0a5e7e8 commit 2b31565

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

flaml/automl/automl.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -2604,11 +2604,12 @@ def cv_score_agg_func(val_loss_folds, log_metrics_folds):
26042604
min_sample_size = min_sample_size or self._settings.get("min_sample_size")
26052605
use_ray = self._settings.get("use_ray") if use_ray is None else use_ray
26062606
use_spark = self._settings.get("use_spark") if use_spark is None else use_spark
2607-
spark_available, spark_error_msg = check_spark()
26082607
if use_spark and use_ray is not False:
26092608
raise ValueError("use_spark and use_ray cannot be both True.")
2610-
elif use_spark and not spark_available:
2611-
raise spark_error_msg
2609+
elif use_spark:
2610+
spark_available, spark_error_msg = check_spark()
2611+
if not spark_available:
2612+
raise spark_error_msg
26122613

26132614
old_level = logger.getEffectiveLevel()
26142615
self.verbose = verbose
@@ -2626,18 +2627,20 @@ def cv_score_agg_func(val_loss_folds, log_metrics_folds):
26262627
"Ray installed, setting use_ray to True. If you want to use Spark, set use_spark to True."
26272628
)
26282629
use_ray = True
2629-
elif spark_available:
2630-
logger.warning(
2631-
"n_concurrent_trials > 1 is only supported when using Ray or Spark. "
2632-
"Spark installed, setting use_spark to True. If you want to use Ray, set use_ray to True."
2633-
)
2634-
use_spark = True
26352630
else:
2636-
logger.warning(
2637-
"n_concurrent_trials > 1 is only supported when using Ray or Spark. "
2638-
"Neither Ray nor Spark installed, setting n_concurrent_trials to 1."
2639-
)
2640-
n_concurrent_trials = 1
2631+
spark_available, _ = check_spark()
2632+
if spark_available:
2633+
logger.warning(
2634+
"n_concurrent_trials > 1 is only supported when using Ray or Spark. "
2635+
"Spark installed, setting use_spark to True. If you want to use Ray, set use_ray to True."
2636+
)
2637+
use_spark = True
2638+
else:
2639+
logger.warning(
2640+
"n_concurrent_trials > 1 is only supported when using Ray or Spark. "
2641+
"Neither Ray nor Spark installed, setting n_concurrent_trials to 1."
2642+
)
2643+
n_concurrent_trials = 1
26412644

26422645
self._state.n_jobs = n_jobs
26432646
self._n_concurrent_trials = n_concurrent_trials

0 commit comments

Comments
 (0)