forked from microsoft/nni
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request microsoft#137 from Microsoft/master
merge master
- Loading branch information
Showing
6 changed files
with
115 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,92 @@ | ||
# NNI Annotation Introduction | ||
# NNI Annotation | ||
|
||
For good user experience and reduce user effort, we need to design a good annotation grammar. | ||
## Overview | ||
|
||
If users use NNI system, they only need to: | ||
To improve user experience and reduce user effort, we design an annotation grammar. Using NNI annotation, users can adapt their code to NNI just by adding some standalone annotating strings, which does not affect the execution of the original code. | ||
|
||
1. Annotation variable in code as: | ||
Below is an example: | ||
|
||
'''@nni.variable(nni.choice(2,3,5,7),name=self.conv_size)''' | ||
```python | ||
'''@nni.variable(nni.choice(0.1, 0.01, 0.001), name=learning_rate)''' | ||
learning_rate = 0.1 | ||
``` | ||
The meaning of this example is that NNI will choose one of several values (0.1, 0.01, 0.001) to assign to the learning_rate variable. Specifically, this first line is an NNI annotation, which is a single string. Following is an assignment statement. What nni does here is to replace the right value of this assignment statement according to the information provided by the annotation line. | ||
|
||
2. Annotation intermediate in code as: | ||
|
||
'''@nni.report_intermediate_result(test_acc)''' | ||
In this way, users could either run the python code directly or launch NNI to tune hyper-parameter in this code, without changing any codes. | ||
|
||
3. Annotation output in code as: | ||
## Types of Annotation: | ||
|
||
'''@nni.report_final_result(test_acc)''' | ||
In NNI, there are mainly four types of annotation: | ||
|
||
4. Annotation `function_choice` in code as: | ||
|
||
'''@nni.function_choice(max_pool(h_conv1, self.pool_size),avg_pool(h_conv1, self.pool_size),name=max_pool)''' | ||
### 1. Annotate variables | ||
|
||
In this way, they can easily implement automatic tuning on NNI. | ||
`'''@nni.variable(sampling_algo, name)'''` | ||
|
||
For `@nni.variable`, `nni.choice` is the type of search space and there are 10 types to express your search space as follows: | ||
`@nni.variable` is used in NNI to annotate a variable. | ||
|
||
1. `@nni.variable(nni.choice(option1,option2,...,optionN),name=variable)` | ||
Which means the variable value is one of the options, which should be a list The elements of options can themselves be stochastic expressions | ||
**Arguments** | ||
|
||
2. `@nni.variable(nni.randint(upper),name=variable)` | ||
Which means the variable value is a random integer in the range [0, upper). | ||
- **sampling_algo**: Sampling algorithm that specifies a search space. User should replace it with a built-in NNI sampling function whose name consists of an `nni.` identification and a search space type specified in [SearchSpaceSpec](https://nni.readthedocs.io/en/latest/SearchSpaceSpec.html) such as `choice` or `uniform`. | ||
- **name**: The name of the variable that the selected value will be assigned to. Note that this argument should be the same as the left value of the following assignment statement. | ||
|
||
3. `@nni.variable(nni.uniform(low, high),name=variable)` | ||
Which means the variable value is a value uniformly between low and high. | ||
There are 10 types to express your search space as follows: | ||
|
||
4. `@nni.variable(nni.quniform(low, high, q),name=variable)` | ||
Which means the variable value is a value like round(uniform(low, high) / q) * q | ||
* `@nni.variable(nni.choice(option1,option2,...,optionN),name=variable)` | ||
Which means the variable value is one of the options, which should be a list The elements of options can themselves be stochastic expressions | ||
* `@nni.variable(nni.randint(upper),name=variable)` | ||
Which means the variable value is a random integer in the range [0, upper). | ||
* `@nni.variable(nni.uniform(low, high),name=variable)` | ||
Which means the variable value is a value uniformly between low and high. | ||
* `@nni.variable(nni.quniform(low, high, q),name=variable)` | ||
Which means the variable value is a value like round(uniform(low, high) / q) * q | ||
* `@nni.variable(nni.loguniform(low, high),name=variable)` | ||
Which means the variable value is a value drawn according to exp(uniform(low, high)) so that the logarithm of the return value is uniformly distributed. | ||
* `@nni.variable(nni.qloguniform(low, high, q),name=variable)` | ||
Which means the variable value is a value like round(exp(uniform(low, high)) / q) * q | ||
* `@nni.variable(nni.normal(mu, sigma),name=variable)` | ||
Which means the variable value is a real value that's normally-distributed with mean mu and standard deviation sigma. | ||
* `@nni.variable(nni.qnormal(mu, sigma, q),name=variable)` | ||
Which means the variable value is a value like round(normal(mu, sigma) / q) * q | ||
* `@nni.variable(nni.lognormal(mu, sigma),name=variable)` | ||
Which means the variable value is a value drawn according to exp(normal(mu, sigma)) | ||
* `@nni.variable(nni.qlognormal(mu, sigma, q),name=variable)` | ||
Which means the variable value is a value like round(exp(normal(mu, sigma)) / q) * q | ||
|
||
5. `@nni.variable(nni.loguniform(low, high),name=variable)` | ||
Which means the variable value is a value drawn according to exp(uniform(low, high)) so that the logarithm of the return value is uniformly distributed. | ||
Below is an example: | ||
|
||
6. `@nni.variable(nni.qloguniform(low, high, q),name=variable)` | ||
Which means the variable value is a value like round(exp(uniform(low, high)) / q) * q | ||
```python | ||
'''@nni.variable(nni.choice(0.1, 0.01, 0.001), name=learning_rate)''' | ||
learning_rate = 0.1 | ||
``` | ||
|
||
7. `@nni.variable(nni.normal(label, mu, sigma),name=variable)` | ||
Which means the variable value is a real value that's normally-distributed with mean mu and standard deviation sigma. | ||
### 2. Annotate functions | ||
|
||
8. `@nni.variable(nni.qnormal(label, mu, sigma, q),name=variable)` | ||
Which means the variable value is a value like round(normal(mu, sigma) / q) * q | ||
`'''@nni.function_choice(*functions, name)'''` | ||
|
||
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)) | ||
`@nni.function_choice` is used to choose one from several functions. | ||
|
||
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 | ||
**Arguments** | ||
|
||
- **functions**: Several functions that are waiting to be selected from. Note that it should be a complete function call with arguments. Such as `max_pool(hidden_layer, pool_size)`. | ||
- **name**: The name of the function that will be replaced in the following assignment statement. | ||
|
||
An example here is: | ||
|
||
```python | ||
"""@nni.function_choice(max_pool(hidden_layer, pool_size), avg_pool(hidden_layer, pool_size), name=max_pool)""" | ||
h_pooling = max_pool(hidden_layer, pool_size) | ||
``` | ||
|
||
### 3. Annotate intermediate result | ||
|
||
`'''@nni.report_intermediate_result(metrics)'''` | ||
|
||
`@nni.report_intermediate_result` is used to report intermediate result, whose usage is the same as `nni.report_intermediate_result` in [Trials.md](https://nni.readthedocs.io/en/latest/Trials.html) | ||
|
||
### 4. Annotate final result | ||
|
||
`'''@nni.report_final_result(metrics)'''` | ||
|
||
`@nni.report_final_result` is used to report the final result of the current trial, whose usage is the same as `nni.report_final_result` in [Trials.md](https://nni.readthedocs.io/en/latest/Trials.html) |