[DAY21] 用 Azure Machine Learning SDK 建立运算资源

DAY21 用 Azure Machine Learning SDK 建立运算资源

资料集也建立完成了,今天我们就来建立运算资源(VM)吧!还记得我们之前讨论过运算资源的四种型式:

  1. Compute instances
  2. Compute clusters
  3. Inference clusters AKS
  4. Attached compute
    如果忘记了的话可以回到这篇去阅读。

第三项是部署的部份,等到我们讲到用 SDK 部署的时候再来讲。

建立运算资源

  1. 建立 cluster 运算资源,我们要用 azureml.core.compute.ComputeTarget 类别和 AmlCompute 类别。而建立 compute instance
    我们要用 ComputeInstance 类别。

程序码参考如下:

from azureml.core import Workspace
from azureml.core.compute import ComputeTarget, AmlCompute

ws = Workspace.from_config()

compute_name = 'aml-sdk'

# 设定要建立 VM 的规格、包含节点数目,是否专用等等。如果不用 cluster,改用 ComputeInstance
compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_DS11_V2',
                                                       min_nodes=0, max_nodes=4,
                                                       vm_priority='dedicated')

# 建立 VM
aml_cluster = ComputeTarget.create(ws, compute_name, compute_config)
aml_cluster.wait_for_completion(show_output=True) # 加这行可以看到建立的进度
  1. 一般在实务上,会用 Try Catch 的型式包起来,如果该 VM 没有存在,那就建立起来。程序码改写如下:
from azureml.core.compute import ComputeTarget, AmlCompute
from azureml.core.compute_target import ComputeTargetException

compute_name = "aml-sdk"

# 确认该运算资源是否存在
try:
    aml_cluster = ComputeTarget(workspace=ws, name=compute_name)
    print('查无此VM')
except ComputeTargetException:
    # 如果不存在就建立
    compute_config = AmlCompute.provisioning_configuration(vm_size='STANDARD_DS11_V2',
                                                           max_nodes=4)
    aml_cluster = ComputeTarget.create(ws, compute_name, compute_config)

aml_cluster.wait_for_completion(show_output=True)
  1. 我们也可以进到图形化介面里去看,可以看到刚刚我们要建立的运算资源,真的建立起来了,如下图。
    Build compute resource with azure machine learning sdk

  2. 如果要用 Attached compute,就要 import 对应运算资源的类别。例如说,你要用 Databricks,就要引入 DatabricksCompute 类别,要用 HDInsight,就要引入 HDInsightCompute 类别。建议当需要时,再去查询文件。

  3. 除了范例之外,其实还有很多参数是可以做设定的哦!例如说你建立了 Compute instance,还可以再建立其虚拟网路。详细的技术文件可以参考这里做查询。

今天我们完成了运算资源的建立,明天我们来建立环境吧!


<<:  Urban Kitchen 名厨都汇自助餐厅 #万豪酒店 #澳门银河渡假村 Galaxy Macau

>>:  【Day21】人力资源篇-HR

Day 26 Ruby Symbol

在 Ruby 内有符号(Symbol)这个物件,他跟字串的用法蛮像的,但本质上则不一样。 究竟 Sy...

[Java Day04] 1.2. 型别

教材网址 https://coding104.blogspot.com/2021/06/java-t...

[Day26]- 新手的Web系列CRLF 0x1

Day26- 新手的Web系列CRLF 0x1 正文 CRLF(CRLF Injection Att...

Day12回圈(Ⅱ)

像是我们很常碰到的成绩也可以用if/else回圈来操作,假设90分以上是A,80分以上是B,…到60...

Day01 - 缘起:怎麽了?为什麽?如何掌握过於自由的程序码?

“Any fool can write code that a computer can unde...