Skip to content

Commit edcb324

Browse files
Automatic per run time limit selection (#884)
* Automatic per run time limit selection * Spell-fix * Incorporating comments from commit * Flake8 * Remove slack for ensemble builder (Not needed)
1 parent ffead2b commit edcb324

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

autosklearn/automl.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,26 @@ def fit(
433433
else:
434434
if self._per_run_time_limit is None or \
435435
self._per_run_time_limit > time_left_for_smac:
436-
print('Time limit for a single run is higher than total time '
437-
'limit. Capping the limit for a single run to the total '
438-
'time given to SMAC (%f)' % time_left_for_smac)
436+
self._logger.warning(
437+
'Time limit for a single run is higher than total time '
438+
'limit. Capping the limit for a single run to the total '
439+
'time given to SMAC (%f)' % time_left_for_smac
440+
)
439441
per_run_time_limit = time_left_for_smac
440442
else:
441443
per_run_time_limit = self._per_run_time_limit
442444

445+
# Make sure that at least 2 models are created for the ensemble process
446+
num_models = time_left_for_smac // per_run_time_limit
447+
if num_models < 2:
448+
per_run_time_limit = time_left_for_smac//2
449+
self._logger.warning(
450+
"Capping the per_run_time_limit to {} to have "
451+
"time for a least 2 models in each process.".format(
452+
per_run_time_limit
453+
)
454+
)
455+
443456
_proc_smac = AutoMLSMBO(
444457
config_space=self.configuration_space,
445458
dataset_name=self._dataset_name,

autosklearn/estimators.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AutoSklearnEstimator(BaseEstimator):
2121
def __init__(
2222
self,
2323
time_left_for_this_task=3600,
24-
per_run_time_limit=360,
24+
per_run_time_limit=None,
2525
initial_configurations_via_metalearning=25,
2626
ensemble_size: int = 50,
2727
ensemble_nbest=50,
@@ -56,7 +56,7 @@ def __init__(
5656
models. By increasing this value, *auto-sklearn* has a higher
5757
chance of finding better models.
5858
59-
per_run_time_limit : int, optional (default=360)
59+
per_run_time_limit : int, optional (default=1/10 of time_left_for_this_task)
6060
Time limit for a single call to the machine learning model.
6161
Model fitting will be terminated if the machine learning
6262
algorithm runs over the time limit. Set this value high enough so
@@ -344,8 +344,19 @@ def fit(self, **kwargs):
344344
'only one of them.'
345345
)
346346

347+
# Handle the number of jobs and the time for them
347348
if self.n_jobs is None or self.n_jobs == 1:
348349
self._n_jobs = 1
350+
elif self.n_jobs == -1:
351+
self._n_jobs = joblib.cpu_count()
352+
else:
353+
self._n_jobs = self.n_jobs
354+
355+
# Automatically set the cutoff time per task
356+
if self.per_run_time_limit is None:
357+
self.per_run_time_limit = self._n_jobs * self.time_left_for_this_task // 10
358+
359+
if self.n_jobs is None or self.n_jobs == 1:
349360
shared_mode = self.shared_mode
350361
seed = self.seed
351362
automl = self.build_automl(
@@ -366,11 +377,6 @@ def fit(self, **kwargs):
366377
output_directory=self.output_folder,
367378
)
368379

369-
if self.n_jobs == -1:
370-
self._n_jobs = joblib.cpu_count()
371-
else:
372-
self._n_jobs = self.n_jobs
373-
374380
shared_mode = True
375381
seeds = set()
376382
for i in range(self._n_jobs):

0 commit comments

Comments
 (0)