SearchSpaceSpec.md 7.21 KB
Newer Older
Yan Ni's avatar
Yan Ni committed
1
# Search Space
2

Yan Ni's avatar
Yan Ni committed
3
## Overview
4

Yan Ni's avatar
Yan Ni committed
5
6
7
8
In NNI, tuner will sample parameters/architecture according to the search space, which is defined as a json file.

To define a search space, users should define the name of variable, the type of sampling strategy and its parameters.

Lee's avatar
Lee committed
9
* An example of search space definition as follow:
10

11
```yaml
12
13
14
15
16
17
18
19
20
21
{
    "dropout_rate":{"_type":"uniform","_value":[0.1,0.5]},
    "conv_size":{"_type":"choice","_value":[2,3,5,7]},
    "hidden_size":{"_type":"choice","_value":[124, 512, 1024]},
    "batch_size":{"_type":"choice","_value":[50, 250, 500]},
    "learning_rate":{"_type":"uniform","_value":[0.0001, 0.1]}
}

```

22
Take the first line as an example. `dropout_rate` is defined as a variable whose priori distribution is a uniform distribution of a range from `0.1` and `0.5`.
Yan Ni's avatar
Yan Ni committed
23
24
25
26

## Types

All types of sampling strategies and their parameter are listed here:
27
28

* {"_type":"choice","_value":options}
Lee's avatar
Lee committed
29
30
31

  * Which means the variable's value is one of the options. Here 'options' should be a list. Each element of options is a number of string. It could also be a nested sub-search-space, this sub-search-space takes effect only when the corresponding element is chosen. The variables in this sub-search-space could be seen as conditional variables.

32
  * An simple [example](https://github.com/microsoft/nni/tree/master/examples/trials/mnist-nested-search-space/search_space.json) of [nested] search space definition. If an element in the options list is a dict, it is a sub-search-space, and for our built-in tuners you have to add a key '_name' in this dict, which helps you to identify which element is chosen. Accordingly, here is a [sample](https://github.com/microsoft/nni/tree/master/examples/trials/mnist-nested-search-space/sample.json) which users can get from nni with nested search space definition. Tuners which support nested search space is as follows:
Lee's avatar
Lee committed
33
34
35
36
37

    - Random Search 
    - TPE
    - Anneal
    - Evolution
xuehui's avatar
xuehui committed
38

39
* {"_type":"randint","_value":[lower, upper]}
Lee's avatar
Lee committed
40

Chi Song's avatar
Chi Song committed
41
  * For now, we implement the "randint" distribution with "quniform", which means the variable value is a value like round(uniform(lower, upper)). The type of chosen value is float. If you want to use integer value, please convert it explicitly.
xuehui's avatar
xuehui committed
42

43
* {"_type":"uniform","_value":[low, high]}
44
45
  * Which means the variable value is a value uniformly between low and high.
  * When optimizing, this variable is constrained to a two-sided interval.
xuehui's avatar
xuehui committed
46

47
* {"_type":"quniform","_value":[low, high, q]}
48
  * Which means the variable value is a value like clip(round(uniform(low, high) / q) * q, low, high), where the clip operation is used to constraint the generated value in the bound. For example, for _value specified as [0, 10, 2.5], possible values are [0, 2.5, 5.0, 7.5, 10.0]; For _value specified as [2, 10, 5], possible values are [2, 5, 10].
49

50
  * Suitable for a discrete value with respect to which the objective is still somewhat "smooth", but which should be bounded both above and below. If you want to uniformly choose integer from a range [low, high], you can write `_value` like this: `[low, high, 1]`.
xuehui's avatar
xuehui committed
51

52
* {"_type":"loguniform","_value":[low, high]}
53
54
  * Which means the variable value is a value drawn from a range [low, high] according to a loguniform distribution like exp(uniform(log(low), log(high))), so that the logarithm of the return value is uniformly distributed.
  * When optimizing, this variable is constrained to be positive.
xuehui's avatar
xuehui committed
55

56
* {"_type":"qloguniform","_value":[low, high, q]}
Chi Song's avatar
Chi Song committed
57
  * Which means the variable value is a value like clip(round(loguniform(low, high) / q) * q, low, high), where the clip operation is used to constraint the generated value in the bound.
58
  * Suitable for a discrete variable with respect to which the objective is "smooth" and gets smoother with the size of the value, but which should be bounded both above and below.
xuehui's avatar
xuehui committed
59

60
* {"_type":"normal","_value":[mu, sigma]}
Lee's avatar
Lee committed
61

62
  * Which means the variable value is a real value that's normally-distributed with mean mu and standard deviation sigma. When optimizing, this is an unconstrained variable.
xuehui's avatar
xuehui committed
63

64
* {"_type":"qnormal","_value":[mu, sigma, q]}
65
66
  * Which means the variable value is a value like round(normal(mu, sigma) / q) * q
  * Suitable for a discrete variable that probably takes a value around mu, but is fundamentally unbounded.
xuehui's avatar
xuehui committed
67

68
* {"_type":"lognormal","_value":[mu, sigma]}
Lee's avatar
Lee committed
69

70
  * Which means the variable value is a value drawn according to exp(normal(mu, sigma)) so that the logarithm of the return value is normally distributed. When optimizing, this variable is constrained to be positive.
xuehui's avatar
xuehui committed
71

72
* {"_type":"qlognormal","_value":[mu, sigma, q]}
73
74
  * Which means the variable value is a value like round(exp(normal(mu, sigma)) / q) * q
  * Suitable for a discrete variable with respect to which the objective is smooth and gets smoother with the size of the variable, which is bounded from one side.
75

Zejun Lin's avatar
Zejun Lin committed
76
77
78
79
80
* {"_type":"mutable_layer","_value":{mutable_layer_infomation}}
  * Type for [Neural Architecture Search Space][1]. Value is also a dictionary, which contains key-value pairs representing respectively name and search space of each mutable_layer.
  * For now, users can only use this type of search space with annotation, which means that there is no need to define a json file for search space since it will be automatically generated according to the annotation in trial code.
  * For detailed usage, please refer to [General NAS Interfaces][1].

Yan Ni's avatar
Yan Ni committed
81
82
83
84
85
86
87
88
89
90
## Search Space Types Supported by Each Tuner

|                   | choice  | randint | uniform | quniform | loguniform | qloguniform | normal  | qnormal | lognormal | qlognormal |
|:------:|:------:|:------:|:------:|:------:|:------:|:------:|:------:|:------:|:------:|:------:|
| TPE Tuner         | ✓ | ✓ | ✓ | ✓  | ✓    | ✓     | ✓ | ✓ | ✓   | ✓    |
| Random Search Tuner| ✓ | ✓ | ✓ | ✓  | ✓    | ✓     | ✓ | ✓ | ✓   | ✓    |
| Anneal Tuner   | ✓ | ✓ | ✓ | ✓  | ✓    | ✓     | ✓ | ✓ | ✓   | ✓    |
| Evolution Tuner   | ✓ | ✓ | ✓ | ✓  | ✓    | ✓     | ✓ | ✓ | ✓   | ✓    |
| SMAC Tuner        | ✓ | ✓ | ✓ | ✓  | ✓    |      |  |  |    |     |
| Batch Tuner       | ✓ |  |  |   |     |      |  |  |    |     |
91
| Grid Search Tuner | ✓ | ✓ |  | ✓  |     | |  |  |    |     |
Yan Ni's avatar
Yan Ni committed
92
93
| Hyperband Advisor | ✓ | ✓ | ✓ | ✓  | ✓    | ✓     | ✓ | ✓ | ✓   | ✓    |
| Metis Tuner   | ✓ | ✓ | ✓ | ✓  |     |      |  |  |    |     |
Guoxin's avatar
Guoxin committed
94
| GP Tuner   | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |  |  |    |     |
Yan Ni's avatar
Yan Ni committed
95
96


97
Known Limitations:
Yan Ni's avatar
Yan Ni committed
98

99
100
101
102
103
104
* Note that Metis Tuner only supports numerical `choice` now

* Note that for nested search space:

    * Only Random Search/TPE/Anneal/Evolution tuner supports nested search space

xuehui's avatar
xuehui committed
105
    * We do not support nested search space "Hyper Parameter" in visualization now, the enhancement is being considered in #1110(https://github.com/microsoft/nni/issues/1110), any suggestions or discussions or contributions are warmly welcomed
Zejun Lin's avatar
Zejun Lin committed
106

Chi Song's avatar
Chi Song committed
107
[1]: ../AdvancedFeature/GeneralNasInterfaces.md