Getting started with Advanced HPO Algorithms

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.0.15b20201020'

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, 53351.46KB/s]
100%|██████████| 2521/2521 [00:00<00:00, 42760.94KB/s]
3KB [00:00, 3780.92KB/s]
8KB [00:00, 9449.29KB/s]
15KB [00:00, 16530.36KB/s]
2998KB [00:00, 26402.87KB/s]
881KB [00:00, 56235.55KB/s]
3KB [00:00, 4221.04KB/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)
/var/lib/jenkins/miniconda3/envs/autogluon_docs/lib/python3.7/site-packages/distributed/worker.py:3382: UserWarning: Large object of size 1.30 MB detected in task graph:
  (<function run_mlp_openml at 0x7f3eb96b7680>, {'ar ... 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.475936 ; Training: accuracy=0.260079 ; Validation: accuracy=0.531250
Epoch 2 ; Time: 0.893917 ; Training: accuracy=0.496365 ; Validation: accuracy=0.655247
Epoch 3 ; Time: 1.335829 ; Training: accuracy=0.559650 ; Validation: accuracy=0.694686
Epoch 4 ; Time: 1.795821 ; Training: accuracy=0.588896 ; Validation: accuracy=0.711063
Epoch 5 ; Time: 2.203621 ; Training: accuracy=0.609385 ; Validation: accuracy=0.726939
Epoch 6 ; Time: 2.608896 ; Training: accuracy=0.628139 ; Validation: accuracy=0.745321
Epoch 7 ; Time: 3.015644 ; Training: accuracy=0.641193 ; Validation: accuracy=0.750501
Epoch 8 ; Time: 3.421513 ; Training: accuracy=0.653751 ; Validation: accuracy=0.763202
Epoch 9 ; Time: 3.827371 ; Training: accuracy=0.665482 ; Validation: accuracy=0.766043
Epoch 1 ; Time: 0.438031 ; Training: accuracy=0.121624 ; Validation: accuracy=0.290588
Epoch 1 ; Time: 0.339496 ; Training: accuracy=0.082676 ; Validation: accuracy=0.180493
Epoch 1 ; Time: 2.826516 ; Training: accuracy=0.669320 ; Validation: accuracy=0.805051
Epoch 2 ; Time: 5.586527 ; Training: accuracy=0.787728 ; Validation: accuracy=0.831481
Epoch 3 ; Time: 8.289062 ; Training: accuracy=0.817993 ; Validation: accuracy=0.835522
Epoch 4 ; Time: 11.025535 ; Training: accuracy=0.833665 ; Validation: accuracy=0.850505
Epoch 5 ; Time: 13.827775 ; Training: accuracy=0.844444 ; Validation: accuracy=0.850505
Epoch 6 ; Time: 16.629258 ; Training: accuracy=0.851327 ; Validation: accuracy=0.858418
Epoch 7 ; Time: 19.417185 ; Training: accuracy=0.857214 ; Validation: accuracy=0.875926
Epoch 8 ; Time: 22.144598 ; Training: accuracy=0.862935 ; Validation: accuracy=0.868350
Epoch 9 ; Time: 24.854277 ; Training: accuracy=0.868325 ; Validation: accuracy=0.887037
Epoch 1 ; Time: 0.423962 ; Training: accuracy=0.039706 ; Validation: accuracy=0.034799
Epoch 1 ; Time: 0.689588 ; Training: accuracy=0.038557 ; Validation: accuracy=0.036364
Epoch 1 ; Time: 3.596249 ; Training: accuracy=0.054377 ; Validation: accuracy=0.201043
Epoch 1 ; Time: 1.332941 ; Training: accuracy=0.038831 ; Validation: accuracy=0.041414
Epoch 1 ; Time: 0.350344 ; Training: accuracy=0.182261 ; Validation: accuracy=0.566035
Epoch 2 ; Time: 0.633542 ; Training: accuracy=0.281931 ; Validation: accuracy=0.594731
Epoch 3 ; Time: 0.920952 ; Training: accuracy=0.312706 ; Validation: accuracy=0.597583
Epoch 1 ; Time: 0.616915 ; Training: accuracy=0.107742 ; Validation: accuracy=0.082636
Epoch 1 ; Time: 0.391797 ; Training: accuracy=0.036153 ; Validation: accuracy=0.038552
Epoch 1 ; Time: 2.121353 ; Training: accuracy=0.044264 ; Validation: accuracy=0.064804
Epoch 1 ; Time: 0.485896 ; Training: accuracy=0.069043 ; Validation: accuracy=0.043108
Epoch 1 ; Time: 0.325946 ; Training: accuracy=0.608491 ; Validation: accuracy=0.720622
Epoch 2 ; Time: 0.594569 ; Training: accuracy=0.737504 ; Validation: accuracy=0.753393
Epoch 3 ; Time: 0.858920 ; Training: accuracy=0.750579 ; Validation: accuracy=0.754386
Epoch 4 ; Time: 1.123217 ; Training: accuracy=0.760427 ; Validation: accuracy=0.784343
Epoch 5 ; Time: 1.382238 ; Training: accuracy=0.780619 ; Validation: accuracy=0.749917
Epoch 6 ; Time: 1.645781 ; Training: accuracy=0.781778 ; Validation: accuracy=0.784508
Epoch 7 ; Time: 1.916693 ; Training: accuracy=0.800397 ; Validation: accuracy=0.793446
Epoch 8 ; Time: 2.190966 ; Training: accuracy=0.804369 ; Validation: accuracy=0.809831
Epoch 9 ; Time: 2.462913 ; Training: accuracy=0.798080 ; Validation: accuracy=0.796260
Epoch 1 ; Time: 0.470865 ; Training: accuracy=0.204056 ; Validation: accuracy=0.411667
Epoch 2 ; Time: 0.823017 ; Training: accuracy=0.199255 ; Validation: accuracy=0.404000
Epoch 3 ; Time: 1.160357 ; Training: accuracy=0.192798 ; Validation: accuracy=0.343667
Epoch 1 ; Time: 0.498855 ; Training: accuracy=0.108962 ; Validation: accuracy=0.196069
Epoch 1 ; Time: 1.650545 ; Training: accuracy=0.062303 ; Validation: accuracy=0.147899
Epoch 1 ; Time: 0.359802 ; Training: accuracy=0.517409 ; Validation: accuracy=0.717570
Epoch 2 ; Time: 0.638220 ; Training: accuracy=0.761221 ; Validation: accuracy=0.795939
Epoch 3 ; Time: 0.909343 ; Training: accuracy=0.817409 ; Validation: accuracy=0.836214
Epoch 4 ; Time: 1.181349 ; Training: accuracy=0.848680 ; Validation: accuracy=0.854338
Epoch 5 ; Time: 1.455974 ; Training: accuracy=0.875000 ; Validation: accuracy=0.872294
Epoch 6 ; Time: 1.809388 ; Training: accuracy=0.885231 ; Validation: accuracy=0.880685
Epoch 7 ; Time: 2.107616 ; Training: accuracy=0.895132 ; Validation: accuracy=0.899983
Epoch 8 ; Time: 2.380855 ; Training: accuracy=0.908911 ; Validation: accuracy=0.893606
Epoch 9 ; Time: 2.650465 ; Training: accuracy=0.912624 ; Validation: accuracy=0.903507
Epoch 1 ; Time: 0.316215 ; Training: accuracy=0.046294 ; Validation: accuracy=0.047993
Epoch 1 ; Time: 0.305593 ; Training: accuracy=0.584513 ; Validation: accuracy=0.735953
Epoch 2 ; Time: 0.542033 ; Training: accuracy=0.773251 ; Validation: accuracy=0.785786
Epoch 3 ; Time: 0.780288 ; Training: accuracy=0.814244 ; Validation: accuracy=0.815050
Epoch 4 ; Time: 1.012158 ; Training: accuracy=0.838675 ; Validation: accuracy=0.837291
Epoch 5 ; Time: 1.241914 ; Training: accuracy=0.854410 ; Validation: accuracy=0.846656
Epoch 6 ; Time: 1.471853 ; Training: accuracy=0.862029 ; Validation: accuracy=0.860535
Epoch 7 ; Time: 1.701171 ; Training: accuracy=0.873375 ; Validation: accuracy=0.856856
Epoch 8 ; Time: 1.930624 ; Training: accuracy=0.886625 ; Validation: accuracy=0.862375
Epoch 9 ; Time: 2.161841 ; Training: accuracy=0.884886 ; Validation: accuracy=0.877926
Epoch 1 ; Time: 3.460322 ; Training: accuracy=0.554128 ; Validation: accuracy=0.596904
Epoch 2 ; Time: 6.828423 ; Training: accuracy=0.638263 ; Validation: accuracy=0.653096
Epoch 3 ; Time: 10.390887 ; Training: accuracy=0.655338 ; Validation: accuracy=0.677826
Epoch 1 ; Time: 0.288997 ; Training: accuracy=0.220784 ; Validation: accuracy=0.338167
Epoch 1 ; Time: 3.393524 ; Training: accuracy=0.563495 ; Validation: accuracy=0.742093
Epoch 2 ; Time: 6.694010 ; Training: accuracy=0.675232 ; Validation: accuracy=0.769179
Epoch 3 ; Time: 10.193220 ; Training: accuracy=0.707477 ; Validation: accuracy=0.799630
Epoch 4 ; Time: 13.596288 ; Training: accuracy=0.719247 ; Validation: accuracy=0.785162
Epoch 5 ; Time: 16.970407 ; Training: accuracy=0.725464 ; Validation: accuracy=0.820659
Epoch 6 ; Time: 20.280869 ; Training: accuracy=0.736240 ; Validation: accuracy=0.811070
Epoch 7 ; Time: 23.624769 ; Training: accuracy=0.739390 ; Validation: accuracy=0.817799
Epoch 8 ; Time: 26.960829 ; Training: accuracy=0.742706 ; Validation: accuracy=0.812921
Epoch 9 ; Time: 30.292256 ; Training: accuracy=0.745938 ; Validation: accuracy=0.812079
Epoch 1 ; Time: 3.458178 ; Training: accuracy=0.577089 ; Validation: accuracy=0.679509
Epoch 2 ; Time: 6.848602 ; Training: accuracy=0.668186 ; Validation: accuracy=0.657638
Epoch 3 ; Time: 10.219289 ; Training: accuracy=0.678548 ; Validation: accuracy=0.690612
Epoch 1 ; Time: 1.348769 ; Training: accuracy=0.631893 ; Validation: accuracy=0.781650
Epoch 2 ; Time: 2.592382 ; Training: accuracy=0.767677 ; Validation: accuracy=0.827609
Epoch 3 ; Time: 3.816023 ; Training: accuracy=0.798477 ; Validation: accuracy=0.819192
Epoch 4 ; Time: 5.085861 ; Training: accuracy=0.816278 ; Validation: accuracy=0.852862
Epoch 5 ; Time: 6.321653 ; Training: accuracy=0.816857 ; Validation: accuracy=0.843771
Epoch 6 ; Time: 7.554066 ; Training: accuracy=0.831595 ; Validation: accuracy=0.865320
Epoch 7 ; Time: 8.803202 ; Training: accuracy=0.831181 ; Validation: accuracy=0.858081
Epoch 8 ; Time: 10.005773 ; Training: accuracy=0.835320 ; Validation: accuracy=0.871044
Epoch 9 ; Time: 11.207174 ; Training: accuracy=0.848402 ; Validation: accuracy=0.870875

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 searcher_data_size searcher_params_kernel_covariance_scale searcher_params_kernel_inv_bw0 ... searcher_params_kernel_inv_bw7 searcher_params_kernel_inv_bw8 searcher_params_mean_mean_value searcher_params_noise_variance target_epoch task_id time_since_start time_step time_this_iter best
0 0 0.478328 1 0.468750 0.473670 0.531250 0.561416 NaN 1.0 1.0 ... 1.0 1.0 0.0 0.001 9 0 0.563175 1.603202e+09 0.507031 0.468750
1 0 0.895592 2 0.344753 0.412930 0.655247 0.978680 1.0 1.0 1.0 ... 1.0 1.0 0.0 0.001 9 0 0.980119 1.603202e+09 0.417244 0.344753
2 0 1.337302 3 0.305314 0.439306 0.694686 1.420390 1.0 1.0 1.0 ... 1.0 1.0 0.0 0.001 9 0 1.421104 1.603202e+09 0.441710 0.305314
3 0 1.797228 4 0.288937 0.457677 0.711063 1.880316 2.0 1.0 1.0 ... 1.0 1.0 0.0 0.001 9 0 1.881001 1.603202e+09 0.459926 0.288937
4 0 2.205090 5 0.273061 0.406248 0.726939 2.288178 2.0 1.0 1.0 ... 1.0 1.0 0.0 0.001 9 0 2.288859 1.603202e+09 0.407862 0.273061

5 rows × 26 columns

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')
../../_images/output_mlp_cb387f_18_1.png

Diving Deeper

Now, you are ready to try HPO on your own machine learning models (if you use PyTorch, have a look at MNIST Training in PyTorch). 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.