Skip to content

Commit 1a77ed3

Browse files
Merge pull request #78903 from Blackmist/cli-stop-monitor
Cli stop monitor
2 parents c605f29 + 9e46055 commit 1a77ed3

File tree

1 file changed

+115
-3
lines changed

1 file changed

+115
-3
lines changed

articles/machine-learning/service/how-to-manage-runs.md

Lines changed: 115 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ms.date: 04/05/2019
1616

1717
# Start, monitor, and cancel training runs in Python
1818

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.
2020

2121
This article shows examples of the following tasks:
2222

@@ -41,8 +41,12 @@ You'll need the following items:
4141
print(azureml.core.VERSION)
4242
```
4343

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+
4446
## Start a run and its logging process
4547

48+
### Using the SDK
49+
4650
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.
4751

4852
```Python
@@ -62,8 +66,45 @@ notebook_run = exp.start_logging()
6266
notebook_run.log(name="message", value="Hello from run!")
6367
```
6468

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+
65104
## Monitor the status of a run
66105

106+
### Using the SDK
107+
67108
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.
68109

69110
```Python
@@ -93,9 +134,35 @@ with exp.start_logging() as notebook_run:
93134
print("Has it completed?",notebook_run.get_status())
94135
```
95136

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+
96159
## Cancel or fail runs
97160

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 or if 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:
99166

100167
```Python
101168
run_config = ScriptRunConfig(source_directory='.', script='hello_with_delay.py')
@@ -116,10 +183,23 @@ local_script_run.fail()
116183
print(local_script_run.get_status())
117184
```
118185

186+
### Using the CLI
187+
188+
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+
119196
## Create child runs
120197

121198
Create child runs to group together related runs, such as for different hyperparameter-tuning iterations.
122199

200+
> [!NOTE]
201+
> Child runs can only be created using the SDK.
202+
123203
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:
124204

125205
```Python
@@ -153,6 +233,8 @@ In Azure Machine Learning service, you can use properties and tags to help organ
153233

154234
### Add properties and tags
155235

236+
#### Using the SDK
237+
156238
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:
157239

158240
```Python
@@ -186,15 +268,45 @@ local_script_run.tag("worth another look")
186268
print(local_script_run.get_tags())
187269
```
188270

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+
189284
### Query properties and tags
190285

191286
You can query runs within an experiment to return a list of runs that match specific properties and tags.
192287

288+
#### Using the SDK
289+
193290
```Python
194291
list(exp.get_runs(properties={"author":"azureml-user"},tags={"quality":"fantastic run"}))
195292
list(exp.get_runs(properties={"author":"azureml-user"},tags="worth another look"))
196293
```
197294

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+
198310
## Example notebooks
199311

200312
The following notebooks demonstrate the concepts in this article:
@@ -205,4 +317,4 @@ The following notebooks demonstrate the concepts in this article:
205317

206318
## Next steps
207319

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

Comments
 (0)