Skip to content

Commit 054b413

Browse files
Merge pull request #211979 from sdgilley/sdg-v2-ci
compute instance update to v2
2 parents b4945ff + a0a0300 commit 054b413

File tree

2 files changed

+135
-80
lines changed

2 files changed

+135
-80
lines changed

articles/machine-learning/how-to-create-manage-compute-instance.md

Lines changed: 38 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ ms.topic: how-to
1010
author: swatig007
1111
ms.author: swatig
1212
ms.reviewer: sgilley
13-
ms.date: 08/05/2022
13+
ms.date: 09/21/2022
1414
---
1515

1616
# Create and manage an Azure Machine Learning compute instance
1717

18-
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
19-
[!INCLUDE [cli v2](../../includes/machine-learning-cli-v2.md)]
18+
[!INCLUDE [dev v2](../../includes/machine-learning-dev-v2.md)]
2019

21-
> [!div class="op_single_selector" title1="Select the Azure Machine Learning CLI version you are using:"]
22-
> * [CLI v1](v1/how-to-create-manage-compute-instance.md)
23-
> * [CLI v2 (current version)](how-to-create-manage-compute-instance.md)
20+
> [!div class="op_single_selector" title1="Select the Azure Machine Learning SDK or CLI version you are using:"]
21+
> * [v1](v1/how-to-create-manage-compute-instance.md)
22+
> * [v2 (current version)](how-to-create-manage-compute-instance.md)
2423
2524
Learn how to create and manage a [compute instance](concept-compute-instance.md) in your Azure Machine Learning workspace.
2625

@@ -43,7 +42,12 @@ Compute instances can run jobs securely in a [virtual network environment](how-t
4342

4443
* An Azure Machine Learning workspace. For more information, see [Create an Azure Machine Learning workspace](how-to-manage-workspace.md).
4544

46-
* The [Azure CLI extension for Machine Learning service (v2)](https://aka.ms/sdk-v2-install), [Azure Machine Learning Python SDK](/python/api/overview/azure/ml/intro), or the [Azure Machine Learning Visual Studio Code extension](how-to-setup-vs-code.md).
45+
* The [Azure CLI extension for Machine Learning service (v2)](https://aka.ms/sdk-v2-install), [Azure Machine Learning Python SDK (v2)](https://aka.ms/sdk-v2-install), or the [Azure Machine Learning Visual Studio Code extension](how-to-setup-vs-code.md).
46+
47+
* If using the Python SDK, [set up your development environment with a workspace](how-to-configure-environment.md). Once your environment is set up, attach to the workspace in your Python script:
48+
49+
[!INCLUDE [connect ws v2](../../includes/machine-learning-connect-ws-v2.md)]
50+
4751

4852
## Create
4953

@@ -62,42 +66,14 @@ The following example demonstrates how to create a compute instance:
6266

6367
# [Python SDK](#tab/python)
6468

65-
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
66-
67-
```python
68-
import datetime
69-
import time
70-
71-
from azureml.core.compute import ComputeTarget, ComputeInstance
72-
from azureml.core.compute_target import ComputeTargetException
73-
74-
# Choose a name for your instance
75-
# Compute instance name should be unique across the azure region
76-
compute_name = "ci{}".format(ws._workspace_id)[:10]
77-
78-
# Verify that instance does not exist already
79-
try:
80-
instance = ComputeInstance(workspace=ws, name=compute_name)
81-
print('Found existing instance, use it.')
82-
except ComputeTargetException:
83-
compute_config = ComputeInstance.provisioning_configuration(
84-
vm_size='STANDARD_D3_V2',
85-
ssh_public_access=False,
86-
# vnet_resourcegroup_name='<my-resource-group>',
87-
# vnet_name='<my-vnet-name>',
88-
# subnet_name='default',
89-
# admin_user_ssh_public_key='<my-sshkey>'
90-
)
91-
instance = ComputeInstance.create(ws, compute_name, compute_config)
92-
instance.wait_for_completion(show_output=True)
93-
```
69+
[!INCLUDE [sdk v2](../../includes/machine-learning-sdk-v2.md)]
9470

95-
For more information on the classes, methods, and parameters used in this example, see the following reference documents:
71+
[!notebook-python[](~/azureml-examples-main/sdk/resources/compute/compute.ipynb?name=ci_basic)]
9672

97-
* [ComputeInstance class](/python/api/azureml-core/azureml.core.compute.computeinstance.computeinstance)
98-
* [ComputeTarget.create](/python/api/azureml-core/azureml.core.compute.computetarget#create-workspace--name--provisioning-configuration-)
99-
* [ComputeInstance.wait_for_completion](/python/api/azureml-core/azureml.core.compute.computeinstance(class)#wait-for-completion-show-output-false--is-delete-operation-false-)
73+
For more information on the classes, methods, and parameters used in this example, see the following reference documents:
10074

75+
* [`AmlCompute` class](/python/api/azure-ai-ml/azure.ai.ml.entities.amlcompute)
76+
* [`ComputeInstance` class](/python/api/azure-ai-ml/azure.ai.ml.entities.computeinstance)
10177

10278
# [Azure CLI](#tab/azure-cli)
10379

@@ -140,7 +116,7 @@ Where the file *create-instance.yml* is:
140116
* Assign the computer to another user. For more about assigning to other users, see [Create on behalf of](#create-on-behalf-of-preview)
141117
* Provision with a setup script (preview) - for more information about how to create and use a setup script, see [Customize the compute instance with a script](how-to-customize-compute-instance.md).
142118
* Add schedule (preview). Schedule times for the compute instance to automatically start and/or shutdown. See [schedule details](#schedule-automatic-start-and-stop-preview) below.
143-
* Enable auto-stop (preview). Configure a compute instance to automatically shutdown if it is inactive. See [configure auto-stop](#configure-auto-stop-preview) for more details.
119+
* Enable auto-stop (preview). Configure a compute instance to automatically shut down if it's inactive. For more information, see [configure auto-stop](#configure-auto-stop-preview).
144120

145121

146122

@@ -162,13 +138,13 @@ SSH access is disabled by default. SSH access can't be changed after creation.
162138
To avoid getting charged for a compute instance that is switched on but inactive, you can configure auto-stop.
163139

164140
A compute instance is considered inactive if the below conditions are met:
165-
* No active Jupyter Kernel sessions (this translates to no Notebooks usage via Jupyter, JupyterLab or Interactive notebooks)
141+
* No active Jupyter Kernel sessions (which translates to no Notebooks usage via Jupyter, JupyterLab or Interactive notebooks)
166142
* No active Jupyter terminal sessions
167143
* No active AzureML runs or experiments
168144
* No SSH connections
169145
* No VS code connections; you must close your VS Code connection for your compute instance to be considered inactive. Sessions are auto-terminated if VS code detects no activity for 3 hours.
170146

171-
Note that activity on custom applications installed on the compute instance is not considered. There are also some basic bounds around inactivity time periods; CI must be inactive for a minimum of 15 mins and a maximum of 3 days.
147+
Activity on custom applications installed on the compute instance isn't considered. There are also some basic bounds around inactivity time periods; CI must be inactive for a minimum of 15 mins and a maximum of three days.
172148

173149
This setting can be configured during CI creation or for existing CIs via the following interfaces:
174150
* AzureML Studio
@@ -189,20 +165,20 @@ This setting can be configured during CI creation or for existing CIs via the fo
189165
}
190166
```
191167
192-
* CLIv2 (YAML) -- only configurable during new CI creation
168+
* CLIv2 (YAML): only configurable during new CI creation
193169
194170
```YAML
195171
# Note that this is just a snippet for the idle shutdown property. Refer to the "Create" Azure CLI section for more information.
196172
idle_time_before_shutdown_minutes: 30
197173
```
198174
199-
* Python SDKv2 -- only configurable during new CI creation
175+
* Python SDKv2: only configurable during new CI creation
200176
201177
```Python
202178
ComputeInstance(name=ci_basic_name, size="STANDARD_DS3_v2", idle_time_before_shutdown_minutes="30")
203179
```
204180
205-
* ARM Templates -- only configurable during new CI creation
181+
* ARM Templates: only configurable during new CI creation
206182
```JSON
207183
// Note that this is just a snippet for the idle shutdown property in an ARM template
208184
{
@@ -211,16 +187,16 @@ This setting can be configured during CI creation or for existing CIs via the fo
211187
```
212188
213189
### Azure policy support
214-
Administrators can use a built-in [Azure Policy](./../governance/policy/overview.md) definition to enfore auto-stop on all compute instances in a given subscription/resource-group.
190+
Administrators can use a built-in [Azure Policy](./../governance/policy/overview.md) definition to enforce auto-stop on all compute instances in a given subscription/resource-group.
215191
216192
1. Navigate to Azure Policy in the Azure portal.
217193
2. Under "Definitions", look for the idle shutdown policy.
218194
219-
:::image type="content" source="media/how-to-create-attach-studio/idle-shutdown-policy.png" alt-text="Screenshot for the idle shutdown policy in Azure Portal.":::
195+
:::image type="content" source="media/how-to-create-attach-studio/idle-shutdown-policy.png" alt-text="Screenshot for the idle shutdown policy in Azure portal.":::
220196
221197
3. Assign policy to the necessary scope.
222198
223-
You can also create your own custom Azure policy. For example, if the below policy is assigned, all new compute instances will have auto-stop configured with a 60 minute inactivity period.
199+
You can also create your own custom Azure policy. For example, if the below policy is assigned, all new compute instances will have auto-stop configured with a 60-minute inactivity period.
224200
225201
```json
226202
{
@@ -541,47 +517,35 @@ You can [create a schedule](#schedule-automatic-start-and-stop-preview) for the
541517
542518
# [Python SDK](#tab/python)
543519

544-
[!INCLUDE [sdk v1](../../includes/machine-learning-sdk-v1.md)]
520+
[!INCLUDE [sdk v2](../../includes/machine-learning-sdk-v2.md)]
545521

546522

547-
In the examples below, the name of the compute instance is **instance**
523+
In the examples below, the name of the compute instance is stored in the variable `ci_basic_name`.
548524

549525
* Get status
550526

551-
```python
552-
# get_status() gets the latest status of the ComputeInstance target
553-
instance.get_status()
554-
```
527+
[!notebook-python[](~/azureml-examples-main/sdk/resources/compute/compute.ipynb?name=ci_basic_state)]
528+
555529

556530
* Stop
557531

558-
```python
559-
# stop() is used to stop the ComputeInstance
560-
# Stopping ComputeInstance will stop the billing meter and persist the state on the disk.
561-
# Available Quota will not be changed with this operation.
562-
instance.stop(wait_for_completion=True, show_output=True)
563-
```
532+
[!notebook-python[](~/azureml-examples-main/sdk/resources/compute/compute.ipynb?name=stop_compute)]
533+
564534

565535
* Start
566536

567-
```python
568-
# start() is used to start the ComputeInstance if it is in stopped state
569-
instance.start(wait_for_completion=True, show_output=True)
570-
```
537+
[!notebook-python[](~/azureml-examples-main/sdk/resources/compute/compute.ipynb?name=start_compute)]
538+
571539

572540
* Restart
573541

574-
```python
575-
# restart() is used to restart the ComputeInstance
576-
instance.restart(wait_for_completion=True, show_output=True)
577-
```
542+
[!notebook-python[](~/azureml-examples-main/sdk/resources/compute/compute.ipynb?name=restart_compute)]
543+
578544

579545
* Delete
580546

581-
```python
582-
# delete() is used to delete the ComputeInstance target. Useful if you want to re-use the compute name
583-
instance.delete(wait_for_completion=True, show_output=True)
584-
```
547+
[!notebook-python[](~/azureml-examples-main/sdk/resources/compute/compute.ipynb?name=delete_compute)]
548+
585549

586550
# [Azure CLI](#tab/azure-cli)
587551

@@ -638,7 +602,7 @@ For each compute instance in a workspace that you created (or that was created f
638602
639603
---
640604
641-
[Azure RBAC](../role-based-access-control/overview.md) allows you to control which users in the workspace can create, delete, start, stop, restart a compute instance. All users in the workspace contributor and owner role can create, delete, start, stop, and restart compute instances across the workspace. However, only the creator of a specific compute instance, or the user assigned if it was created on their behalf, is allowed to access Jupyter, JupyterLab, and RStudio on that compute instance. A compute instance is dedicated to a single user who has root access, and can terminal in through Jupyter/JupyterLab/RStudio. Compute instance will have single-user sign-in and all actions will use that user’s identity for Azure RBAC and attribution of experiment jobs. SSH access is controlled through public/private key mechanism.
605+
[Azure RBAC](../role-based-access-control/overview.md) allows you to control which users in the workspace can create, delete, start, stop, restart a compute instance. All users in the workspace contributor and owner role can create, delete, start, stop, and restart compute instances across the workspace. However, only the creator of a specific compute instance, or the user assigned if it was created on their behalf, is allowed to access Jupyter, JupyterLab, and RStudio on that compute instance. A compute instance is dedicated to a single user who has root access. That user has access to Jupyter/JupyterLab/RStudio running on the instance. Compute instance will have single-user sign-in and all actions will use that user’s identity for Azure RBAC and attribution of experiment jobs. SSH access is controlled through public/private key mechanism.
642606
643607
These actions can be controlled by Azure RBAC:
644608
* *Microsoft.MachineLearningServices/workspaces/computes/read*

0 commit comments

Comments
 (0)