Getting started with Advanced HPO Algorithms

This tutorial provides a complete example of how to use AutoGluon’s state-of-the-art hyperparameter optimization (HPO) algorithms to tune a basic Multi-Layer Perceptron (MLP) model, which is the most basic type of neural network.

Loading libraries

# Basic utils for folder manipulations etc
import time
import multiprocessing # to count the number of CPUs available

# External tools to load and process data
import numpy as np
import pandas as pd

# MXNet (NeuralNets)
import mxnet as mx
from mxnet import gluon, autograd
from mxnet.gluon import nn

# AutoGluon and HPO tools
import autogluon.core as ag
from autogluon.mxnet.utils import load_and_split_openml_data

Check the version of MxNet, you should be fine with version >= 1.5

mx.__version__
'1.7.0'

You can also check the version of AutoGluon and the specific commit and check that it matches what you want.

import autogluon.core.version
ag.version.__version__
'0.2.1b20210617'

Hyperparameter Optimization of a 2-layer MLP

Setting up the context

Here we declare a few “environment variables” setting the context for what we’re doing

OPENML_TASK_ID = 6                # describes the problem we will tackle
RATIO_TRAIN_VALID = 0.33          # split of the training data used for validation
RESOURCE_ATTR_NAME = 'epoch'      # how do we measure resources   (will become clearer further)
REWARD_ATTR_NAME = 'objective'    # how do we measure performance (will become clearer further)

NUM_CPUS = multiprocessing.cpu_count()

Preparing the data

We will use a multi-way classification task from OpenML. Data preparation includes:

  • Missing values are imputed, using the ‘mean’ strategy of sklearn.impute.SimpleImputer

  • Split training set into training and validation

  • Standardize inputs to mean 0, variance 1

X_train, X_valid, y_train, y_valid, n_classes = load_and_split_openml_data(
    OPENML_TASK_ID, RATIO_TRAIN_VALID, download_from_openml=False)
n_classes
100%|██████████| 704/704 [00:00<00:00, 60477.01KB/s]
100%|██████████| 2521/2521 [00:00<00:00, 19683.10KB/s]
3KB [00:00, 3018.21KB/s]
8KB [00:00, 5259.32KB/s]
15KB [00:00, 13239.60KB/s]
2998KB [00:00, 42079.33KB/s]
881KB [00:00, 60610.53KB/s]
3KB [00:00, 2614.90KB/s]
26

The problem has 26 classes.

Declaring a model specifying a hyperparameter space with AutoGluon

Two layer MLP where we optimize over:

  • the number of units on the first layer

  • the number of units on the second layer

  • the dropout rate after each layer

  • the learning rate

  • the scaling

  • the @ag.args decorator allows us to specify the space we will optimize over, this matches the ConfigSpace syntax

The body of the function run_mlp_openml is pretty simple:

  • it reads the hyperparameters given via the decorator

  • it defines a 2 layer MLP with dropout

  • it declares a trainer with the ‘adam’ loss function and a provided learning rate

  • it trains the NN with a number of epochs (most of that is boilerplate code from mxnet)

  • the reporter at the end is used to keep track of training history in the hyperparameter optimization

Note: The number of epochs and the hyperparameter space are reduced to make for a shorter experiment

@ag.args(n_units_1=ag.space.Int(lower=16, upper=128),
         n_units_2=ag.space.Int(lower=16, upper=128),
         dropout_1=ag.space.Real(lower=0, upper=.75),
         dropout_2=ag.space.Real(lower=0, upper=.75),
         learning_rate=ag.space.Real(lower=1e-6, upper=1, log=True),
         batch_size=ag.space.Int(lower=8, upper=128),
         scale_1=ag.space.Real(lower=0.001, upper=10, log=True),
         scale_2=ag.space.Real(lower=0.001, upper=10, log=True),
         epochs=9)
def run_mlp_openml(args, reporter, **kwargs):
    # Time stamp for elapsed_time
    ts_start = time.time()
    # Unwrap hyperparameters
    n_units_1 = args.n_units_1
    n_units_2 = args.n_units_2
    dropout_1 = args.dropout_1
    dropout_2 = args.dropout_2
    scale_1 = args.scale_1
    scale_2 = args.scale_2
    batch_size = args.batch_size
    learning_rate = args.learning_rate

    ctx = mx.cpu()
    net = nn.Sequential()
    with net.name_scope():
        # Layer 1
        net.add(nn.Dense(n_units_1, activation='relu',
                         weight_initializer=mx.initializer.Uniform(scale=scale_1)))
        # Dropout
        net.add(gluon.nn.Dropout(dropout_1))
        # Layer 2
        net.add(nn.Dense(n_units_2, activation='relu',
                         weight_initializer=mx.initializer.Uniform(scale=scale_2)))
        # Dropout
        net.add(gluon.nn.Dropout(dropout_2))
        # Output
        net.add(nn.Dense(n_classes))
    net.initialize(ctx=ctx)

    trainer = gluon.Trainer(net.collect_params(), 'adam',
                            {'learning_rate': learning_rate})

    for epoch in range(args.epochs):
        ts_epoch = time.time()

        train_iter = mx.io.NDArrayIter(
                        data={'data': X_train},
                        label={'label': y_train},
                        batch_size=batch_size,
                        shuffle=True)
        valid_iter = mx.io.NDArrayIter(
                        data={'data': X_valid},
                        label={'label': y_valid},
                        batch_size=batch_size,
                        shuffle=False)

        metric = mx.metric.Accuracy()
        loss = gluon.loss.SoftmaxCrossEntropyLoss()

        for batch in train_iter:
            data = batch.data[0].as_in_context(ctx)
            label = batch.label[0].as_in_context(ctx)
            with autograd.record():
                output = net(data)
                L = loss(output, label)
            L.backward()
            trainer.step(data.shape[0])
            metric.update([label], [output])

        name, train_acc = metric.get()

        metric = mx.metric.Accuracy()
        for batch in valid_iter:
            data = batch.data[0].as_in_context(ctx)
            label = batch.label[0].as_in_context(ctx)
            output = net(data)
            metric.update([label], [output])

        name, val_acc = metric.get()

        print('Epoch %d ; Time: %f ; Training: %s=%f ; Validation: %s=%f' % (
            epoch + 1, time.time() - ts_start, name, train_acc, name, val_acc))

        ts_now = time.time()
        eval_time = ts_now - ts_epoch
        elapsed_time = ts_now - ts_start

        # The resource reported back (as 'epoch') is the number of epochs
        # done, starting at 1
        reporter(
            epoch=epoch + 1,
            objective=float(val_acc),
            eval_time=eval_time,
            time_step=ts_now,
            elapsed_time=elapsed_time)

Note: The annotation epochs=9 specifies the maximum number of epochs for training. It becomes available as args.epochs. Importantly, it is also processed by HyperbandScheduler below in order to set its max_t attribute.

Recommendation: Whenever writing training code to be passed as train_fn to a scheduler, if this training code reports a resource (or time) attribute, the corresponding maximum resource value should be included in train_fn.args:

  • If the resource attribute (time_attr of scheduler) in train_fn is epoch, make sure to include epochs=XYZ in the annotation. This allows the scheduler to read max_t from train_fn.args.epochs. This case corresponds to our example here.

  • If the resource attribute is something else than epoch, you can also include the annotation max_t=XYZ, which allows the scheduler to read max_t from train_fn.args.max_t.

Annotating the training function by the correct value for max_t simplifies scheduler creation (since max_t does not have to be passed), and avoids inconsistencies between train_fn and the scheduler.

Running the Hyperparameter Optimization

You can use the following schedulers:

  • FIFO (fifo)

  • Hyperband (either the stopping (hbs) or promotion (hbp) variant)

And the following searchers:

  • Random search (random)

  • Gaussian process based Bayesian optimization (bayesopt)

  • SkOpt Bayesian optimization (skopt; only with FIFO scheduler)

Note that the method known as (asynchronous) Hyperband is using random search. Combining Hyperband scheduling with the bayesopt searcher uses a novel method called asynchronous BOHB.

Pick the combination you’re interested in (doing the full experiment takes around 120 seconds, see the time_out parameter), running everything with multiple runs can take a fair bit of time. In real life, you will want to choose a larger time_out in order to obtain good performance.

SCHEDULER = "hbs"
SEARCHER = "bayesopt"
def compute_error(df):
    return 1.0 - df["objective"]

def compute_runtime(df, start_timestamp):
        return df["time_step"] - start_timestamp

def process_training_history(task_dicts, start_timestamp,
                             runtime_fn=compute_runtime,
                             error_fn=compute_error):
    task_dfs = []
    for task_id in task_dicts:
        task_df = pd.DataFrame(task_dicts[task_id])
        task_df = task_df.assign(task_id=task_id,
                                 runtime=runtime_fn(task_df, start_timestamp),
                                 error=error_fn(task_df),
                                 target_epoch=task_df["epoch"].iloc[-1])
        task_dfs.append(task_df)

    result = pd.concat(task_dfs, axis="index", ignore_index=True, sort=True)
    # re-order by runtime
    result = result.sort_values(by="runtime")
    # calculate incumbent best -- the cumulative minimum of the error.
    result = result.assign(best=result["error"].cummin())
    return result

resources = dict(num_cpus=NUM_CPUS, num_gpus=0)
search_options = {
    'num_init_random': 2,
    'debug_log': True}
if SCHEDULER == 'fifo':
    myscheduler = ag.scheduler.FIFOScheduler(
        run_mlp_openml,
        resource=resources,
        searcher=SEARCHER,
        search_options=search_options,
        time_out=120,
        time_attr=RESOURCE_ATTR_NAME,
        reward_attr=REWARD_ATTR_NAME)

else:
    # This setup uses rung levels at 1, 3, 9 epochs. We just use a single
    # bracket, so this is in fact successive halving (Hyperband would use
    # more than 1 bracket).
    # Also note that since we do not use the max_t argument of
    # HyperbandScheduler, this value is obtained from train_fn.args.epochs.
    sch_type = 'stopping' if SCHEDULER == 'hbs' else 'promotion'
    myscheduler = ag.scheduler.HyperbandScheduler(
        run_mlp_openml,
        resource=resources,
        searcher=SEARCHER,
        search_options=search_options,
        time_out=120,
        time_attr=RESOURCE_ATTR_NAME,
        reward_attr=REWARD_ATTR_NAME,
        type=sch_type,
        grace_period=1,
        reduction_factor=3,
        brackets=1)

# run tasks
myscheduler.run()
myscheduler.join_jobs()

results_df = process_training_history(
                myscheduler.training_history.copy(),
                start_timestamp=myscheduler._start_time)
The meaning of 'time_out' has changed. Previously, jobs started before
'time_out' were allowed to continue until stopped by other means. Now,
we stop jobs once 'time_out' is passed (at the next metric reporting).
If you like to keep the old behaviour, use
   'stop_jobs_after_time_out=False'
/var/lib/jenkins/workspace/workspace/autogluon-tutorial-course-v3/venv/lib/python3.7/site-packages/distributed/worker.py:3693: UserWarning: Large object of size 1.24 MiB detected in task graph:
  (0, <function run_mlp_openml at 0x7ff7c8142b90>, { ... sReporter}, [])
Consider scattering large objects ahead of time
with client.scatter to reduce scheduler burden and
keep data on workers

    future = client.submit(func, big_data)    # bad

    big_future = client.scatter(big_data)     # good
    future = client.submit(func, big_future)  # good
  % (format_bytes(len(b)), s)
Epoch 1 ; Time: 0.477558 ; Training: accuracy=0.260079 ; Validation: accuracy=0.531250
Epoch 2 ; Time: 0.926306 ; Training: accuracy=0.496365 ; Validation: accuracy=0.655247
Epoch 3 ; Time: 1.347836 ; Training: accuracy=0.559650 ; Validation: accuracy=0.694686
Epoch 4 ; Time: 1.763352 ; Training: accuracy=0.588896 ; Validation: accuracy=0.711063
Epoch 5 ; Time: 2.182273 ; Training: accuracy=0.609385 ; Validation: accuracy=0.726939
Epoch 6 ; Time: 2.606787 ; Training: accuracy=0.628139 ; Validation: accuracy=0.745321
Epoch 7 ; Time: 3.096855 ; Training: accuracy=0.641193 ; Validation: accuracy=0.750501
Epoch 8 ; Time: 3.512447 ; Training: accuracy=0.653751 ; Validation: accuracy=0.763202
Epoch 9 ; Time: 3.928287 ; Training: accuracy=0.665482 ; Validation: accuracy=0.766043
Epoch 1 ; Time: 0.684918 ; Training: accuracy=0.468667 ; Validation: accuracy=0.610047
Epoch 2 ; Time: 1.288070 ; Training: accuracy=0.532903 ; Validation: accuracy=0.653394
Epoch 3 ; Time: 1.901027 ; Training: accuracy=0.574653 ; Validation: accuracy=0.673723
Epoch 1 ; Time: 0.286105 ; Training: accuracy=0.035362 ; Validation: accuracy=0.023936
Epoch 1 ; Time: 1.962954 ; Training: accuracy=0.087313 ; Validation: accuracy=0.248822
Epoch 1 ; Time: 0.287443 ; Training: accuracy=0.038651 ; Validation: accuracy=0.037234
Epoch 1 ; Time: 0.681948 ; Training: accuracy=0.296826 ; Validation: accuracy=0.615886
Epoch 2 ; Time: 1.353010 ; Training: accuracy=0.463961 ; Validation: accuracy=0.676421
Epoch 3 ; Time: 1.965988 ; Training: accuracy=0.512068 ; Validation: accuracy=0.705017
Epoch 4 ; Time: 2.580548 ; Training: accuracy=0.537775 ; Validation: accuracy=0.727258
Epoch 5 ; Time: 3.192033 ; Training: accuracy=0.558935 ; Validation: accuracy=0.721070
Epoch 6 ; Time: 3.802810 ; Training: accuracy=0.567614 ; Validation: accuracy=0.731104
Epoch 7 ; Time: 4.435659 ; Training: accuracy=0.575302 ; Validation: accuracy=0.745652
Epoch 8 ; Time: 5.063155 ; Training: accuracy=0.592660 ; Validation: accuracy=0.753846
Epoch 9 ; Time: 5.701333 ; Training: accuracy=0.600926 ; Validation: accuracy=0.754348
Epoch 1 ; Time: 0.394171 ; Training: accuracy=0.039519 ; Validation: accuracy=0.040168
Epoch 1 ; Time: 0.803925 ; Training: accuracy=0.198015 ; Validation: accuracy=0.469750
Epoch 1 ; Time: 0.593307 ; Training: accuracy=0.130043 ; Validation: accuracy=0.157239
Epoch 1 ; Time: 0.332187 ; Training: accuracy=0.309317 ; Validation: accuracy=0.611204
Epoch 2 ; Time: 0.592013 ; Training: accuracy=0.457060 ; Validation: accuracy=0.679933
Epoch 3 ; Time: 0.845018 ; Training: accuracy=0.493830 ; Validation: accuracy=0.698997
Epoch 4 ; Time: 1.100274 ; Training: accuracy=0.497971 ; Validation: accuracy=0.716221
Epoch 5 ; Time: 1.364486 ; Training: accuracy=0.520248 ; Validation: accuracy=0.716388
Epoch 6 ; Time: 1.615621 ; Training: accuracy=0.521242 ; Validation: accuracy=0.727090
Epoch 7 ; Time: 1.888830 ; Training: accuracy=0.535321 ; Validation: accuracy=0.727090
Epoch 8 ; Time: 2.139275 ; Training: accuracy=0.539627 ; Validation: accuracy=0.714047
Epoch 9 ; Time: 2.399411 ; Training: accuracy=0.543685 ; Validation: accuracy=0.732274
Epoch 1 ; Time: 1.062734 ; Training: accuracy=0.363478 ; Validation: accuracy=0.608579
Epoch 2 ; Time: 2.153181 ; Training: accuracy=0.476790 ; Validation: accuracy=0.646257
Epoch 3 ; Time: 3.160325 ; Training: accuracy=0.505056 ; Validation: accuracy=0.671320
Epoch 1 ; Time: 0.501831 ; Training: accuracy=0.570437 ; Validation: accuracy=0.718964
Epoch 2 ; Time: 0.948579 ; Training: accuracy=0.663360 ; Validation: accuracy=0.730493
Epoch 3 ; Time: 1.385855 ; Training: accuracy=0.692543 ; Validation: accuracy=0.769089
Epoch 4 ; Time: 1.824470 ; Training: accuracy=0.722470 ; Validation: accuracy=0.779282
Epoch 5 ; Time: 2.291054 ; Training: accuracy=0.723793 ; Validation: accuracy=0.800334
Epoch 6 ; Time: 2.762347 ; Training: accuracy=0.740079 ; Validation: accuracy=0.809691
Epoch 7 ; Time: 3.277444 ; Training: accuracy=0.746445 ; Validation: accuracy=0.815539
Epoch 8 ; Time: 3.842523 ; Training: accuracy=0.758433 ; Validation: accuracy=0.810860
Epoch 9 ; Time: 4.315505 ; Training: accuracy=0.754134 ; Validation: accuracy=0.800668
Epoch 1 ; Time: 3.691919 ; Training: accuracy=0.547828 ; Validation: accuracy=0.694650
Epoch 2 ; Time: 7.509448 ; Training: accuracy=0.651691 ; Validation: accuracy=0.752860
Epoch 3 ; Time: 11.315792 ; Training: accuracy=0.678714 ; Validation: accuracy=0.790545
Epoch 4 ; Time: 15.201903 ; Training: accuracy=0.691893 ; Validation: accuracy=0.775908
Epoch 5 ; Time: 18.954807 ; Training: accuracy=0.704824 ; Validation: accuracy=0.796265
Epoch 6 ; Time: 22.639043 ; Training: accuracy=0.703498 ; Validation: accuracy=0.788863
Epoch 7 ; Time: 26.357956 ; Training: accuracy=0.703332 ; Validation: accuracy=0.778600
Epoch 8 ; Time: 30.114948 ; Training: accuracy=0.714357 ; Validation: accuracy=0.799462
Epoch 9 ; Time: 33.841030 ; Training: accuracy=0.722646 ; Validation: accuracy=0.791050
Epoch 1 ; Time: 0.283794 ; Training: accuracy=0.513634 ; Validation: accuracy=0.748869
Epoch 2 ; Time: 0.511022 ; Training: accuracy=0.725653 ; Validation: accuracy=0.804657
Epoch 3 ; Time: 0.734235 ; Training: accuracy=0.775052 ; Validation: accuracy=0.830625
Epoch 4 ; Time: 0.958217 ; Training: accuracy=0.803232 ; Validation: accuracy=0.860948
Epoch 5 ; Time: 1.180534 ; Training: accuracy=0.822627 ; Validation: accuracy=0.871670
Epoch 6 ; Time: 1.403594 ; Training: accuracy=0.832242 ; Validation: accuracy=0.883062
Epoch 7 ; Time: 1.625424 ; Training: accuracy=0.847741 ; Validation: accuracy=0.893617
Epoch 8 ; Time: 1.943211 ; Training: accuracy=0.853709 ; Validation: accuracy=0.900486
Epoch 9 ; Time: 2.260176 ; Training: accuracy=0.864650 ; Validation: accuracy=0.898140
Epoch 1 ; Time: 0.598239 ; Training: accuracy=0.405403 ; Validation: accuracy=0.657587
Epoch 2 ; Time: 1.035864 ; Training: accuracy=0.566424 ; Validation: accuracy=0.727440
Epoch 3 ; Time: 1.456839 ; Training: accuracy=0.609385 ; Validation: accuracy=0.727106
Epoch 1 ; Time: 0.418754 ; Training: accuracy=0.373232 ; Validation: accuracy=0.691142
Epoch 2 ; Time: 0.879598 ; Training: accuracy=0.643229 ; Validation: accuracy=0.779221
Epoch 3 ; Time: 1.237756 ; Training: accuracy=0.719497 ; Validation: accuracy=0.817016
Epoch 4 ; Time: 1.596778 ; Training: accuracy=0.761519 ; Validation: accuracy=0.840659
Epoch 5 ; Time: 1.960386 ; Training: accuracy=0.795682 ; Validation: accuracy=0.862804
Epoch 6 ; Time: 2.323480 ; Training: accuracy=0.813219 ; Validation: accuracy=0.873293
Epoch 7 ; Time: 2.685375 ; Training: accuracy=0.822649 ; Validation: accuracy=0.885947
Epoch 8 ; Time: 3.051356 ; Training: accuracy=0.843411 ; Validation: accuracy=0.892274
Epoch 9 ; Time: 3.413407 ; Training: accuracy=0.848623 ; Validation: accuracy=0.894272
Epoch 1 ; Time: 0.404102 ; Training: accuracy=0.252142 ; Validation: accuracy=0.476946
Epoch 1 ; Time: 1.959923 ; Training: accuracy=0.425373 ; Validation: accuracy=0.728788
Epoch 2 ; Time: 3.881068 ; Training: accuracy=0.544693 ; Validation: accuracy=0.763300
Epoch 3 ; Time: 5.742419 ; Training: accuracy=0.593449 ; Validation: accuracy=0.794781
Epoch 4 ; Time: 7.592021 ; Training: accuracy=0.610779 ; Validation: accuracy=0.775253
Epoch 5 ; Time: 9.496632 ; Training: accuracy=0.631426 ; Validation: accuracy=0.782155
Epoch 6 ; Time: 11.367236 ; Training: accuracy=0.647678 ; Validation: accuracy=0.799663
Epoch 7 ; Time: 13.225552 ; Training: accuracy=0.660779 ; Validation: accuracy=0.817508
Epoch 8 ; Time: 15.083567 ; Training: accuracy=0.655390 ; Validation: accuracy=0.825421
Epoch 9 ; Time: 17.020407 ; Training: accuracy=0.672305 ; Validation: accuracy=0.824411
Epoch 1 ; Time: 0.346701 ; Training: accuracy=0.372860 ; Validation: accuracy=0.683468
Epoch 2 ; Time: 0.680805 ; Training: accuracy=0.539664 ; Validation: accuracy=0.749328
Epoch 3 ; Time: 0.914280 ; Training: accuracy=0.573733 ; Validation: accuracy=0.768985
Epoch 1 ; Time: 0.488072 ; Training: accuracy=0.434675 ; Validation: accuracy=0.647643
Epoch 1 ; Time: 0.280178 ; Training: accuracy=0.189803 ; Validation: accuracy=0.493684
Epoch 1 ; Time: 0.973188 ; Training: accuracy=0.558375 ; Validation: accuracy=0.764310
Epoch 2 ; Time: 1.875164 ; Training: accuracy=0.733499 ; Validation: accuracy=0.828451

Analysing the results

The training history is stored in the results_df, the main fields are the runtime and 'best' (the objective).

Note: You will get slightly different curves for different pairs of scheduler/searcher, the time_out here is a bit too short to really see the difference in a significant way (it would be better to set it to >1000s). Generally speaking though, hyperband stopping / promotion + model will tend to significantly outperform other combinations given enough time.

results_df.head()
bracket elapsed_time epoch error eval_time objective runtime target_epoch task_id terminated time_step best
0 0 0.480202 1 0.468750 0.472203 0.531250 1.402453 9 0 NaN 1.623901e+09 0.468750
1 0 0.928164 2 0.344753 0.443558 0.655247 1.850415 9 0 NaN 1.623901e+09 0.344753
2 0 1.349618 3 0.305314 0.419158 0.694686 2.271868 9 0 NaN 1.623901e+09 0.305314
3 0 1.765286 4 0.288937 0.413044 0.711063 2.687536 9 0 NaN 1.623901e+09 0.288937
4 0 2.183937 5 0.273061 0.416413 0.726939 3.106187 9 0 NaN 1.623901e+09 0.273061
import matplotlib.pyplot as plt

plt.figure(figsize=(12, 8))

runtime = results_df['runtime'].values
objective = results_df['best'].values

plt.plot(runtime, objective, lw=2)
plt.xticks(fontsize=12)
plt.xlim(0, 120)
plt.ylim(0, 0.5)
plt.yticks(fontsize=12)
plt.xlabel("Runtime [s]", fontsize=14)
plt.ylabel("Objective", fontsize=14)
Text(0, 0.5, 'Objective')

Diving Deeper

Now, you are ready to try HPO on your own machine learning models (if you use PyTorch, have a look at Tune PyTorch Model on MNIST). While AutoGluon comes with well-chosen defaults, it can pay off to tune it to your specific needs. Here are some tips which may come useful.

Logging the Search Progress

First, it is a good idea in general to switch on debug_log, which outputs useful information about the search progress. This is already done in the example above.

The outputs show which configurations are chosen, stopped, or promoted. For BO and BOHB, a range of information is displayed for every get_config decision. This log output is very useful in order to figure out what is going on during the search.

Configuring HyperbandScheduler

The most important knobs to turn with HyperbandScheduler are max_t, grace_period, reduction_factor, brackets, and type. The first three determine the rung levels at which stopping or promotion decisions are being made.

  • The maximum resource level max_t (usually, resource equates to epochs, so max_t is the maximum number of training epochs) is typically hardcoded in train_fn passed to the scheduler (this is run_mlp_openml in the example above). As already noted above, the value is best fixed in the ag.args decorator as epochs=XYZ, it can then be accessed as args.epochs in the train_fn code. If this is done, you do not have to pass max_t when creating the scheduler.

  • grace_period and reduction_factor determine the rung levels, which are grace_period, grace_period * reduction_factor, grace_period * (reduction_factor ** 2), etc. All rung levels must be less or equal than max_t. It is recommended to make max_t equal to the largest rung level. For example, if grace_period = 1, reduction_factor = 3, it is in general recommended to use max_t = 9, max_t = 27, or max_t = 81. Choosing a max_t value “off the grid” works against the successive halving principle that the total resources spent in a rung should be roughly equal between rungs. If in the example above, you set max_t = 10, about a third of configurations reaching 9 epochs are allowed to proceed, but only for one more epoch.

  • With reduction_factor, you tune the extent to which successive halving filtering is applied. The larger this integer, the fewer configurations make it to higher number of epochs. Values 2, 3, 4 are commonly used.

  • Finally, grace_period should be set to the smallest resource (number of epochs) for which you expect any meaningful differentiation between configurations. While grace_period = 1 should always be explored, it may be too low for any meaningful stopping decisions to be made at the first rung.

  • brackets sets the maximum number of brackets in Hyperband (make sure to study the Hyperband paper or follow-ups for details). For brackets = 1, you are running successive halving (single bracket). Higher brackets have larger effective grace_period values (so runs are not stopped until later), yet are also chosen with less probability. We recommend to always consider successive halving (brackets = 1) in a comparison.

  • Finally, with type (values stopping, promotion) you are choosing different ways of extending successive halving scheduling to the asynchronous case. The method for the default stopping is simpler and seems to perform well, but promotion is more careful promoting configurations to higher resource levels, which can work better in some cases.

Asynchronous BOHB

Finally, here are some ideas for tuning asynchronous BOHB, apart from tuning its HyperbandScheduling component. You need to pass these options in search_options.

  • We support a range of different surrogate models over the criterion functions across resource levels. All of them are jointly dependent Gaussian process models, meaning that data collected at all resource levels are modelled together. The surrogate model is selected by gp_resource_kernel, values are matern52, matern52-res-warp, exp-decay-sum, exp-decay-combined, exp-decay-delta1. These are variants of either a joint Matern 5/2 kernel over configuration and resource, or the exponential decay model. Details about the latter can be found here.

  • Fitting a Gaussian process surrogate model to data encurs a cost which scales cubically with the number of datapoints. When applied to expensive deep learning workloads, even multi-fidelity asynchronous BOHB is rarely running up more than 100 observations or so (across all rung levels and brackets), and the GP computations are subdominant. However, if you apply it to cheaper train_fn and find yourself beyond 2000 total evaluations, the cost of GP fitting can become painful. In such a situation, you can explore the options opt_skip_period and opt_skip_num_max_resource. The basic idea is as follows. By far the most expensive part of a get_config call (picking the next configuration) is the refitting of the GP model to past data (this entails re-optimizing hyperparameters of the surrogate model itself). The options allow you to skip this expensive step for most get_config calls, after some initial period. Check the docstrings for details about these options. If you find yourself in such a situation and gain experience with these skipping features, make sure to contact the AutoGluon developers – we would love to learn about your use case.