使用 CLI v1 建立和管理 Azure Machine Learning 計算執行個體

適用於:Azure CLI ml 延伸模組第 1 版Python SDK azureml 第 1 版

了解如何在您的 Azure Machine Learning 工作區中,使用 CLI v1 建立和管理計算執行個體

請在雲端中使用計算執行個體來作為已完整設定和完全受控的開發環境。 針對開發和測試,您也可以使用執行個體做為訓練計算目標推斷目標。 計算執行個體可以平行執行多個作業,並具有作業佇列。 在開發環境中,無法與您工作區中的其他使用者共用計算執行個體。

計算執行個體可在虛擬網路環境中安全地執行作業,而無須企業開啟 SSH 連接埠。 作業會在容器化環境中執行,並在 Docker 容器中封裝模型的相依性。

在本文中,您將學會如何:

  • 建立計算執行個體
  • 管理 (啟動、停止、重新啟動、刪除) 計算執行個體

注意

本文僅涵蓋如何使用 CLI v1 執行這些工作。 如需其他管理計算執行個體的最新方式,請參閱建立 Azure Machine Learning 計算叢集

必要條件

建立

重要

以下標示的項目 (預覽版) 目前處於公開預覽狀態。 此預覽版本會在沒有服務等級協定的情況下提供,不建議用於實際執行工作負載。 可能不支援特定功能,或可能已經限制功能。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款

估計時間:約 5 分鐘。

建立計算執行個體是工作區的一次性程序。 您可以將計算重複使用於開發工作站,或作為訓練用的計算目標。 您可以將多個計算執行個體附加至工作區。

適用於計算執行個體建立的專用核心每個區域、VM 系列配額與總計區域配額會統一,並與 Azure Machine Learning 定型計算叢集配額共用。 停止計算執行個體並不會釋放配額,以確保您能夠重新啟動計算執行個體。 建立計算執行個體之後,就無法變更其虛擬機器大小。

下列範例將示範如何建立計算執行個體:

適用於:Python SDK azureml v1

import datetime
import time

from azureml.core.compute import ComputeTarget, ComputeInstance
from azureml.core.compute_target import ComputeTargetException

# Choose a name for your instance
# Compute instance name should be unique across the azure region
compute_name = "ci{}".format(ws._workspace_id)[:10]

# Verify that instance does not exist already
try:
    instance = ComputeInstance(workspace=ws, name=compute_name)
    print('Found existing instance, use it.')
except ComputeTargetException:
    compute_config = ComputeInstance.provisioning_configuration(
        vm_size='STANDARD_D3_V2',
        ssh_public_access=False,
        # vnet_resourcegroup_name='<my-resource-group>',
        # vnet_name='<my-vnet-name>',
        # subnet_name='default',
        # admin_user_ssh_public_key='<my-sshkey>'
    )
    instance = ComputeInstance.create(ws, compute_name, compute_config)
    instance.wait_for_completion(show_output=True)

如需此範例中所使用的類別、方法和參數的詳細資訊,請參閱下列參考文件:

管理

啟動、停止、重新啟動、刪除計算執行個體。 計算執行個體不會自動縮小,因此請務必停止資源以避免持續收費。 停止計算執行個體會將其解除配置。 然後再於需要時加以啟動。 停止計算執行個體會停止計算時數的計費,但您仍需支付磁片、公用 IP 和標準負載平衡器的費用。

提示

計算執行個體具有 120GB 的 OS 磁碟。 若您用盡磁碟空間,請先使用終端清除至少 1-2 GB 的空間,然後再停止或重新啟動計算執行個體。 請不要從終端機發出 sudo 關機來停止計算執行個體。 計算執行個體上的暫存磁碟大小取決於所選擇的 VM 大小,並掛接於/mnt。

適用於:Python SDK azureml v1

在下列所有範例中,計算執行個體的名稱為 instance

  • 取得狀態

    # get_status() gets the latest status of the ComputeInstance target
    instance.get_status()
    
  • Stop

    # stop() is used to stop the ComputeInstance
    # Stopping ComputeInstance will stop the billing meter and persist the state on the disk.
    # Available Quota will not be changed with this operation.
    instance.stop(wait_for_completion=True, show_output=True)
    
  • 開始

    # start() is used to start the ComputeInstance if it is in stopped state
    instance.start(wait_for_completion=True, show_output=True)
    
  • 重新啟動

    # restart() is used to restart the ComputeInstance
    instance.restart(wait_for_completion=True, show_output=True)
    
  • 刪除

    # delete() is used to delete the ComputeInstance target. Useful if you want to re-use the compute name
    instance.delete(wait_for_completion=True, show_output=True)
    

Azure RBAC 可讓您控制工作區中的哪些使用者可以建立、刪除、啟動、停止、重新啟動計算執行個體。 工作區參與者和擁有者角色中的所有使用者都可以在工作區中建立、刪除、啟動、停止和重新啟動計算執行個體。 不過,只允許特定計算實例的建立者或代表他們指派的使用者存取 Jupyter、JupyterLab、RStudio 和 Posit Workbench (先前稱為 RStudio Workbench 的使用者在該計算實例上) 。 計算執行個體僅供具有根存取權的單一使用者使用。 該使用者可以存取實例上執行的 Jupyter/JupyterLab/RStudio/Posit Workbench。 計算實例將會有單一使用者登入,而且所有動作都會使用該使用者的 Azure RBAC 身分識別,以及實驗執行的屬性。 SSH 存取是透過公開/私密金鑰機制來加以控制的。

這些動作可由 Azure RBAC 控制:

  • Microsoft.MachineLearningServices/workspaces/computes/read
  • Microsoft.MachineLearningServices/workspaces/computes/write
  • Microsoft.MachineLearningServices/workspaces/computes/delete
  • Microsoft.MachineLearningServices/workspaces/computes/start/action
  • Microsoft.MachineLearningServices/workspaces/computes/stop/action
  • Microsoft.MachineLearningServices/workspaces/computes/restart/action
  • Microsoft.MachineLearningServices/workspaces/computes/updateSchedules/action

若要建立計算執行個體,您將需要下列動作的權限:

  • Microsoft.MachineLearningServices/workspaces/computes/write
  • Microsoft.MachineLearningServices/workspaces/checkComputeNameAvailability/action

後續步驟