You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/machine-learning/service/how-to-manage-runs.md
+115-3Lines changed: 115 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ ms.date: 04/05/2019
16
16
17
17
# Start, monitor, and cancel training runs in Python
18
18
19
-
The [Azure Machine Learning SDK for Python](https://docs.microsoft.com/python/api/overview/azure/ml/intro?view=azure-ml-py)provides various methods to monitor, organize, and manage your runs for training and experimentation.
19
+
The [Azure Machine Learning SDK for Python](https://docs.microsoft.com/python/api/overview/azure/ml/intro?view=azure-ml-py)and [Machine Learning CLI](reference-azure-machine-learning-cli.md) provide various methods to monitor, organize, and manage your runs for training and experimentation.
20
20
21
21
This article shows examples of the following tasks:
22
22
@@ -41,8 +41,12 @@ You'll need the following items:
41
41
print(azureml.core.VERSION)
42
42
```
43
43
44
+
* The [Azure CLI](https://docs.microsoft.com/cli/azure/?view=azure-cli-latest) and [CLI extension for Azure Machine Learning service](reference-azure-machine-learning-cli.md).
45
+
44
46
## Start a run and its logging process
45
47
48
+
### Using the SDK
49
+
46
50
Set up your experiment by importing the [Workspace](https://docs.microsoft.com/python/api/azureml-core/azureml.core.workspace.workspace?view=azure-ml-py), [Experiment](https://docs.microsoft.com/python/api/azureml-core/azureml.core.experiment.experiment?view=azure-ml-py), [Run](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run(class)?view=azure-ml-py), and [ScriptRunConfig](https://docs.microsoft.com/python/api/azureml-core/azureml.core.scriptrunconfig?view=azure-ml-py) classes from the [azureml.core](https://docs.microsoft.com/python/api/azureml-core/azureml.core?view=azure-ml-py) package.
notebook_run.log(name="message", value="Hello from run!")
63
67
```
64
68
69
+
### Using the CLI
70
+
71
+
To start a run of your experiment, use the following steps:
72
+
73
+
1. From a shell or command prompt, use the Azure CLI to authenticate to your Azure subscription:
74
+
75
+
```azurecli-interactive
76
+
az login
77
+
```
78
+
79
+
1. Attach a workspace configuration to the folder that contains your training script. Replace `myworkspace`with your Azure Machine Learning service workspace. Replace `myresourcegroup`with the Azure resource group that contains your workspace:
80
+
81
+
```azurecli-interactive
82
+
az ml folder attach -w myworkspace -g myresourcegroup
83
+
```
84
+
85
+
This command creates a `.azureml` subdirectory that contains example runconfig and conda environment files. It also contains a `config.json`file that is used to communicate with your Azure Machine Learning workspace.
86
+
87
+
For more information, see [az ml folder attach](https://docs.microsoft.com/cli/azure/ext/azure-cli-ml/ml/folder?view=azure-cli-latest#ext-azure-cli-ml-az-ml-folder-attach).
88
+
89
+
2. To start the run, use the following command. When using this command, specify the name of the runconfig file (the text before \*.runconfig if you are looking at your file system) against the -c parameter.
90
+
91
+
```azurecli-interactive
92
+
az ml run submit-script -c sklearn -e testexperiment train.py
93
+
```
94
+
95
+
> [!TIP]
96
+
> The `az ml folder attach` command created a `.azureml` subdirectory, which contains two example runconfig files.
97
+
>
98
+
> If you have a Python script that creates a run configuration object programmatically, you can use [RunConfig.save()](https://docs.microsoft.com/python/api/azureml-core/azureml.core.runconfiguration?view=azure-ml-py#save-path-none--name-none--separate-environment-yaml-false-) to save it as a runconfig file.
99
+
>
100
+
> For more example runconfig files, see [https://github.com/MicrosoftDocs/pipelines-azureml/tree/master/.azureml](https://github.com/MicrosoftDocs/pipelines-azureml/tree/master/.azureml).
101
+
102
+
For more information, see [az ml run submit-script](https://docs.microsoft.com/cli/azure/ext/azure-cli-ml/ml/run?view=azure-cli-latest#ext-azure-cli-ml-az-ml-run-submit-script).
103
+
65
104
## Monitor the status of a run
66
105
106
+
### Using the SDK
107
+
67
108
Get the status of a run with the [`get_status()`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run(class)?view=azure-ml-py#get-status--) method.
68
109
69
110
```Python
@@ -93,9 +134,35 @@ with exp.start_logging() as notebook_run:
93
134
print("Has it completed?",notebook_run.get_status())
94
135
```
95
136
137
+
### Using the CLI
138
+
139
+
1. To view a list of runs for your experiment, use the following command. Replace `experiment`with the name of your experiment:
140
+
141
+
```azurecli-interactive
142
+
az ml run list--experiment-name experiment
143
+
```
144
+
145
+
This command returns a JSON document that lists information about runs for this experiment.
146
+
147
+
For more information, see [az ml experiment list](https://docs.microsoft.com/cli/azure/ext/azure-cli-ml/ml/experiment?view=azure-cli-latest#ext-azure-cli-ml-az-ml-experiment-list).
148
+
149
+
2. To view information on a specific run, use the following command. Replace `runid`with the ID of the run:
150
+
151
+
```azurecli-interactive
152
+
az ml run show -r runid
153
+
```
154
+
155
+
This command returns a JSON document that lists information about the run.
156
+
157
+
For more information, see [az ml run show](https://docs.microsoft.com/cli/azure/ext/azure-cli-ml/ml/run?view=azure-cli-latest#ext-azure-cli-ml-az-ml-run-show).
158
+
96
159
## Cancel or fail runs
97
160
98
-
If you notice a mistake or if your run is taking too long to finish, use the [`cancel()`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run(class)?view=azure-ml-py#cancel--) method to stop the run before it finishes and mark it as canceled.
161
+
If you notice a mistake orif your run is taking too long to finish, you can cancel the run.
162
+
163
+
### Using the SDK
164
+
165
+
To cancel a run using the SDK, use the [`cancel()`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run(class)?view=azure-ml-py#cancel--) method:
To cancel a run using the CLI, use the following command. Replace `runid`with the ID of the run
189
+
190
+
```azurecli-interactive
191
+
az ml run cancel -r runid
192
+
```
193
+
194
+
For more information, see [az ml run cancel](https://docs.microsoft.com/cli/azure/ext/azure-cli-ml/ml/run?view=azure-cli-latest#ext-azure-cli-ml-az-ml-run-cancel).
195
+
119
196
## Create child runs
120
197
121
198
Create child runs to group together related runs, such asfor different hyperparameter-tuning iterations.
122
199
200
+
> [!NOTE]
201
+
> Child runs can only be created using the SDK.
202
+
123
203
This code example uses the `hello_with_children.py` script to create a batch of five child runs from within a submitted run by using the [`child_run()`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run(class)?view=azure-ml-py#child-run-name-none--run-id-none--outputs-none-) method:
124
204
125
205
```Python
@@ -153,6 +233,8 @@ In Azure Machine Learning service, you can use properties and tags to help organ
153
233
154
234
### Add properties and tags
155
235
236
+
#### Using the SDK
237
+
156
238
To add searchable metadata to your runs, use the [`add_properties()`](https://docs.microsoft.com/python/api/azureml-core/azureml.core.run(class)?view=azure-ml-py#add-properties-properties-) method. For example, the following code adds the `"author"` property to the run:
157
239
158
240
```Python
@@ -186,15 +268,45 @@ local_script_run.tag("worth another look")
186
268
print(local_script_run.get_tags())
187
269
```
188
270
271
+
#### Using the CLI
272
+
273
+
> [!NOTE]
274
+
> Using the CLI, you can only add or update tags.
275
+
276
+
To add or update a tag, use the following command:
277
+
278
+
```azurecli-interactive
279
+
az ml run update -r runid --add-tag quality='fantastic run'
280
+
```
281
+
282
+
For more information, see [az ml run update](https://docs.microsoft.com/cli/azure/ext/azure-cli-ml/ml/run?view=azure-cli-latest#ext-azure-cli-ml-az-ml-run-update).
283
+
189
284
### Query properties and tags
190
285
191
286
You can query runs within an experiment to return a list of runs that match specific properties and tags.
list(exp.get_runs(properties={"author":"azureml-user"},tags="worth another look"))
196
293
```
197
294
295
+
#### Using the CLI
296
+
297
+
The Azure CLI supports [JMESPath](http://jmespath.org) queries, which can be used to filter runs based on properties and tags. To use a JMESPath query with the Azure CLI, specify it with the `--query` parameter. The following examples show basic queries using properties and tags:
298
+
299
+
```azurecli-interactive
300
+
# list runs where the author property = 'azureml-user'
301
+
az ml run list--experiment-name experiment [?properties.author=='azureml-user']
302
+
# list runs where the tag contains a key that starts with 'worth another look'
303
+
az ml run list--experiment-name experiment [?tags.keys(@)[?starts_with(@, 'worth another look')]]
304
+
# list runs where the author property = 'azureml-user' and the 'quality' tag starts with 'fantastic run'
305
+
az ml run list--experiment-name experiment [?properties.author=='azureml-user'&& tags.quality=='fantastic run']
306
+
```
307
+
308
+
For more information on querying Azure CLI results, see [Query Azure CLI command output](https://docs.microsoft.com/cli/azure/query-azure-cli?view=azure-cli-latest).
309
+
198
310
## Example notebooks
199
311
200
312
The following notebooks demonstrate the concepts in this article:
@@ -205,4 +317,4 @@ The following notebooks demonstrate the concepts in this article:
205
317
206
318
## Next steps
207
319
208
-
* To learn how to log metrics for your experiments, see [Log metrics during training runs](how-to-track-experiments.md).
320
+
* To learn how to log metrics for your experiments, see [Log metrics during training runs](how-to-track-experiments.md).
0 commit comments