Unverified Commit 1d6db235 authored by fishyds's avatar fishyds Committed by GitHub
Browse files

Merge branch 'master' into v0.5

parents 3c1ff6cc efa479b0
...@@ -6,7 +6,7 @@ So when user want to write a Trial running on NNI, she/he should: ...@@ -6,7 +6,7 @@ So when user want to write a Trial running on NNI, she/he should:
**1)Have an original Trial could run**, **1)Have an original Trial could run**,
Trial's code could be any machine learning code that could run in local. Here we use ```mnist-keras.py``` as example: Trial's code could be any machine learning code that could run in local. Here we use `mnist-keras.py` as example:
```python ```python
import argparse import argparse
...@@ -86,7 +86,7 @@ if __name__ == '__main__': ...@@ -86,7 +86,7 @@ if __name__ == '__main__':
**2)Get configure from Tuner** **2)Get configure from Tuner**
User import ```nni``` and use ```nni.get_next_parameter()``` to receive configure. Please noted **10**, **24** and **25** line in the following code. User import `nni` and use `nni.get_next_parameter()` to receive configure. Please noted **10**, **24** and **25** line in the following code.
```python ```python
...@@ -121,7 +121,7 @@ if __name__ == '__main__': ...@@ -121,7 +121,7 @@ if __name__ == '__main__':
**3) Send intermediate result** **3) Send intermediate result**
Use ```nni.report_intermediate_result``` to send intermediate result to Assessor. Please noted **5** line in the following code. Use `nni.report_intermediate_result` to send intermediate result to Assessor. Please noted **5** line in the following code.
```python ```python
...@@ -144,7 +144,7 @@ def train(args, params): ...@@ -144,7 +144,7 @@ def train(args, params):
``` ```
**4) Send final result** **4) Send final result**
Use ```nni.report_final_result``` to send final result to Trial. Please noted **15** line in the following code. Use `nni.report_final_result` to send final result to Tuner. Please noted **15** line in the following code.
```python ```python
... ...
......
...@@ -36,17 +36,17 @@ chmod +x ./download.sh ...@@ -36,17 +36,17 @@ chmod +x ./download.sh
1. download "dev-v1.1.json" and "train-v1.1.json" in https://rajpurkar.github.io/SQuAD-explorer/ 1. download "dev-v1.1.json" and "train-v1.1.json" in https://rajpurkar.github.io/SQuAD-explorer/
``` ```bash
wget https://rajpurkar.github.io/SQuAD-explorer/dataset/train-v1.1.json wget https://rajpurkar.github.io/SQuAD-explorer/dataset/train-v1.1.json
wget https://rajpurkar.github.io/SQuAD-explorer/dataset/dev-v1.1.json wget https://rajpurkar.github.io/SQuAD-explorer/dataset/dev-v1.1.json
``` ```
2. download "glove.840B.300d.txt" in https://nlp.stanford.edu/projects/glove/ 2. download "glove.840B.300d.txt" in https://nlp.stanford.edu/projects/glove/
``` ```bash
wget http://nlp.stanford.edu/data/glove.840B.300d.zip wget http://nlp.stanford.edu/data/glove.840B.300d.zip
unzip glove.840B.300d.zip unzip glove.840B.300d.zip
``` ```
### Update configuration ### Update configuration
Modify `nni/examples/trials/ga_squad/config.yml`, here is the default configuration: Modify `nni/examples/trials/ga_squad/config.yml`, here is the default configuration:
......
...@@ -23,8 +23,11 @@ Assuming additive a Gaussian noise and the noise parameter is initialized to its ...@@ -23,8 +23,11 @@ Assuming additive a Gaussian noise and the noise parameter is initialized to its
We determine the maximum probability value of the new combined parameter vector by learing the historical data. Use such value to predict the future trial performance, and stop the inadequate experiments to save computing resource. We determine the maximum probability value of the new combined parameter vector by learing the historical data. Use such value to predict the future trial performance, and stop the inadequate experiments to save computing resource.
Concretely,this algorithm goes through three stages of learning, predicting and assessing. Concretely,this algorithm goes through three stages of learning, predicting and assessing.
* Step1: Learning. We will learning about the trial history of the current trial and determine the \xi at Bayesian angle. First of all, We fit each curve using the least squares method(implement by `fit_theta`) to save our time. After we obtained the parameters, we filter the curve and remove the outliers(implement by `filter_curve`). Fially, we use the MCMC sampling method(implement by `mcmc_sampling`) to adjust the weight of each curve. Up to now, we have dertermined all the parameters in \xi.
* Step1: Learning. We will learning about the trial history of the current trial and determine the \xi at Bayesian angle. First of all, We fit each curve using the least squares method(implement by `fit_theta`) to save our time. After we obtained the parameters, we filter the curve and remove the outliers(implement by `filter_curve`). Finally, we use the MCMC sampling method(implement by `mcmc_sampling`) to adjust the weight of each curve. Up to now, we have dertermined all the parameters in \xi.
* Step2: Predicting. Calculates the expected final result accuracy(implement by `f_comb`) at target position(ie the total number of epoch) by the \xi and the formula of the combined model. * Step2: Predicting. Calculates the expected final result accuracy(implement by `f_comb`) at target position(ie the total number of epoch) by the \xi and the formula of the combined model.
* Step3: If the fitting result doesn't converge, the predicted value will be `None`, in this case we return `AssessResult.Good` to ask for future accuracy information and predict again. Furthermore, we will get a positive value by `predict()` function, if this value is strictly greater than the best final performance in history * `THRESHOLD`(default value = 0.95), return `AssessResult.Good`, otherwise, return `AssessResult.Bad` * Step3: If the fitting result doesn't converge, the predicted value will be `None`, in this case we return `AssessResult.Good` to ask for future accuracy information and predict again. Furthermore, we will get a positive value by `predict()` function, if this value is strictly greater than the best final performance in history * `THRESHOLD`(default value = 0.95), return `AssessResult.Good`, otherwise, return `AssessResult.Bad`
The figure below is the result of our algorithm on MNIST trial history data, where the green point represents the data obtained by Assessor, the blue point represents the future but unknown data, and the red line is the Curve predicted by the Curve fitting assessor. The figure below is the result of our algorithm on MNIST trial history data, where the green point represents the data obtained by Assessor, the blue point represents the future but unknown data, and the red line is the Curve predicted by the Curve fitting assessor.
......
...@@ -2,12 +2,12 @@ Hyperband on nni ...@@ -2,12 +2,12 @@ Hyperband on nni
=== ===
## 1. Introduction ## 1. Introduction
[Hyperband][1] is a popular automl algorithm. The basic idea of Hyperband is that it creates several brackets, each bracket has `n` randomly generated hyperparameter configurations, each configuration uses `r` resource (e.g., epoch number, batch number). After the `n` configurations is finished, it chooses top `n/eta` configurations and runs them using increased `r*eta` resource. At last, it chooses the best configuration it has found so far. [Hyperband][1] is a popular automl algorithm. The basic idea of Hyperband is that it creates several buckets, each bucket has `n` randomly generated hyperparameter configurations, each configuration uses `r` resource (e.g., epoch number, batch number). After the `n` configurations is finished, it chooses top `n/eta` configurations and runs them using increased `r*eta` resource. At last, it chooses the best configuration it has found so far.
## 2. Implementation with fully parallelism ## 2. Implementation with fully parallelism
Frist, this is an example of how to write an automl algorithm based on MsgDispatcherBase, rather than Tuner and Assessor. Hyperband is implemented in this way because it integrates the functions of both Tuner and Assessor, thus, we call it advisor. Frist, this is an example of how to write an automl algorithm based on MsgDispatcherBase, rather than Tuner and Assessor. Hyperband is implemented in this way because it integrates the functions of both Tuner and Assessor, thus, we call it advisor.
Second, this implementation fully leverages Hyperband's internal parallelism. More specifically, the next bracket is not started strictly after the current bracket, instead, it starts when there is available resource. Second, this implementation fully leverages Hyperband's internal parallelism. More specifically, the next bucket is not started strictly after the current bucket, instead, it starts when there is available resource.
## 3. Usage ## 3. Usage
To use Hyperband, you should add the following spec in your experiment's yaml config file: To use Hyperband, you should add the following spec in your experiment's yaml config file:
...@@ -43,7 +43,7 @@ Here is a concrete example of `R=81` and `eta=3`: ...@@ -43,7 +43,7 @@ Here is a concrete example of `R=81` and `eta=3`:
|3 |3 27 |1 81 | | | | |3 |3 27 |1 81 | | | |
|4 |1 81 | | | | | |4 |1 81 | | | | |
`s` means bracket, `n` means the number of configurations that are generated, the corresponding `r` means how many STEPS these configurations run. `i` means round, for example, bracket 4 has 5 rounds, bracket 3 has 4 rounds. `s` means bucket, `n` means the number of configurations that are generated, the corresponding `r` means how many STEPS these configurations run. `i` means round, for example, bucket 4 has 5 rounds, bucket 3 has 4 rounds.
About how to write trial code, please refer to the instructions under `examples/trials/mnist-hyperband/`. About how to write trial code, please refer to the instructions under `examples/trials/mnist-hyperband/`.
......
# Network Morphism Tuner on NNI # Network Morphism Tuner on NNI
## 1. Intorduction ## 1. Introduction
[Autokeras](https://arxiv.org/abs/1806.10282) is a popular automl tools using Network Morphism. The basic idea of Autokeras is to use Bayesian Regression to estimate the metric of the Neural Network Architecture. Each time, it generates several child networks from father networks. Then it uses a naïve Bayesian regression estimate its metric value from history trained results of network and metric value pair. Next, it chooses the the child which has best estimated performance and adds it to the training queue. Inspired by its work and referring to its [code](https://github.com/jhfjhfj1/autokeras), we implement our Network Morphism method in our NNI platform. [Autokeras](https://arxiv.org/abs/1806.10282) is a popular automl tools using Network Morphism. The basic idea of Autokeras is to use Bayesian Regression to estimate the metric of the Neural Network Architecture. Each time, it generates several child networks from father networks. Then it uses a naïve Bayesian regression estimate its metric value from history trained results of network and metric value pair. Next, it chooses the the child which has best estimated performance and adds it to the training queue. Inspired by its work and referring to its [code](https://github.com/jhfjhfj1/autokeras), we implement our Network Morphism method in our NNI platform.
......
...@@ -10,7 +10,7 @@ Click the tab "Overview". ...@@ -10,7 +10,7 @@ Click the tab "Overview".
## View job accuracy ## View job accuracy
Click the tab "Optimization Progress" to see the point graph of all trials. Hover every point to see its specific accuracy. Click the tab "Default Metric" to see the point graph of all trials. Hover every point to see its specific accuracy.
## View hyper parameter ## View hyper parameter
...@@ -21,16 +21,11 @@ Click the tab "Hyper Parameter" to see the parallel graph. ...@@ -21,16 +21,11 @@ Click the tab "Hyper Parameter" to see the parallel graph.
## View trial status ## View trial status
Click the tab "Trial Status" to see the status of the all trials. Specifically: Click the tab "Trials Detail" to see the status of the all trials. Specifically:
* Trial duration: trial's duration in the bar graph. * Trial duration: trial's duration in the bar graph.
* Trial detail: trial's id, trial's duration, start time, end time, status, accuracy and search space file. * Trial detail: trial's id, trial's duration, start time, end time, status, accuracy and search space file.
* Kill: you can kill a job that status is running. * Kill: you can kill a job that status is running.
* Tensor: you can see a job in the tensorflow graph, it will link to the Tensorboard page.
## Control
Click the tab "Control" to add a new trial or update the search_space file and some experiment parameters.
## Feedback ## Feedback
......
...@@ -9,23 +9,28 @@ python >= 3.5 ...@@ -9,23 +9,28 @@ python >= 3.5
## Installation ## Installation
1. Enter tools directory 1. Enter tools directory
2. Use pip to install packages 1. Use pip to install packages
* Install for current user: * Install for current user:
```bash
python3 -m pip install --user -e . python3 -m pip install --user -e .
```
* Install for all users: * Install for all users:
```bash
python3 -m pip install -e . python3 -m pip install -e .
```
1. Change the mode of nnictl file 1. Change the mode of nnictl file
```bash
chmod +x ./nnictl chmod +x ./nnictl
```
2. Add nnictl to your PATH system environment variable. 1. Add nnictl to your PATH system environment variable.
* You could use `export` command to set PATH variable temporary. * You could use `export` command to set PATH variable temporary.
...@@ -33,6 +38,7 @@ python >= 3.5 ...@@ -33,6 +38,7 @@ python >= 3.5
* Or you could edit your `/etc/profile` file. * Or you could edit your `/etc/profile` file.
```txt
1.sudo vim /etc/profile 1.sudo vim /etc/profile
2.At the end of the file, add 2.At the end of the file, add
...@@ -42,11 +48,10 @@ python >= 3.5 ...@@ -42,11 +48,10 @@ python >= 3.5
save and exit. save and exit.
3.source /etc/profile 3.source /etc/profile
```
## To start using NNI CTL ## To start using NNI CTL
please reference to the [NNI CTL document]. please reference to the [NNI CTL document].
[NNI CTL document]: ../docs/NNICTLDOC.md [NNI CTL document]: ../docs/NNICTLDOC.md
...@@ -20,7 +20,7 @@ If users use NNI system, they only need to: ...@@ -20,7 +20,7 @@ If users use NNI system, they only need to:
'''@nni.function_choice(max_pool(h_conv1, self.pool_size),avg_pool(h_conv1, self.pool_size),name=max_pool)''' '''@nni.function_choice(max_pool(h_conv1, self.pool_size),avg_pool(h_conv1, self.pool_size),name=max_pool)'''
In this way, they can easily realize automatic tuning on NNI. In this way, they can easily implement automatic tuning on NNI.
For `@nni.variable`, `nni.choice` is the type of search space and there are 10 types to express your search space as follows: For `@nni.variable`, `nni.choice` is the type of search space and there are 10 types to express your search space as follows:
...@@ -51,5 +51,5 @@ For `@nni.variable`, `nni.choice` is the type of search space and there are 10 t ...@@ -51,5 +51,5 @@ For `@nni.variable`, `nni.choice` is the type of search space and there are 10 t
9. `@nni.variable(nni.lognormal(label, mu, sigma),name=variable)` 9. `@nni.variable(nni.lognormal(label, mu, sigma),name=variable)`
Which means the variable value is a value drawn according to exp(normal(mu, sigma)) Which means the variable value is a value drawn according to exp(normal(mu, sigma))
10. `@nni.variable(nni.qlognormal(label, mu, sigma, q),name=variable)` 10. `@nni.variable(nni.qlognormal(label, mu, sigma, q),name=variable)`
Which means the variable value is a value like round(exp(normal(mu, sigma)) / q) * q Which means the variable value is a value like round(exp(normal(mu, sigma)) / q) * q
...@@ -21,10 +21,12 @@ ...@@ -21,10 +21,12 @@
import json import json
import os import os
import sys
import shutil import shutil
import string import string
from subprocess import Popen, PIPE, call, check_output from subprocess import Popen, PIPE, call, check_output, check_call
import tempfile import tempfile
from nni.constants import ModuleName
from nni_annotation import * from nni_annotation import *
from .launcher_utils import validate_all_content from .launcher_utils import validate_all_content
from .rest_utils import rest_put, rest_post, check_rest_server, check_rest_server_quick, check_response from .rest_utils import rest_put, rest_post, check_rest_server, check_rest_server_quick, check_response
...@@ -282,6 +284,17 @@ def set_experiment(experiment_config, mode, port, config_file_name): ...@@ -282,6 +284,17 @@ def set_experiment(experiment_config, mode, port, config_file_name):
def launch_experiment(args, experiment_config, mode, config_file_name, experiment_id=None): def launch_experiment(args, experiment_config, mode, config_file_name, experiment_id=None):
'''follow steps to start rest server and start experiment''' '''follow steps to start rest server and start experiment'''
nni_config = Config(config_file_name) nni_config = Config(config_file_name)
# check packages for tuner
if experiment_config.get('tuner') and experiment_config['tuner'].get('builtinTunerName'):
tuner_name = experiment_config['tuner']['builtinTunerName']
module_name = ModuleName[tuner_name]
try:
check_call([sys.executable, '-c', 'import %s'%(module_name)])
except ModuleNotFoundError as e:
print_error('The tuner %s should be installed through nnictl'%(tuner_name))
exit(1)
# start rest server # start rest server
rest_process, start_time = start_rest_server(args.port, experiment_config['trainingServicePlatform'], mode, config_file_name, experiment_id) rest_process, start_time = start_rest_server(args.port, experiment_config['trainingServicePlatform'], mode, config_file_name, experiment_id)
nni_config.set_config('restServerPid', rest_process.pid) nni_config.set_config('restServerPid', rest_process.pid)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment