PaiMode.md 10.1 KB
Newer Older
1
2
**Run an Experiment on OpenPAI**
===
3
NNI supports running an experiment on [OpenPAI](https://github.com/Microsoft/pai), called pai mode. Before starting to use NNI pai mode, you should have an account to access an [OpenPAI](https://github.com/Microsoft/pai) cluster. See [here](https://github.com/Microsoft/pai#how-to-deploy) if you don't have any OpenPAI account and want to deploy an OpenPAI cluster. In pai mode, your trial program will run in pai's container created by Docker.
4

5
6
[toc]

7
## Setup environment
8

9
**Step 1. Install NNI, follow the install guide [here](../Tutorial/QuickStart.md).**   
10

11
**Step 2. Get token.**
12
13

Open web portal of OpenPAI, and click `My profile` button in the top-right side.
14
<img src="../../img/pai_profile.jpg" style="zoom: 80%;" />
15

SparkSnail's avatar
SparkSnail committed
16
Click `copy` button in the page to copy a jwt token.
17
<img src="../../img/pai_token.jpg" style="zoom:67%;" />
18

19
**Step 3. Mount NFS storage to local machine.**  
20
21

  Click `Submit job` button in web portal.
22
<img src="../../img/pai_job_submission_page.jpg" style="zoom: 50%;" />
23
24

  Find the data management region in job submission page.
25
<img src="../../img/pai_data_management_page.jpg" style="zoom: 33%;" />  
26
27

The `Preview container paths` is the NFS host and path that OpenPAI provided, you need to mount the corresponding host and path to your local machine first, then NNI could use the OpenPAI's NFS storage.  
28
For example, use the following command:
29
30

```bash
SparkSnail's avatar
SparkSnail committed
31
sudo mount -t nfs4 gcr-openpai-infra02:/pai/data /local/mnt
32
33
34
```
Then the `/data` folder in container will be mounted to `/local/mnt` folder in your local machine.  
You could use the following configuration in your NNI's config file:
35
36

```yaml
37
nniManagerNFSMountPath: /local/mnt
38
```
39

40
**Step 4. Get OpenPAI's storage config name and nniManagerMountPath**
41

42
43
44
The `Team share storage` field is storage configuration used to specify storage value in OpenPAI. You can get `paiStorageConfigName` and `containerNFSMountPath` field in `Team share storage`, for example:

```yaml
45
46
paiStorageConfigName: confignfs-data
containerNFSMountPath: /mnt/confignfs-data
47
```
48

49
50


51
## Run an experiment
52

53
Use `examples/trials/mnist-annotation` as an example. The NNI config YAML file's content is like:
Chi Song's avatar
Chi Song committed
54

Yan Ni's avatar
Yan Ni committed
55
```yaml
56
57
58
59
60
61
62
63
64
65
authorName: your_name
experimentName: auto_mnist
# how many trials could be concurrently running
trialConcurrency: 2
# maximum experiment running duration
maxExecDuration: 3h
# empty means never stop
maxTrialNum: 100
# choice: local, remote, pai
trainingServicePlatform: pai
LongzeSong's avatar
LongzeSong committed
66
67
# search space file
searchSpacePath: search_space.json
68
# choice: true, false
69
70
71
72
73
74
75
76
77
78
79
useAnnotation: true
tuner:
  builtinTunerName: TPE
  classArgs:
    optimize_mode: maximize
trial:
  command: python3 mnist.py
  codeDir: ~/nni/examples/trials/mnist-annotation
  gpuNum: 0
  cpuNum: 1
  memoryMB: 8196
80
  image: msranni/nni:latest
81
  virtualCluster: default
SparkSnail's avatar
SparkSnail committed
82
83
  nniManagerNFSMountPath: /local/mnt
  containerNFSMountPath: /mnt/confignfs-data
84
  paiStorageConfigName: confignfs-data
85
86
87
# Configuration to access OpenPAI Cluster
paiConfig:
  userName: your_pai_nni_user
88
  token: your_pai_token
89
  host: 10.1.1.1
90
91
  # optional, experimental feature.
  reuse: true
92
```
Chi Song's avatar
Chi Song committed
93

SparkSnail's avatar
SparkSnail committed
94
Note: You should set `trainingServicePlatform: pai` in NNI config YAML file if you want to start experiment in pai mode. The host field in configuration file is PAI's job submission page uri, like `10.10.5.1`, the default http protocol in NNI is `http`, if your PAI's cluster enabled https, please use the uri in `https://10.10.5.1` format.
95

96
97


98
99
### Trial configurations

100
Compared with [LocalMode](LocalMode.md) and [RemoteMachineMode](RemoteMachineMode.md), `trial` configuration in pai mode has the following additional keys:
101
102

* cpuNum
103
104
105

  Optional key. Should be positive number based on your trial program's CPU  requirement. If it is not set in trial configuration, it should be set in the config file specified in `paiConfigPath` field.

106
* memoryMB
107
108
109

  Optional key. Should be positive number based on your trial program's memory requirement. If it is not set in trial configuration, it should be set in the config file specified in `paiConfigPath` field.

110
* image
111
112
113

  Optional key. In pai mode, your trial program will be scheduled by OpenPAI to run in [Docker container](https://www.docker.com/). This key is used to specify the Docker image used to create the container in which your trial will run.

114
  We already build a docker image [nnimsra/nni](https://hub.docker.com/r/msranni/nni/) on [Docker Hub](https://hub.docker.com/). It contains NNI python packages, Node modules and javascript artifact files required to start experiment, and all of NNI dependencies. The docker file used to build this image can be found at [here](https://github.com/Microsoft/nni/tree/v1.9/deployment/docker/Dockerfile). You can either use this image directly in your config file, or build your own image based on it. If it is not set in trial configuration, it should be set in the config file specified in `paiConfigPath` field.
115

116
* virtualCluster
117
118
119

  Optional key. Set the virtualCluster of OpenPAI. If omitted, the job will run on default virtual cluster.

120
* nniManagerNFSMountPath
121
122
123

  Required key. Set the mount path in your nniManager machine.

124
* containerNFSMountPath
125
126
127

  Required key. Set the mount path in your container used in OpenPAI.

128
* paiStorageConfigName:
129
130
131
132
133
134
135

  Optional key. Set the storage name used in OpenPAI. If it is not set in trial configuration, it should be set in the config file specified in `paiConfigPath` field.

* command

  Optional key. Set the commands used in OpenPAI container.

SparkSnail's avatar
SparkSnail committed
136
* paiConfigPath
137
138
139
140
141
142
  Optional key. Set the file path of OpenPAI job configuration, the file is in yaml format.

  If users set `paiConfigPath` in NNI's configuration file, no need to specify the fields `command`, `paiStorageConfigName`, `virtualCluster`, `image`, `memoryMB`, `cpuNum`, `gpuNum` in `trial` configuration. These fields will use the values from the config file specified by  `paiConfigPath`.

  Note:
  1. The job name in OpenPAI's configuration file will be replaced by a new job name, the new job name is created by NNI, the name format is nni_exp_${this.experimentId}_trial_${trialJobId}.
143

144
  2. If users set multiple taskRoles in OpenPAI's configuration file, NNI will wrap all of these taksRoles and start multiple tasks in one trial job, users should ensure that only one taskRole report metric to NNI, otherwise there might be some conflict error.
145

146
147


148
### OpenPAI configurations
149

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
`paiConfig` includes OpenPAI specific configurations,

* userName

  Required key. User name of OpenPAI platform.

* token

  Required key. Authentication key of OpenPAI platform.

* host

  Required key. The host of OpenPAI platform. It's OpenPAI's job submission page uri, like `10.10.5.1`, the default http protocol in NNI is `http`, if your OpenPAI cluster enabled https, please use the uri in `https://10.10.5.1` format.

* reuse (experimental feature)

  Optional key, default is false. If it's true, NNI will reuse OpenPAI jobs to run as many as possible trials. It can save time of creating new jobs. User needs to make sure each trial can run independent in same job, for example, avoid loading checkpoint from previous trials.
167

168
Once complete to fill NNI experiment config file and save (for example, save as exp_pai.yml), then run the following command
169
170

```bash
171
nnictl create --config exp_pai.yml
172
```
173

174
to start the experiment in pai mode. NNI will create OpenPAI job for each trial, and the job name format is something like `nni_exp_{experiment_id}_trial_{trial_id}`.
175
You can see jobs created by NNI in the OpenPAI cluster's web portal, like:
xuehui's avatar
xuehui committed
176
![](../../img/nni_pai_joblist.jpg)
177

178
Notice: In pai mode, NNIManager will start a rest server and listen on a port which is your NNI WebUI's port plus 1. For example, if your WebUI port is `8080`, the rest server will listen on `8081`, to receive metrics from trial job running in Kubernetes. So you should `enable 8081` TCP port in your firewall rule to allow incoming traffic.
179

180
Once a trial job is completed, you can goto NNI WebUI's overview page (like http://localhost:8080/oview) to check trial's information.
181
182

Expand a trial information in trial list view, click the logPath link like:
183
<img src="../../img/nni_webui_joblist.jpg" style="zoom: 30%;" />
184
185

And you will be redirected to HDFS web portal to browse the output files of that trial in HDFS:
186
<img src="../../img/nni_trial_hdfs_output.jpg" style="zoom: 80%;" />
187
188
189

You can see there're three fils in output folder: stderr, stdout, and trial.log

190
191


192
## data management
193

194
Before using NNI to start your experiment, users should set the corresponding mount data path in your nniManager machine. OpenPAI has their own storage(NFS, AzureBlob ...), and the storage will used in OpenPAI will be mounted to the container when it start a job. Users should set the OpenPAI storage type by `paiStorageConfigName` field to choose a storage in OpenPAI. Then users should mount the storage to their nniManager machine, and set the `nniManagerNFSMountPath` field in configuration file, NNI will generate bash files and copy data in `codeDir` to the `nniManagerNFSMountPath` folder, then NNI will start a trial job. The data in `nniManagerNFSMountPath` will be sync to OpenPAI storage, and will be mounted to OpenPAI's container. The data path in container is set in `containerNFSMountPath`, NNI will enter this folder first, and then run scripts to start a trial job. 
195

196
197


198
## version check
199

200
201
NNI support version check feature in since version 0.6. It is a policy to insure the version of NNIManager is consistent with trialKeeper, and avoid errors caused by version incompatibility.
Check policy:
202

203
1. NNIManager before v0.6 could run any version of trialKeeper, trialKeeper support backward compatibility.
204
205
206
207
2. Since version 0.6, NNIManager version should keep same with triakKeeper version. For example, if NNIManager version is 0.6, trialKeeper version should be 0.6 too.
3. Note that the version check feature only check first two digits of version.For example, NNIManager v0.6.1 could use trialKeeper v0.6 or trialKeeper v0.6.2, but could not use trialKeeper v0.5.1 or trialKeeper v0.7.

If you could not run your experiment and want to know if it is caused by version check, you could check your webUI, and there will be an error message about version check.
208
209

<img src="../../img/version_check.png" style="zoom: 80%;" />