|
| 1 | +--- |
| 2 | +title: 'Migrate compute management from SDK v1 to v2' |
| 3 | +titleSuffix: Azure Machine Learning |
| 4 | +description: Migrate compute management from v1 to v2 of Azure Machine Learning SDK |
| 5 | +services: machine-learning |
| 6 | +ms.service: machine-learning |
| 7 | +ms.subservice: mldata |
| 8 | +ms.topic: reference |
| 9 | +author: vijetajo |
| 10 | +ms.author: vijetaj |
| 11 | +ms.date: 09/28/2022 |
| 12 | +ms.reviewer: sgilley |
| 13 | +ms.custom: migration |
| 14 | +--- |
| 15 | + |
| 16 | +# Migrate compute management from SDK v1 to v2 |
| 17 | + |
| 18 | +The compute management functionally remains unchanged with the v2 development platform. |
| 19 | + |
| 20 | +This article gives a comparison of scenario(s) in SDK v1 and SDK v2. |
| 21 | + |
| 22 | + |
| 23 | +## Create compute instance |
| 24 | + |
| 25 | +* SDK v1 |
| 26 | + |
| 27 | + ```python |
| 28 | + import datetime |
| 29 | + import time |
| 30 | + |
| 31 | + from azureml.core.compute import ComputeTarget, ComputeInstance |
| 32 | + from azureml.core.compute_target import ComputeTargetException |
| 33 | + |
| 34 | + # Compute Instances need to have a unique name across the region. |
| 35 | + # Here we create a unique name with current datetime |
| 36 | + ci_basic_name = "basic-ci" + datetime.datetime.now().strftime("%Y%m%d%H%M") |
| 37 | + |
| 38 | + compute_config = ComputeInstance.provisioning_configuration( |
| 39 | + vm_size='STANDARD_DS3_V2' |
| 40 | + ) |
| 41 | + instance = ComputeInstance.create(ws, ci_basic_name , compute_config) |
| 42 | + instance.wait_for_completion(show_output=True) |
| 43 | + ``` |
| 44 | + |
| 45 | +* SDK v2 |
| 46 | + |
| 47 | + ```python |
| 48 | + # Compute Instances need to have a unique name across the region. |
| 49 | + # Here we create a unique name with current datetime |
| 50 | + from azure.ai.ml.entities import ComputeInstance, AmlCompute |
| 51 | + import datetime |
| 52 | + |
| 53 | + ci_basic_name = "basic-ci" + datetime.datetime.now().strftime("%Y%m%d%H%M") |
| 54 | + ci_basic = ComputeInstance(name=ci_basic_name, size="STANDARD_DS3_v2") |
| 55 | + ml_client.begin_create_or_update(ci_basic) |
| 56 | + ``` |
| 57 | + |
| 58 | +## Create compute cluster |
| 59 | + |
| 60 | +* SDK v1 |
| 61 | + |
| 62 | + ```python |
| 63 | + from azureml.core.compute import ComputeTarget, AmlCompute |
| 64 | + from azureml.core.compute_target import ComputeTargetException |
| 65 | + |
| 66 | + # Choose a name for your CPU cluster |
| 67 | + cpu_cluster_name = "cpucluster" |
| 68 | + compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_DS3_V2', |
| 69 | + max_nodes=4) |
| 70 | + cpu_cluster = ComputeTarget.create(ws, cpu_cluster_name, compute_config) |
| 71 | + cpu_cluster.wait_for_completion(show_output=True) |
| 72 | + ``` |
| 73 | + |
| 74 | +* SDK v2 |
| 75 | + |
| 76 | + ```python |
| 77 | + from azure.ai.ml.entities import AmlCompute |
| 78 | + cpu_cluster_name = "cpucluster" |
| 79 | + cluster_basic = AmlCompute( |
| 80 | + name=cpu_cluster_name, |
| 81 | + type="amlcompute", |
| 82 | + size="STANDARD_DS3_v2", |
| 83 | + max_instances=4 |
| 84 | + ) |
| 85 | + ml_client.begin_create_or_update(cluster_basic) |
| 86 | + ``` |
| 87 | + |
| 88 | +## Mapping of key functionality in SDK v1 and SDK v2 |
| 89 | + |
| 90 | +|Functionality in SDK v1|Rough mapping in SDK v2| |
| 91 | +|-|-| |
| 92 | +|[Method/API in SDK v1 (use links to ref docs)](/python/api/azureml-core/azureml.core.compute.amlcompute(class))|[Method/API in SDK v2 (use links to ref docs)](/python/api/azure-ai-ml/azure.ai.ml.entities.amlcompute)| |
| 93 | + |
| 94 | +## Next steps |
| 95 | + |
| 96 | +* [Create and manage an Azure Machine Learning compute instance](how-to-create-manage-compute-instance.md) |
| 97 | +* [Create an Azure Machine Learning compute cluster](how-to-create-attach-compute-cluster.md) |
0 commit comments