Skip to content

Commit 5423c42

Browse files
author
Larry Franks
committed
incorporating feedback
1 parent 79eb61a commit 5423c42

File tree

1 file changed

+58
-29
lines changed

1 file changed

+58
-29
lines changed

articles/machine-learning/how-to-manage-environments-v2.md

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,43 @@ git clone --depth 1 https://github.com/Azure/azureml-examples
4545

4646
Note that `--depth 1` clones only the latest commit to the repository, which reduces time to complete the operation.
4747

48+
### Connect to the workspace
49+
50+
> [!TIP]
51+
> Use the tabs below to select the method you want to use to work with environments. Selecting a tab will automatically switch all the tabs in this article to the same tab. You can select another tab at any time.
52+
53+
# [Azure CLI](#tab/cli)
54+
55+
When using the Azure CLI, you need identifier parameters - a subscription, resource group, and workspace name. While you can specify these parameters for each command, you can also set defaults that will be used for all the commands. Use the following commands to set default values. Replace `<subscription ID>`, `<AzureML workspace name>`, and `<resource group>` with the values for your configuration:
56+
57+
```azurecli
58+
az account set --subscription <subscription ID>
59+
az configure --defaults workspace=<AzureML workspace name> group=<resource group>
60+
```
61+
62+
# [Python SDK](#tab/python)
63+
64+
To connect to the workspace, you need identifier parameters - a subscription, resource group, and workspace name. You'll use these details in the `MLClient` from the `azure.ai.ml` namespace to get a handle to the required Azure Machine Learning workspace. To authenticate, you use the [default Azure authentication](/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python&preserve-view=true). Check this [example](https://github.com/Azure/azureml-examples/blob/v2samplesreorg/sdk/python/jobs/configuration.ipynb) for more details on how to configure credentials and connect to a workspace.
65+
66+
```python
67+
#import required libraries for workspace
68+
from azure.ai.ml import MLClient
69+
from azure.identity import DefaultAzureCredential
70+
71+
#import required libraries for environments examples
72+
from azure.ai.ml.entities import Environment, BuildContext
73+
74+
#Enter details of your AzureML workspace
75+
subscription_id = '<SUBSCRIPTION_ID>'
76+
resource_group = '<RESOURCE_GROUP>'
77+
workspace = '<AZUREML_WORKSPACE_NAME>'
78+
79+
#connect to the workspace
80+
ml_client = MLClient(DefaultAzureCredential(), subscription_id, resource_group, workspace)
81+
```
82+
83+
---
84+
4885
## Curated environments
4986

5087
There are two types of environments in Azure ML: curated and custom environments. Curated environments are predefined environments containing popular ML frameworks and tooling. Custom environments are user-defined and can be created via `az ml environment create`.
@@ -57,15 +94,7 @@ You can see the set of available curated environments in the Azure ML studio UI,
5794

5895
## Create an environment
5996

60-
You can define an environment from a conda specification, Docker image, or Docker build context.
61-
62-
The Azure CLI allows you to define the environment using a YAML specification file and create the environment using the following CLI command:
63-
64-
```cli
65-
az ml environment create --file my_environment.yml
66-
```
67-
68-
For the YAML reference documentation for Azure ML environments, see [CLI (v2) environment YAML schema](reference-yaml-environment.md).
97+
You can define an environment from a Docker image, a Docker build context, and a conda specification with Docker image.
6998

7099
### Create an environment from a Docker image
71100

@@ -83,7 +112,7 @@ To create the environment:
83112
az ml environment create --file assets/environment/docker-image.yml
84113
```
85114

86-
# [Python SDK](#tab/sdk)
115+
# [Python SDK](#tab/python)
87116

88117
The following example creates an environment from a Docker image. An image from the official PyTorch repository on Docker Hub is specified via the `image` property.
89118

@@ -121,7 +150,7 @@ To create the environment:
121150
az ml environment create --file assets/environment/docker-context.yml
122151
```
123152

124-
# [Python SDK](#tab/sdk)
153+
# [Python SDK](#tab/python)
125154

126155
In the following example, the local path to the build context folder is specified in the `path' parameter. Azure ML will look for a Dockerfile named `Dockerfile` at the root of the build context.
127156

@@ -156,7 +185,7 @@ To create the environment:
156185
az ml environment create --file assets/environment/docker-image-plus-conda.yml
157186
```
158187

159-
## [Python SDK](#tab/sdk)
188+
## [Python SDK](#tab/python)
160189

161190
The relative path to the conda file is specified using the `conda_file` parameter.
162191

@@ -188,7 +217,7 @@ List all the environments in your workspace:
188217
az ml environment list
189218
```
190219

191-
# [Python SDK](#tab/sdk)
220+
# [Python SDK](#tab/python)
192221

193222
```python
194223
envs = ml_client.environments.list()
@@ -206,7 +235,7 @@ List all the environment versions under a given name:
206235
az ml environment list --name docker-image-example
207236
```
208237

209-
# [Python SDK](#tab/sdk)
238+
# [Python SDK](#tab/python)
210239

211240
```python
212241
envs = ml_client.environments.list(name="docker-image-example")
@@ -226,7 +255,7 @@ Get the details of a specific environment:
226255
az ml environment list --name docker-image-example --version 1
227256
```
228257

229-
# [Python SDK](#tab/sdk)
258+
# [Python SDK](#tab/python)
230259

231260
```python
232261
env = ml_client.environments.get(name="docker-image-example", version="1")
@@ -244,7 +273,7 @@ Update mutable properties of a specific environment:
244273
az ml environment update --name docker-image-example --version 1 --set description="This is an updated description."
245274
```
246275

247-
# [Python SDK](#tab/sdk)
276+
# [Python SDK](#tab/python)
248277

249278
```python
250279
env.description="This is an updated description."
@@ -255,21 +284,21 @@ ml_client.environments.create_or_update(environment=env)
255284
> [!IMPORTANT]
256285
> For environments, only `description` and `tags` can be updated. All other properties are immutable; if you need to change any of those properties you should create a new version of the environment.
257286
258-
### Archive and restore
287+
### Archive
259288

260-
Archiving an environment will hide it by default from list queries (`az ml environment list`). You can still continue to reference and use an archived environment in your workflows. You can archive either an environment container or a specific environment version.
289+
Archiving an environment will hide it by default from list queries (`az ml environment list`). You can still continue to reference and use an archived environment in your workflows. You can archive either all versions of an environment or only a specific version.
261290

262-
Archiving an environment container will archive all versions of the environment under that given name. If you create a new environment version under an archived environment container, that new version will automatically be set as archived as well.
291+
If you don't specify a version, all versions of the environment under that given name will be archived. If you create a new environment version under an archived environment container, that new version will automatically be set as archived as well.
263292

264-
Archive an environment container:
293+
Archive all versions of an environment:
265294

266295
# [Azure CLI](#tab/cli)
267296

268297
```cli
269298
az ml environment archive --name docker-image-example
270299
```
271300

272-
# [Python SDK](#tab/sdk)
301+
# [Python SDK](#tab/python)
273302

274303
```python
275304
ml_client.environments.archive(name="docker-image-example")
@@ -285,7 +314,7 @@ Archive a specific environment version:
285314
az ml environment archive --name docker-image-example --version 1
286315
```
287316

288-
# [Python SDK](#tab/sdk)
317+
# [Python SDK](#tab/python)
289318

290319
```python
291320
ml_client.environments.archive(name="docker-image-example", version="1")
@@ -295,25 +324,25 @@ ml_client.environments.archive(name="docker-image-example", version="1")
295324

296325
You can restore an archived environment to no longer hide it from list queries.
297326

298-
If an entire environment container is archived, you can restore that archived container. You can't restore only a specific environment version if the entire environment container is archived - you'll need to restore the entire container.
327+
If you archived all versions of an environment, you can't restore only a specific version - you'll need to restore all versions.
299328

300-
Restore an environment container:
329+
Restore all environment versions:
301330

302331
# [Azure CLI](#tab/cli)
303332

304333
```cli
305334
az ml environment restore --name docker-image-example
306335
```
307336

308-
# [Python SDK](#tab/sdk)
337+
# [Python SDK](#tab/python)
309338

310339
```python
311340
ml_client.environments.restore(name="docker-image-example")
312341
```
313342

314343
---
315344

316-
If only individual environment version(s) within an environment container are archived, you can restore those individual version(s).
345+
If only individual environment version(s) are archived, you can restore those individual version(s).
317346

318347
Restore a specific environment version:
319348

@@ -323,7 +352,7 @@ Restore a specific environment version:
323352
az ml environment restore --name docker-image-example --version 1
324353
```
325354

326-
# [Python SDK](#tab/sdk)
355+
# [Python SDK](#tab/python)
327356

328357
```python
329358
ml_client.environments.restore(name="docker-image-example", version="1")
@@ -337,7 +366,7 @@ ml_client.environments.restore(name="docker-image-example", version="1")
337366

338367
To use an environment for a training job, specify the `environment` field of the job YAML configuration. You can either reference an existing registered Azure ML environment via `environment: azureml:<environment-name>:<environment-version>` or `environment: azureml:<environment-name>@latest` (to reference the latest version of an environment), or define an environment specification inline. If defining an environment inline, don't specify the `name` and `version` fields, as these environments are treated as "unregistered" environments and aren't tracked in your environment asset registry.
339368

340-
# [Python SDK](#tab/sdk)
369+
# [Python SDK](#tab/python)
341370

342371
To use an environment for a training job, specify the `environment` property of the [command](/python/api/azure-ai-ml/azure.ai.ml#azure-ai-ml-command).
343372

@@ -358,7 +387,7 @@ You can also use environments for your model deployments for both online and bat
358387

359388
For more information on how to use environments in deployments, see [Deploy and score a machine learning model by using a managed online endpoint](how-to-deploy-managed-online-endpoints.md).
360389

361-
# [Python SDK](#tab/sdk)
390+
# [Python SDK](#tab/python)
362391

363392
You can also use environments for your model deployments. For more information, see [Deploy and score a machine learning model](how-to-deploy-managed-online-endpoint-sdk-v2.md).
364393

0 commit comments

Comments
 (0)