Search Algorithms

AutoGluon System Implementatin Logic

Important components of the AutoGluon system include the Searcher, Scheduler and Resource Manager:

  • The Searcher suggests hyperparameter configurations for the next training job.

  • The Scheduler runs the training job when computation resources become available.

In this tutorial, we illustrate how various search algorithms work and compare their performance via toy experiments.

FIFO Scheduling vs. Early Stopping

In this section, we compare the different behaviors of a sequential First In, First Out (FIFO) scheduler using autogluon.scheduler.FIFOScheduler vs. a preemptive scheduling algorithm autogluon.scheduler.HyperbandScheduler that early-terminates certain training jobs that do not appear promising during their early stages.

Create a Dummy Training Function

import numpy as np
import autogluon as ag

@ag.args(, 1e-2, log=True),, 1e-2))
def train_fn(args, reporter):
    for e in range(10):
        dummy_accuracy = 1 - np.power(1.8, -np.random.uniform(e, 2*e))
        reporter(epoch=e+1, accuracy=dummy_accuracy,, wd=args.wd)

FIFO Scheduler

This scheduler runs training trials in order. When there are more resources available than required for a single training job, multiple training jobs may be run in parallel.

scheduler = ag.scheduler.FIFOScheduler(train_fn,
                                       resource={'num_cpus': 2, 'num_gpus': 0},
Starting Experiments
Num of Finished Tasks is 0
Num of Pending Tasks is 20
HBox(children=(FloatProgress(value=0.0, max=20.0), HTML(value='')))

Visualize the results:

scheduler.get_training_curves(plot=True, use_legend=False)

Hyperband Scheduler

AutoGluon implements different variants of Hyperband scheduling, as selected by type. In the stopping variant (the default), the scheduler terminates training trials that don’t appear promising during the early stages to free up compute resources for more promising hyperparameter configurations.

scheduler = ag.scheduler.HyperbandScheduler(train_fn,
                                            resource={'num_cpus': 2, 'num_gpus': 0},
Starting Experiments
Num of Finished Tasks is 0
Num of Pending Tasks is 100
HBox(children=(FloatProgress(value=0.0), HTML(value='')))

In this example, trials are stopped early after 1, 3, or 9 epochs. Only a small fraction of most promising jobs run for the full number of 10 epochs. Since the majority of trials are stopped early, we can afford a larger num_trials. Visualize the results:

scheduler.get_training_curves(plot=True, use_legend=False)

Random Search vs. Reinforcement Learning

In this section, we demonstrate the behaviors of random search and reinforcement learning in a simple simulation environment.

Create a Reward Function for Toy Experiments

Import the packages:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

Input Space x = [0: 99], y = [0: 99]. The rewards is a combination of 2 gaussians as shown in the following figure:

Generate the simulated reward as a mixture of 2 gaussians:

def gaussian2d(x, y, x0, y0, xalpha, yalpha, A):
    return A * np.exp( -((x-x0)/xalpha)**2 -((y-y0)/yalpha)**2)

x, y = np.linspace(0, 99, 100), np.linspace(0, 99, 100)
X, Y = np.meshgrid(x, y)

Z = np.zeros(X.shape)
ps = [(20, 70, 35, 40, 1),
      (80, 40, 20, 20, 0.7)]
for p in ps:
    Z += gaussian2d(X, Y, *p)

Visualize the reward space:

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(X, Y, Z, cmap='plasma')

Create Training Function

We can simply define an AutoGluon searchable function with a decorator ag.args. The reporter is used to communicate with AutoGluon search and scheduling algorithms.

def rl_simulation(args, reporter):
    x, y = args.x, args.y

Reinforcement Learning

rl_scheduler = ag.scheduler.RLScheduler(rl_simulation,
                                        resource={'num_cpus': 1, 'num_gpus': 0},
print('Best config: {}, best reward: {}'.format(rl_scheduler.get_best_config(), rl_scheduler.get_best_reward()))
Reserved DistributedResource(
    Node = Remote REMOTE_ID: 0,
    <Remote: 'inproc://' processes=1 threads=8, memory=33.24 GB>
    nCPUs = 0) in Remote REMOTE_ID: 0,
    <Remote: 'inproc://' processes=1 threads=8, memory=33.24 GB>
Starting Experiments
Num of Finished Tasks is 0
Num of Pending Tasks is 300
100%|██████████| 76/76 [00:31<00:00,  2.44it/s]
Best config: {'x.choice': 21, 'y.choice': 74}, best reward: 0.9892484241569526

Compare the performance

Get the result history:

results_rl = [v[0]['accuracy'] for v in rl_scheduler.training_history.values()]
results_random = [v[0]['accuracy'] for v in random_scheduler.training_history.values()]

Average result every 10 trials:

import statistics
results1 = [statistics.mean(results_random[i:i+10]) for i in range(0, len(results_random), 10)]
results2 = [statistics.mean(results_rl[i:i+10]) for i in range(0, len(results_rl), 10)]

Plot the results:

plt.plot(range(len(results1)), results1, range(len(results2)), results2)
[<matplotlib.lines.Line2D at 0x7f71b2e90450>,
 <matplotlib.lines.Line2D at 0x7f71b13b2dd0>]