AMLMode.md 3.48 KB
Newer Older
SparkSnail's avatar
SparkSnail committed
1
2
3
4
5
6
7
**Run an Experiment on Azure Machine Learning**
===
NNI supports running an experiment on [AML](https://azure.microsoft.com/en-us/services/machine-learning/) , called aml mode.

## Setup environment
Step 1. Install NNI, follow the install guide [here](../Tutorial/QuickStart.md).   

8
Step 2. Create an Azure account/subscription using this [link](https://azure.microsoft.com/en-us/free/services/machine-learning/). If you already have an Azure account/subscription, skip this step.
SparkSnail's avatar
SparkSnail committed
9

10
Step 3. Install the Azure CLI on your machine, follow the install guide [here](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest).
SparkSnail's avatar
SparkSnail committed
11

12
13
14
15
16
17
18
19
20
21
22
23
Step 4. Authenticate to your Azure subscription from the CLI. To authenticate interactively, open a command line or terminal and use the following command:
```
az login
```

Step 5. Log into your Azure account with a web browser and create a Machine Learning resource. You will need to choose a resource group and specific a workspace name. Then download `config.json` which will be used later.
![](../../img/aml_workspace.png)

Step 6. Create an AML cluster as the computeTarget.
![](../../img/aml_cluster.png)

Step 7. Open a command line and install AML package environment.
SparkSnail's avatar
SparkSnail committed
24
```
25
26
python3 -m pip install azureml
python3 -m pip install azureml-sdk
SparkSnail's avatar
SparkSnail committed
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
```

## Run an experiment
Use `examples/trials/mnist-tfv1` as an example. The NNI config YAML file's content is like:

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

Note: You should set `trainingServicePlatform: aml` in NNI config YAML file if you want to start experiment in aml mode.

Compared with [LocalMode](LocalMode.md) trial configuration in aml mode have these additional keys:
* image
65
    * required key. The docker image name used in job. The image `msranni/nni` of this example only support GPU computeTargets.
SparkSnail's avatar
SparkSnail committed
66
67
68

amlConfig:
* subscriptionId
69
    * required key, the subscriptionId of your account
SparkSnail's avatar
SparkSnail committed
70
* resourceGroup
71
    * required key, the resourceGroup of your account
SparkSnail's avatar
SparkSnail committed
72
* workspaceName
73
74
75
76
77
78
79
    * required key, the workspaceName of your account
* computeTarget
    * required key, the compute cluster name you want to use in your AML workspace. See Step 6.
* maxTrialNumPerGpu
    * optional key, used to specify the max concurrency trial number on a GPU device.
* useActiveGpu
    * optional key, used to specify whether to use a GPU if there is another process. By default, NNI will use the GPU only if there is no other active process in the GPU.
80
81
82
83
84

The required information of amlConfig could be found in the downloaded `config.json` in Step 5.

Run the following commands to start the example experiment:
```
85
git clone -b ${NNI_VERSION} https://github.com/microsoft/nni
86
87
88
89
90
91
cd nni/examples/trials/mnist-tfv1

# modify config_aml.yml ...

nnictl create --config config_aml.yml
```
Yuge Zhang's avatar
Yuge Zhang committed
92
Replace `${NNI_VERSION}` with a released version name or branch name, e.g., `v1.8`.