overview.rst 6.44 KB
Newer Older
liuzhe-lz's avatar
liuzhe-lz committed
1
2
3
4
5
6
7
8
Hyperparameter Optimization Overview
====================================

Auto hyperparameter optimization (HPO), or auto tuning, is one of the key features of NNI.

Introduction to HPO
-------------------

liuzhe-lz's avatar
liuzhe-lz committed
9
10
11
12
In machine learning, a hyperparameter is a parameter whose value is used to control learning process,
and HPO is the problem of choosing a set of optimal hyperparameters for a learning algorithm.
(`From <https://en.wikipedia.org/wiki/Hyperparameter_(machine_learning)>`__
`Wikipedia <https://en.wikipedia.org/wiki/Hyperparameter_optimization>`__)
liuzhe-lz's avatar
liuzhe-lz committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

Following code snippet demonstrates a naive HPO process:

.. code-block:: python

    best_hyperparameters = None
    best_accuracy = 0

    for learning_rate in [0.1, 0.01, 0.001, 0.0001]:
        for momentum in [i / 10 for i in range(10)]:
            for activation_type in ['relu', 'tanh', 'sigmoid']:
                model = build_model(activation_type)
                train_model(model, learning_rate, momentum)
                accuracy = evaluate_model(model)

                if accuracy > best_accuracy:
                    best_accuracy = accuracy
                    best_hyperparameters = (learning_rate, momentum, activation_type)

Yuge Zhang's avatar
Yuge Zhang committed
32
    print('Best hyperparameters:', best_hyperparameters)
liuzhe-lz's avatar
liuzhe-lz committed
33
34
35
36

You may have noticed, the example will train 4×10×3=120 models in total.
Since it consumes so much computing resources, you may want to:

liuzhe-lz's avatar
liuzhe-lz committed
37
38
39
1. Find the best set of hyperparameters with less iterations.
2. Train the models on distributed platforms.
3. Have a portal to monitor and control the process.
liuzhe-lz's avatar
liuzhe-lz committed
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

And NNI will do them for you.

Key Features of NNI HPO
-----------------------

Tuning Algorithms
^^^^^^^^^^^^^^^^^

NNI provides *tuners* to speed up the process of finding best hyperparameter set.

A tuner, or a tuning algorithm, decides the order in which hyperparameter sets are evaluated.
Based on the results of historical hyperparameter sets, an efficient tuner can predict where the best hyperparameters locates around,
and finds them in much fewer attempts.

The naive example above evaluates all possible hyperparameter sets in constant order, ignoring the historical results.
This is the brute-force tuning algorithm called *grid search*.

NNI has out-of-the-box support for a variety of popular tuners.
It includes naive algorithms like random search and grid search, Bayesian-based algorithms like TPE and SMAC,
RL based algorithms like PPO, and much more.

Main article: :doc:`tuners`

Training Platforms
^^^^^^^^^^^^^^^^^^

If you are not interested in distributed platforms, you can simply run NNI HPO with current computer,
just like any ordinary Python library.

And when you want to leverage more computing resources, NNI provides built-in integration for training platforms
from simple on-premise servers to scalable commercial clouds.

With NNI you can write one piece of model code, and concurrently evaluate hyperparameter sets on local machine, SSH servers,
Kubernetes-based clusters, AzureML service, and much more.

liuzhe-lz's avatar
liuzhe-lz committed
76
Main article: :doc:`/experiment/training_service`
liuzhe-lz's avatar
liuzhe-lz committed
77

liuzhe-lz's avatar
liuzhe-lz committed
78
79
Web Portal
^^^^^^^^^^
liuzhe-lz's avatar
liuzhe-lz committed
80
81
82
83

NNI provides a web portal to monitor training progress, to visualize hyperparameter performance,
to manually customize hyperparameters, and to manage multiple HPO experiments.

liuzhe-lz's avatar
liuzhe-lz committed
84
85
86
87
Main article: :doc:`/experiment/web_portal`

.. image:: ../../static/img/webui.gif
    :width: 100%
liuzhe-lz's avatar
liuzhe-lz committed
88
89
90
91

Tutorials
---------

liuzhe-lz's avatar
liuzhe-lz committed
92
To start using NNI HPO, choose the quickstart tutorial of your favorite framework:
liuzhe-lz's avatar
liuzhe-lz committed
93

liuzhe-lz's avatar
liuzhe-lz committed
94
95
* :doc:`PyTorch tutorial </tutorials/hpo_quickstart_pytorch/main>`
* :doc:`TensorFlow tutorial </tutorials/hpo_quickstart_tensorflow/main>`
liuzhe-lz's avatar
liuzhe-lz committed
96
97
98
99
100
101

Extra Features
--------------

After you are familiar with basic usage, you can explore more HPO features:

liuzhe-lz's avatar
liuzhe-lz committed
102
103
104
105
106
* :doc:`Use command line tool to create and manage experiments (nnictl) </reference/nnictl>`
* :doc:`Early stop non-optimal models (assessor) <assessors>`
* :doc:`TensorBoard integration <tensorboard>`
* :doc:`Implement your own algorithm <custom_algorithm>`
* :doc:`Benchmark tuners <hpo_benchmark>`
liuzhe-lz's avatar
liuzhe-lz committed
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

Built-in Algorithms
-------------------

Tuning Algorithms
^^^^^^^^^^^^^^^^^

Main article: :doc:`tuners`

.. list-table::
    :header-rows: 1
    :widths: auto

    * - Name
      - Category
      - Brief Description

    * - :class:`Random <nni.algorithms.hpo.random_tuner.RandomTuner>`
      - Basic
      - Naive random search.

    * - :class:`GridSearch <nni.algorithms.hpo.gridsearch_tuner.GridSearchTuner>`
      - Basic
      - Brute-force search.

    * - :class:`TPE <nni.algorithms.hpo.tpe_tuner.TpeTuner>`
      - Bayesian
      - Tree-structured Parzen Estimator.

    * - :class:`Anneal <nni.algorithms.hpo.hyperopt_tuner.HyperoptTuner>`
      - Classic
      - Simulated annealing algorithm.

    * - :class:`Evolution <nni.algorithms.hpo.evolution_tuner.EvolutionTuner>`
      - Classic
      - Naive evolution algorithm.

    * - :class:`SMAC <nni.algorithms.hpo.smac_tuner.SMACTuner>`
      - Bayesian
      - Sequential Model-based optimization for general Algorithm Configuration.

    * - :class:`Hyperband <nni.algorithms.hpo.hyperband_advisor.Hyperband>`
      - Advanced
      - Evaluate more hyperparameter sets by adaptively allocating resources.

    * - :class:`MetisTuner <nni.algorithms.hpo.metis_tuner.MetisTuner>`
      - Bayesian
      - Robustly optimizing tail latencies of cloud systems.

    * - :class:`BOHB <nni.algorithms.hpo.bohb_advisor.BOHB>`
      - Advanced
      - Bayesian Optimization with HyperBand.

    * - :class:`GPTuner <nni.algorithms.hpo.gp_tuner.GPTuner>`
      - Bayesian
      - Gaussian Process.

    * - :class:`PBTTuner <nni.algorithms.hpo.pbt_tuner.PBTTuner>`
      - Advanced
      - Population Based Training of neural networks.

    * - :class:`DNGOTuner <nni.algorithms.hpo.dngo_tuner.DNGOTuner>`
      - Bayesian
liuzhe-lz's avatar
liuzhe-lz committed
170
      - Deep Networks for Global Optimization.
liuzhe-lz's avatar
liuzhe-lz committed
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

    * - :class:`PPOTuner <nni.algorithms.hpo.ppo_tuner.PPOTuner>`
      - RL
      - Proximal Policy Optimization.

    * - :class:`BatchTuner <nni.algorithms.hpo.batch_tuner.BatchTuner>`
      - Basic
      - Manually specify hyperparameter sets.

Early Stopping
^^^^^^^^^^^^^^

Main article: :doc:`assessors`

.. list-table::
    :header-rows: 1
    :widths: auto

    * - Name
      - Brief Description

    * - :class:`Medianstop <nni.algorithms.hpo.medianstop_assessor.MedianstopAssessor>`
      - Stop if the hyperparameter set performs worse than median at any step.

    * - :class:`Curvefitting <nni.algorithms.hpo.curvefitting_assessor.CurvefittingAssessor>`
      - Stop if the learning curve will likely converge to suboptimal result.