2018-08-19 11:00:55 -07:00
Tune: Scalable Hyperparameter Search
====================================
2017-11-23 11:31:59 -08:00
2018-08-19 11:00:55 -07:00
.. image :: images/tune.png
:scale: 30%
:align: center
2018-04-17 09:57:35 -07:00
2018-08-19 11:00:55 -07:00
Tune is a scalable framework for hyperparameter search with a focus on deep learning and deep reinforcement learning.
2018-02-02 23:03:12 -08:00
2018-08-19 11:00:55 -07:00
You can find the code for Tune `here on GitHub <https://github.com/ray-project/ray/tree/master/python/ray/tune> `__ .
2018-04-17 09:57:35 -07:00
2018-03-19 12:55:10 -07:00
Features
--------
2018-09-12 22:32:56 -07:00
* Supports any deep learning framework, including PyTorch, TensorFlow, and Keras.
2018-03-19 12:55:10 -07:00
2018-08-19 11:00:55 -07:00
* Choose among scalable hyperparameter and model search techniques such as:
2018-03-19 12:55:10 -07:00
2018-08-19 11:00:55 -07:00
- `Population Based Training (PBT) <tune-schedulers.html#population-based-training-pbt> `__
2018-03-19 12:55:10 -07:00
2018-08-19 11:00:55 -07:00
- `Median Stopping Rule <tune-schedulers.html#median-stopping-rule> `__
2018-03-19 12:55:10 -07:00
2018-08-19 11:00:55 -07:00
- `HyperBand <tune-schedulers.html#asynchronous-hyperband> `__
2018-03-19 12:55:10 -07:00
2018-08-19 11:00:55 -07:00
* Mix and match different hyperparameter optimization approaches - such as using `HyperOpt with HyperBand`_ .
2018-03-19 12:55:10 -07:00
2018-08-19 11:00:55 -07:00
* Visualize results with `TensorBoard <https://www.tensorflow.org/get_started/summaries_and_tensorboard> `__ , `parallel coordinates (Plot.ly) <https://plot.ly/python/parallel-coordinates-plot/> `__ , and `rllab's VisKit <https://media.readthedocs.org/pdf/rllab/latest/rllab.pdf> `__ .
2018-03-19 12:55:10 -07:00
2018-08-19 11:00:55 -07:00
* Scale to running on a large distributed cluster without changing your code.
2018-03-19 12:55:10 -07:00
2018-08-19 11:00:55 -07:00
* Parallelize training for models with GPU requirements or algorithms that may themselves be parallel and distributed, using Tune's `resource-aware scheduling <tune-usage.html#using-gpus-resource-allocation> `__ ,
2018-03-19 12:55:10 -07:00
2018-08-19 11:00:55 -07:00
Take a look at `the User Guide <tune-usage.html> `__ for a comprehensive overview on how to use Tune's features.
2017-11-23 11:31:59 -08:00
2018-08-19 11:00:55 -07:00
Getting Started
---------------
2017-11-23 11:31:59 -08:00
2018-08-19 11:00:55 -07:00
Installation
~~~~~~~~~~~~
2018-08-04 21:27:39 -07:00
2018-08-19 11:00:55 -07:00
You'll need to first `install ray <installation.html> `__ to import Tune.
2018-08-04 21:27:39 -07:00
.. code-block :: bash
2018-08-19 11:00:55 -07:00
pip install ray
2018-08-04 21:27:39 -07:00
2018-08-19 11:00:55 -07:00
Quick Start
~~~~~~~~~~~
2018-04-04 11:08:26 -07:00
2018-08-19 11:00:55 -07:00
This example runs a small grid search over a neural network training function using Tune, reporting status on the command line until the stopping condition of `` mean_accuracy >= 99 `` is reached. Tune works with any deep learning framework.
2018-04-17 09:57:35 -07:00
2018-08-19 11:00:55 -07:00
Tune uses Ray as a backend, so we will first import and initialize Ray.
2018-04-17 09:57:35 -07:00
.. code-block :: python
import ray
2018-08-19 11:00:55 -07:00
import ray.tune as tune
2018-04-17 09:57:35 -07:00
ray.init()
2018-01-25 16:39:00 -08:00
2018-08-19 11:00:55 -07:00
For the function you wish to tune, pass in a `` reporter `` object:
2018-03-03 13:01:49 -08:00
.. code-block :: python
2018-08-19 11:00:55 -07:00
:emphasize-lines: 1,9
2018-03-03 13:01:49 -08:00
2018-08-19 11:00:55 -07:00
def train_func(config, reporter): # add a reporter arg
model = ( ... )
optimizer = SGD(model.parameters(),
momentum=config["momentum"])
dataset = ( ... )
2018-03-03 13:01:49 -08:00
2018-08-19 11:00:55 -07:00
for idx, (data, target) in enumerate(dataset):
accuracy = model.fit(data, target)
reporter(mean_accuracy=accuracy) # report metrics
2018-03-03 13:01:49 -08:00
2018-08-19 11:00:55 -07:00
**Finally** , configure your search and execute it on your Ray cluster:
2018-02-12 14:01:19 -08:00
.. code-block :: python
2018-08-19 11:00:55 -07:00
all_trials = tune.run_experiments({
2018-02-12 14:01:19 -08:00
"my_experiment": {
2018-08-19 11:00:55 -07:00
"run": train_func,
"stop": {"mean_accuracy": 99},
"config": {"momentum": tune.grid_search([0.1, 0.2])}
}
2018-02-12 14:01:19 -08:00
})
2018-08-19 11:00:55 -07:00
Tune can be used anywhere Ray can, e.g. on your laptop with `` ray.init() `` embedded in a Python script, or in an `auto-scaling cluster <autoscaling.html> `__ for massive parallelism.
2018-01-24 13:45:10 -08:00
2018-08-19 11:00:55 -07:00
Citing Tune
-----------
2018-01-24 13:45:10 -08:00
2018-08-19 11:00:55 -07:00
If Tune helps you in your academic research, you are encouraged to cite `our paper <https://arxiv.org/abs/1807.05118> `__ . Here is an example bibtex:
2018-01-24 13:45:10 -08:00
2018-08-19 11:00:55 -07:00
.. code-block :: tex
2018-01-24 13:45:10 -08:00
2018-08-19 11:00:55 -07:00
@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}
}
2018-01-24 13:45:10 -08:00
2018-04-17 09:57:35 -07:00
2018-08-19 11:00:55 -07:00
.. _HyperOpt with HyperBand: https://github.com/ray-project/ray/blob/master/python/ray/tune/examples/hyperopt_example.py