AMLMode.md 3.22 KB
Newer Older
Chi Song's avatar
Chi Song committed
1
2
3
4
5
6
7
**在 Azure Machine Learning 上运行 Experiment**
===
NNI 支持在 [AML](https://azure.microsoft.com/zh-cn/services/machine-learning/) 上运行 Experiment,称为 aml 模式。

## 设置环境
步骤 1. 参考[指南](../Tutorial/QuickStart.md)安装 NNI。

8
步骤 2. 通过此 [链接](https://azure.microsoft.com/en-us/free/services/machine-learning/) 创建 Azure 账户/订阅。 如果已有 Azure 账户/订阅,跳过此步骤。
Chi Song's avatar
Chi Song committed
9

10
步骤 3. 在机器上安装 Azure CLI,参照[](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)安装指南。
Chi Song's avatar
Chi Song committed
11

12
步骤 4. 从CLI验证您的Azure订阅。 要进行交互式身份验证,请打开命令行或终端并使用以下命令:
Chi Song's avatar
Chi Song committed
13
```
14
15
16
17
18
19
20
21
22
23
24
az login
```

步骤 5. 使用 Web 浏览器登录Azure帐户,并创建机器学习资源。 需要选择资源组并指定工作空间的名称。 之后下载 `config.json`,该文件将会在后面用到。 ![](../../img/aml_workspace.png)

步骤 6. 创建 AML 集群作为计算集群。 ![](../../img/aml_cluster.png)

步骤 7. 打开命令行并安装 AML 环境。
```
python3 -m pip install azureml
python3 -m pip install azureml-sdk
Chi Song's avatar
Chi Song committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
```

## 运行 Experiment
`examples/trials/mnist-tfv1` 为例。 NNI 的 YAML 配置文件如下:

```yaml
authorName: default
experimentName: example_mnist
trialConcurrency: 1
maxExecDuration: 1h
maxTrialNum: 10
trainingServicePlatform: aml
searchSpacePath: search_space.json
#可选项: true, false
useAnnotation: false
tuner:
  #可选项: TPE, Random, Anneal, Evolution, BatchTuner, MetisTuner, GPTuner
  #SMAC (SMAC should be installed through nnictl)
  builtinTunerName: TPE
  classArgs:
    #可选项: maximize, minimize
    optimize_mode: maximize
trial:
  command: python3 mnist.py
  codeDir: .
  image: msranni/nni
51
  gpuNum: 1
Chi Song's avatar
Chi Song committed
52
53
54
55
amlConfig:
  subscriptionId: ${replace_to_your_subscriptionId}
  resourceGroup: ${replace_to_your_resourceGroup}
  workspaceName: ${replace_to_your_workspaceName}
56
  computeTarget: ${replace_to_your_computeTarget}
Chi Song's avatar
Chi Song committed
57
58
59
60
61
62
```

注意:如果用 aml 模式运行,需要在 YAML 文件中设置 `trainingServicePlatform: aml`

[本机模式](LocalMode.md)的 Trial 配置相比,aml 模式下的键值还有:
* image
63
    * 必填。 作业中使用的 Docker 映像名称。 此示例中的镜像 `msranni/nni` 只支持 GPU 计算集群。
Chi Song's avatar
Chi Song committed
64
65
66

amlConfig:
* subscriptionId
67
    * 必填,Azure 订阅的 Id
Chi Song's avatar
Chi Song committed
68
* resourceGroup
69
    * 必填,Azure 订阅的资源组
Chi Song's avatar
Chi Song committed
70
* workspaceName
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
    * 必填,Azure 订阅的工作空间
* computeTarget
    * 必填,要在 AML 工作区中使用的计算机集群名称。 见步骤6。
* maxTrialNumPerGpu
    * 可选,用于指定 GPU 设备上的最大并发 Trial 的数量。
* useActiveGpu
    * 可选,用于指定 GPU 上存在其他进程时是否使用此 GPU。 默认情况下,NNI 仅在 GPU 中没有其他活动进程时才使用 GPU。

amlConfig 需要的信息可以从步骤 5 下载的 `config.json` 找到。

运行以下命令来启动示例示例 Experiment:
```
git clone -b ${NNI_VERSION} https://github.com/microsoft/nni
cd nni/examples/trials/mnist-tfv1

# 修改 config.aml ...

nnictl create --config config_aml.yml
```
`${NNI_VERSION}` 替换为发布的版本或分支名称,例如:`v1.8`