Unverified Commit b8b49a34 authored by Chi Song's avatar Chi Song Committed by GitHub
Browse files

Chinese Translation (#1198)

parent 4d3ad73d
......@@ -61,11 +61,12 @@ NNI (Neural Network Intelligence) 是自动机器学习(AutoML)的工具包
<li><a href="examples/tuners/enas_nni/README_zh_CN.md">ENAS</a></li>
<li><a href="docs/zh_CN/BuiltinTuner.md#MetisTuner">Metis Tuner</a></li>
<li><a href="docs/zh_CN/BuiltinTuner.md#BOHB">BOHB</a></li>
<li><a href="docs/zh_CN/BuiltinTuner.md#GPTuner">GP Tuner</a></li>
</ul>
<a href="docs/zh_CN/BuiltinAssessors.md">Assessor(评估器)</a>
<a href="docs/zh_CN/BuiltinAssessor.md">Assessor(评估器)</a>
<ul>
<li><a href="docs/zh_CN/BuiltinAssessors.md#Medianstop">Median Stop</a></li>
<li><a href="docs/zh_CN/BuiltinAssessors.md#Curvefitting">Curve Fitting</a></li>
<li><a href="docs/zh_CN/BuiltinAssessor.md#Medianstop">Median Stop</a></li>
<li><a href="docs/zh_CN/BuiltinAssessor.md#Curvefitting">Curve Fitting</a></li>
</ul>
</td>
<td>
......@@ -101,12 +102,6 @@ NNI (Neural Network Intelligence) 是自动机器学习(AutoML)的工具包
## **安装和验证**
在 Windows 本机模式下,并且是第一次使用 PowerShell 来运行脚本,需要**使用管理员权限**运行一次下列命令:
```bash
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
```
**通过 pip 命令安装**
* 当前支持 Linux,MacOS 和 Windows(本机,远程,OpenPAI 模式),在 Ubuntu 16.04 或更高版本,MacOS 10.14.1 以及 Windows 10.1809 上进行了测试。 在 `python >= 3.5` 的环境中,只需要运行 `pip install` 即可完成安装。
......@@ -138,7 +133,7 @@ Linux 和 macOS
*`python >= 3.5` 的环境中运行命令: `git``wget`,确保安装了这两个组件。
```bash
git clone -b v0.7 https://github.com/Microsoft/nni.git
git clone -b v0.8 https://github.com/Microsoft/nni.git
cd nni
source install.sh
```
......@@ -148,9 +143,9 @@ Windows
*`python >=3.5` 的环境中运行命令: `git``PowerShell`,确保安装了这两个组件。
```bash
git clone -b v0.7 https://github.com/Microsoft/nni.git
git clone -b v0.8 https://github.com/Microsoft/nni.git
cd nni
powershell .\install.ps1
powershell -ExecutionPolicy Bypass -file install.ps1
```
参考[安装 NNI](docs/zh_CN/Installation.md) 了解系统需求。
......@@ -164,7 +159,7 @@ Windows 上参考 [Windows 上使用 NNI](docs/zh_CN/NniOnWindows.md)。
* 通过克隆源代码下载示例。
```bash
git clone -b v0.7 https://github.com/Microsoft/nni.git
git clone -b v0.8 https://github.com/Microsoft/nni.git
```
Linux 和 macOS
......
# Built-in Tuners
NNI provides state-of-the-art tuning algorithm as our builtin-tuners and makes them easy to use. Below is the brief summary of NNI currently built-in Tuners:
NNI provides state-of-the-art tuning algorithm as our built-in tuners and makes them easy to use. Below is the brief summary of NNI currently built-in tuners:
Note: Click the **Tuner's name** to get the Tuner's installation requirements, suggested scenario and using example. The link for a detailed description of the algorithm is at the end of the suggested scenario of each tuner. Here is an [article](./CommunitySharings/HpoComparision.md) about the comparison of different Tuners on several problems.
......@@ -11,28 +11,27 @@ Currently we support the following algorithms:
|[__TPE__](#TPE)|The Tree-structured Parzen Estimator (TPE) is a sequential model-based optimization (SMBO) approach. SMBO methods sequentially construct models to approximate the performance of hyperparameters based on historical measurements, and then subsequently choose new hyperparameters to test based on this model. [Reference Paper](https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf)|
|[__Random Search__](#Random)|In Random Search for Hyper-Parameter Optimization show that Random Search might be surprisingly simple and effective. We suggest that we could use Random Search as the baseline when we have no knowledge about the prior distribution of hyper-parameters. [Reference Paper](http://www.jmlr.org/papers/volume13/bergstra12a/bergstra12a.pdf)|
|[__Anneal__](#Anneal)|This simple annealing algorithm begins by sampling from the prior, but tends over time to sample from points closer and closer to the best ones observed. This algorithm is a simple variation on the random search that leverages smoothness in the response surface. The annealing rate is not adaptive.|
|[__Naive Evolution__](#Evolution)|Naive Evolution comes from Large-Scale Evolution of Image Classifiers. It randomly initializes a population-based on search space. For each generation, it chooses better ones and does some mutation (e.g., change a hyperparameter, add/remove one layer) on them to get the next generation. Naive Evolution requires many trials to works, but it's very simple and easy to expand new features. [Reference paper](https://arxiv.org/pdf/1703.01041.pdf)|
|[__SMAC__](#SMAC)|SMAC is based on Sequential Model-Based Optimization (SMBO). It adapts the most prominent previously used model class (Gaussian stochastic process models) and introduces the model class of random forests to SMBO, in order to handle categorical parameters. The SMAC supported by nni is a wrapper on the SMAC3 Github repo. Notice, SMAC need to be installed by `nnictl package` command. [Reference Paper,](https://www.cs.ubc.ca/~hutter/papers/10-TR-SMAC.pdf) [Github Repo](https://github.com/automl/SMAC3)|
|[__Naïve Evolution__](#Evolution)|Naïve Evolution comes from Large-Scale Evolution of Image Classifiers. It randomly initializes a population-based on search space. For each generation, it chooses better ones and does some mutation (e.g., change a hyperparameter, add/remove one layer) on them to get the next generation. Naïve Evolution requires many trials to works, but it's very simple and easy to expand new features. [Reference paper](https://arxiv.org/pdf/1703.01041.pdf)|
|[__SMAC__](#SMAC)|SMAC is based on Sequential Model-Based Optimization (SMBO). It adapts the most prominent previously used model class (Gaussian stochastic process models) and introduces the model class of random forests to SMBO, in order to handle categorical parameters. The SMAC supported by NNI is a wrapper on the SMAC3 GitHub repo. Notice, SMAC need to be installed by `nnictl package` command. [Reference Paper,](https://www.cs.ubc.ca/~hutter/papers/10-TR-SMAC.pdf) [GitHub Repo](https://github.com/automl/SMAC3)|
|[__Batch tuner__](#Batch)|Batch tuner allows users to simply provide several configurations (i.e., choices of hyper-parameters) for their trial code. After finishing all the configurations, the experiment is done. Batch tuner only supports the type choice in search space spec.|
|[__Grid Search__](#GridSearch)|Grid Search performs an exhaustive searching through a manually specified subset of the hyperparameter space defined in the searchspace file. Note that the only acceptable types of search space are choice, quniform, qloguniform. The number q in quniform and qloguniform has special meaning (different from the spec in search space spec). It means the number of values that will be sampled evenly from the range low and high.|
|[__Hyperband__](#Hyperband)|Hyperband tries to use the limited resource to explore as many configurations as possible, and finds out the promising ones to get the final result. The basic idea is generating many configurations and to run them for the small number of trial budget to find out promising one, then further training those promising ones to select several more promising one.[Reference Paper](https://arxiv.org/pdf/1603.06560.pdf)|
|[__Network Morphism__](#NetworkMorphism)|Network Morphism provides functions to automatically search for architecture of deep learning models. Every child network inherits the knowledge from its parent network and morphs into diverse types of networks, including changes of depth, width, and skip-connection. Next, it estimates the value of a child network using the historic architecture and metric pairs. Then it selects the most promising one to train. [Reference Paper](https://arxiv.org/abs/1806.10282)|
|[__Metis Tuner__](#MetisTuner)|Metis offers the following benefits when it comes to tuning parameters: While most tools only predict the optimal configuration, Metis gives you two outputs: (a) current prediction of optimal configuration, and (b) suggestion for the next trial. No more guesswork. While most tools assume training datasets do not have noisy data, Metis actually tells you if you need to re-sample a particular hyper-parameter. [Reference Paper](https://www.microsoft.com/en-us/research/publication/metis-robustly-tuning-tail-latencies-cloud-systems/)|
|[__BOHB__](#BOHB)|BOHB is a follow-up work of Hyperband. It targets the weakness of Hyperband that new configurations are generated randomly without leveraging finished trials. For the name BOHB, HB means Hyperband, BO means Byesian Optimization. BOHB leverages finished trials by building multiple TPE models, a proportion of new configurations are generated through these models. [Reference Paper](https://arxiv.org/abs/1807.01774)|
|[__GP Tuner__](#GPTuner)|Gaussian Process Tuner is a sequential model-based optimization (SMBO) approach with Gaussian Process as the surrogate. [Reference Paper, ](https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf)[Github Repo](https://github.com/fmfn/BayesianOptimization)|
<br>
|[__BOHB__](#BOHB)|BOHB is a follow-up work of Hyperband. It targets the weakness of Hyperband that new configurations are generated randomly without leveraging finished trials. For the name BOHB, HB means Hyperband, BO means Bayesian Optimization. BOHB leverages finished trials by building multiple TPE models, a proportion of new configurations are generated through these models. [Reference Paper](https://arxiv.org/abs/1807.01774)|
|[__GP Tuner__](#GPTuner)|Gaussian Process Tuner is a sequential model-based optimization (SMBO) approach with Gaussian Process as the surrogate. [Reference Paper](https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf), [Github Repo](https://github.com/fmfn/BayesianOptimization)|
## Usage of Builtin Tuners
## Usage of Built-in Tuners
Use builtin tuner provided by NNI SDK requires to declare the **builtinTunerName** and **classArgs** in `config.yml` file. In this part, we will introduce the detailed usage about the suggested scenarios, classArg requirements and example for each tuner.
Use built-in tuner provided by NNI SDK requires to declare the **builtinTunerName** and **classArgs** in `config.yml` file. In this part, we will introduce the detailed usage about the suggested scenarios, classArg requirements and example for each tuner.
Note: Please follow the format when you write your `config.yml` file. Some builtin tuner need to be installed by `nnictl package`, like SMAC.
Note: Please follow the format when you write your `config.yml` file. Some built-in tuner need to be installed by `nnictl package`, like SMAC.
<a name="TPE"></a>
![](https://placehold.it/15/1589F0/000000?text=+) `TPE`
> Builtin Tuner Name: **TPE**
> Built-in Tuner Name: **TPE**
**Suggested scenario**
......@@ -59,7 +58,7 @@ tuner:
![](https://placehold.it/15/1589F0/000000?text=+) `Random Search`
> Builtin Tuner Name: **Random**
> Built-in Tuner Name: **Random**
**Suggested scenario**
......@@ -83,7 +82,7 @@ tuner:
![](https://placehold.it/15/1589F0/000000?text=+) `Anneal`
> Builtin Tuner Name: **Anneal**
> Built-in Tuner Name: **Anneal**
**Suggested scenario**
......@@ -108,9 +107,9 @@ tuner:
<a name="Evolution"></a>
![](https://placehold.it/15/1589F0/000000?text=+) `Naive Evolution`
![](https://placehold.it/15/1589F0/000000?text=+) `Naïve Evolution`
> Builtin Tuner Name: **Evolution**
> Built-in Tuner Name: **Evolution**
**Suggested scenario**
......@@ -133,9 +132,9 @@ tuner:
![](https://placehold.it/15/1589F0/000000?text=+) `SMAC`
> Builtin Tuner Name: **SMAC**
> Built-in Tuner Name: **SMAC**
**Please note that SMAC doesn't support running on windows currently. The specific reason can be referred to this [github issue](https://github.com/automl/SMAC3/issues/483).**
**Please note that SMAC doesn't support running on windows currently. The specific reason can be referred to this [GitHub issue](https://github.com/automl/SMAC3/issues/483).**
**Installation**
......@@ -169,7 +168,7 @@ tuner:
![](https://placehold.it/15/1589F0/000000?text=+) `Batch Tuner`
> Builtin Tuner Name: BatchTuner
> Built-in Tuner Name: BatchTuner
**Suggested scenario**
......@@ -208,7 +207,7 @@ The search space file including the high-level key `combine_params`. The type of
![](https://placehold.it/15/1589F0/000000?text=+) `Grid Search`
> Builtin Tuner Name: **Grid Search**
> Built-in Tuner Name: **Grid Search**
**Suggested scenario**
......@@ -230,7 +229,7 @@ tuner:
![](https://placehold.it/15/1589F0/000000?text=+) `Hyperband`
> Builtin Advisor Name: **Hyperband**
> Built-in Advisor Name: **Hyperband**
**Suggested scenario**
......@@ -260,11 +259,11 @@ advisor:
![](https://placehold.it/15/1589F0/000000?text=+) `Network Morphism`
> Builtin Tuner Name: **NetworkMorphism**
> Built-in Tuner Name: **NetworkMorphism**
**Installation**
NetworkMorphism requires [pyTorch](https://pytorch.org/get-started/locally), so users should install it first.
NetworkMorphism requires [PyTorch](https://pytorch.org/get-started/locally), so users should install it first.
**Suggested scenario**
......@@ -298,13 +297,13 @@ tuner:
![](https://placehold.it/15/1589F0/000000?text=+) `Metis Tuner`
> Builtin Tuner Name: **MetisTuner**
> Built-in Tuner Name: **MetisTuner**
Note that the only acceptable types of search space are `choice`, `quniform`, `uniform` and `randint`.
**Suggested scenario**
Similar to TPE and SMAC, Metis is a black-box tuner. If your system takes a long time to finish each trial, Metis is more favorable than other approaches such as random search. Furthermore, Metis provides guidance on the subsequent trial. Here is an [example](https://github.com/Microsoft/nni/tree/master/examples/trials/auto-gbdt/search_space_metis.json) about the use of Metis. User only need to send the final result like `accuracy` to tuner, by calling the nni SDK. [Detailed Description](./MetisTuner.md)
Similar to TPE and SMAC, Metis is a black-box tuner. If your system takes a long time to finish each trial, Metis is more favorable than other approaches such as random search. Furthermore, Metis provides guidance on the subsequent trial. Here is an [example](https://github.com/Microsoft/nni/tree/master/examples/trials/auto-gbdt/search_space_metis.json) about the use of Metis. User only need to send the final result like `accuracy` to tuner, by calling the NNI SDK. [Detailed Description](./MetisTuner.md)
**Requirement of classArg**
......@@ -326,7 +325,7 @@ tuner:
![](https://placehold.it/15/1589F0/000000?text=+) `BOHB Advisor`
> Builtin Tuner Name: **BOHB**
> Built-in Tuner Name: **BOHB**
**Installation**
......@@ -338,7 +337,7 @@ nnictl package install --name=BOHB
**Suggested scenario**
Similar to Hyperband, it is suggested when you have limited computation resource but have relatively large search space. It performs well in the scenario that intermediate result (e.g., accuracy) can reflect good or bad of final result (e.g., accuracy) to some extent. In this case, it may converges to a better configuration due to bayesian optimization usage. [Detailed Description](./BohbAdvisor.md)
Similar to Hyperband, it is suggested when you have limited computation resource but have relatively large search space. It performs well in the scenario that intermediate result (e.g., accuracy) can reflect good or bad of final result (e.g., accuracy) to some extent. In this case, it may converges to a better configuration due to Bayesian optimization usage. [Detailed Description](./BohbAdvisor.md)
**Requirement of classArg**
......@@ -366,19 +365,18 @@ advisor:
max_budget: 27
eta: 3
```
<br>
<a name="GPTuner"></a>
![](https://placehold.it/15/1589F0/000000?text=+) `GP Tuner`
> Builtin Tuner Name: **GPTuner**
> Built-in Tuner Name: **GPTuner**
Note that the only acceptable types of search space are `choice`, `randint`, `uniform`, `quniform`, `loguniform`, `qloguniform`.
**Suggested scenario**
As a strategy in Sequential Model-based Global Optimization(SMBO) algorithm, GP Tuner uses a proxy optimization problem (finding the maximum of the acquisition function) that, albeit still a hard problem, is cheaper (in the computational sense) and common tools can be employed. Therefore GP Tuner is most adequate for situations where the function to be optimized is a very expensive endeavor. GP can be used when the computation resource is limited. While GP Tuner has a computationoal cost that grows at *O(N^3)* due to the requirement of inverting the Gram matrix, so it's not suitable when lots of trials are needed. [Detailed Description](./GPTuner.md)
As a strategy in Sequential Model-based Global Optimization(SMBO) algorithm, GP Tuner uses a proxy optimization problem (finding the maximum of the acquisition function) that, albeit still a hard problem, is cheaper (in the computational sense) and common tools can be employed. Therefore GP Tuner is most adequate for situations where the function to be optimized is a very expensive endeavor. GP can be used when the computation resource is limited. While GP Tuner has a computational cost that grows at *O(N^3)* due to the requirement of inverting the Gram matrix, so it's not suitable when lots of trials are needed. [Detailed Description](./GPTuner.md)
**Requirement of classArg**
......@@ -390,7 +388,7 @@ As a strategy in Sequential Model-based Global Optimization(SMBO) algorithm, GP
* **alpha** (*float, optional, default = 1e-6*) - Used to specify Gaussian Process Regressor. Larger values correspond to increased noise level in the observations.
* **cold_start_num** (*int, optional, default = 10*) - Number of random exploration to perform before Gaussian Process. Random exploration can help by diversifying the exploration space.
* **selection_num_warm_up** (*int, optional, default = 1e5*) - Number of random points to evaluate for getting the point which maximizes the acquisition function.
* **selection_num_starting_points** (*int, optional, default = 250*) - Nnumber of times to run L-BFGS-B from a random starting point after the warmup.
* **selection_num_starting_points** (*int, optional, default = 250*) - Number of times to run L-BFGS-B from a random starting point after the warmup.
**Usage example**
......
......@@ -79,7 +79,7 @@ advisor:
* **bandwidth_factor**(< 1>浮点数, 可选, 默认值为3.0 </em>): 为了鼓励多样性,把优化EI的点加宽,即把KDE中采样的点乘以这个因子,从而增加KDE中的带宽。 如果不熟悉 KDE,建议保留默认值。
* **min_bandwidth**(< 1>float, 可选, 默认值 = 0.001 </em>): 为了保持多样性, 即使所有好的样本对其中一个参数具有相同的值,使用最小带宽 (默认值: 1e-3) 而不是零。 如果不熟悉 KDE,建议保留默认值。
*请注意, 目前 NNI 的浮点类型仅支持十进制表示,必须使用0.333 来代替1/3,0.001代替1e-3。*
*目前 NNI 的浮点类型仅支持十进制表示,必须使用 0.333 来代替 1/3,0.001代替 1e-3。*
## 4. 文件结构
......
......@@ -6,25 +6,24 @@ NNI 提供了先进的调优算法,使用上也很简单。 下面是内置 Tu
当前支持的 Tuner:
| Tuner | 算法简介 |
| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Tuner(调参器) | 算法简介 |
| ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [**TPE**](#TPE) | Tree-structured Parzen Estimator (TPE) 是一种 sequential model-based optimization(SMBO,即基于序列模型优化)的方法。 SMBO 方法根据历史指标数据来按顺序构造模型,来估算超参的性能,随后基于此模型来选择新的超参。 [参考论文](https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf) |
| [**Random Search**](#Random) | 在超参优化时,随机搜索算法展示了其惊人的简单和效果。 建议当不清楚超参的先验分布时,采用随机搜索作为基准。 [参考论文](http://www.jmlr.org/papers/volume13/bergstra12a/bergstra12a.pdf) |
| [**Anneal**](#Anneal) | 这种简单的退火算法从先前的采样开始,会越来越靠近发现的最佳点取样。 此算法是随机搜索的简单变体,利用了反应曲面的平滑性。 退火率不是自适应的。 |
| [**Naive Evolution**](#Evolution) | 朴素进化算法来自于大规模图像分类进化。 它会基于搜索空间随机生成一个种群。 在每一代中,会选择较好的结果,并对其下一代进行一些变异(例如,改动一个超参,增加或减少一层)。 进化算法需要很多次 Trial 才能有效,但它也非常简单,也很容易扩展新功能。 [参考论文](https://arxiv.org/pdf/1703.01041.pdf) |
| [**SMAC**](#SMAC) | SMAC 基于 Sequential Model-Based Optimization (SMBO,即序列的基于模型优化方法)。 它利用使用过的结果好的模型(高斯随机过程模型),并将随机森林引入到 SMBO 中,来处理分类参数。 SMAC 算法包装了 Github 的 SMAC3。 注意:SMAC 需要通过 `nnictl package` 命令来安装。 [参考论文,](https://www.cs.ubc.ca/~hutter/papers/10-TR-SMAC.pdf) [Github 代码库](https://github.com/automl/SMAC3) |
| [**Batch tuner**](#Batch) | Batch Tuner 能让用户简单的提供几组配置(如,超参选项的组合)。 当所有配置都执行完后,Experiment 即结束。 Batch Tuner 仅支持 choice 类型。 |
| [**Grid Search**](#GridSearch) | Grid Search 会穷举定义在搜索空间文件中的所有超参组合。 网格搜索可以使用的类型有 choice, quniform, qloguniform。 quniform 和 qloguniform 中的数值 q 具有特别的含义(不同于搜索空间文档中的说明)。 它表示了在最高值与最低值之间采样的值的数量。 |
| [**Random Search(随机搜索)**](#Random) | 在超参优化时,随机搜索算法展示了其惊人的简单和效果。 建议当不清楚超参的先验分布时,采用随机搜索作为基准。 [参考论文](http://www.jmlr.org/papers/volume13/bergstra12a/bergstra12a.pdf) |
| [**Anneal(退火算法)**](#Anneal) | 这种简单的退火算法从先前的采样开始,会越来越靠近发现的最佳点取样。 此算法是随机搜索的简单变体,利用了反应曲面的平滑性。 退火率不是自适应的。 |
| [**Naive Evolution(进化算法)**](#Evolution) | 朴素进化算法来自于大规模图像分类进化。 它会基于搜索空间随机生成一个种群。 在每一代中,会选择较好的结果,并对其下一代进行一些变异(例如,改动一个超参,增加或减少一层)。 进化算法需要很多次 Trial 才能有效,但它也非常简单,也很容易扩展新功能。 [参考论文](https://arxiv.org/pdf/1703.01041.pdf) |
| [**SMAC**](#SMAC) | SMAC 基于 Sequential Model-Based Optimization (SMBO,即序列的基于模型优化方法)。 它利用使用过的结果好的模型(高斯随机过程模型),并将随机森林引入到 SMBO 中,来处理分类参数。 SMAC 算法包装了 Github 的 SMAC3。 注意:SMAC 需要通过 `nnictl package` 命令来安装。 [参考论文,](https://www.cs.ubc.ca/~hutter/papers/10-TR-SMAC.pdf) [Github 代码库](https://github.com/automl/SMAC3) |
| [**Batch Tuner(批量调参器)**](#Batch) | Batch Tuner 能让用户简单的提供几组配置(如,超参选项的组合)。 当所有配置都执行完后,Experiment 即结束。 Batch Tuner 仅支持 choice 类型。 |
| [**Grid Search(遍历搜索)**](#GridSearch) | Grid Search 会穷举定义在搜索空间文件中的所有超参组合。 网格搜索可以使用的类型有 choice, quniform, qloguniform。 quniform 和 qloguniform 中的数值 q 具有特别的含义(不同于搜索空间文档中的说明)。 它表示了在最高值与最低值之间采样的值的数量。 |
| [**Hyperband**](#Hyperband) | Hyperband 试图用有限的资源来探索尽可能多的组合,并发现最好的结果。 它的基本思路是生成大量的配置,并使用少量的资源来找到有可能好的配置,然后继续训练找到其中更好的配置。 [参考论文](https://arxiv.org/pdf/1603.06560.pdf) |
| [**Network Morphism**](#NetworkMorphism) | Network Morphism 提供了深度学习模型的自动架构搜索功能。 每个子网络都继承于父网络的知识和形态,并变换网络的不同形态,包括深度,宽度,跨层连接(skip-connection)。 然后使用历史的架构和指标,来估计子网络的值。 后会选择最有希望的模型进行训练。 [参考论文](https://arxiv.org/abs/1806.10282) |
| [**Network Morphism**](#NetworkMorphism) | Network Morphism 提供了深度学习模型的自动架构搜索功能。 每个子网络都继承于父网络的知识和形态,并变换网络的不同形态,包括深度,宽度,跨层连接(skip-connection)。 然后使用历史的架构和指标,来估计子网络的值。 后会选择最有希望的模型进行训练。 [参考论文](https://arxiv.org/abs/1806.10282) |
| [**Metis Tuner**](#MetisTuner) | 大多数调参工具仅仅预测最优配置,而 Metis 的优势在于有两个输出:(a) 最优配置的当前预测结果, 以及 (b) 下一次 Trial 的建议。 它不进行随机取样。 大多数工具假设训练集没有噪声数据,但 Metis 会知道是否需要对某个超参重新采样。 [参考论文](https://www.microsoft.com/en-us/research/publication/metis-robustly-tuning-tail-latencies-cloud-systems/) |
| [**BOHB**](#BOHB) | BOHB 是 Hyperband 算法的后续工作。 Hyperband 在生成新的配置时,没有利用已有的 Trial 结果,而本算法利用了 Trial 结果。 BOHB 中,HB 表示 Hyperband,BO 表示贝叶斯优化(Byesian Optimization)。 BOHB 会建立多个 TPE 模型,从而利用已完成的 Trial 生成新的配置。 [参考论文](https://arxiv.org/abs/1807.01774) |
<br />
| [**GP Tuner**](#GPTuner) | Gaussian Process(高斯过程) Tuner 是序列化的基于模型优化(SMBO)的方法,并使用了高斯过程来替代。 [参考论文](https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf)[Github 库](https://github.com/fmfn/BayesianOptimization) |
## 用法
要使用 NNI 内置的 Tuner,需要在 `config.yml` 文件中添加 **builtinTunerName****classArgs**。 这一节会介绍推荐的场景、参数等详细用法以及例。
要使用 NNI 内置的 Tuner,需要在 `config.yml` 文件中添加 **builtinTunerName****classArgs**。 这一节会介绍推荐的场景、参数等详细用法以及例。
注意:参考样例中的格式来创建新的 `config.yml` 文件。 一些内置的 Tuner 还需要通过 `nnictl package` 命令先安装,如 SMAC。
......@@ -112,7 +111,7 @@ tuner:
**建议场景**
此算法对计算资源的需求相对较高。 需要非常大的初始种群,以免落入局部最优中。 如果 Trial 时间很短,或使用了 Assessor,就非常适合此算法。 如果 Trial 代码支持权重迁移,即每次 Trial 会从上一轮继承已经收敛的权重,建议使用此算法。 这会大大提高训练速度。 [详细说明](./EvolutionTuner.md)
此算法对计算资源的需求相对较高。 需要非常大的初始种群,以免落入局部最优中。 如果 Trial 时间很短,或使用了 Assessor,就非常适。 如果 Trial 代码支持权重迁移,即每次 Trial 会从上一轮继承已经收敛的权重,建议使用此算法。 这会大大提高训练速度。 [详细说明](./EvolutionTuner.md)
**示例**
......@@ -327,7 +326,7 @@ tuner:
**安装**
BOHB Advisor 的使用依赖 [ConfigSpace](https://github.com/automl/ConfigSpace) 包,第一次使用 BOHB 的时候,在命令行运行以下的指令来安装 ConfigSpace。
BOHB Advisor 的使用依赖 [ConfigSpace](https://github.com/automl/ConfigSpace) 包,第一次使用 BOHB ,在命令行运行以下命令安装 ConfigSpace。
```bash
nnictl package install --name=BOHB
......@@ -335,7 +334,7 @@ nnictl package install --name=BOHB
**建议场景**
与 Hyperband 类似, 当计算资源有限但搜索空间相对较大时, 建议使用此方法。 中间结果能够很好的反映最终结果的情况下,此算法会非常有效。 在这种情况下, 由于贝叶斯优化使用, 它可能会收敛到更好的配置。 [详细说明](./BohbAdvisor.md)
与 Hyperband 类似当计算资源有限但搜索空间相对较大时建议使用此方法。 中间结果能够很好的反映最终结果的情况下,此算法会非常有效。 在这种情况下, 由于贝叶斯优化使用, 它可能会收敛到更好的配置。 [详细说明](./BohbAdvisor.md)
**参数**
......@@ -363,3 +362,45 @@ advisor:
max_budget: 27
eta: 3
```
<a name="GPTuner"></a>
![](https://placehold.it/15/1589F0/000000?text=+) `GP Tuner`
> 名称:**GPTuner**
注意,搜索空间接受的类型包括 `choice`, `randint`, `uniform`, `quniform`, `loguniform`, `qloguniform`
**建议场景**
作为序列的基于模型的全局优化(SMBO)算法,GP Tuner 使用了代理优化问题(找到采集函数的最大值)。虽然这仍然是个难题,但成本更低(从计算的角度来看),并且有通用的工具。 因此,GP Tuner 适合于函数的优化成本非常高时来使用。 GP 也可在计算资源非常有限时使用。 由于需要反转 Gram 矩阵,GP Tuner 的计算复杂度以 *O(N^3)* 的速度增长,因此不适合于需要大量 Trial 的情形。 [详细说明](./GPTuner.md)
**参数**
* **optimize_mode** (*'maximize' 或 'minimize', 可选项, 默认值为 'maximize'*) - 如果为 'maximize',表示 Tuner 的目标是将指标最大化。 如果为 'minimize',表示 Tuner 的目标是将指标最小化。
* **utility** (*'ei', 'ucb' 或 'poi', 可选, 默认值为 'ei'*) - 工具函数的类型(采集函数)。 'ei', 'ucb' 和 'poi' 分别对应 '期望的改进(Expected Improvement)', '上限置信度边界(Upper Confidence Bound)' 和 '改进概率(Probability of Improvement)'。
* **kappa** (*float, 可选, 默认值为 5*) - 用于 'ucb' 函数。 `kappa` 越大,Tuner 的探索性越高。
* **xi** (*float, 可选, 默认值为 0*) - 用于 'ei' 和 'poi' 函数。 `xi` 越大,Tuner 的探索性越高。
* **nu** (*float, 可选, 默认为 2.5*) - 用于指定 Matern 核。 nu 越小,近似函数的平滑度越低。
* **alpha** (*float, 可选, 默认值为 1e-6*) - 用于高斯过程回归器。 值越大,表示观察中的噪声水平越高。
* **cold_start_num** (*int, 可选, 默认值为 10*) - 在高斯过程前执行随机探索的数量。 随机探索可帮助提高探索空间的广泛性。
* **selection_num_warm_up** (*int, 可选, 默认为 1e5*) - 用于获得最大采集函数而评估的随机点数量。
* **selection_num_starting_points** (*int, 可选, 默认为 250*) - 预热后,从随机七十点运行 L-BFGS-B 的次数。
**示例**
```yaml
# config.yml
tuner:
builtinTunerName: GPTuner
classArgs:
optimize_mode: maximize
utility: 'ei'
kappa: 5.0
xi: 0.0
nu: 2.5
alpha: 1e-6
cold_start_num: 10
selection_num_warm_up: 100000
selection_num_starting_points: 250
```
\ No newline at end of file
# 神经网络结构搜索的对比
*匿名作者*
训练和比较 NAS(神经网络架构搜索)的模型,包括 Autokeras,DARTS,ENAS 和 NAO。
源码链接如下:
- Autokeras: <https://github.com/jhfjhfj1/autokeras>
- DARTS: <https://github.com/quark0/darts>
- ENAS: <https://github.com/melodyguan/enas>
- NAO: <https://github.com/renqianluo/NAO>
## 实验说明
为了避免算法仅仅在 **CIFAR-10** 数据集上过拟合,还对比了包括 Fashion-MNIST, CIFAR-100, OUI-Adience-Age, ImageNet-10-1 (ImageNet的子集) 和 ImageNet-10-2 (ImageNet 的另一个子集) 在内的其它 5 个数据集。 分别从 ImageNet 中抽取 10 种不同类别标签的子集,组成 ImageNet10-1 和 ImageNet10-2 数据集 。
| 数据集 | 训练数据集大小 | 类别标签数 | 数据集说明 |
|:--------------------------------------------------------------------------------------- | ------- | ----- | ----------------------------------------------------------- |
| [Fashion-MNIST](https://github.com/zalandoresearch/fashion-mnist) | 60,000 | 10 | T恤上衣,裤子,套头衫,连衣裙,外套,凉鞋,衬衫,运动鞋,包和踝靴。 |
| [CIFAR-10](https://www.cs.toronto.edu/~kriz/cifar.html) | 50,000 | 10 | 飞机,汽车,鸟类,猫,鹿,狗,青蛙,马,船和卡车。 |
| [CIFAR-100](https://www.cs.toronto.edu/~kriz/cifar.html) | 50,000 | 100 | 和 CIFAR-10 类似,但总共有 100 个类,每个类有 600 张图。 |
| [OUI-Adience-Age](https://talhassner.github.io/home/projects/Adience/Adience-data.html) | 26,580 | 8 | 8 个年龄组类别 (0-2, 4-6, 8-13, 15-20, 25-32, 38-43, 48-53, 60-)。 |
| [ImageNet-10-1](http://www.image-net.org/) | 9,750 | 10 | 咖啡杯、电脑键盘、餐桌、衣柜、割草机、麦克风、秋千、缝纫机、里程表和燃气泵。 |
| [ImageNet-10-2](http://www.image-net.org/) | 9,750 | 10 | 鼓,班吉,口哨,三角钢琴,小提琴,管风琴,原声吉他,长号,长笛和萨克斯。 |
没有改变源码中的 Fine-tuning 方法。 为了匹配每个任务,改变了源码中模型的输入图片大小和输出类别数目的部分。
所有 NAS 方法模型搜索时间和重训练时间都是**两天**。 所有结果都是基于**三次重复实验**。 评估计算机有一块 Nvidia Tesla P100 GPU、112GB 内存和 2.60GHz CPU (Intel E5-2690)。
NAO 需要太多的计算资源,因此只使用提供 Pipeline 脚本的 NAO-WS。
对于 AutoKeras,使用了 0.2.18 版本的代码, 因为这是开始实验时的最新版本。
## NAS 结果对比
| NAS | AutoKeras (%) | ENAS (macro) (%) | ENAS (micro) (%) | DARTS (%) | NAO-WS (%) |
| --------------- |:-------------:|:----------------:|:----------------:|:---------:|:----------:|
| Fashion-MNIST | 91.84 | 95.44 | 95.53 | **95.74** | 95.20 |
| CIFAR-10 | 75.78 | 95.68 | **96.16** | 94.23 | 95.64 |
| CIFAR-100 | 43.61 | 78.13 | 78.84 | **79.74** | 75.75 |
| OUI-Adience-Age | 63.20 | **80.34** | 78.55 | 76.83 | 72.96 |
| ImageNet-10-1 | 61.80 | 77.07 | 79.80 | **80.48** | 77.20 |
| ImageNet-10-2 | 37.20 | 58.13 | 56.47 | 60.53 | **61.20** |
很遗憾,我们无法复现论文中所有的结果。
论文中提供的最佳或平均结果:
| NAS | AutoKeras(%) | ENAS (macro) (%) | ENAS (micro) (%) | DARTS (%) | NAO-WS (%) |
| --------- | ------------ |:----------------:|:----------------:|:--------------:|:-----------:|
| CIFAR- 10 | 88.56(best) | 96.13(best) | 97.11(best) | 97.17(average) | 96.47(best) |
AutoKeras,由于其算法中的随机因素,它在所有数据集中的表现相对较差。
ENAS,ENAS(macro)在 OUI-Adience-Age 数据集中表现较好,并且 ENAS(micro)在 CIFAR-10 数据集中表现较好。
对于DARTS,在某些数据集上具有良好的结果,但在某些数据集中具有比较大的方差。 DARTS 三次实验中的差异在 OUI-Audience-Age 数据集上可达 5.37%(绝对值),在 ImageNet-10-1 数据集上可达4.36%(绝对值)。
NAO-WS 在 ImageNet-10-2 中表现良好,但在 OUI-Adience-Age 中表现非常差。
## 参考文献
1. Jin, Haifeng, Qingquan Song, and Xia Hu. "Efficient neural architecture search with network morphism." *arXiv preprint arXiv:1806.10282* (2018).
2. Liu, Hanxiao, Karen Simonyan, and Yiming Yang. "Darts: Differentiable architecture search." arXiv preprint arXiv:1806.09055 (2018).
3. Pham, Hieu, et al. "Efficient Neural Architecture Search via Parameters Sharing." international conference on machine learning (2018): 4092-4101.
4. Luo, Renqian, et al. "Neural Architecture Optimization." neural information processing systems (2018): 7827-7838.
\ No newline at end of file
......@@ -98,8 +98,11 @@
| HyperBand | 0.414065 | 0.415222 | 0.417628 |
| HyperBand | 0.416807 | 0.417549 | 0.418828 |
| HyperBand | 0.415550 | 0.415977 | 0.417186 |
| GP | 0.414353 | 0.418563 | 0.420263 |
| GP | 0.414395 | 0.418006 | 0.420431 |
| GP | 0.412943 | 0.416566 | 0.418443 |
Metis 算法因为其高斯计算过程的复杂度为 O(n^3) 而运行非常慢,因此仅执行了 300 次 Trial。
此例中,所有算法都使用了默认参数。 Metis 算法因为其高斯计算过程的复杂度为 O(n^3) 而运行非常慢,因此仅执行了 300 次 Trial。
## RocksDB 的 'fillrandom' 和 'readrandom' 基准测试
......
# 超参数优化的对比
*匿名作者*
超参优化算法在几个问题上的对比。
超参数优化算法如下:
- [Random Search(随机搜索)](../Builtin_Tuner.md#Random)
- [Grid Search(遍历搜索)](../Builtin_Tuner.md#Random)
- [Evolution](../Builtin_Tuner.md#Evolution)
- [Anneal(退火算法)](../Builtin_Tuner.md#Anneal)
- [Metis](../Builtin_Tuner.md#MetisTuner)
- [TPE](../Builtin_Tuner.md#TPE)
- [SMAC](../Builtin_Tuner.md#SMAC)
- [HyperBand](../Builtin_Tuner.md#Hyperband)
- [BOHB](../Builtin_Tuner.md#BOHB)
所有算法都在 NNI 本机环境下运行。
环境:
OS: Linux Ubuntu 16.04 LTS
CPU: Intel(R) Xeon(R) CPU E5-2690 v3 @ 2.60GHz 2600 MHz
Memory: 112 GB
NNI Version: v0.7
NNI 模式(local|pai|remote): local
Python 版本: 3.6
使用的虚拟环境: Conda
是否在 Docker 中运行: no
## AutoGBDT 示例
### 问题描述
超参搜索上的非凸问题 [AutoGBDT](../gbdt_example.md)
### 搜索空间
```json
{
"num_leaves": {
"_type": "choice",
"_value": [10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 48, 64, 96, 128]
},
"learning_rate": {
"_type": "choice",
"_value": [0.00001, 0.0001, 0.001, 0.01, 0.05, 0.1, 0.2, 0.5]
},
"max_depth": {
"_type": "choice",
"_value": [-1, 2, 3, 4, 5, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 48, 64, 96, 128]
},
"feature_fraction": {
"_type": "choice",
"_value": [0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]
},
"bagging_fraction": {
"_type": "choice",
"_value": [0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]
},
"bagging_freq": {
"_type": "choice",
"_value": [1, 2, 4, 8, 10, 12, 14, 16]
}
}
```
总搜索空间为 1, 204, 224 次,将最大 Trial 次数设置为1000。 时间限制为 48 小时。
### 结果
| 算法 | 最好的损失值 | 最好的 5 次损失的平均值 | 最好的 10 次损失的平均 |
| ------------------- | ------------ | ------------- | ------------- |
| Random Search(随机搜索) | 0.418854 | 0.420352 | 0.421553 |
| Random Search(随机搜索) | 0.417364 | 0.420024 | 0.420997 |
| Random Search(随机搜索) | 0.417861 | 0.419744 | 0.420642 |
| Grid Search(遍历搜索) | 0.498166 | 0.498166 | 0.498166 |
| Evolution | 0.409887 | 0.409887 | 0.409887 |
| Evolution | 0.413620 | 0.413875 | 0.414067 |
| Evolution | 0.409887 | 0.409887 | 0.409887 |
| Anneal(退火算法) | 0.414877 | 0.417289 | 0.418281 |
| Anneal(退火算法) | 0.409887 | 0.409887 | 0.410118 |
| Anneal(退火算法) | 0.413683 | 0.416949 | 0.417537 |
| Metis | 0.416273 | 0.420411 | 0.422380 |
| Metis | 0.420262 | 0.423175 | 0.424816 |
| Metis | 0.421027 | 0.424172 | 0.425714 |
| TPE | 0.414478 | 0.414478 | 0.414478 |
| TPE | 0.415077 | 0.417986 | 0.418797 |
| TPE | 0.415077 | 0.417009 | 0.418053 |
| SMAC | **0.408386** | **0.408386** | **0.408386** |
| SMAC | 0.414012 | 0.414012 | 0.414012 |
| SMAC | **0.408386** | **0.408386** | **0.408386** |
| BOHB | 0.410464 | 0.415319 | 0.417755 |
| BOHB | 0.418995 | 0.420268 | 0.422604 |
| BOHB | 0.415149 | 0.418072 | 0.418932 |
| HyperBand | 0.414065 | 0.415222 | 0.417628 |
| HyperBand | 0.416807 | 0.417549 | 0.418828 |
| HyperBand | 0.415550 | 0.415977 | 0.417186 |
Metis 算法因为其高斯计算过程的复杂度为 O(n^3) 而运行非常慢,因此仅执行了 300 次 Trial。
## RocksDB 的 'fillrandom' 和 'readrandom' 基准测试
### 问题描述
[DB_Bench](https://github.com/facebook/rocksdb/wiki/Benchmarking-tools) 是用来做 [RocksDB](https://rocksdb.org/) 性能基准测试的工具。 有多个参数需要调优。
`DB_Bench` 的性能与计算机配置和安装方法有关。 在 `DB_Bench` Linux 系统上运行,并将 Rock 作为共享库安装。
#### 计算机配置
RocksDB: version 6.1
CPU: 6 * Intel(R) Xeon(R) CPU E5-2690 v4 @ 2.60GHz
CPUCache: 35840 KB
Keys: 16 bytes each
Values: 100 bytes each (50 bytes after compression)
Entries: 1000000
#### 存储性能
**延迟**:每个 IO 请求都需要一些时间才能完成,这称为平均延迟。 有几个因素会影响此时间,包括网络连接质量和硬盘IO性能。
**IOPS****每秒的 IO 操作数量**,这意味着可以在一秒钟内完成的*读取或写入操作次数*
**IO 大小****每个 IO 请求的大小**。 根据操作系统和需要磁盘访问的应用程序、服务,它将同时发出读取或写入一定数量数据的请求。
**吞吐量(以 MB/s 为单位)= 平均 IO 大小 x IOPS **
IOPS 与在线处理能力有关,我们在实验中使用 IOPS 作为指标。
### 搜索空间
```json
{
"max_background_compactions": {
"_type": "quniform",
"_value": [1, 256, 1]
},
"block_size": {
"_type": "quniform",
"_value": [1, 500000, 1]
},
"write_buffer_size": {
"_type": "quniform",
"_value": [1, 130000000, 1]
},
"max_write_buffer_number": {
"_type": "quniform",
"_value": [1, 128, 1]
},
"min_write_buffer_number_to_merge": {
"_type": "quniform",
"_value": [1, 32, 1]
},
"level0_file_num_compaction_trigger": {
"_type": "quniform",
"_value": [1, 256, 1]
},
"level0_slowdown_writes_trigger": {
"_type": "quniform",
"_value": [1, 1024, 1]
},
"level0_stop_writes_trigger": {
"_type": "quniform",
"_value": [1, 1024, 1]
},
"cache_size": {
"_type": "quniform",
"_value": [1, 30000000, 1]
},
"compaction_readahead_size": {
"_type": "quniform",
"_value": [1, 30000000, 1]
},
"new_table_reader_for_compaction_inputs": {
"_type": "randint",
"_value": [1]
}
}
```
搜索空间非常大(约10 的 40 次方),将最大 Trial 次数设置为 100 以限制资源。
### 结果
#### fillrandom 基准
| 模型 | 最高 IOPS(重复 1 次) | 最高 IOPS(重复 2 次) | 最高 IOPS(重复 3 次) |
| ------------ | --------------- | --------------- | --------------- |
| Random | 449901 | 427620 | 477174 |
| Anneal(退火算法) | 461896 | 467150 | 437528 |
| Evolution | 436755 | 389956 | 389790 |
| TPE | 378346 | 482316 | 468989 |
| SMAC | 491067 | 490472 | **491136** |
| Metis | 444920 | 457060 | 454438 |
图:
![](../../img/hpo_rocksdb_fillrandom.png)
#### readrandom 基准
| 模型 | 最高 IOPS(重复 1 次) | 最高 IOPS(重复 2 次) | 最高 IOPS(重复 3 次) |
| ------------ | --------------- | --------------- | --------------- |
| Random | 2276157 | 2285301 | 2275142 |
| Anneal(退火算法) | 2286330 | 2282229 | 2284012 |
| Evolution | 2286524 | 2283673 | 2283558 |
| TPE | 2287366 | 2282865 | 2281891 |
| SMAC | 2270874 | 2284904 | 2282266 |
| Metis | **2287696** | 2283496 | 2277701 |
图:
![](../../img/hpo_rocksdb_readrandom.png)
\ No newline at end of file
......@@ -46,7 +46,7 @@
## 文档
文档使用了 [sphinx](http://sphinx-doc.org/) 来生成,支持 [Markdown](https://guides.github.com/features/mastering-markdown/)[reStructuredText](http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html) 格式。 所有文档都在 <docs> 目录下。
文档使用了 [sphinx](http://sphinx-doc.org/) 来生成,支持 [Markdown](https://guides.github.com/features/mastering-markdown/)[reStructuredText](http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html) 格式。 所有文档都在 [docs/zh_CN](docs) 目录下。
* 在提交文档改动前,请先**在本地生成文档**`cd docs/zh_CN && make html`,然后,可以在 `docs/zh_CN/_build/html` 目录下找到所有生成的网页。 请认真分析生成日志中的**每个 WARNING**,这非常有可能是或**空连接**或其它问题。
......
......@@ -31,7 +31,7 @@ class CustomizedTuner(Tuner):
def __init__(self, ...):
...
def receive_trial_result(self, parameter_id, parameters, value):
def receive_trial_result(self, parameter_id, parameters, value, **kwargs):
'''
接收 Trial 的最终结果。
parameter_id: int
......@@ -41,7 +41,7 @@ class CustomizedTuner(Tuner):
# 实现代码
...
def generate_parameters(self, parameter_id):
def generate_parameters(self, parameter_id, **kwargs):
'''
返回 Trial 的超参组合的序列化对象
parameter_id: int
......@@ -51,14 +51,14 @@ class CustomizedTuner(Tuner):
...
```
`receive_trial_result` 从输入中会接收 `parameter_id, parameters, value` 参数。 Tuner 会收到 Trial 进程发送的完全一样的 `value` 值。
`receive_trial_result` 从输入中会接收 `parameter_id, parameters, value` 参数。 Tuner 会收到 Trial 进程发送的完全一样的 `value` 值。 如果在 Experiment 配置文件里 `multiPhase``true`, 会有一个附加的 `trial_job_id``**kwargs` 参数中返回给 `receive_trial_result``generate_parameters`
`generate_parameters` 函数返回的 `your_parameters`,会被 NNI SDK 打包为 json。 然后 SDK 会将 json 对象解包给 Trial 进程。因此,Trial 进程会收到来自 Tuner 的完全相同的 `your_parameters`
例如: 如下实现了 `generate_parameters`
```python
def generate_parameters(self, parameter_id):
def generate_parameters(self, parameter_id, **kwargs):
'''
返回 Trial 的超参组合的序列化对象
parameter_id: int
......
......@@ -2,10 +2,10 @@
创建 Experiment 时,需要给 nnictl 命令提供配置文件的路径。 配置文件是 YAML 格式,需要保证其格式正确。 本文介绍了配置文件的内容,并提供了一些示例和模板。
- [Experiment(实验)配置参考](#experiment-config-reference)
- [模板](#template)
- [说明](#configuration-spec)
- [样例](#examples)
- [Experiment(实验)配置参考](#Experiment-config-reference)
- [模板](#Template)
- [说明](#Configuration-spec)
- [样例](#Examples)
<a name="Template"></a>
......@@ -128,14 +128,17 @@ machineList:
- 说明
**authorName** 是创建 Experiment 的作者。 待定: 增加默认值
**authorName** 是创建 Experiment 的作者。
待定: 增加默认值
- **experimentName**
- 说明
**experimentName** 是 Experiment 的名称。
待实现:增加默认值
**experimentName** 是创建的 Experiment 的名称。
待定: 增加默认值
- **trialConcurrency**
......@@ -153,11 +156,17 @@ machineList:
注意:maxExecDuration 设置的是 Experiment 执行的时间,不是 Trial 的。 如果 Experiment 达到了设置的最大时间,Experiment 不会停止,但不会再启动新的 Trial 作业。
- **versionCheck**
- 说明
NNI 会校验 remote, pai 和 Kubernetes 模式下 NNIManager 与 trialKeeper 进程的版本。 如果需要禁用版本校验,versionCheck 应设置为 false。
- **debug**
- 说明
NNI 会校验 remote, pai 和 Kubernetes 模式下 NNIManager 与 trialKeeper 进程的版本。 如果需要禁用版本校验,debug 应设置为 true
调试模式会将 versionCheck 设置为 False,并将 logLevel 设置为 'debug'
- **maxTrialNum**
......@@ -171,7 +180,7 @@ machineList:
**trainingServicePlatform** 定义运行 Experiment 的平台,包括:{**local**, **remote**, **pai**, **kubeflow**}.
- **local** 在本机的 ubuntu 上运行 Experiment。
- **local** 在本机的 Ubuntu 上运行 Experiment。
- **remote** 将任务提交到远程的 Ubuntu 上,必须用 **machineList** 来指定远程的 SSH 连接信息。
......@@ -259,7 +268,7 @@ machineList:
__gpuNum__ 指定了运行 Tuner 进程的 GPU 数量。 此字段的值必须是正整数。
注意: 只能使用一种方法来指定 Tuner,例如:设置{tunerName, optimizationMode} 或 {tunerCommand, tunerCwd},不能同时设置。
注意: 只能使用一种方法来指定 Tuner,例如:设置 {tunerName, optimizationMode} 或 {tunerCommand, tunerCwd},不能同时设置两者
- **includeIntermediateResults**
......@@ -281,7 +290,7 @@ machineList:
- **classArgs**
**classArgs** 指定了 Assessor 算法的参数
**classArgs** 指定了 Assessor 算法的参数
- **codeDir**, **classFileName**, **className****classArgs**
......@@ -495,7 +504,7 @@ machineList:
- **keyVault**
如果用户使用 Azure Kubernetes Service,需要设置 keyVault 来使用 Azure 存储账户的私钥。 参考: https://docs.microsoft.com/en-us/azure/key-vault/key-vault-manage-with-cli2
如果用户使用 Azure Kubernetes Service,需要设置 keyVault 来使用 Azure 存储账户的私钥。 参考: https://docs.microsoft.com/zh-cn/azure/key-vault/key-vault-manage-with-cli2
- **vaultName**
......
# **在 FrameworkController 上运行 Experiment**
# 在 FrameworkController 上运行 Experiment
NNI 支持使用 [FrameworkController](https://github.com/Microsoft/frameworkcontroller),来运行 Experiment,称之为 frameworkcontroller 模式。 FrameworkController 构建于 Kubernetes 上,用于编排各种应用。这样,可以不用为某个深度学习框架安装 Kubeflow 的 tf-operator 的 pytorch-operator 等。 而直接用 FrameworkController 作为 NNI Experiment 的训练服务。
=== NNI 支持使用 [FrameworkController](https://github.com/Microsoft/frameworkcontroller),来运行 Experiment,称之为 frameworkcontroller 模式。 FrameworkController 构建于 Kubernetes 上,用于编排各种应用。这样,可以不用为某个深度学习框架安装 Kubeflow 的 tf-operator 的 pytorch-operator 等。 而直接用 FrameworkController 作为 NNI Experiment 的训练服务。
## 私有部署的 Kubernetes 的准备工作
......@@ -8,54 +8,59 @@ NNI 支持使用 [FrameworkController](https://github.com/Microsoft/frameworkcon
2. 配置 **kubeconfig** 文件,NNI 将使用此配置与 Kubernetes API 服务交互。 默认情况下,NNI 管理器会使用 $(HOME)/.kube/config 作为 kubeconfig 文件的路径。 也可以通过环境变量 **KUBECONFIG** 来指定其它 kubeconfig 文件。 根据[指南](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig)了解更多 kubeconfig 的信息。
3. 如果 NNI Trial 作业需要 GPU 资源,需按照[指南](https://github.com/NVIDIA/k8s-device-plugin)来配置 **Kubernetes 下的 Nvidia 插件**
4. 准备 **NFS 服务器** 并导出通用的装载 (mount),推荐将 NFS 服务器路径映射到 `root_squash 选项`,否则可能会在 NNI 复制文件到 NFS 时出现权限问题。 参考[页面](https://linux.die.net/man/5/exports),来了解关于 root_squash 选项,或 **Azure File Storage**
5. 在安装 NNI 并运行 nnictl 的计算机上安装 **NFS 客户端**。 运行此命令安装 NFSv4 客户端: ```apt-get install nfs-common```
5. 在安装 NNI 并运行 nnictl 的计算机上安装 **NFS 客户端**。 运行此命令安装 NFSv4 客户端:
```bash
apt-get install nfs-common
```
6. 参考[指南](QuickStart.md)安装 **NNI**
## Azure 部署的 Kubernetes 的准备工作
1. NNI 支持基于 Azure Kubernetes Service 的 Kubeflow,参考[指南](https://azure.microsoft.com/en-us/services/kubernetes-service/)来设置 Azure Kubernetes Service。
2. 安装 [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)**kubectl**。 使用 `az login` 命令来设置 Azure 账户吗,并将 kubectl 客户端连接到 AKS,参考此[指南](https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough#connect-to-the-cluster)
3. 参考此[指南](https://docs.microsoft.com/en-us/azure/storage/common/storage-quickstart-create-account?tabs=portal)来创建 Azure 文件存储账户。 NNI 需要 Azure Storage Service 来存取代码和输出文件。
4. NNI 需要访问密钥来连接 Azure 存储服务,NNI 使用 [Azure Key Vault](https://azure.microsoft.com/en-us/services/key-vault/) 服务来保护私钥。 设置 Azure Key Vault 服务,并添加密钥到 Key Vault 中来存取 Azure 存储账户。 参考[指南](https://docs.microsoft.com/en-us/azure/key-vault/quick-create-cli)来存储访问密钥。
1. NNI 支持基于 Azure Kubernetes Service 的 Kubeflow,参考[指南](https://azure.microsoft.com/zh-cn/services/kubernetes-service/)来设置 Azure Kubernetes Service。
2. 安装 [Azure CLI](https://docs.microsoft.com/zh-cn/cli/azure/install-azure-cli?view=azure-cli-latest)**kubectl**。 使用 `az login` 命令来设置 Azure 账户吗,并将 kubectl 客户端连接到 AKS,参考此[指南](https://docs.microsoft.com/zh-cn/azure/aks/kubernetes-walkthrough#connect-to-the-cluster)
3. 参考此[指南](https://docs.microsoft.com/zh-cn/azure/storage/common/storage-quickstart-create-account?tabs=portal)来创建 Azure 文件存储账户。 NNI 需要 Azure Storage Service 来存取代码和输出文件。
4. NNI 需要访问密钥来连接 Azure 存储服务,NNI 使用 [Azure Key Vault](https://azure.microsoft.com/zh-cn/services/key-vault/) 服务来保护私钥。 设置 Azure Key Vault 服务,并添加密钥到 Key Vault 中来存取 Azure 存储账户。 参考[指南](https://docs.microsoft.com/zh-cn/azure/key-vault/quick-create-cli)来存储访问密钥。
## 安装 FrameworkController
参考[指南](https://github.com/Microsoft/frameworkcontroller/tree/master/example/run)来在 Kubernetes 集群中配置 Frameworkcontroller。NNI 通过 statefulset 模式来 支持 Frameworkcontroller。
参考[指南](https://github.com/Microsoft/frameworkcontroller/tree/master/example/run)来在 Kubernetes 集群中配置 FrameworkController。NNI 通过 statefulset 模式来 支持 FrameworkController。
## 设计
参考[Kubeflow 训练服务](./KubeflowMode.md),Frameworkcontroller 服务管道非常类似。
参考[Kubeflow 训练服务](./KubeflowMode.md),FrameworkController 服务管道非常类似。
## 样例
Frameworkcontroller 配置文件的格式如下:
authorName: default
experimentName: example_mnist
trialConcurrency: 1
maxExecDuration: 10h
maxTrialNum: 100
#可选项: local, remote, pai, kubeflow, frameworkcontroller
trainingServicePlatform: frameworkcontroller
searchSpacePath: ~/nni/examples/trials/mnist/search_space.json
#可选项: true, false
useAnnotation: false
tuner:
FrameworkController 配置文件的格式如下:
```yaml
authorName: default
experimentName: example_mnist
trialConcurrency: 1
maxExecDuration: 10h
maxTrialNum: 100
#可选项: local, remote, pai, kubeflow, frameworkcontroller
trainingServicePlatform: frameworkcontroller
searchSpacePath: ~/nni/examples/trials/mnist/search_space.json
#可选项: true, false
useAnnotation: false
tuner:
#可选项: TPE, Random, Anneal, Evolution
builtinTunerName: TPE
classArgs:
#可选项: maximize, minimize
optimize_mode: maximize
assessor:
assessor:
builtinAssessorName: Medianstop
classArgs:
optimize_mode: maximize
gpuNum: 0
trial:
trial:
codeDir: ~/nni/examples/trials/mnist
taskRoles:
- name: worker
taskNum: 1
command: python3 mnist.py
......@@ -66,16 +71,17 @@ Frameworkcontroller 配置文件的格式如下:
frameworkAttemptCompletionPolicy:
minFailedTaskCount: 1
minSucceededTaskCount: 1
frameworkcontrollerConfig:
frameworkcontrollerConfig:
storage: nfs
nfs:
server: {your_nfs_server}
path: {your_nfs_server_exported_path}
```
如果使用了 Azure Kubernetes Service,需要在 YAML 文件中如下设置 `frameworkcontrollerConfig`
frameworkcontrollerConfig:
```yaml
frameworkcontrollerConfig:
storage: azureStorage
keyVault:
vaultName: {your_vault_name}
......@@ -83,11 +89,12 @@ Frameworkcontroller 配置文件的格式如下:
azureStorage:
accountName: {your_storage_account_name}
azureShare: {your_azure_share_name}
```
注意:如果用 FrameworkController 模式运行,需要在 YAML 文件中显式设置 `trainingServicePlatform: frameworkcontroller`
FrameworkController 模式的 Trial 配置格式,是 FrameworkController 官方配置的简化版。参考 [frameworkcontroller 的 tensorflow 样例](https://github.com/Microsoft/frameworkcontroller/blob/master/example/framework/scenario/tensorflow/cpu/tensorflowdistributedtrainingwithcpu.yaml) 了解详情。
frameworkcontroller 模式中的 Trial 配置使用以下主键:
* taskRoles: 配置文件中可以设置多个任务角色,每个任务角色都是在 Kubernetes 集群中的基本执行单元。
......@@ -98,11 +105,11 @@ frameworkcontroller 模式中的 Trial 配置使用以下主键:
* cpuNum: 容器中要使用的 CPU 数量。
* memoryMB: 容器的内存限制。
* image: 用来创建 pod,并运行程序的 Docker 映像。
* frameworkAttemptCompletionPolicy: 运行框架的策略,参考[用户手册](https://github.com/Microsoft/frameworkcontroller/blob/master/doc/user-manual.md#frameworkattemptcompletionpolicy)了解更多信息。 这些策略可以用来控制 pod,例如,如果 worker 任务停止了,但 ps 没有停止,CompletionPolicy 策略可以停止 ps。
* frameworkAttemptCompletionPolicy: 运行框架的策略,参考[用户手册](https://github.com/Microsoft/frameworkcontroller/blob/master/doc/user-manual.md#frameworkattemptcompletionpolicy)了解更多信息。 这些策略可以用来控制 pod,例如,如果 worker 任务停止了,但 ps 还在运行,要通过完成策略来停止 ps。
## 如何运行示例
准备好配置文件后,通过运行 nnictl 来启动 Experiment。 在 Frameworkcontroller 上开始 Experiment 的方法与 Kubeflow 类似,可参考[指南](./KubeflowMode.md)了解更多信息。
准备好配置文件后,通过运行 nnictl 来启动 Experiment。 在 FrameworkController 上开始 Experiment 的方法与 Kubeflow 类似,可参考[指南](./KubeflowMode.md)了解更多信息。
## 版本校验
......
# NNI 中的 GP Tuner
## GP Tuner
贝叶斯优化会构建一个能最好的描述优化目标的后验分布函数(使用高斯过程)。 随着观测值的增加,后验分布会得到改善,会在参数空间中确定哪些范围值得进一步探索,哪一些不值得。
GP Tuner 被设计为通过最大化或最小化步数来找到最接近最优结果的参数组合。 GP Tuner 使用了代理优化问题(找到采集函数的最大值)。虽然这仍然是个难题,但成本更低(从计算的角度来看),并且有通用的工具。 因此,贝叶斯优化适合于采样函数的成本非常高时来使用。
优化方法在 [Algorithms for Hyper-Parameter Optimization](https://papers.nips.cc/paper/4443-algorithms-for-hyper-parameter-optimization.pdf) 的第三章有详细描述。
\ No newline at end of file
......@@ -8,8 +8,9 @@ TrainingService 是与平台管理、任务调度相关的模块。 TrainingServ
![](../img/NNIDesign.jpg)
NNI 的架构如图所示。 NNIManager 是系统的核心管理模块,负责调用 TrainingService 来管理 Trial,并负责不同模块之间的通信。 Dispatcher 是消息处理中心。 TrainingService 是管理任务的模块,它和 NNIManager 通信,并且根据平台的特点有不同的实现。 当前,NNI 支持本地平台、[远程平台](RemoteMachineMode.md)[OpenPAI 平台](PaiMode.md)[Kubeflow 平台](KubeflowMode.md)[FrameworkController 平台](FrameworkController.md)
在这个文档中,会简要介绍 TrainingService 的设计。 如果要添加新的 TrainingService,只需要继承 TrainingServcie 类并实现相应的方法,不需要理解NNIManager、Dispatcher 等其它模块的细节。
NNI 的架构如图所示。 NNIManager 是系统的核心管理模块,负责调用 TrainingService 来管理 Trial,并负责不同模块之间的通信。 Dispatcher 是消息处理中心。 TrainingService 是管理任务的模块,它和 NNIManager 通信,并且根据平台的特点有不同的实现。 当前,NNI 支持本机,[远程平台](RemoteMachineMode.md)[OpenPAI 平台](PaiMode.md)[Kubeflow 平台](KubeflowMode.md) 以及 [FrameworkController 平台](FrameworkController.md)
本文中,会介绍 TrainingService 的简要设计。 如果要添加新的 TrainingService,只需要继承 TrainingServcie 类并实现相应的方法,不需要理解NNIManager、Dispatcher 等其它模块的细节。
## 代码文件夹结构
......@@ -67,7 +68,8 @@ NNI 的文件夹结构如下:
TrainingService 父类有一些抽象方法,用户需要继承并实现这些抽象方法。
**setClusterMetadata(key: string, value: string)**
ClusterMetadata 是与平台数据有关的方法,例如,在远程平台上的 ClusterMetadata 定义是:
ClusterMetadata 是与平台细节相关的数据,例如,ClusterMetadata 在远程服务器的定义是:
export class RemoteMachineMeta {
public readonly ip : string;
......@@ -96,10 +98,12 @@ ClusterMetadata 是与平台数据有关的方法,例如,在远程平台上
Metadata 中包括了主机地址,用户名和其它平台相关配置。 用户需要定义自己的 Metadata 格式,并在这个方法中相应实现。 这个方法在 Experiment 启动之前调用。
**getClusterMetadata(key: string)**
这个方法返回 metadata 的内容,如果不需要使用这个方法,可将方法内容留空。
此函数将返回相应值的元数据值,如果不需要使用,可留空。
**submitTrialJob(form: JobApplicationForm)**
SubmitTrialJob 是用来提交 Trial 任务的方法,用户需要在这个方法中生成 TrialJobDetail 类型的实例。 TrialJobDetail 定义如下:
SubmitTrialJob 是用来提交新 Trial 任务的函数,需要生成一个 TrialJobDetail 类型的任务实例。 TrialJobDetail 定义如下:
interface TrialJobDetail {
readonly id: string;
......@@ -119,36 +123,49 @@ SubmitTrialJob 是用来提交 Trial 任务的方法,用户需要在这个方
根据不同的实现,用户可能需要把 Trial 任务放入队列中,并不断地从队里中取出任务进行提交。 或者也可以直接在这个方法中完成作业提交过程。
**cancelTrialJob(trialJobId: string, isEarlyStopped?: boolean)**
如果这个方法被调用, Trial 应该被取消执行。 不同的平台有不同的取消作业的方式,这个方法应该根据不同平台的特点,实现相应的细节。
如果此函数被调用,应取消平台启动的 Trial。 不同的平台有不同的取消作业的方式,这个方法应该根据不同平台的特点,实现相应的细节。
**updateTrialJob(trialJobId: string, form: JobApplicationForm)**
这个方法用来更新 Trial 的状态,不同平台有不同的检测作业状态的方法,并把状态更新为`RUNNING`, `SUCCEED`, `FAILED` 等。
调用此函数可更新 Trial 的任务状态,Trial 任务状态根据不同的平台来检测,并需要更新为 `RUNNING`, `SUCCEED`, `FAILED` 等状态。
**getTrialJob(trialJobId: string)**
这个方法用来根据 Trial Id 来返回相应的 Trial 实例。
此函数根据 trialJobId 返回 trialJob 的实例。
**listTrialJobs()**
用户需要在这个方法中把所有的 Trial 实例放入一个列表中,并返回。
用户需要将所有 Trial 任务详情存入列表并返回。
**addTrialJobMetricListener(listener: (metric: TrialJobMetric) => void)**
NNI 会启动一个 EventEmitter 来处理作业的指标数据,如果有检测到有新的数据,EventEmitter就会被触发,来执行相应的事件。 用户需要在这个方法中开始 EventEmitter。
NNI 会启动一个 EventEmitter 来处理任务的指标数据,如果有检测到有新的数据,EventEmitter就会被触发,来执行相应的事件。 用户需要在这个方法中开始 EventEmitter。
**removeTrialJobMetricListener(listener: (metric: TrialJobMetric) => void)**
移除 EventEmitter。
关闭 EventEmitter。
**run()**
Run() 函数是 TrainingService 的主循环,用户可以在这个函数中循环执行他们的代码逻辑,这个函数在实验结束前会一直循环执行。
**cleanUp()**
当实验结束后,这个方法用来清除实验环境。 用户需要在这个方法中实现与平台相关的清除操作。
当实验结束后,此方法用来清除实验环境。 用户需要在这个方法中实现与平台相关的清除操作。
## TrialKeeper 工具
NNI 提供了 TrialKeeper 工具,用来帮助维护 Trial 任务。 可以在 `nni/tools/nni_trial_tool` 文件夹中找到 TrialKeeper 的源代码。 如果想要运行在云平台上,这是维护任务的好工具。 TrialKeeper 的架构如下:
NNI 提供了 TrialKeeper 工具,用来帮助维护 Trial 任务。 可以在 `nni/tools/nni_trial_tool` 文件夹中找到 TrialKeeper 的源代码。 如果想要运行在云平台上,这是维护任务的好工具。
TrialKeeper 的架构如下:
![](../img/trialkeeper.jpg)
当用户需要在远程云平台上运行作业,要把作业启动的命令行传入 TrailKeeper 中,并在远程云平台上启动 TriakKeeper 进程。 注意,TrialKeeper 在远程平台中使用 RESTful 服务来和 TrainingService 进行通信,用户需要在本地机器启动一个 RESTful 服务来接受 TrialKeeper 的请求。 关于 RESTful 服务的源代码可以在 `nni/src/nni_manager/training_service/common/clusterJobRestServer.ts` 文件夹中找到.
当用户需要在远程云平台上运行作业,要把作业启动的命令行传入 TrailKeeper 中,并在远程云平台上启动 TrailKeeper 进程。 注意,TrialKeeper 在远程平台中使用 RESTful 服务来和 TrainingService 进行通信,用户需要在本地机器启动一个 RESTful 服务来接受 TrialKeeper 的请求。 关于 RESTful 服务的源代码可以在 `nni/src/nni_manager/training_service/common/clusterJobRestServer.ts` 文件夹中找到.
## 参考
更多关于如何调试的信息,请[参考这里](HowToDebug.md)
关于如何贡献代码,请[参考这里](Contributing.md)
\ No newline at end of file
有关调试的进一步信息,可参考[这里](HowToDebug.md)
如何参与贡献的指南,请参考[这里](Contributing.md)
\ No newline at end of file
......@@ -28,12 +28,6 @@
## **在 Windows 上安装**
在第一次使用 PowerShell 运行脚本时,需要用**使用管理员权限**运行如下命令:
```powershell
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
```
推荐使用 Anaconda 或 Miniconda。
* **通过 pip 命令安装 NNI**
......@@ -48,12 +42,10 @@ Set-ExecutionPolicy -ExecutionPolicy Unrestricted
先决条件:`python >=3.5`, `git`, `PowerShell`
然后可以使用管理员或当前用户安装 NNI:
```bash
git clone -b v0.8 https://github.com/Microsoft/nni.git
cd nni
powershell .\install.ps1
powershell -ExecutionPolicy Bypass -file install.ps1
```
## **系统需求**
......
# **在 Kubeflow 上运行 Experiment**
# 在 Kubeflow 上运行 Experiment
NNI 支持在 [Kubeflow](https://github.com/kubeflow/kubeflow)上运行,称为 kubeflow 模式。 在开始使用 NNI 的 kubeflow 模式前,需要有一个 kubernetes 集群,可以是私有部署的,或者是 [Azure Kubernetes Service(AKS)](https://azure.microsoft.com/en-us/services/kubernetes-service/),并需要一台配置好 [kubeconfig](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) 的 Ubuntu 计算机连接到此 kubernetes 集群。 如果不熟悉 Kubernetes,可先浏览[这里](https://kubernetes.io/docs/tutorials/kubernetes-basics/)。 在 kubeflow 模式下,每个 Trial 程序会在 Kubernetes 集群中作为一个 kubeflow 作业来运行。
===
NNI 支持在 [Kubeflow](https://github.com/kubeflow/kubeflow)上运行,称为 kubeflow 模式。 在开始使用 NNI 的 Kubeflow 模式前,需要有一个 Kubernetes 集群,可以是私有部署的,或者是 [Azure Kubernetes Service(AKS)](https://azure.microsoft.com/zh-cn/services/kubernetes-service/),并需要一台配置好 [kubeconfig](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/) 的 Ubuntu 计算机连接到此 Kubernetes 集群。 如果不熟悉 Kubernetes,可先浏览[这里](https://kubernetes.io/docs/tutorials/kubernetes-basics/)。 在 kubeflow 模式下,每个 Trial 程序会在 Kubernetes 集群中作为一个 Kubeflow 作业来运行。
## 私有部署的 Kubernetes 的准备工作
1. 采用 Kubernetes 1.8 或更高版本。 根据[指南](https://kubernetes.io/docs/setup/)来安装 Kubernetes。
2. 在 Kubernetes 集群中下载、安装、部署 **Kubelow**。 根据[指南](https://www.kubeflow.org/docs/started/getting-started/)安装 Kubeflow。
2. 在 Kubernetes 集群中下载、安装、部署 **Kubeflow**。 根据[指南](https://www.kubeflow.org/docs/started/getting-started/)安装 Kubeflow。
3. 配置 **kubeconfig** 文件,NNI 将使用此配置与 Kubernetes API 服务交互。 默认情况下,NNI 管理器会使用 $(HOME)/.kube/config 作为 kubeconfig 文件的路径。 也可以通过环境变量 **KUBECONFIG** 来指定其它 kubeconfig 文件。 根据[指南](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig)了解更多 kubeconfig 的信息。
4. 如果 NNI Trial 作业需要 GPU 资源,需按照[指南](https://github.com/NVIDIA/k8s-device-plugin)来配置 **Kubernetes 下的 Nvidia 插件**
5. 准备 **NFS 服务器** 并导出通用的装载 (mount),推荐将 NFS 服务器路径映射到 `root_squash 选项`,否则可能会在 NNI 复制文件到 NFS 时出现权限问题。 参考[页面](https://linux.die.net/man/5/exports),来了解关于 root_squash 选项,或 **Azure File Storage**
6. 在安装 NNI 并运行 nnictl 的计算机上安装 **NFS 客户端**。 运行此命令安装 NFSv4 客户端:
apt-get install nfs-common
6. 在安装 NNI 并运行 nnictl 的计算机上安装 **NFS 客户端**。 运行此命令安装 NFSv4 客户端: ```apt-get install nfs-common```
7. 参考[指南](QuickStart.md)安装 **NNI**
## Azure 部署的 Kubernetes 的准备工作
1. NNI 支持基于 Azure Kubernetes Service 的 Kubeflow,参考[指南](https://azure.microsoft.com/en-us/services/kubernetes-service/)来设置 Azure Kubernetes Service。
2. 安装 [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)**kubectl**。 使用 `az login` 命令来设置 Azure 账户吗,并将 kubectl 客户端连接到 AKS,参考此[指南](https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough#connect-to-the-cluster)
1. NNI 支持基于 Azure Kubernetes Service 的 Kubeflow,参考[指南](https://azure.microsoft.com/zh-cn/services/kubernetes-service/)来设置 Azure Kubernetes Service。
2. 安装 [Azure CLI](https://docs.microsoft.com/zh-cn/cli/azure/install-azure-cli?view=azure-cli-latest)**kubectl**。 使用 `az login` 命令来设置 Azure 账户吗,并将 kubectl 客户端连接到 AKS,参考此[指南](https://docs.microsoft.com/zh-cn/azure/aks/kubernetes-walkthrough#connect-to-the-cluster)
3. 在 Azure Kubernetes Service 上部署 Kubeflow,参考此[指南](https://www.kubeflow.org/docs/started/getting-started/)
4. 参考此[指南](https://docs.microsoft.com/en-us/azure/storage/common/storage-quickstart-create-account?tabs=portal)来创建 Azure 文件存储账户。 NNI 需要 Azure Storage Service 来存取代码和输出文件。
5. NNI 需要访问密钥来连接 Azure 存储服务,NNI 使用 [Azure Key Vault](https://azure.microsoft.com/en-us/services/key-vault/) 服务来保护私钥。 设置 Azure Key Vault 服务,并添加密钥到 Key Vault 中来存取 Azure 存储账户。 参考[指南](https://docs.microsoft.com/en-us/azure/key-vault/quick-create-cli)来存储访问密钥。
4. 参考此[指南](https://docs.microsoft.com/zh-cn/azure/storage/common/storage-quickstart-create-account?tabs=portal)来创建 Azure 文件存储账户。 NNI 需要 Azure Storage Service 来存取代码和输出文件。
5. NNI 需要访问密钥来连接 Azure 存储服务,NNI 使用 [Azure Key Vault](https://azure.microsoft.com/zh-cn/services/key-vault/) 服务来保护私钥。 设置 Azure Key Vault 服务,并添加密钥到 Key Vault 中来存取 Azure 存储账户。 参考[指南](https://docs.microsoft.com/zh-cn/azure/key-vault/quick-create-cli)来存储访问密钥。
## 设计
![](../img/kubeflow_training_design.png) Kubeflow 训练服务会实例化一个 kubernetes 客户端来与 Kubernetes 集群的 API 服务器交互。
![](../img/kubeflow_training_design.png) Kubeflow 训练服务会实例化一个 Kubernetes 客户端来与 Kubernetes 集群的 API 服务器交互。
对于每个 Trial,会上传本机 codeDir 路径(在 nni_config.yml 中配置)中的所有文件,包括 parameter.cfg 这样的生成的文件到存储卷中。 当前支持两种存储卷:[nfs](https://en.wikipedia.org/wiki/Network_File_System)[Azure 文件存储](https://azure.microsoft.com/en-us/services/storage/files/),需要在 NNI 的 YAML 文件中进行配置。 当文件准备好后,Kubeflow 训练服务会调用 Kubernetes 的 API 来创建 Kubeflow 作业 ([tf-operator](https://github.com/kubeflow/tf-operator) 作业或 [pytorch-operator](https://github.com/kubeflow/pytorch-operator) 作业) ,并将存储卷挂载到作业的 pod 中。 Kubeflow 作业的输出文件,例如 stdout, stderr, trial.log 以及模型文件,也会被复制回存储卷。 NNI 会在网页中显示每个 Trial 的存储卷的 URL,以便浏览日志和输出文件。
对于每个 Trial,会上传本机 codeDir 路径(在 nni_config.yml 中配置)中的所有文件,包括 parameter.cfg 这样的生成的文件到存储卷中。 当前支持两种存储卷:[nfs](https://en.wikipedia.org/wiki/Network_File_System)[Azure 文件存储](https://azure.microsoft.com/zh-cn/services/storage/files/),需要在 NNI 的 YAML 文件中进行配置。 当文件准备好后,Kubeflow 训练服务会调用 Kubernetes 的 API 来创建 Kubeflow 作业 ([tf-operator](https://github.com/kubeflow/tf-operator) 作业或 [pytorch-operator](https://github.com/kubeflow/pytorch-operator) 作业) ,并将存储卷挂载到作业的 pod 中。 Kubeflow 作业的输出文件,例如 stdout, stderr, trial.log 以及模型文件,也会被复制回存储卷。 NNI 会在网页中显示每个 Trial 的存储卷的 URL,以便浏览日志和输出文件。
## 支持的操作符(operator)
NNI 仅支持 kubeflow 的 tf-operator 和 pytorch-operator,其它操作符未经测试。 可以在配置文件中设置操作符类型。 这是 tf-operator 的设置:
NNI 仅支持 Kubeflow 的 tf-operator 和 pytorch-operator,其它操作符未经测试。 可以在配置文件中设置操作符类型。 这是 tf-operator 的设置:
kubeflowConfig:
```yaml
kubeflowConfig:
operator: tf-operator
```
这是 pytorch-operator 的设置:
kubeflowConfig:
```yaml
kubeflowConfig:
operator: pytorch-operator
```
如果要使用 tf-operator,需要在 Trial 配置中设置 `ps``worker`。如果要使用 pytorch-operator,需要在 Trial 配置中设置 `master``worker`
## 支持的存储类型
NNI 支持使用 NFS 和 Azure 存储来存储代码和输出文件,可在配置文件进行相应的配置。
NFS 存储配置如下:
kubeflowConfig:
```yaml
kubeflowConfig:
storage: nfs
nfs:
# NFS 服务器 IP, 如 10.10.10.10
server: {your_nfs_server_ip}
# NFS 服务器的导出路径,如 /var/nfs/nni
path: {your_nfs_server_export_path}
```
如果使用了 Azure 存储,需要在 YAML 文件中如下设置 `kubeflowConfig`
kubeflowConfig:
```yaml
kubeflowConfig:
storage: azureStorage
keyVault:
vaultName: {your_vault_name}
......@@ -70,34 +74,35 @@ NFS 存储配置如下:
azureStorage:
accountName: {your_storage_account_name}
azureShare: {your_azure_share_name}
```
## 运行 Experiment
`examples/trials/mnist` 为例。 这是一个 TensorFlow 作业,使用了 Kubeflow 的 tf-operator。 NNI 的 YAML 配置文件如下:
authorName: default
experimentName: example_mnist
trialConcurrency: 2
maxExecDuration: 1h
maxTrialNum: 20
#可选项: local, remote, pai, kubeflow
trainingServicePlatform: kubeflow
searchSpacePath: search_space.json
#可选项: true, false
useAnnotation: false
tuner:
```yaml
authorName: default
experimentName: example_mnist
trialConcurrency: 2
maxExecDuration: 1h
maxTrialNum: 20
#可选项: local, remote, pai, kubeflow
trainingServicePlatform: kubeflow
searchSpacePath: search_space.json
#可选项: true, false
useAnnotation: false
tuner:
#可选项: TPE, Random, Anneal, Evolution
builtinTunerName: TPE
classArgs:
#可选项: maximize, minimize
optimize_mode: maximize
assessor:
assessor:
builtinAssessorName: Medianstop
classArgs:
optimize_mode: maximize
gpuNum: 0
trial:
trial:
codeDir: .
worker:
replicas: 2
......@@ -113,7 +118,7 @@ NFS 存储配置如下:
cpuNum: 1
memoryMB: 8196
image: msranni/nni:latest
kubeflowConfig:
kubeflowConfig:
operator: tf-operator
apiVersion: v1alpha2
storage: nfs
......@@ -122,29 +127,30 @@ NFS 存储配置如下:
server: {your_nfs_server_ip}
# NFS 服务器的导出路径,如 /var/nfs/nni
path: {your_nfs_server_export_path}
```
注意:如果用 Kubeflow 模式运行,需要在 YAML 文件中显式设置 `trainingServicePlatform: kubeflow`
如果要运行 Pytorch 作业,需要如下配置:
authorName: default
experimentName: example_mnist_distributed_pytorch
trialConcurrency: 1
maxExecDuration: 1h
maxTrialNum: 10
#可选项: local, remote, pai, kubeflow
trainingServicePlatform: kubeflow
searchSpacePath: search_space.json
#可选项: true, false
useAnnotation: false
tuner:
```yaml
authorName: default
experimentName: example_mnist_distributed_pytorch
trialConcurrency: 1
maxExecDuration: 1h
maxTrialNum: 10
#可选项: local, remote, pai, kubeflow
trainingServicePlatform: kubeflow
searchSpacePath: search_space.json
#可选项: true, false
useAnnotation: false
tuner:
#可选项: TPE, Random, Anneal, Evolution
builtinTunerName: TPE
classArgs:
#可选项: maximize, minimize
optimize_mode: minimize
trial:
trial:
codeDir: .
master:
replicas: 1
......@@ -160,7 +166,7 @@ NFS 存储配置如下:
cpuNum: 1
memoryMB: 2048
image: msranni/nni:latest
kubeflowConfig:
kubeflowConfig:
operator: pytorch-operator
apiVersion: v1alpha2
nfs:
......@@ -168,7 +174,7 @@ NFS 存储配置如下:
server: {your_nfs_server_ip}
# NFS 服务器导出路径,如 /var/nfs/nni
path: {your_nfs_server_export_path}
```
Kubeflow 模式的配置有下列主键:
......@@ -193,8 +199,9 @@ Kubeflow 模式的配置有下列主键:
完成并保存 NNI Experiment 配置文件后(例如可保存为:exp_kubeflow.yml),运行以下命令:
nnictl create --config exp_kubeflow.yml
```bash
nnictl create --config exp_kubeflow.yml
```
来在 Kubeflow 模式下启动 Experiment。 NNI 会为每个 Trial 创建 Kubeflow tfjob 或 pytorchjob,作业名称的格式为 `nni_exp_{experiment_id}_trial_{trial_id}`。 可以在 Kubernetes 面板中看到创建的 Kubeflow tfjob。
......
......@@ -2,7 +2,7 @@
## Metis Tuner
大多数调参工具仅仅预测最优配置,而 [Metis](https://www.microsoft.com/en-us/research/publication/metis-robustly-tuning-tail-latencies-cloud-systems/) 的优势在于有两个输出:(a) 最优配置的当前预测结果, 以及 (b) 下一次 Trial 的建议。 不再需要随机猜测!
大多数调参工具仅仅预测最优配置,而 [Metis](https://www.microsoft.com/zh-cn/research/publication/metis-robustly-tuning-tail-latencies-cloud-systems/) 的优势在于有两个输出:(a) 最优配置的当前预测结果, 以及 (b) 下一次 Trial 的建议。 不再需要随机猜测!
大多数工具假设训练集没有噪声数据,但 Metis 会知道是否需要对某个超参重新采样。
......
......@@ -39,7 +39,16 @@ Trial 代码中使用多阶段非常容易,样例如下:
### 编写使用多阶段的 Tuner:
强烈建议首先阅读[自定义 Tuner](https://nni.readthedocs.io/en/latest/Customize_Tuner.html),再开始编写多阶段 Tuner。 与普通 Tuner 不同的是,必须继承于 `MultiPhaseTuner`(在 nni.multi_phase_tuner 中)。 `Tuner``MultiPhaseTuner` 之间最大的不同是,MultiPhaseTuner 多了一些信息,即 `trial_job_id`。 有了这个信息, Tuner 能够知道哪个 Trial 在请求配置信息, 返回的结果是哪个 Trial 的。 通过此信息,Tuner 能够灵活的为不同的 Trial 及其阶段实现功能。 例如,可在 generate_parameters 方法中使用 trial_job_id 来为特定的 Trial 任务生成超参。
强烈建议首先阅读[自定义 Tuner](https://nni.readthedocs.io/en/latest/Customize_Tuner.html),再开始编写多阶段 Tuner。 与普通 Tuner 一样,需要从 `Tuner` 类继承。 当通过配置启用多阶段时(将 `multiPhase` 设为 true),Tuner 会通过下列方法得到一个新的参数 `trial_job_id`
generate_parameters
generate_multiple_parameters
receive_trial_result
receive_customized_trial_result
trial_end
有了这个信息, Tuner 能够知道哪个 Trial 在请求配置信息, 返回的结果是哪个 Trial 的。 通过此信息,Tuner 能够灵活的为不同的 Trial 及其阶段实现功能。 例如,可在 generate_parameters 方法中使用 trial_job_id 来为特定的 Trial 任务生成超参。
当然,要使用自定义的多阶段 Tuner ,也需要**在 Experiment 的 YAML 配置文件中增加`multiPhase: true`**
......
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