Commit 6545540d authored by Chi Song's avatar Chi Song Committed by QuanluZhang
Browse files

Chinese translation (#924)

parent 7ba8922b
......@@ -2,15 +2,16 @@
创建 Experiment 时,需要给 nnictl 命令提供配置文件的路径。 配置文件是 YAML 格式,需要保证其格式正确。 本文介绍了配置文件的内容,并提供了一些示例和模板。
* [模板](#Template) (配置文件的模板)
* [配置说明](#Configuration) (配置文件每个项目的说明)
* [样例](#Examples) (配置文件样例)
- [Experiment(实验)配置参考](#experiment-config-reference)
- [模板](#template)
- [说明](#configuration-spec)
- [样例](#examples)
<a name="Template"></a>
## 模板
* **简化版(不包含 Annotation(标记)和 Assessor)**
- **简化版(不包含 Annotation(标记)和 Assessor)**
```yaml
authorName:
......@@ -42,7 +43,7 @@ machineList:
passwd:
```
* **使用 Assessor**
- **使用 Assessor**
```yaml
authorName:
......@@ -81,7 +82,7 @@ machineList:
passwd:
```
* **使用 Annotation**
- **使用 Annotation**
```yaml
authorName:
......@@ -123,364 +124,382 @@ machineList:
## 说明
* **authorName**
- **authorName**
* 说明
- 说明
**authorName** 是创建 Experiment 的作者。 待定: 增加默认值
* **experimentName**
- **experimentName**
* 说明
- 说明
**experimentName** 是 Experiment 的名称。
待实现:增加默认值
* **trialConcurrency**
- **trialConcurrency**
* 说明
- 说明
**trialConcurrency** 定义了并发尝试任务的最大数量。
注意:如果 trialGpuNum 大于空闲的 GPU 数量,并且并发的 Trial 任务数量还没达到 trialConcurrency,Trial 任务会被放入队列,等待分配 GPU 资源。
* **maxExecDuration**
- **maxExecDuration**
* 说明
- 说明
**maxExecDuration** 定义 Experiment 执行的最长时间。时间单位:{**s**, **m**, **h**, **d**},分别代表:{*seconds*, *minutes*, *hours*, *days*}。
注意:maxExecDuration 设置的是 Experiment 执行的时间,不是 Trial 的。 如果 Experiment 达到了设置的最大时间,Experiment 不会停止,但不会再启动新的 Trial 作业。
* **maxTrialNum**
- **debug**
* 说明
- 说明
NNI 会检查 remote, pai 和 Kubernetes 模式下管理器以及 trialKeeper 进程的版本。 如果需要禁用版本检查,debug 应设置为 true。
- **maxTrialNum**
- 说明
**maxTrialNum** 定义了 Trial 任务的最大数量,成功和失败的都计算在内。
* **trainingServicePlatform**
- **trainingServicePlatform**
* 说明
- 说明
**trainingServicePlatform** 定义运行 Experiment 的平台,包括:{**local**, **remote**, **pai**, **kubeflow**}.
* **local** 在本机的 ubuntu 上运行 Experiment。
- **local** 在本机的 ubuntu 上运行 Experiment。
* **remote** 将任务提交到远程的 Ubuntu 上,必须用 **machineList** 来指定远程的 SSH 连接信息。
- **remote** 将任务提交到远程的 Ubuntu 上,必须用 **machineList** 来指定远程的 SSH 连接信息。
* **pai** 提交任务到微软开源的 [OpenPAI](https://github.com/Microsoft/pai) 上。 更多 OpenPAI 配置,参考 [pai 模式](./PAIMode.md)
- **pai** 提交任务到微软开源的 [OpenPAI](https://github.com/Microsoft/pai) 上。 更多 OpenPAI 配置,参考 [pai 模式](./PAIMode.md)
* **kubeflow** 提交任务至 [Kubeflow](https://www.kubeflow.org/docs/about/kubeflow/)。 NNI 支持基于 Kubeflow 的 Kubenetes,以及[Azure Kubernetes](https://azure.microsoft.com/en-us/services/kubernetes-service/)
- **kubeflow** 提交任务至 [Kubeflow](https://www.kubeflow.org/docs/about/kubeflow/)。 NNI 支持基于 Kubeflow 的 Kubenetes,以及[Azure Kubernetes](https://azure.microsoft.com/en-us/services/kubernetes-service/)
* **searchSpacePath**
- **searchSpacePath**
* 说明
- 说明
**searchSpacePath** 定义搜索空间文件的路径,此文件必须在运行 nnictl 的本机。
注意: 如果设置了 useAnnotation=True,searchSpacePath 字段必须被删除。
* **useAnnotation**
- **useAnnotation**
* 说明
- 说明
**useAnnotation** 定义使用标记来分析代码并生成搜索空间。
注意: 如果设置了 useAnnotation=True,searchSpacePath 字段必须被删除。
* **nniManagerIp**
- **nniManagerIp**
* 说明
- 说明
**nniManagerIp** 设置 NNI 管理器运行的 IP 地址。 此字段为可选项,如果没有设置,则会使用 eth0 的 IP 地址。
注意: 可在 NNI 管理器机器上运行 ifconfig 来检查 eth0 是否存在。 如果不存在,推荐显式设置 nnimanagerIp。
* **logDir**
- **logDir**
* 说明
- 说明
**logDir** 配置存储日志和数据的目录。 默认值是 `<user home directory>/nni/experiment`
* **logLevel**
- **logLevel**
* 说明
- 说明
**logLevel** 为 Experiment 设置日志级别,支持的日志级别有:`trace, debug, info, warning, error, fatal`。 默认值是 `info`
* **Tuner**
- **logCollection**
- 说明
**logCollection** 设置在 remote, pai, kubeflow, frameworkcontroller 平台下收集日志的方法。 日志支持两种设置,一种是通过 `http`,让 Trial 将日志通过 POST 方法发回日志,这种方法会减慢 trialKeeper 的速度。 另一种方法是 `none`,Trial 不将日志回传回来,仅仅回传 Job 的指标。 如果日志较大,可将此参数设置为 `none`
* 说明
- **Tuner**
- 说明
**tuner** 指定了 Experiment 的 Tuner 算法。有两种方法可设置 Tuner。 一种方法是使用 SDK 提供的 Tuner,需要设置 **builtinTunerName****classArgs**。 另一种方法,是使用用户自定义的 Tuner,需要设置 **codeDirectory****classFileName****className****classArgs**
* **builtinTunerName****classArgs**
- **builtinTunerName****classArgs**
* **builtinTunerName**
- **builtinTunerName**
**builtinTunerName** 指定了系统 Tuner 的名字,NNI SDK 提供了多种 Tuner,如:{**TPE**, **Random**, **Anneal**, **Evolution**, **BatchTuner**, **GridSearch**}。
* **classArgs**
- **classArgs**
**classArgs** 指定了 Tuner 算法的参数。 如果 **builtinTunerName** 是{**TPE**, **Random**, **Anneal**, **Evolution**},用户需要设置 **optimize_mode**
* **codeDir**, **classFileName**, **className****classArgs**
- **codeDir**, **classFileName**, **className****classArgs**
* **codeDir**
- **codeDir**
**codeDir** 指定 Tuner 代码的目录。
* **classFileName**
- **classFileName**
**classFileName** 指定 Tuner 文件名。
* **className**
- **className**
**className** 指定 Tuner 类名。
* **classArgs**
- **classArgs**
**classArgs** 指定了 Tuner 算法的参数。
* **gpuNum**
- **gpuNum**
**gpuNum** 指定了运行 Tuner 进程的 GPU 数量。 此字段的值必须是正整数。
__gpuNum__ 指定了运行 Tuner 进程的 GPU 数量。 此字段的值必须是正整数。
注意: 只能使用一种方法来指定 Tuner,例如:设置{tunerName, optimizationMode} 或 {tunerCommand, tunerCwd},不能同时设置。
* **Assessor**
* 说明
- **includeIntermediateResults**
如果 __includeIntermediateResults__ 为 true,最后一个 Assessor 的中间结果会被发送给 Tuner 作为最终结果。 __includeIntermediateResults__ 的默认值为 false。
- **Assessor**
- 说明
**assessor** 指定了 Experiment 的 Assessor 算法。有两种方法可设置 Assessor。 一种方法是使用 SDK 提供的 Assessor,需要设置 **builtinAssessorName****classArgs**。 另一种方法,是使用用户自定义的 Assessor,需要设置 **codeDirectory****classFileName****className****classArgs**
* **builtinAssessorName****classArgs**
- **builtinAssessorName****classArgs**
* **builtinAssessorName**
- **builtinAssessorName**
**builtinAssessorName** 指定了系统 Assessor 的名称, NNI 内置的 Assessor 有 {**Medianstop**,等等}。
* **classArgs**
- **classArgs**
**classArgs** 指定了 Assessor 算法的参数。
* **codeDir**, **classFileName**, **className****classArgs**
- **codeDir**, **classFileName**, **className****classArgs**
* **codeDir**
- **codeDir**
**codeDir** 指定 Assessor 代码的目录。
* **classFileName**
- **classFileName**
**classFileName** 指定 Assessor 文件名。
* **className**
- **className**
**className** 指定 Assessor 类名。
* **classArgs**
- **classArgs**
**classArgs** 指定了 Assessor 算法的参数。
* **gpuNum**
- **gpuNum**
**gpuNum** 指定了运行 Assessor 进程的 GPU 数量。 此字段的值必须是正整数。
注意: 只能使用一种方法来指定 Assessor,例如:设置 {assessorName, optimizationMode} 或 {assessorCommand, assessorCwd},不能同时设置。如果不需要使用 Assessor,可将其置为空。
* **trial (local, remote)**
- **trial (local, remote)**
* **command**
- **command**
**command** 指定了运行 Trial 进程的命令行。
* **codeDir**
- **codeDir**
**codeDir** 指定了 Trial 代码文件的目录。
* **gpuNum**
- **gpuNum**
**gpuNum** 指定了运行 Trial 进程的 GPU 数量。 默认值为 0。
* **trial (pai)**
- **trial (pai)**
* **command**
- **command**
**command** 指定了运行 Trial 进程的命令行。
* **codeDir**
- **codeDir**
**codeDir** 指定了 Trial 代码文件的目录。
* **gpuNum**
- **gpuNum**
**gpuNum** 指定了运行 Trial 进程的 GPU 数量。 默认值为 0。
* **cpuNum**
- **cpuNum**
**cpuNum** 指定了 OpenPAI 容器中使用的 CPU 数量。
* **memoryMB**
- **memoryMB**
**memoryMB** 指定了 OpenPAI 容器中使用的内存数量。
* **image**
- **image**
**image** 指定了 OpenPAI 中使用的 docker 映像。
* **dataDir**
- **dataDir**
**dataDir** 是 HDFS 中用到的数据目录变量。
* **outputDir**
- **outputDir**
**outputDir** 是 HDFS 中用到的输出目录变量。在 OpenPAI 中,stdout 和 stderr 文件会在作业完成后,存放在此目录中。
* **trial (kubeflow)**
- **trial (kubeflow)**
* **codeDir**
- **codeDir**
**codeDir** 指定了代码文件的本机路径。
* **ps (可选)**
- **ps (可选)**
**ps** 是 Kubeflow 的 Tensorflow-operator 配置。
* **replicas**
- **replicas**
**replicas****ps** 角色的副本数量。
* **command**
- **command**
**command** 是在 **ps** 的容器中运行的脚本命令。
* **gpuNum**
- **gpuNum**
**gpuNum** 是在 **ps** 容器中使用的 GPU 数量。
* **cpuNum**
- **cpuNum**
**cpuNum** 是在 **ps** 容器中使用的 CPU 数量。
* **memoryMB**
- **memoryMB**
**memoryMB** 指定了容器中使用的内存数量。
* **image**
- **image**
**image** 设置了 **ps** 使用的 docker 映像。
* **worker**
- **worker**
**worker** 是 Kubeflow 的 Tensorflow-operator 配置。
* **replicas**
- **replicas**
**replicas****worker** 角色的副本数量。
* **command**
- **command**
**command** 是在 **worker** 的容器中运行的脚本命令。
* **gpuNum**
- **gpuNum**
**gpuNum** 是在 **worker** 容器中使用的 GPU 数量。
* **cpuNum**
- **cpuNum**
**cpuNum** 是在 **worker** 容器中使用的 CPU 数量。
* **memoryMB**
- **memoryMB**
**memoryMB** 指定了容器中使用的内存数量。
* **image**
- **image**
**image** 设置了 **worker** 使用的 docker 映像。
* **machineList**
- **machineList**
如果 **trainingServicePlatform** 为 remote,则需要设置 **machineList**。否则应将其置为空。
* **ip**
- **ip**
**ip** 是远程计算机的 ip 地址。
* **port**
- **port**
**端口** 是用于连接远程计算机的 ssh 端口。
注意:如果 port 设为空,则为默认值 22。
* **username**
- **username**
**username** 是远程计算机的用户名。
* **passwd**
- **passwd**
**passwd** 指定了账户的密码。
* **sshKeyPath**
- **sshKeyPath**
如果要使用 ssh 密钥登录远程计算机,则需要设置 **sshKeyPath****sshKeyPath** 为有效的 ssh 密钥文件路径。
注意:如果同时设置了 passwd 和 sshKeyPath,NNI 会使用 passwd。
* **passphrase**
- **passphrase**
**passphrase** 用于保护 ssh 密钥,如果没有使用,可为空。
* **kubeflowConfig**:
- **kubeflowConfig**:
* **operator**
- **operator**
**operator** 指定了 kubeflow 使用的 operator,NNI 当前版本支持 **tf-operator**
* **存储**
- **storage**
**storage** 指定了 kubeflow 的存储类型,包括 {**nfs****azureStorage**}。 此字段可选,默认值为 **nfs**。 如果使用了 azureStorage,此字段必须填写。
* **nfs**
- **nfs**
**server** 是 NFS 服务器的地址
**path** 是 NFS 挂载的路径
* **keyVault**
- **keyVault**
如果用户使用 Azure Kubernetes Service,需要设置 keyVault 来使用 Azure 存储账户的私钥。 参考: https://docs.microsoft.com/en-us/azure/key-vault/key-vault-manage-with-cli2
* **vaultName**
- **vaultName**
**vaultName** 是 az 命令中 `--vault-name` 的值。
* **name**
- **name**
**name** 是 az 命令中 `--name` 的值。
* **azureStorage**
- **azureStorage**
如果用户使用了 Azure Kubernetes Service,需要设置 Azure 存储账户来存放代码文件。
* **accountName**
- **accountName**
**accountName** 是 Azure 存储账户的名称。
* **azureShare**
- **azureShare**
**azureShare** 是 Azure 文件存储的共享参数。
* **paiConfig**
- **paiConfig**
* **userName**
- **userName**
**userName** 是 OpenPAI 的用户名。
* **password**
- **password**
**password** 是 OpenPAI 用户的密码。
* **host**
- **host**
**host** 是 OpenPAI 的主机地址。
......@@ -488,7 +507,7 @@ machineList:
## 样例
* **本机模式**
- **本机模式**
如果要在本机运行 Trial 任务,并使用标记来生成搜索空间,可参考下列配置:
......@@ -583,9 +602,9 @@ machineList:
gpuNum: 0
```
* **远程模式**
- **远程模式**
如果在远程服务器上运行 Trial 任务,需要增加服务器信息:
如果在远程服务器上运行 Trial 任务,需要增加服务器信息:
```yaml
authorName: test
......@@ -627,7 +646,7 @@ machineList:
passphrase: qwert
```
* **pai 模式**
- **pai 模式**
```yaml
authorName: test
......@@ -668,7 +687,7 @@ machineList:
host: 10.10.10.10
```
* **Kubeflow 模式**
- **Kubeflow 模式**
使用 NFS 存储。
......
# **How to Implement TrainingService in NNI**
## Overview
TrainingService is a module related to platform management and job schedule in NNI. TrainingService is designed to be easily implemented, we define an abstract class TrainingService as the parent class of all kinds of TrainignService, users just need to inherit the parent class and complete their own clild class if they want to implement customized TrainingService.
## System architecture
![](../img/NNIDesign.jpg)
The brief system architecture of NNI is shown in the picture. NNIManager is the core management module of system, in charge of calling TrainingService to manage trial jobs and the communication between different modules. Dispatcher is a message processing center responsible for message dispatch. TrainingService is a module to manage trial jobs, it communicates with nniManager module, and has different instance according to different training platform. For the time being, NNI supports local platfrom, [remote platfrom](RemoteMachineMode.md), [PAI platfrom](PAIMode.md), [kubeflow platform](KubeflowMode.md) and [FrameworkController platfrom](FrameworkController.md).
In this document, we introduce the brief design of TrainingService. If users want to add a new TrainingService instance, they just need to complete a child class to implement TrainingService, don't need to understand the code detail of NNIManager, Dispatcher or other modules.
## Folder structure of code
NNI's folder structure is shown below:
nni
|- deployment
|- docs
|- examaples
|- src
| |- nni_manager
| | |- common
| | |- config
| | |- core
| | |- coverage
| | |- dist
| | |- rest_server
| | |- training_service
| | | |- common
| | | |- kubernetes
| | | |- local
| | | |- pai
| | | |- remote_machine
| | | |- test
| |- sdk
| |- webui
|- test
|- tools
| |-nni_annotation
| |-nni_cmd
| |-nni_gpu_tool
| |-nni_trial_tool
`nni/src/` folder stores the most source code of NNI. The code in this folder is related to NNIManager, TrainingService, SDK, WebUI and other modules. Users could find the abstract class of TrainingService in `nni/src/nni_manager/common/trainingService.ts` file, and they should put their own implemented TrainingService in `nni/src/nni_manager/training_service` folder. If users have implemented their own TrainingService code, they should also supplement the unit test of the code, and place them in `nni/src/nni_manager/training_service/test` folder.
## Function annotation of TrainingService
abstract class TrainingService {
public abstract listTrialJobs(): Promise<TrialJobDetail[]>;
public abstract getTrialJob(trialJobId: string): Promise<TrialJobDetail>;
public abstract addTrialJobMetricListener(listener: (metric: TrialJobMetric) => void): void;
public abstract removeTrialJobMetricListener(listener: (metric: TrialJobMetric) => void): void;
public abstract submitTrialJob(form: JobApplicationForm): Promise<TrialJobDetail>;
public abstract updateTrialJob(trialJobId: string, form: JobApplicationForm): Promise<TrialJobDetail>;
public abstract get isMultiPhaseJobSupported(): boolean;
public abstract cancelTrialJob(trialJobId: string, isEarlyStopped?: boolean): Promise<void>;
public abstract setClusterMetadata(key: string, value: string): Promise<void>;
public abstract getClusterMetadata(key: string): Promise<string>;
public abstract cleanUp(): Promise<void>;
public abstract run(): Promise<void>;
}
The parent class of TrainingService has a few abstract functions, users need to inherit the parent class and implement all of these abstract functions.
**setClusterMetadata(key: string, value: string)**
ClusterMetadata is the data related to platform details, for examples, the ClusterMetadata defined in remote machine server is:
export class RemoteMachineMeta {
public readonly ip : string;
public readonly port : number;
public readonly username : string;
public readonly passwd?: string;
public readonly sshKeyPath?: string;
public readonly passphrase?: string;
public gpuSummary : GPUSummary | undefined;
/* GPU Reservation info, the key is GPU index, the value is the job id which reserves this GPU*/
public gpuReservation : Map<number, string>;
constructor(ip : string, port : number, username : string, passwd : string,
sshKeyPath : string, passphrase : string) {
this.ip = ip;
this.port = port;
this.username = username;
this.passwd = passwd;
this.sshKeyPath = sshKeyPath;
this.passphrase = passphrase;
this.gpuReservation = new Map<number, string>();
}
}
The metadata includes the host address, the username or other configuration related to the platform. Users need to define their own metadata format, and set the metadata instance in this function. This function is called before the experiment is started to set the configuration of remote machines.
**getClusterMetadata(key: string)**
This function will return the metadata value according to the values, it could be left empty if users don't need to use it.
**submitTrialJob(form: JobApplicationForm)**
SubmitTrialJob is a function to submit new trial jobs, users should generate a job instance in TrialJobDetail type. TrialJobDetail is defined as follow:
interface TrialJobDetail {
readonly id: string;
readonly status: TrialJobStatus;
readonly submitTime: number;
readonly startTime?: number;
readonly endTime?: number;
readonly tags?: string[];
readonly url?: string;
readonly workingDirectory: string;
readonly form: JobApplicationForm;
readonly sequenceId: number;
isEarlyStopped?: boolean;
}
According to different kinds of implementation, users could put the job detail into a job queue, and keep fetching the job from the queue and start preparing and running them. Or they could finish preparing and running process in this function, and return job detail after the submit work.
**cancelTrialJob(trialJobId: string, isEarlyStopped?: boolean)**
If this function is called, the trial started by the platform should be canceled. Different kind of platform has diffenent methods to calcel a running job, this function should be implemented according to specific platform.
**updateTrialJob(trialJobId: string, form: JobApplicationForm)**
This function is called to update the trial job's status, trial job's status should be detected according to different platform, and be updated to `RUNNING`, `SUCCEED`, `FAILED` etc.
**getTrialJob(trialJobId: string)**
This function returns a trialJob detail instance according to trialJobId.
**listTrialJobs()**
Users should put all of trial job detail information into a list, and return the list.
**addTrialJobMetricListener(listener: (metric: TrialJobMetric) => void)**
NNI will hold an EventEmitter to get job metrics, if there is new job metrics detected, the EventEmitter will be triggered. Users should start the EventEmitter in this function.
**removeTrialJobMetricListener(listener: (metric: TrialJobMetric) => void)**
Close the EventEmitter.
**run()**
The run() function is a main loop function in TrainingService, users could set a while loop to execute their logic code, and finish executing them when the experiment is stopped.
**cleanUp()**
This function is called to clean up the environment when a experiment is stopped. Users should do the platform-related cleaning operation in this function.
## TrialKeeper tool
NNI offers a TrialKeeper tool to help maintaining trial jobs. Users can find the source code in `nni/tools/nni_trial_tool`. If users want to run trial jobs in cloud platform, this tool will be a fine choice to help keeping trial running in the platform. The running architecture of TrialKeeper is show as follow:
![](../img/trialkeeper.jpg)
When users submit a trial job to cloud platform, they should wrap their trial command into TrialKeeper, and start a TrialKeeper process in cloud platform. Notice that TrialKeeper use restful server to communicate with TrainingService, users should start a restful server in local machine to receive metrics sent from TrialKeeper. The source code about restful server could be found in `nni/src/nni_manager/training_service/common/clusterJobRestServer.ts`.
## Reference
For more information about how to debug, please [refer](HowToDebug.md).
The guide line of how to contribute, please [refer](CONTRIBUTING).
\ No newline at end of file
# **如何在 NNI 中使用 Docker**
## 概述
[Docker](https://www.docker.com/) 是一种工具, 可通过启动容器, 使用户能够更轻松地根据自己的操作系统部署和运行应用程序。 Docker 不是虚拟机, 它不创建虚拟操作系统, 但是它允许不同的应用程序使用相同的操作系统内核, 并通过容器隔离不同的应用程序。
用户可以使用docker进行 NNI 实验, NNI 在docker hub上提供了一个官方的镜像 [msranni/nni](https://hub.docker.com/r/msranni/nni)
## 在本机使用docker
### 第一步:docker的安装
在你开始使用docker进行NNI实验之前,你首先需要在本地机器上安装docker运行程序。 [参考](https://docs.docker.com/install/linux/docker-ce/ubuntu/)
### 第二步:启动docker容器
如果你已经在本地机器上安装了docker程序,你可以启动docker容器来运行NNI实验了。 因为NNI会在docker容器里面启动web UI进程,并且监听一个端口,因此你需要指定一个在主机和docker容器里面的端口映射,这个映射可以让你在容器外面访问docker容器里面的进程。 通过访问主机的ip和端口,你就可以访问容器里面的Web网页进程了。
例如,你可以通过如下命令来启动docker容器:
docker run -i -t -p [hostPort]:[containerPort] [image]
-i: 使用交互模式启动docker
-t: Docker分配一个输入终端。
-p: 端口映射,映射主机端口和容器端口。
可以参考[这里](https://docs.docker.com/v17.09/edge/engine/reference/run/),获取更多的命令参考。
注意:
NNI只支持Ubuntu和macOS操作系统,请指定正确的docker镜像。如果你希望在docker里面使用gpu,请使用nvidia-docker。
### 步骤3:在docker容器里面运行NNI
如果你直接使用NNI的官方镜像`msranni/nni`来启动实验,你可以直接使用`nnictl`命令。 NNI的官方镜像有最基础的python环境和深度学习框架。
如果你使用你自己的docker镜像,你首先需要安装NNI环境。[参考](Installation.md)
如果你想要使用NNI的官方例子,你可以通过以下git命令来克隆NNI:
git clone https://github.com/Microsoft/nni.git
然后可以进入`nni/examples/trials`文件夹来启动实验。
等你准备完NNI环境,你可以通过`nnictl`命令来启动实验,[参考](QuickStart.md).
## 在远程平台上运行docker
NNI支持在[远程平台](RemoteMachineMode.md)上启动实验,在远程机器里运行任务。 因为docker可以运行独立的Ubuntu系统和SSH服务,因此docker容器可以作为远程平台来运行NNI.
### 步骤1:设置docker环境
你首先应该在远程机器上安装docker工具,[参考](https://docs.docker.com/install/linux/docker-ce/ubuntu/).
为了保证docker容器可以被NNI实验连接上,你应该在你自己的docker容器里面安装SSH服务,并做SSH相关配置。 如果你想在docker容器里面使用SSH服务,你应该配置SSH密码登录或者私钥登录,[参考](https://docs.docker.com/engine/examples/running_ssh_service/)
注意:
NNI的官方镜像msranni/nni暂时不支持SSH服务,你应该构建自己的带有SSH服务的镜像,或者使用其他的带有SSH服务的镜像。
### 第二步:在远程机器上启动docker容器
SSH容器需要一个端口,你需要把docker的SSH服务端口暴露给NNI作为连接端口。 例如,如果你设置容器的端口**`A`**作为SSH端口,你应该把端口**`A`**映射到主机的端口**`B`**,NNI会连接端口**`B`**作为SSH服务端口,你的主机会把连接到端口**`B`**的连接映射到端口**`A`**,NNI就可以连接到你的容器中了。
例如,你可以通过如下命令来启动docker容器:
docker run -dit -p [hostPort]:[containerPort] [image]
`containerPort`是在docker容器中指定的端口,`hostPort`是主机的端口。 你可以设置你的NNI配置,连接到`hostPort`,这个连接会被转移到你的docker容器中。 更多的命定信息,可以[参考](https://docs.docker.com/v17.09/edge/engine/reference/run/).
注意:
如果你使用你自己构建的docker容器,请保证这个容器中有基础的python运行时环境和NNI SDK环境。 如果你想要在docker容器里面使用gpu,请使用nvidia-docker。
### 步骤三:运行NNI实验
你可以在你的配置文件中,设置训练平台为远程平台,然后设置`machineList`配置。[参考](RemoteMachineMode.md)。 注意你应该设置正确的`port``username`, `passwd`或者`sshKeyPath`
`port`: 主机的端口,映射到docker的SSH端口中。
`username`: docker容器的用户名。
`passWd: ` docker容器的密码。
`sshKeyPath:` docker容器私钥的存储路径。
设置完配置文件,你就可以启动实验了,[参考](QuickStart.md)
\ No newline at end of file
......@@ -46,6 +46,12 @@ nnictl 支持的命令:
| ------------ | ----- | --- | ---------------------- |
| --config, -c | True | | Experiment 的 YAML 配置文件 |
| --port, -p | False | | RESTful 服务的端口 |
| --debug, -d | False | | 设置为调试模式 |
注意:
调试模式会禁用 Trialkeeper 中的版本检查功能。
<a name="resume"></a>
......@@ -64,9 +70,10 @@ nnictl 支持的命令:
* 选项
| 参数及缩写 | 是否必需 | 默认值 | 说明 |
| ---------- | ----- | --- | -------------------------------- |
| ----------- | ----- | --- | -------------------------------- |
| id | False | | 要恢复的 Experiment 标识 |
| --port, -p | False | | 要恢复的 Experiment 使用的 RESTful 服务端口 |
| --debug, -d | False | | 设置为调试模式 |
<a name="stop"></a>
......@@ -207,9 +214,9 @@ nnictl 支持的命令:
* 选项
| 参数及缩写 | 是否必需 | 默认值 | 说明 |
| ------------- | ----- | --- | --------------------- |
| id | False | | 需要设置的 Experiment 的 id |
| --trialid, -t | True | | 需要终止的 Trial 的 id。 |
| ---------------- | ----- | --- | --------------------- |
| id | False | | 要终止的 Trial 的 id |
| --experiment, -E | True | | Trial 的 Experiment id |
<a name="top"></a>
......@@ -359,8 +366,9 @@ nnictl 支持的命令:
* 选项
| 参数及缩写 | 是否必需 | 默认值 | 说明 |
| ----- | ----- | --- | ---------- |
| id | False | | Trial 的 id |
| ---------------- | ----- | --- | ----------------------------- |
| id | False | | 需要显示日志路径的 Trial id |
| --experiment, -E | False | | 如果 id 为空,则需要添加 Experiment id。 |
<a name="webui"></a>
......
......@@ -58,6 +58,10 @@ paiConfig:
* 可选。 指定了 Trial 用于下载数据的 HDFS 数据目录。 格式应为 hdfs://{your HDFS host}:9000/{数据目录}
* outputDir
* 可选。 指定了 Trial 的 HDFS 输出目录。 Trial 在完成(成功或失败)后,Trial 的 stdout, stderr 会被 NNI 自动复制到此目录中。 格式应为 hdfs://{your HDFS host}:9000/{输出目录}
* virturlCluster
* 可选。 设置 OpenPAI 的 virtualCluster,即虚拟集群。 如果未设置此参数,将使用默认的虚拟集群。
* shmMB
* 可选。 设置 OpenPAI 的 shmMB,即 Docker 中的共享内存。
完成并保存 NNI Experiment 配置文件后(例如可保存为:exp_pai.yml),运行以下命令:
......
......@@ -9,3 +9,4 @@
Annotation<AnnotationSpec>
配置<ExperimentConfig>
搜索空间<SearchSpaceSpec>
实现训练平台<HowToImplementTrainingService>
\ No newline at end of file
......@@ -96,7 +96,7 @@ with tf.Session() as sess:
batch_size = 128
for i in range(10000):
batch = mnist.train.next_batch(batch_size)
+ """@nni.variable(nni.choice(1, 5), name=dropout_rate)"""
+ """@nni.variable(nni.choice(0.1, 0.5), name=dropout_rate)"""
dropout_rate = 0.5
mnist_network.train_step.run(feed_dict={mnist_network.images: batch[0],
mnist_network.labels: batch[1],
......
......@@ -11,4 +11,5 @@
Assessor<assessors>
Web 界面<WebUI>
训练平台<training_services>
如何使用 Docker <HowToUseDocker>
高级功能<advanced>
\ No newline at end of file
......@@ -6,7 +6,7 @@ Network Morphism (网络形态)是内置的 Tuner,它使用了网络形态
### 1. 训练框架支持
网络形态当前基于框架,还没有实现与框架脱离的方法。 当前支持 Pytorch 和 Keras。 如果熟悉 JSON 中间格式,可以在自定义的训练框架中生成自己的模型。 随后,我们会将中间结果从 JSON 转换为 ONNX,从而能够成为[标准的中间表示](https://github.com/onnx/onnx/blob/master/docs/IR.md)
网络形态当前基于框架,还没有实现与框架脱离的方法。 当前支持 PyTorch 和 Keras。 如果熟悉 JSON 中间格式,可以在自定义的训练框架中生成自己的模型。 随后,我们会将中间结果从 JSON 转换为 ONNX,从而能够成为[标准的中间表示](https://github.com/onnx/onnx/blob/master/docs/IR.md)
### 2. 安装需求
......
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