Blog

Comparing Modern Scalable Hyperparameter Tuning Methods

Source: pixabay
Source: pixabay

In this post, we’ll compare the following hyper-parameter optimization methods.

Experiment

we’ll train a simple DCGAN on the MNIST dataset and optimize the model for maximizing the inception score.

We’ll use Ray Tune to perform these experiments and track the results on the W&B dashboard.

I also did a video on my channel that goes in-depth in explaining this experiment -

Link to the Live Dashboard

The Search Space

We’ll use the same search space for all the experiments in order to make the comparison fair.

config = {
        "netG_lr": lambda: np.random.uniform(1e-2, 1e-5),
        "netD_lr": lambda: np.random.uniform(1e-2, 1e-5),
        "beta1": [0.3,0.5,0.8]
}

Let’s perform a random search across the search space to see how well it optimizes. This will also act as the baseline metric for our comparison. Our experimental setup has 2 GPUs and 4 CPUs. We’ll parallelize the operation across multiple GPUs. Ray Tune does this automatically for you if you specify the resources_per_trail.

analysis = tune.run(
    dcgan_train,
    resources_per_trial={'gpu': 1,'cpu':2}, # Tune will use this information to parallelize the tuning operation
    num_samples=10,
    config=config
)

Let’s see the results

Image by author
Image by author

Inference

As expected, we get varied results.

The basic idea behind Bayesian Hyperparameter tuning is to not be completely random in your choice for hyper-parameters but instead use the information from the prior runs to choose the hyperparameters for the next run. Tune supports HyperOpt which implements Bayesian search algorithms. Here’s how you do it.

Here’s what results look like

Image by author
Image by author

Inference

The idea Asynchronous Hyperband is to eliminate or terminate the runs that don’t perform well. It makes sense to combine this method with the Bayesian search to see if we can further reduce the wastage of resources on the runs that don’t optimize. We just need to make a small change in our code to accommodate Hyperband.

Let us now see how this performs

Image by author
Image by author

Inference

Population-Based Training illustration
Image source: the companion W&B report

The last tuning algorithm that we’ll cover is population-based training (PBT) introduced by Deepmind research. The basic idea behind the algorithm in layman terms:

Let us now look at the results.

Image by author
Image by author

Inference

The results look quite surprising. There are multiple factors that are unique about these results.

The answer is the hyper-parameter mutation done by the PBT scheduler. After every T time steps, the algorithm also mutates the values of hyper-parameters to maximize the desired metric. Here's how the parameters were mutated by the PBT scheduler for this experiment.

Let us now see how the hyper-parameters were adjusted by the PBT algorithm to maximize the inception score

Image by author
Image by author
Image by author
Image by author

We’ll now reduce the number of runs to 5 in order to make things difficult for PBT. Let’s see how it performs under this restricted circumstance.

Image by author
Image by author

Here’s how the final comparison of the average inception scores looks like. We’ve averaged across 5 run sets:

Image by author
Image by author

If you enjoyed reading this, you can follow me on twitter to get more updates. I also make deep learning videos on my youtube channel.