Unverified Commit 36e6e350 authored by SparkSnail's avatar SparkSnail Committed by GitHub
Browse files

Merge pull request #221 from microsoft/master

merge master
parents 543239c6 7cbde508
...@@ -44,7 +44,7 @@ maxExecDuration: 10h ...@@ -44,7 +44,7 @@ maxExecDuration: 10h
maxTrialNum: 100 maxTrialNum: 100
#可选项: local, remote, pai, kubeflow, frameworkcontroller #可选项: local, remote, pai, kubeflow, frameworkcontroller
trainingServicePlatform: frameworkcontroller trainingServicePlatform: frameworkcontroller
searchSpacePath: ~/nni/examples/trials/mnist/search_space.json searchSpacePath: ~/nni/examples/trials/mnist-tfv1/search_space.json
#可选项: true, false #可选项: true, false
useAnnotation: false useAnnotation: false
tuner: tuner:
...@@ -59,7 +59,7 @@ assessor: ...@@ -59,7 +59,7 @@ assessor:
optimize_mode: maximize optimize_mode: maximize
gpuNum: 0 gpuNum: 0
trial: trial:
codeDir: ~/nni/examples/trials/mnist codeDir: ~/nni/examples/trials/mnist-tfv1
taskRoles: taskRoles:
- name: worker - name: worker
taskNum: 1 taskNum: 1
......
...@@ -78,7 +78,7 @@ kubeflowConfig: ...@@ -78,7 +78,7 @@ kubeflowConfig:
## 运行 Experiment ## 运行 Experiment
`examples/trials/mnist` 为例。 这是一个 TensorFlow 作业,使用了 Kubeflow 的 tf-operator。 NNI 的 YAML 配置文件如下: `examples/trials/mnist-tfv1` 为例。 这是一个 TensorFlow 作业,使用了 Kubeflow 的 tf-operator。 NNI 的 YAML 配置文件如下:
```yaml ```yaml
authorName: default authorName: default
......
# **教程:使用 NNI API 在本地创建和运行 Experiment** # **教程:使用 NNI API 在本地创建和运行 Experiment**
本教程会使用 [~/examples/trials/mnist] 样例来解释如何在本地使用 NNI API 来创建并运行 Experiment。 本教程会使用 [~/examples/trials/mnist-tfv1] 样例来解释如何在本地使用 NNI API 来创建并运行 Experiment。
> 在开始前 > 在开始前
......
...@@ -16,9 +16,9 @@ NNI 支持通过 SSH 通道在多台计算机上运行 Experiment,称为 `remo ...@@ -16,9 +16,9 @@ NNI 支持通过 SSH 通道在多台计算机上运行 Experiment,称为 `remo
## 运行 Experiment ## 运行 Experiment
另一台计算机,或在其中任何一台上安装 NNI,并运行 nnictl 工具 将 NNI 安装在可以访问上述三台计算机的网络的另一台计算机,或者仅在三台计算机中的任何一台上运行 `nnictl` 即可启动 Experiment
`examples/trials/mnist-annotation` 为例。 `cat ~/nni/examples/trials/mnist-annotation/config_remote.yml` 来查看详细配置 `examples/trials/mnist-annotation` 为例。 此处示例在 `examples/trials/mnist-annotation/config_remote.yml`
```yaml ```yaml
authorName: default authorName: default
...@@ -58,27 +58,13 @@ machineList: ...@@ -58,27 +58,13 @@ machineList:
passwd: bob123 passwd: bob123
``` ```
可以使用不同系统来在远程计算机上运行 Experiment。 `codeDir` 中的文件会被自动上传到远程服务器。 可在不同的操作系统上运行 NNI (Windows, Linux, MacOS),来在远程机器上(仅支持 Linux)运行 Experiment。
#### Linux 和 macOS
填好 `machineList` 部分,然后运行:
```bash
nnictl create --config ~/nni/examples/trials/mnist-annotation/config_remote.yml
```
来启动 Experiment。
#### Windows
填好 `machineList` 部分,然后运行:
```bash ```bash
nnictl create --config %userprofile%\nni\examples\trials\mnist-annotation\config_remote.yml nnictl create --config examples/trials/mnist-annotation/config_remote.yml
``` ```
来启动 Experiment 也可使用公钥/私钥对,而非用户名/密码进行身份验证。 有关高级用法,请参考[实验配置参考](../Tutorial/ExperimentConfig.md)
## 版本校验 ## 版本校验
......
NNI Compressor 上使用知识蒸馏
===
## 知识蒸馏 (Knowledge Distillation)
知识蒸馏,在 [Distilling the Knowledge in a Neural Networ](https://arxiv.org/abs/1503.02531) 中,压缩模型被训练成模拟预训练的大模型。 这种训练设置也称为"师生(teacher-student)"方式,其中大模型是教师,小模型是学生。
![](../../img/distill.png)
### 用法
PyTorch 代码
```python
from knowledge_distill.knowledge_distill import KnowledgeDistill
kd = KnowledgeDistill(kd_teacher_model, kd_T=5)
alpha = 1
beta = 0.8
for batch_idx, (data, target) in enumerate(train_loader):
data, target = data.to(device), target.to(device)
optimizer.zero_grad()
output = model(data)
loss = F.cross_entropy(output, target)
# 只需要添加以下行来使用知识蒸馏微调模型
loss = alpha * loss + beta * kd.loss(data=data, student_out=output)
loss.backward()
```
#### 知识蒸馏的用户配置
* **kd_teacher_model:** 预训练过的教师模型
* **kd_T:** 用于平滑教师模型输出的温度。
完整代码可在这里找到
\ No newline at end of file
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
在深度学习中,用 CNN 来分类 MNIST 数据,就像介绍编程语言中的 `hello world` 样例。 因此,NNI 将 MNIST 作为样例来介绍功能。 样例如下: 在深度学习中,用 CNN 来分类 MNIST 数据,就像介绍编程语言中的 `hello world` 样例。 因此,NNI 将 MNIST 作为样例来介绍功能。 样例如下:
- [MNIST 中使用 NNI API](#mnist) - [MNIST 中使用 NNI API (TensorFlow v1.x)](#mnist-tfv1)
- [MNIST 中使用 NNI API (TensorFlow v2.x)](#mnist-tfv2)
- [MNIST 中使用 NNI 标记(annotation)](#mnist-annotation) - [MNIST 中使用 NNI 标记(annotation)](#mnist-annotation)
- [在 Keras 中使用 MNIST](#mnist-keras) - [在 Keras 中使用 MNIST](#mnist-keras)
- [MNIST -- 用批处理 Tuner 来调优](#mnist-batch) - [MNIST -- 用批处理 Tuner 来调优](#mnist-batch)
...@@ -11,12 +12,19 @@ ...@@ -11,12 +12,19 @@
- [用 Kubeflow 运行分布式的 MNIST (tensorflow)](#mnist-kubeflow-tf) - [用 Kubeflow 运行分布式的 MNIST (tensorflow)](#mnist-kubeflow-tf)
- [用 Kubeflow 运行分布式的 MNIST (PyTorch)](#mnist-kubeflow-pytorch) - [用 Kubeflow 运行分布式的 MNIST (PyTorch)](#mnist-kubeflow-pytorch)
<a name="mnist"></a> <a name="mnist-tfv1"></a>
**MNIST 中使用 NNI API** **MNIST 中使用 NNI API (TensorFlow v1.x)**
这是个简单的卷积网络,有两个卷积层,两个池化层和一个全连接层。 调优的超参包括 dropout 比率,卷积层大小,隐藏层(全连接层)大小等等。 它能用 NNI 中大部分内置的 Tuner 来调优,如 TPE,SMAC,Random。 样例的 YAML 文件也启用了评估器来提前终止一些中间结果不好的尝试。 这是个简单的卷积网络,有两个卷积层,两个池化层和一个全连接层。 调优的超参包括 dropout 比率,卷积层大小,隐藏层(全连接层)大小等等。 它能用 NNI 中大部分内置的 Tuner 来调优,如 TPE,SMAC,Random。 样例的 YAML 文件也启用了评估器来提前终止一些中间结果不好的尝试。
`代码目录: examples/trials/mnist/` `代码目录: examples/trials/mnist-tfv1/`
<a name="mnist-tfv2"></a>
**MNIST 中使用 NNI API (TensorFlow v2.x)**
与上述示例的网络相同,但使用了 TensorFlow v2.x Keras API。
`代码目录: examples/trials/mnist-tfv2/`
<a name="mnist-annotation"></a> <a name="mnist-annotation"></a>
**MNIST 中使用 NNI 标记(annotation)** **MNIST 中使用 NNI 标记(annotation)**
......
...@@ -10,9 +10,9 @@ RocksDB 的性能表现非常依赖于调优操作。 但由于其底层技术 ...@@ -10,9 +10,9 @@ RocksDB 的性能表现非常依赖于调优操作。 但由于其底层技术
db_bench</code> 已经加入到了 `PATH` 中。 参考[这里](../Tutorial/QuickStart.md),了解如何安装并准备 NNI 环境,参考[这里](https://github.com/facebook/rocksdb/blob/master/INSTALL.md)来编译 RocksDB 以及 `db_bench`</p> db_bench</code> 已经加入到了 `PATH` 中。 参考[这里](../Tutorial/QuickStart.md),了解如何安装并准备 NNI 环境,参考[这里](https://github.com/facebook/rocksdb/blob/master/INSTALL.md)来编译 RocksDB 以及 `db_bench`</p>
此简单脚本 [`db_bench_installation.sh`](../../../examples/trials/systems/rocksdb-fillrandom/db_bench_installation.sh) 可帮助编译并在 Ubuntu 上安装 `db_bench` 及其依赖包。 可遵循相同的过程在其它系统中安装 RocksDB。 此简单脚本 [`db_bench_installation.sh`](https://github.com/microsoft/nni/tree/master/examples/trials/systems/rocksdb-fillrandom/db_bench_installation.sh) 可帮助编译并在 Ubuntu 上安装 `db_bench` 及其依赖包。 可遵循相同的过程在其它系统中安装 RocksDB。
*代码目录:[`example/trials/systems/rocksdb-fillrandom`](../../../examples/trials/systems/rocksdb-fillrandom)* *代码路径:[`example/trials/systems/rocksdb-fillrandom`](https://github.com/microsoft/nni/tree/master/examples/trials/systems/rocksdb-fillrandom)*
...@@ -48,7 +48,7 @@ db_bench</code> 已经加入到了 `PATH` 中。 参考[这里](../Tutorial/Quic ...@@ -48,7 +48,7 @@ db_bench</code> 已经加入到了 `PATH` 中。 参考[这里](../Tutorial/Quic
``` ```
*代码目录:[`example/trials/systems/rocksdb-fillrandom/search_space.json`](../../../examples/trials/systems/rocksdb-fillrandom/search_space.json)* *代码路径:[`example/trials/systems/rocksdb-fillrandom/search_space.json`](https://github.com/microsoft/nni/tree/master/examples/trials/systems/rocksdb-fillrandom/search_space.json)*
...@@ -59,7 +59,7 @@ db_bench</code> 已经加入到了 `PATH` 中。 参考[这里](../Tutorial/Quic ...@@ -59,7 +59,7 @@ db_bench</code> 已经加入到了 `PATH` 中。 参考[这里](../Tutorial/Quic
* 使用 `nni.get_next_parameter()` 来获取下一个系统配置。 * 使用 `nni.get_next_parameter()` 来获取下一个系统配置。
* 使用 `nni.report_final_result(metric)` 来返回测试结果。 * 使用 `nni.report_final_result(metric)` 来返回测试结果。
*代码目录:[`example/trials/systems/rocksdb-fillrandom/main.py`](../../../examples/trials/systems/rocksdb-fillrandom/main.py)* *代码路径:[`example/trials/systems/rocksdb-fillrandom/main.py`](https://github.com/microsoft/nni/tree/master/examples/trials/systems/rocksdb-fillrandom/main.py)*
...@@ -69,11 +69,11 @@ db_bench</code> 已经加入到了 `PATH` 中。 参考[这里](../Tutorial/Quic ...@@ -69,11 +69,11 @@ db_bench</code> 已经加入到了 `PATH` 中。 参考[这里](../Tutorial/Quic
这是使用 SMAC 算法调优 RocksDB 的示例: 这是使用 SMAC 算法调优 RocksDB 的示例:
*代码目录:[`example/trials/systems/rocksdb-fillrandom/config_smac.yml`](../../../examples/trials/systems/rocksdb-fillrandom/config_smac.yml)* *代码路径:[`example/trials/systems/rocksdb-fillrandom/config_smac.yml`](https://github.com/microsoft/nni/tree/master/examples/trials/systems/rocksdb-fillrandom/config_smac.yml)*
这是使用 TPE 算法调优 RocksDB 的示例: 这是使用 TPE 算法调优 RocksDB 的示例:
*代码目录: [`example/trials/systems/rocksdb-fillrandom/config_tpe.yml`](../../../examples/trials/systems/rocksdb-fillrandom/config_tpe.yml)* *代码路径:[`example/trials/systems/rocksdb-fillrandom/config_tpe.yml`](https://github.com/microsoft/nni/tree/master/examples/trials/systems/rocksdb-fillrandom/config_tpe.yml)*
其它 Tuner 算法可以通过相同的方式来使用。 参考[这里](../Tuner/BuiltinTuner.md)了解详情。 其它 Tuner 算法可以通过相同的方式来使用。 参考[这里](../Tuner/BuiltinTuner.md)了解详情。
...@@ -105,7 +105,7 @@ nnictl create --config ./config_tpe.yml ...@@ -105,7 +105,7 @@ nnictl create --config ./config_tpe.yml
详细的实验结果如下图所示。 水平轴是 Trial 的顺序。 垂直轴是指标,此例中为写入的 OPS。 蓝点表示使用的是 SMAC Tuner,橙色表示使用的是 TPE Tuner。 详细的实验结果如下图所示。 水平轴是 Trial 的顺序。 垂直轴是指标,此例中为写入的 OPS。 蓝点表示使用的是 SMAC Tuner,橙色表示使用的是 TPE Tuner。
![image](../../../examples/trials/systems/rocksdb-fillrandom/plot.png) ![image](https://github.com/microsoft/nni/tree/master/examples/trials/systems/rocksdb-fillrandom/plot.png)
下表列出了两个 Tuner 获得的最佳 Trial 以及相应的参数和指标。 不出所料,两个 Tuner 都为 `fillrandom` 测试找到了一样的最佳配置。 下表列出了两个 Tuner 获得的最佳 Trial 以及相应的参数和指标。 不出所料,两个 Tuner 都为 `fillrandom` 测试找到了一样的最佳配置。
......
...@@ -113,22 +113,18 @@ trial: ...@@ -113,22 +113,18 @@ trial:
gpuNum: 0 gpuNum: 0
cpuNum: 1 cpuNum: 1
memoryMB: 32869 memoryMB: 32869
#在 OpenPAI 上运行 NNI 任务的 Docker 映像 # 在 OpenPAI 上运行 NNI 的 Docker 映像
image: msranni/nni:latest image: msranni/nni:latest
#在 OpenPAI 的 hdfs 目录上存储数据的目录,如:'hdfs://host:port/directory'
dataDir: hdfs://10.10.10.10:9000/username/nni
#在 OpenPAI 的 hdfs 目录上存储输出的目录,如:'hdfs://host:port/directory'
outputDir: hdfs://10.10.10.10:9000/username/nni
paiConfig: paiConfig:
#登录 OpenPAI 的用户名 # 登录 OpenPAI 的用户名
userName: username userName: username
#登录 OpenPAI 的密码 # 登录 OpenPAI 的密码
passWord: password passWord: password
# OpenPAI 的 RESTful 服务器地址 # OpenPAI 的 RestFUL 服务器地址
host: 10.10.10.10 host: 10.10.10.10
``` ```
将默认值改为个人账户和服务器信息。 包括 `nniManagerIp`, `dataDir`, `outputDir`, `userName`, `passWord``host` 将默认值改为个人账户和服务器信息。 包括 `nniManagerIp`, `userName`, `passWord``host`
在 "Trial" 部分中,如果需要使用 GPU 来进行架构搜索,可将 `gpuNum``0` 改为 `1`。 根据训练时长,可以增加 `maxTrialNum``maxExecDuration` 在 "Trial" 部分中,如果需要使用 GPU 来进行架构搜索,可将 `gpuNum``0` 改为 `1`。 根据训练时长,可以增加 `maxTrialNum``maxExecDuration`
......
...@@ -132,6 +132,24 @@ Annotation 的语法和用法等,参考 [Annotation](../Tutorial/AnnotationSpe ...@@ -132,6 +132,24 @@ Annotation 的语法和用法等,参考 [Annotation](../Tutorial/AnnotationSpe
useAnnotation: true useAnnotation: true
## 用于调试的独立模式
NNI 支持独立模式,使 Trial 代码无需启动 NNI 实验即可运行。 这样能更容易的找出 Trial 代码中的 Bug。 NNI Annotation 天然支持独立模式,因为添加的 NNI 相关的行都是注释的形式。 NNI Trial API 在独立模式下的行为有所变化,某些 API 返回虚拟值,而某些 API 不报告值。 有关这些 API 的完整列表,请参阅下表。
```python
注意请为 Trial 代码中的超参分配默认值
nni.get_next_parameter返回 {}
nni.report_final_result已在 stdout 上打印日志但不报告
nni.report_intermediate_result已在 stdout 上打印日志但不报告
nni.get_experiment_id返回 "STANDALONE"
nni.get_trial_id返回 "STANDALONE"
nni.get_sequence_id返回 0
```
可使用 [mnist 示例](https://github.com/microsoft/nni/tree/master/examples/trials/mnist-tfv1) 来尝试独立模式。 只需在代码目录下运行 `python3 mnist.py`。 Trial 代码会使用默认超参成功运行。
更多调试的信息,可参考[调试指南](../Tutorial/HowToDebug.md)
## Trial 存放在什么地方? ## Trial 存放在什么地方?
### 本机模式 ### 本机模式
...@@ -162,7 +180,7 @@ echo $? `date +%s%3N` >/home/user_name/nni/experiments/$experiment_id$/trials/$t ...@@ -162,7 +180,7 @@ echo $? `date +%s%3N` >/home/user_name/nni/experiments/$experiment_id$/trials/$t
<a name="more-examples"></a> <a name="more-examples"></a>
## 更多 Trial 的 ## 更多 Trial 的
* [MNIST 样例](MnistExamples.md) * [MNIST 样例](MnistExamples.md)
* [为 CIFAR 10 分类找到最佳的 optimizer](Cifar10Examples.md) * [为 CIFAR 10 分类找到最佳的 optimizer](Cifar10Examples.md)
......
...@@ -35,4 +35,4 @@ advisor: ...@@ -35,4 +35,4 @@ advisor:
## 示例 ## 示例
[参考示例](../../../examples/tuners/mnist_keras_customized_advisor) 参考[示例](https://github.com/microsoft/nni/tree/master/examples/tuners/mnist_keras_customized_advisor)
\ No newline at end of file \ No newline at end of file
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
* 有关 docstrings,参考 [numpydoc docstring 指南](https://numpydoc.readthedocs.io/en/latest/format.html)[pandas docstring 指南](https://python-sprints.github.io/pandas/guide/pandas_docstring.html) * 有关 docstrings,参考 [numpydoc docstring 指南](https://numpydoc.readthedocs.io/en/latest/format.html)[pandas docstring 指南](https://python-sprints.github.io/pandas/guide/pandas_docstring.html)
* 函数的 docstring, **description**, **Parameters**, 以及**Returns**/**Yields** 是必需的。 * 函数的 docstring, **description**, **Parameters**, 以及**Returns**/**Yields** 是必需的。
* 类的 docstring, **description**, **Attributes** 是必需的。 * 类的 docstring, **description**, **Attributes** 是必需的。
* 描述 `dict` 的 docstring 在超参格式描述中多处用到,参考 [RiboKit : 文档标准
* 写作标准的内部准则](https://ribokit.github.io/docs/text/)
## 文档 ## 文档
...@@ -56,4 +58,4 @@ ...@@ -56,4 +58,4 @@
* 需要链接时,尽量使用**相对路径**。 但如果文档是 Markdown 格式的,并且: * 需要链接时,尽量使用**相对路径**。 但如果文档是 Markdown 格式的,并且:
* 图片需要通过嵌入的 HTML 语法来格式化,则需要使用绝对链接,如 `https://user-images.githubusercontent.com/44491713/51381727-e3d0f780-1b4f-11e9-96ab-d26b9198ba65.png`。可以通过将图片拖拽到 [Github Issue](https://github.com/Microsoft/nni/issues/new) 框中来生成这样的链接。 * 图片需要通过嵌入的 HTML 语法来格式化,则需要使用绝对链接,如 `https://user-images.githubusercontent.com/44491713/51381727-e3d0f780-1b4f-11e9-96ab-d26b9198ba65.png`。可以通过将图片拖拽到 [Github Issue](https://github.com/Microsoft/nni/issues/new) 框中来生成这样的链接。
* 如果不能被 sphinx 重新格式化,如源代码等,则需要使用绝对链接。 如果源码连接到本代码库,使用 `https://github.com/Microsoft/nni/tree/master/` 作为根目录 (例如:[mnist.py](https://github.com/Microsoft/nni/blob/master/examples/trials/mnist/mnist.py))。 * 如果不能被 sphinx 重新格式化,如源代码等,则需要使用绝对链接。 如果源码连接到本代码库,使用 `https://github.com/Microsoft/nni/tree/master/` 作为根目录 (例如:[mnist.py](https://github.com/Microsoft/nni/blob/master/examples/trials/mnist-tfv1/mnist.py))。
\ No newline at end of file \ No newline at end of file
This diff is collapsed.
...@@ -41,9 +41,16 @@ nnictl 在执行时,使用 tmp 目录作为临时目录来复制 codeDir 下 ...@@ -41,9 +41,16 @@ nnictl 在执行时,使用 tmp 目录作为临时目录来复制 codeDir 下
无法打开 Web 界面的链接可能有以下几个原因: 无法打开 Web 界面的链接可能有以下几个原因:
* http://127.0.0.1http://172.17.0.1 以及 http://10.0.0.15 都是 localhost。如果在服务器或远程计算机上启动 Experiment, 可将此 IP 替换为所连接的 IP 来查看 Web 界面,如 http://[远程连接的地址]:8080 * `http://127.0.0.1``http://172.17.0.1` 以及 `http://10.0.0.15` 都是 localhost。如果在服务器或远程计算机上启动 Experiment, 可将此 IP 替换为所连接的 IP 来查看 Web 界面,如 `http://[远程连接的地址]:8080`
* 如果使用服务器 IP 后还是无法看到 Web 界面,可检查此服务器上是否有防火墙或需要代理。 或使用此运行 NNI Experiment 的服务器上的浏览器来查看 Web 界面。 * 如果使用服务器 IP 后还是无法看到 Web 界面,可检查此服务器上是否有防火墙或需要代理。 或使用此运行 NNI Experiment 的服务器上的浏览器来查看 Web 界面。
* 另一个可能的原因是 Experiment 启动失败了,NNI 无法读取 Experiment 的信息。 可在如下目录中查看 NNIManager 的日志: ~/nni/experiment/[your_experiment_id] /log/nnimanager.log * 另一个可能的原因是 Experiment 启动失败了,NNI 无法读取 Experiment 的信息。 可在如下目录中查看 NNIManager 的日志: `~/nni/experiment/[your_experiment_id]` `/log/nnimanager.log`
### RESTful 服务器启动失败
可能是网络配置有问题。可检查以下问题。
* 可能需要链接 `127.0.0.1``localhost`。 在 `/etc/hosts` 中增加 `127.0.0.1 localhost`
* 也可能设置了一些代理。检查环境中是否有如 `HTTP_PROXY``HTTPS_PROXY` 的变量,如果有,则需要取消。
### NNI 在 Windows 上的问题 ### NNI 在 Windows 上的问题
......
...@@ -80,3 +80,5 @@ NNI 中有不同的错误类型。 根据严重程度,可分为三类。 当 N ...@@ -80,3 +80,5 @@ NNI 中有不同的错误类型。 根据严重程度,可分为三类。 当 N
![](../../img/trial_error.jpg) ![](../../img/trial_error.jpg)
如图,每个 Trial 都有日志路径,可以从中找到 Trial 的日志和 stderr。 如图,每个 Trial 都有日志路径,可以从中找到 Trial 的日志和 stderr。
除了 Experiment 级调试之外,NNI 还提供调试单个 Trial 的功能,而无需启动整个 Experiment。 有关调试单个 Trial 代码的更多信息,请参考[独立运行模式](../TrialExample/Trials.md#standalone-mode-for-debug)
\ No newline at end of file
# 安装 NNI # 安装 NNI
当前支持在 Linux,Mac 和 Windows(本机,远程和 OpenPAI 模式)下安装。 当前支持在 Linux,Mac 和 Windows 下安装。
## **在 Linux 和 Mac 下安装** ## **在 Linux 和 Mac 下安装**
......
# Windows 上的 NNI(实验阶段的功能) # Windows 上的 NNI(实验阶段的功能)
当前 Windows 上支持本机、远程和 OpenPAI 模式。 推荐 Windows 10 的 1809 版,其经过了测试。 Windows 上运行 NNI 是测试中的功能。 推荐 Windows 10 的 1809 版,其经过了测试。
## **在 Windows 上安装** ## **在 Windows 上安装**
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
完成操作后,使用 **config_windows.yml** 配置来开始 Experiment 进行验证。 完成操作后,使用 **config_windows.yml** 配置来开始 Experiment 进行验证。
```bash ```bash
nnictl create --config nni\examples\trials\mnist\config_windows.yml nnictl create --config nni\examples\trials\mnist-tfv1\config_windows.yml
``` ```
同样,其它示例的 YAML 配置中也需将 Trial 命令的 `python3` 替换为 `python` 同样,其它示例的 YAML 配置中也需将 Trial 命令的 `python3` 替换为 `python`
...@@ -45,6 +45,10 @@ nnictl create --config nni\examples\trials\mnist\config_windows.yml ...@@ -45,6 +45,10 @@ nnictl create --config nni\examples\trials\mnist\config_windows.yml
当前不支持 SMAC,原因可参考[此问题](https://github.com/automl/SMAC3/issues/483) 当前不支持 SMAC,原因可参考[此问题](https://github.com/automl/SMAC3/issues/483)
### 将 Windows 服务器用作远程服务器
目前不支持。
注意: 注意:
* 如果遇到如 `Segmentation fault` 这样的任何错误,参考[常见问题](FAQ.md) * 如果遇到如 `Segmentation fault` 这样的任何错误,参考[常见问题](FAQ.md)
\ No newline at end of file
...@@ -55,19 +55,19 @@ nnictl 支持的命令: ...@@ -55,19 +55,19 @@ nnictl 支持的命令:
> 在默认端口 8080 上创建一个新的 Experiment > 在默认端口 8080 上创建一个新的 Experiment
```bash ```bash
nnictl create --config nni/examples/trials/mnist/config.yml nnictl create --config nni/examples/trials/mnist-tfv1/config.yml
``` ```
> 在指定的端口 8088 上创建新的 Experiment > 在指定的端口 8088 上创建新的 Experiment
```bash ```bash
nnictl create --config nni/examples/trials/mnist/config.yml --port 8088 nnictl create --config nni/examples/trials/mnist-tfv1/config.yml --port 8088
``` ```
> 在指定的端口 8088 上创建新的 Experiment,并启用调试模式 > 在指定的端口 8088 上创建新的 Experiment,并启用调试模式
```bash ```bash
nnictl create --config nni/examples/trials/mnist/config.yml --port 8088 --debug nnictl create --config nni/examples/trials/mnist-tfv1/config.yml --port 8088 --debug
``` ```
注意: 注意:
...@@ -216,10 +216,10 @@ nnictl 支持的命令: ...@@ -216,10 +216,10 @@ nnictl 支持的命令:
* 示例 * 示例
`使用 'examples/trials/mnist/search_space.json' 来更新 Experiment 的搜索空间` `使用 'examples/trials/mnist-tfv1/search_space.json' 来更新 Experiment 的搜索空间`
```bash ```bash
nnictl update searchspace [experiment_id] --filename examples/trials/mnist/search_space.json nnictl update searchspace [experiment_id] --filename examples/trials/mnist-tfv1/search_space.json
``` ```
* **nnictl update concurrency** * **nnictl update concurrency**
......
...@@ -48,7 +48,7 @@ if __name__ == '__main__': ...@@ -48,7 +48,7 @@ if __name__ == '__main__':
run_trial(params) run_trial(params)
``` ```
注意:完整实现请参考 [examples/trials/mnist/mnist_before.py](https://github.com/Microsoft/nni/tree/master/examples/trials/mnist/mnist_before.py) 注意:完整实现请参考 [examples/trials/mnist-tfv1/mnist_before.py](https://github.com/Microsoft/nni/tree/master/examples/trials/mnist-tfv1/mnist_before.py)
上面的代码一次只能尝试一组参数,如果想要调优学习率,需要手工改动超参,并一次次尝试。 上面的代码一次只能尝试一组参数,如果想要调优学习率,需要手工改动超参,并一次次尝试。
...@@ -84,7 +84,7 @@ NNI 用来帮助超参调优。它的流程如下: ...@@ -84,7 +84,7 @@ NNI 用来帮助超参调优。它的流程如下:
+ } + }
``` ```
*实现代码:[search_space.json](https://github.com/Microsoft/nni/tree/master/examples/trials/mnist/search_space.json)* *实现代码:[search_space.json](https://github.com/Microsoft/nni/tree/master/examples/trials/mnist-tfv1/search_space.json)*
**第二步**:修改 `Trial` 代码来从 NNI 获取超参,并返回 NNI 最终结果。 **第二步**:修改 `Trial` 代码来从 NNI 获取超参,并返回 NNI 最终结果。
...@@ -111,7 +111,7 @@ NNI 用来帮助超参调优。它的流程如下: ...@@ -111,7 +111,7 @@ NNI 用来帮助超参调优。它的流程如下:
run_trial(params) run_trial(params)
``` ```
*实现代码:[mnist.py](https://github.com/Microsoft/nni/tree/master/examples/trials/mnist/mnist.py)* *实现代码:[mnist.py](https://github.com/Microsoft/nni/tree/master/examples/trials/mnist-tfv1/mnist.py)*
**第三步**:定义 YAML 格式的`配置`文件,其中声明了搜索空间和 Trial 文件的`路径`,以及`其它信息`,如调优算法,最大尝试次数,最大运行时间等等。 **第三步**:定义 YAML 格式的`配置`文件,其中声明了搜索空间和 Trial 文件的`路径`,以及`其它信息`,如调优算法,最大尝试次数,最大运行时间等等。
...@@ -136,16 +136,16 @@ trial: ...@@ -136,16 +136,16 @@ trial:
注意:**在 Windows 上,需要将 Trial 命令的 `python3` 改为 `python`** 注意:**在 Windows 上,需要将 Trial 命令的 `python3` 改为 `python`**
*实现代码:[config.yml](https://github.com/Microsoft/nni/tree/master/examples/trials/mnist/config.yml)* *实现代码:[config.yml](https://github.com/Microsoft/nni/tree/master/examples/trials/mnist-tfv1/config.yml)*
上面的代码都已准备好,并保存在 [examples/trials/mnist/](https://github.com/Microsoft/nni/tree/master/examples/trials/mnist) 上面的代码都已准备好,并保存在 [examples/trials/mnist-tfv1/](https://github.com/Microsoft/nni/tree/master/examples/trials/mnist-tfv1)
#### Linux 和 macOS #### Linux 和 macOS
从命令行使用 **config.yml** 文件启动 MNIST Experiment 。 从命令行使用 **config.yml** 文件启动 MNIST Experiment 。
```bash ```bash
nnictl create --config nni/examples/trials/mnist/config.yml nnictl create --config nni/examples/trials/mnist-tfv1/config.yml
``` ```
#### Windows #### Windows
...@@ -155,7 +155,7 @@ trial: ...@@ -155,7 +155,7 @@ trial:
**注意**:如果使用 Windows,则需要在 config.yml 文件中,将 `python3` 改为 `python`,或者使用 config_windows.yml 来开始 Experiment。 **注意**:如果使用 Windows,则需要在 config.yml 文件中,将 `python3` 改为 `python`,或者使用 config_windows.yml 来开始 Experiment。
```bash ```bash
nnictl create --config nni\examples\trials\mnist\config_windows.yml nnictl create --config nni\examples\trials\mnist-tfv1\config_windows.yml
``` ```
注意:**nnictl** 是一个命令行工具,用来控制 NNI Experiment,如启动、停止、继续 Experiment,启动、停止 NNIBoard 等等。 查看[这里](Nnictl.md),了解 `nnictl` 更多用法。 注意:**nnictl** 是一个命令行工具,用来控制 NNI Experiment,如启动、停止、继续 Experiment,启动、停止 NNIBoard 等等。 查看[这里](Nnictl.md),了解 `nnictl` 更多用法。
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
Trial 启动 Experiment 来检查环境。 例如,运行命令 Trial 启动 Experiment 来检查环境。 例如,运行命令
nnictl create --config ~/nni/examples/trials/mnist/config.yml nnictl create --config ~/nni/examples/trials/mnist-tfv1/config.yml
并打开网页界面查看 并打开网页界面查看
......
...@@ -6,7 +6,7 @@ Assessor 从 Trial 中接收中间结果,并通过指定的算法决定此 Tri ...@@ -6,7 +6,7 @@ Assessor 从 Trial 中接收中间结果,并通过指定的算法决定此 Tri
这是 MNIST 在使用了 'Curvefitting' Assessor 的 'maximize' 模式后的实验结果,可以看到 Assessor 成功的将大量最终结果不好的 Trial **提前结束** 。 使用 Assessor,能在相同的计算资源下,得到更好的结果。 这是 MNIST 在使用了 'Curvefitting' Assessor 的 'maximize' 模式后的实验结果,可以看到 Assessor 成功的将大量最终结果不好的 Trial **提前结束** 。 使用 Assessor,能在相同的计算资源下,得到更好的结果。
*实现代码:config_assessor.yml <https://github.com/Microsoft/nni/blob/master/examples/trials/mnist/config_assessor.yml>* *实现代码:config_assessor.yml <https://github.com/Microsoft/nni/blob/master/examples/trials/mnist-tfv1/config_assessor.yml>*
.. image:: ../img/Assessor.png .. image:: ../img/Assessor.png
......
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