Tune: Scalable Hyperparameter Tuning

_images/tune.png

Tune is a Python library for experiment execution and hyperparameter tuning at any scale. Core features:

Want to get started? Head over to the 60 second Tune tutorial.

Tip

Join the Ray community slack to discuss Ray Tune (and other Ray libraries)!

Quick Start

To run this example, install the following: pip install 'ray[tune]' torch torchvision.

This example runs a small grid search to train a convolutional neural network using PyTorch and Tune.

from ray import tune


def objective(step, alpha, beta):
    return (0.1 + alpha * step / 100)**(-1) + beta * 0.1


def training_function(config):
    # Hyperparameters
    alpha, beta = config["alpha"], config["beta"]
    for step in range(10):
        # Iterative training function - can be any arbitrary training procedure.
        intermediate_score = objective(step, alpha, beta)
        # Feed the score back back to Tune.
        tune.report(mean_loss=intermediate_score)


analysis = tune.run(
    training_function,
    config={
        "alpha": tune.grid_search([0.001, 0.01, 0.1]),
        "beta": tune.choice([1, 2, 3])
    })

print("Best config: ", analysis.get_best_config(metric="mean_loss"))

# Get a dataframe for analyzing trial results.
df = analysis.dataframe()

If TensorBoard is installed, automatically visualize all trial results:

tensorboard --logdir ~/ray_results
_images/tune-start-tb.png

If using TF2 and TensorBoard, Tune will also automatically generate TensorBoard HParams output:

_images/tune-hparams-coord.png

Why choose Tune?

There are many other hyperparameter optimization libraries out there. If you’re new to Tune, you’re probably wondering, “what makes Tune different?”

Tune offers cutting-edge optimization algorithms.

As a user, you’re probably looking into hyperparameter optimization because you want to quickly increase your model performance.

Tune enables you to leverage a variety of these cutting edge optimization algorithms, reducing the cost of tuning by aggressively terminating bad hyperparameter evaluations, intelligently choosing better parameters to evaluate, or even changing the hyperparameters during training to optimize hyperparameter schedules.

Tune simplifies your workflow.

A key problem with machine learning frameworks is the need to restructure all of your code to fit the framework.

With Tune, you can optimize your model just by adding a few code snippets.

Further, Tune actually removes boilerplate from your code training workflow, automatically managing checkpoints and logging results to tools such as MLFlow and TensorBoard.

Tune provides first-class multi-GPU & distributed training support.

Hyperparameter tuning is known to be highly time-consuming, so it is often necessary to parallelize this process. Most other tuning frameworks require you to implement your own multi-process framework or build your own distributed system to speed up hyperparameter tuning.

However, Tune allows you to transparently parallelize across multiple GPUs and multiple nodes. Tune even has seamless fault tolerance and cloud support, allowing you to scale up your hyperparameter search by 100x while reducing costs by up to 10x by using cheap preemptible instances.

What if I’m already doing hyperparameter tuning?

You might be already using an existing hyperparameter tuning tool such as HyperOpt or Bayesian Optimization.

In this situation, Tune actually allows you to power up your existing workflow. Tune’s Search Algorithms integrate with a variety of popular hyperparameter tuning libraries (such as Nevergrad or HyperOpt) and allow you to seamlessly scale up your optimization process – without sacrificing performance.

Citing Tune

If Tune helps you in your academic research, you are encouraged to cite our paper. Here is an example bibtex:

@article{liaw2018tune,
    title={Tune: A Research Platform for Distributed Model Selection and Training},
    author={Liaw, Richard and Liang, Eric and Nishihara, Robert
            and Moritz, Philipp and Gonzalez, Joseph E and Stoica, Ion},
    journal={arXiv preprint arXiv:1807.05118},
    year={2018}
}