RemoteMachineMode.md 2.47 KB
Newer Older
Chi Song's avatar
Chi Song committed
1
# 在远程计算机上运行 Experiment
Chi Song's avatar
Chi Song committed
2

Chi Song's avatar
Chi Song committed
3
NNI 可以通过 SSH 在多个远程计算机上运行同一个 Experiment,称为 `remote` 模式。 这就像一个轻量级的训练平台。 在此模式下,可以从计算机启动 NNI,并将 Trial 并行调度到远程计算机。
Chi Song's avatar
Chi Song committed
4

Chi Song's avatar
Chi Song committed
5
6
## 远程计算机的要求

Chi Song's avatar
Chi Song committed
7
* 仅支持 Linux 作为远程计算机,其[配置需求](../Tutorial/InstallationLinux.md)与 NNI 本机模式相同。
Chi Song's avatar
Chi Song committed
8

Chi Song's avatar
Chi Song committed
9
* 根据[安装文章](../Tutorial/InstallationLinux.md),在每台计算机上安装 NNI。
Chi Song's avatar
Chi Song committed
10
11
12
13
14
15
16
17
18
19

* 确保远程计算机满足 Trial 代码的环境要求。 如果默认环境不符合要求,可以将设置脚本添加到 NNI 配置的 `command` 字段。

* 确保远程计算机能被运行 `nnictl` 命令的计算机通过 SSH 访问。 同时支持 SSH 的密码和密钥验证方法。 有关高级用法,参考[配置](../Tutorial/ExperimentConfig.md)的 machineList 部分。

* 确保每台计算机上的 NNI 版本一致。

## 运行 Experiment

例如,有三台机器,可使用用户名和密码登录。
Chi Song's avatar
Chi Song committed
20
21
22
23
24
25
26

| IP       | 用户名 | 密码     |
| -------- | --- | ------ |
| 10.1.1.1 | bob | bob123 |
| 10.1.1.2 | bob | bob123 |
| 10.1.1.3 | bob | bob123 |

Chi Song's avatar
Chi Song committed
27
在这三台计算机或另一台能访问这些计算机的环境中安装并运行 NNI。
Chi Song's avatar
Chi Song committed
28

Chi Song's avatar
Chi Song committed
29
`examples/trials/mnist-annotation` 为例。 示例文件 `examples/trials/mnist-annotation/config_remote.yml` 的内容如下:
Chi Song's avatar
Chi Song committed
30
31
32
33
34
35
36

```yaml
authorName: default
experimentName: example_mnist
trialConcurrency: 1
maxExecDuration: 1h
maxTrialNum: 10
Chi Song's avatar
Chi Song committed
37
#choice: local, remote, pai
Chi Song's avatar
Chi Song committed
38
trainingServicePlatform: remote
LongzeSong's avatar
LongzeSong committed
39
40
# 搜索空间文件
searchSpacePath: search_space.json
Chi Song's avatar
Chi Song committed
41
# 可选项: true, false
Chi Song's avatar
Chi Song committed
42
43
useAnnotation: true
tuner:
Chi Song's avatar
Chi Song committed
44
45
  # 可选项: TPE, Random, Anneal, Evolution, BatchTuner
  #SMAC (SMAC 需要先通过 nnictl 来安装)
Chi Song's avatar
Chi Song committed
46
47
  builtinTunerName: TPE
  classArgs:
Chi Song's avatar
Chi Song committed
48
    # 可选项:: maximize, minimize
Chi Song's avatar
Chi Song committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
    optimize_mode: maximize
trial:
  command: python3 mnist.py
  codeDir: .
  gpuNum: 0
#local 模式下 machineList 可为空
machineList:
  - ip: 10.1.1.1
    username: bob
    passwd: bob123
    #使用默认端口 22 时,该配置可跳过
    #port: 22
  - ip: 10.1.1.2
    username: bob
    passwd: bob123
  - ip: 10.1.1.3
    username: bob
    passwd: bob123
```

Chi Song's avatar
Chi Song committed
69
`codeDir` 中的文件会自动上传到远程计算机中。 可在 Windows、Linux 或 macOS 上运行以下命令,在远程 Linux 计算机上启动 Trial:
70
71

```bash
Chi Song's avatar
Chi Song committed
72
nnictl create --config examples/trials/mnist-annotation/config_remote.yml
Chi Song's avatar
Chi Song committed
73
```