Parallel Usage: Spawning workers from the command line

Auto-sklearn uses dask.distributed for parallel optimization.

This example shows how to start the dask scheduler and spawn workers for Auto-sklearn manually from the command line. Use this example as a starting point to parallelize Auto-sklearn across multiple machines.

To run Auto-sklearn in parallel on a single machine check out the example Parallel Usage on a single machine.

If you want to start everything manually from within Python please see

NOTE: Above example is disabled due to issue

You can learn more about the dask command line interface from

When manually passing a dask client to Auto-sklearn, all logic must be guarded by if __name__ == "__main__": statements! We use multiple such statements to properly render this example as a notebook and also allow execution via the command line.


To run Auto-sklearn distributed on multiple machines we need to set up three components:

  1. Auto-sklearn and a dask client. This will manage all workload, find new configurations to evaluate and submit jobs via a dask client. As this runs Bayesian optimization it should be executed on its own CPU.

  2. The dask workers. They will do the actual work of running machine learning algorithms and require their own CPU each.

  3. The scheduler. It manages the communication between the dask client and the different dask workers. As the client and all workers connect to the scheduler it must be started first. This is a light-weight job and does not require its own CPU.

We will now start these three components in reverse order: scheduler, workers and client. Also, in a real setup, the scheduler and the workers should be started from the command line and not from within a Python file via the subprocess module as done here (for the sake of having a self-contained example).

Import statements

import multiprocessing
import subprocess
import time

import dask.distributed
import sklearn.datasets
import sklearn.metrics

from autosklearn.classification import AutoSklearnClassifier
from autosklearn.constants import MULTICLASS_CLASSIFICATION

tmp_folder = '/tmp/autosklearn_parallel_3_example_tmp'

worker_processes = []

0. Setup client-scheduler communication

In this examples the dask scheduler is started without an explicit address and port. Instead, the scheduler takes a free port and stores relevant information in a file for which we provided the name and location. This filename is also given to the worker so they can find all relevant information to connect to the scheduler.

scheduler_file_name = 'scheduler-file.json'

1. Start scheduler

Starting the scheduler is done with the following bash command:

dask-scheduler --scheduler-file scheduler-file.json --idle-timeout 10

We will now execute this bash command from within Python to have a self-contained example:

def cli_start_scheduler(scheduler_file_name):
    command = (
        f"dask-scheduler --scheduler-file {scheduler_file_name} --idle-timeout 10"
    proc =, stdout=subprocess.PIPE,
                          stderr=subprocess.STDOUT, shell=True, check=True)
    while proc.returncode is None:

if __name__ == "__main__":
    process_python_worker = multiprocessing.Process(
        args=(scheduler_file_name, ),

    # Wait a second for the scheduler to become available

2. Start two workers

Starting the scheduler is done with the following bash command:

    dask-worker --nthreads 1 --lifetime 35 --memory-limit 0 \
    --scheduler-file scheduler-file.json

We will now execute this bash command from within Python to have a self-contained example. Please note, that DASK_DISTRIBUTED__WORKER__DAEMON=False is required in this case as dask-worker creates a new process, which by default is not compatible with Auto-sklearn creating new processes in the workers itself. We disable dask’s memory management by passing --memory-limit as Auto-sklearn does the memory management itself.

def cli_start_worker(scheduler_file_name):
    command = (
        "dask-worker --nthreads 1 --lifetime 35 --memory-limit 0 "
        f"--scheduler-file {scheduler_file_name}"
    proc =, stdout=subprocess.PIPE,
                          stderr=subprocess.STDOUT, shell=True)
    while proc.returncode is None:

if __name__ == '__main__':
    for _ in range(2):
        process_cli_worker = multiprocessing.Process(
            args=(scheduler_file_name, ),

    # Wait a second for workers to become available

3. Creating a client in Python

Finally we create a dask cluster which also connects to the scheduler via the information in the file created by the scheduler.

client = dask.distributed.Client(scheduler_file=scheduler_file_name)

Start Auto-sklearn

if __name__ == "__main__":
    X, y = sklearn.datasets.load_breast_cancer(return_X_y=True)
    X_train, X_test, y_train, y_test = \
        sklearn.model_selection.train_test_split(X, y, random_state=1)

    automl = AutoSklearnClassifier(
        # n_jobs is ignored internally as we pass a dask client.
        # Pass a dask client which connects to the previously constructed cluster.
    ), y_train)


    predictions = automl.predict(X_test)
    print("Accuracy score", sklearn.metrics.accuracy_score(y_test, predictions))


/home/runner/work/auto-sklearn/auto-sklearn/autosklearn/metalearning/metalearning/ FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
  self.metafeatures = self.metafeatures.append(metafeatures)
/home/runner/work/auto-sklearn/auto-sklearn/autosklearn/metalearning/metalearning/ FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
auto-sklearn results:
  Dataset name: 47800412-c3dd-11ec-8876-93d4b98a61f7
  Metric: accuracy
  Best validation score: 0.992908
  Number of target algorithm runs: 15
  Number of successful target algorithm runs: 14
  Number of crashed target algorithm runs: 0
  Number of target algorithms that exceeded the time limit: 1
  Number of target algorithms that exceeded the memory limit: 0

Accuracy score 0.9440559440559441

Wait until all workers are closed

This is only necessary if the workers are started from within this python script. In a real application one would start them directly from the command line.

if __name__ == '__main__':
    for process in worker_processes:

Total running time of the script: ( 0 minutes 38.088 seconds)

Gallery generated by Sphinx-Gallery