Skip to content

Commit

Permalink
Merge pull request #282 from microsoft/v2.0
Browse files Browse the repository at this point in the history
V2.0
  • Loading branch information
SparkSnail authored Jan 5, 2021
2 parents 8a85aad + c702241 commit 37b70ba
Show file tree
Hide file tree
Showing 31 changed files with 770 additions and 722 deletions.
199 changes: 0 additions & 199 deletions docs/en_US/TrainingService/PaiYarnMode.rst

This file was deleted.

8 changes: 8 additions & 0 deletions docs/en_US/TrainingService/RemoteMachineMode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,11 @@ If you want multiple commands to be executed, you can use ``&&`` to connect thes
preCommand: command1 && command2 && command3
**Note**\ : Because **preCommand** will execute before other commands each time, it is strongly not recommended to set **preCommand** that will make changes to system, i.e. ``mkdir`` or ``touch``.

Remote machine supports running experiment in reuse mode. In this mode, NNI will reuse remote machine jobs to run as many as possible trials. It can save time of creating new jobs. User needs to make sure each trial can run independent in the same job, for example, avoid loading checkpoint from previous trials.
Follow the setting to enable reuse mode:

.. code-block:: yaml
remoteConfig:
reuse: true
97 changes: 97 additions & 0 deletions docs/en_US/Tutorial/HowToLaunchFromPython.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
**How to Launch an experiment from Python**
===========================================

Overview
--------
Since ``nni v2.0``, we provide a new way to launch experiments. Before that, you need to configure the experiment in the yaml configuration file and then use the experiment ``nnictl`` command to launch the experiment. Now, you can also configure and run experiments directly in python file. If you are familiar with python programming, this will undoubtedly bring you more convenience.

How to Use
----------
After successfully installing ``nni``, you can start the experiment with a python script in the following 3 steps.

..
Step 1 - Initialize a tuner you want to use


.. code-block:: python
from nni.algorithms.hpo.hyperopt_tuner import HyperoptTuner
tuner = HyperoptTuner('tpe')
Very simple, you have successfully initialized a ``HyperoptTuner`` instance called ``tuner``.

See all real `builtin tuners <../builtin_tuner.rst>`__ supported in NNI.

..
Step 2 - Initialize an experiment instance and configure it

.. code-block:: python
experiment = Experiment(tuner=tuner, training_service='local')
Now, you have a ``Experiment`` instance with ``tuner`` you have initialized in the previous step, and this experiment will launch trials on your local machine due to ``training_service='local'``.

See all `training services <../training_services.rst>`__ supported in NNI.

.. code-block:: python
experiment.config.experiment_name = 'test'
experiment.config.trial_concurrency = 2
experiment.config.max_trial_number = 5
experiment.config.search_space = search_space
experiment.config.trial_command = 'python3 mnist.py'
experiment.config.trial_code_directory = Path(__file__).parent
experiment.config.training_service.use_active_gpu = True
Use the form like ``experiment.config.foo = 'bar'`` to configure your experiment.

See `parameter configuration <../reference/experiment_config.rst>`__ required by different training services.

..
Step 3 - Just run

.. code-block:: python
experiment.run(port=8081)
Now, you have successfully launched an NNI experiment. And you can type ``localhost:8081`` in your browser to observe your experiment in real time.

Example
-------
Below is an example for this new launching approach. You can also find this code in :githublink:`mnist-tfv2/launch.py <examples/trials/mnist-tfv2/launch.py>` .

.. code-block:: python
from pathlib import Path
from nni.experiment import Experiment
from nni.algorithms.hpo.hyperopt_tuner import HyperoptTuner
tuner = HyperoptTuner('tpe')
search_space = {
"dropout_rate": { "_type": "uniform", "_value": [0.5, 0.9] },
"conv_size": { "_type": "choice", "_value": [2, 3, 5, 7] },
"hidden_size": { "_type": "choice", "_value": [124, 512, 1024] },
"batch_size": { "_type": "choice", "_value": [16, 32] },
"learning_rate": { "_type": "choice", "_value": [0.0001, 0.001, 0.01, 0.1] }
}
experiment = Experiment(tuner, 'local')
experiment.config.experiment_name = 'test'
experiment.config.trial_concurrency = 2
experiment.config.max_trial_number = 5
experiment.config.search_space = search_space
experiment.config.trial_command = 'python3 mnist.py'
experiment.config.trial_code_directory = Path(__file__).parent
experiment.config.training_service.use_active_gpu = True
experiment.run(8081)
API
---

.. autoclass:: nni.experiment.Experiment
:members:
14 changes: 0 additions & 14 deletions docs/en_US/nnicli_ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,3 @@ NNI client is a python API of ``nnictl``\ , which implements the most commonly u
# stop the experiment, then disconnect the instance from the experiment.
exp.stop_experiment()
References
----------

.. autoclass:: nni.experiment.Experiment
:members:
.. autoclass:: nni.experiment.TrialJob
:members:
.. autoclass:: nni.experiment.TrialHyperParameters
:members:
.. autoclass:: nni.experiment.TrialMetricData
:members:
.. autoclass:: nni.experiment.TrialResult
:members:
1 change: 1 addition & 0 deletions docs/en_US/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ References
NNI Annotation <Tutorial/AnnotationSpec>
SDK API References <sdk_reference>
Supported Framework Library <SupportedFramework_Library>
Launch from python <Tutorial/HowToLaunchFromPython>
1 change: 0 additions & 1 deletion docs/en_US/training_services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Introduction to NNI Training Services
Local<./TrainingService/LocalMode>
Remote<./TrainingService/RemoteMachineMode>
OpenPAI<./TrainingService/PaiMode>
OpenPAI Yarn Mode<./TrainingService/PaiYarnMode>
Kubeflow<./TrainingService/KubeflowMode>
AdaptDL<./TrainingService/AdaptDLMode>
FrameworkController<./TrainingService/FrameworkControllerMode>
Expand Down
32 changes: 0 additions & 32 deletions examples/trials/auto-gbdt/config_paiYarn.yml

This file was deleted.

Loading

0 comments on commit 37b70ba

Please sign in to comment.