index.rst 8.05 KB
Newer Older
Yuge Zhang's avatar
Yuge Zhang committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
NNI Documentation
=================

.. toctree::
   :maxdepth: 2
   :caption: Get Started
   :hidden:

   installation
   quickstart

.. toctree::
   :maxdepth: 2
   :caption: User Guide
   :hidden:

   Hyperparameter Optimization <hpo/index>
18
   nas/toctree
Yuge Zhang's avatar
Yuge Zhang committed
19
   Model Compression <compression/index>
20
21
   feature_engineering/toctree
   experiment/toctree
Yuge Zhang's avatar
Yuge Zhang committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

.. toctree::
   :maxdepth: 2
   :caption: References
   :hidden:

   Python API <reference/python_api>
   reference/experiment_config
   reference/nnictl

.. toctree::
   :maxdepth: 2
   :caption: Misc
   :hidden:

   examples
   sharings/community_sharings
   notes/research_publications
   notes/build_from_source
   notes/contributing
   release
Yuge Zhang's avatar
Yuge Zhang committed
43

44
45
**NNI (Neural Network Intelligence)** is a lightweight but powerful toolkit to help users **automate**:

Yuge Zhang's avatar
Yuge Zhang committed
46
* :doc:`Hyperparameter Optimization </hpo/overview>`
47
* :doc:`Neural Architecture Search </nas/overview>`
Yuge Zhang's avatar
Yuge Zhang committed
48
49
* :doc:`Model Compression </compression/index>`
* :doc:`Feature Engineering </feature_engineering/overview>`
50

Yuge Zhang's avatar
Yuge Zhang committed
51
52
Get Started
-----------
53
54
55
56
57
58
59
60
61

To install the current release:

.. code-block:: bash

   $ pip install nni

See the :doc:`installation guide </installation>` if you need additional help on installation.

Yuge Zhang's avatar
Yuge Zhang committed
62
63
Try your first NNI experiment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
64

Yuge Zhang's avatar
Yuge Zhang committed
65
To run your first NNI experiment:
66

Yuge Zhang's avatar
Yuge Zhang committed
67
.. code-block:: shell
68

Yuge Zhang's avatar
Yuge Zhang committed
69
   $ nnictl hello
70

Yuge Zhang's avatar
Yuge Zhang committed
71
.. note:: you need to have `PyTorch <https://pytorch.org/>`_ (as well as `torchvision <https://pytorch.org/vision/stable/index.html>`_) installed to run this experiment.
72

Yuge Zhang's avatar
Yuge Zhang committed
73
To start your journey now, please follow the :doc:`absolute quickstart of NNI <quickstart>`!
74

Yuge Zhang's avatar
Yuge Zhang committed
75
76
Why choose NNI?
---------------
77

Yuge Zhang's avatar
Yuge Zhang committed
78
79
NNI makes AutoML techniques plug-and-play
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
80

81
82
83
84
85
.. raw:: html

   <div class="codesnippet-card-container">

.. codesnippetcard::
86
   :icon: ../img/thumbnails/hpo-small.svg
87
   :title: Hyper-parameter Tuning
liuzhe-lz's avatar
liuzhe-lz committed
88
   :link: tutorials/hpo_quickstart_pytorch/main
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

   .. code-block::

      params = nni.get_next_parameter()

      class Net(nn.Module):
          ...

      model = Net()
      optimizer = optim.SGD(model.parameters(),
                            params['lr'],
                            params['momentum'])

      for epoch in range(10):
          train(...)

      accuracy = test(model)
      nni.report_final_result(accuracy)

.. codesnippetcard::
109
   :icon: ../img/thumbnails/pruning-small.svg
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
   :title: Model Pruning
   :link: tutorials/pruning_quick_start_mnist

   .. code-block::

      # define a config_list
      config = [{
          'sparsity': 0.8,
          'op_types': ['Conv2d']
      }]

      # generate masks for simulated pruning
      wrapped_model, masks = \
          L1NormPruner(model, config). \
          compress()

126
      # apply the masks for real speedup
127
128
129
130
      ModelSpeedup(unwrapped_model, input, masks). \
          speedup_model()

.. codesnippetcard::
131
   :icon: ../img/thumbnails/quantization-small.svg
132
   :title: Quantization
133
   :link: tutorials/quantization_speedup
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

   .. code-block::

      # define a config_list
      config = [{
          'quant_types': ['input', 'weight'],
          'quant_bits': {'input': 8, 'weight': 8},
          'op_types': ['Conv2d']
      }]

      # in case quantizer needs a extra training
      quantizer = QAT_Quantizer(model, config)
      quantizer.compress()
      # Training...

      # export calibration config and
150
      # generate TensorRT engine for real speedup
151
152
153
154
155
156
157
      calibration_config = quantizer.export_model(
          model_path, calibration_path)
      engine = ModelSpeedupTensorRT(
          model, input_shape, config=calib_config)
      engine.compress()

.. codesnippetcard::
158
   :icon: ../img/thumbnails/multi-trial-nas-small.svg
159
160
161
   :title: Neural Architecture Search
   :link: tutorials/hello_nas

162
   .. code-block:: python
163
164

      # define model space
165
166
167
168
169
170
      class Model(nn.Module):
          self.conv2 = nn.LayerChoice([
              nn.Conv2d(32, 64, 3, 1),
              DepthwiseSeparableConv(32, 64)
          ])
      model_space = Model()
171
172
173
174
175
176
177
178
179
180
      # search strategy + evaluator
      strategy = RegularizedEvolution()
      evaluator = FunctionalEvaluator(
          train_eval_fn)

      # run experiment
      RetiariiExperiment(model_space,
          evaluator, strategy).run()

.. codesnippetcard::
181
   :icon: ../img/thumbnails/one-shot-nas-small.svg
182
   :title: One-shot NAS
183
   :link: nas/exploration_strategy
184
185
186
187
188
189
190
191
192
193
194
195
196
197

   .. code-block::

      # define model space
      space = AnySearchSpace()

      # get a darts trainer
      trainer = DartsTrainer(space, loss, metrics)
      trainer.fit()

      # get final searched architecture
      arch = trainer.export()

.. codesnippetcard::
198
   :icon: ../img/thumbnails/feature-engineering-small.svg
199
   :title: Feature Engineering
J-shang's avatar
J-shang committed
200
   :link: feature_engineering/overview
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218

   .. code-block::

      selector = GBDTSelector()
      selector.fit(
          X_train, y_train,
          lgb_params=lgb_params,
          eval_ratio=eval_ratio,
          early_stopping_rounds=10,
          importance_type='gain',
          num_boost_round=1000)

      # get selected features
      features = selector.get_selected_features()

.. End of code snippet card

.. raw:: html
Yuge Zhang's avatar
Yuge Zhang committed
219

220
   </div>
Yuge Zhang's avatar
Yuge Zhang committed
221

Yuge Zhang's avatar
Yuge Zhang committed
222
223
NNI eases the effort to scale and manage AutoML experiments
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
224
225

.. codesnippetcard::
226
   :icon: ../img/thumbnails/training-service-small.svg
227
   :title: Training Service
228
   :link: experiment/training_service/overview
229
230
231
232
233
234
235
236
   :seemore: See more here.

   An AutoML experiment requires many trials to explore feasible and potentially good-performing models.
   **Training service** aims to make the tuning process easily scalable in a distributed platforms.
   It provides a unified user experience for diverse computation resources (e.g., local machine, remote servers, AKS).
   Currently, NNI supports **more than 9** kinds of training services.

.. codesnippetcard::
237
   :icon: ../img/thumbnails/web-portal-small.svg
238
   :title: Web Portal
239
   :link: experiment/web_portal/web_portal
240
241
242
243
244
245
246
247
   :seemore: See more here.

   Web portal visualizes the tuning process, exposing the ability to inspect, monitor and control the experiment.

   .. image:: ../static/img/webui.gif
      :width: 100%

.. codesnippetcard::
248
   :icon: ../img/thumbnails/experiment-management-small.svg
249
   :title: Experiment Management
250
   :link: experiment/experiment_management
251
252
253
254
255
256
257
   :seemore: See more here.

   The DNN model tuning often requires more than one experiment.
   Users might try different tuning algorithms, fine-tune their search space, or switch to another training service.
   **Experiment management** provides the power to aggregate and compare tuning results from multiple experiments,
   so that the tuning workflow becomes clean and organized.

Yuge Zhang's avatar
Yuge Zhang committed
258
259
Get Support and Contribute Back
-------------------------------
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

NNI is maintained on the `NNI GitHub repository <https://github.com/microsoft/nni>`_. We collect feedbacks and new proposals/ideas on GitHub. You can:

* Open a `GitHub issue <https://github.com/microsoft/nni/issues>`_ for bugs and feature requests.
* Open a `pull request <https://github.com/microsoft/nni/pulls>`_ to contribute code (make sure to read the `contribution guide </contribution>` before doing this).
* Participate in `NNI Discussion <https://github.com/microsoft/nni/discussions>`_ for general questions and new ideas.
* Join the following IM groups.

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

   * - Gitter
     - WeChat
   * -
       .. image:: https://user-images.githubusercontent.com/39592018/80665738-e0574a80-8acc-11ea-91bc-0836dc4cbf89.png
     -
       .. image:: https://github.com/scarlett2018/nniutil/raw/master/wechat.png
278

Yuge Zhang's avatar
Yuge Zhang committed
279
280
Citing NNI
----------
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295

If you use NNI in a scientific publication, please consider citing NNI in your references.

   Microsoft. Neural Network Intelligence (version |release|). https://github.com/microsoft/nni

Bibtex entry (please replace the version with the particular version you are using): ::

   @software{nni2021,
      author = {{Microsoft}},
      month = {1},
      title = {{Neural Network Intelligence}},
      url = {https://github.com/microsoft/nni},
      version = {2.0},
      year = {2021}
   }