使用 Azure Resource Manager 部署 Machine Learning Studio (傳統版) 工作區

適用於:適用於。Machine Learning 工作室 (傳統) 不適用於。Azure Machine Learning

重要

Machine Learning 工作室 (傳統) 的支援將於 2024 年 8 月 31 日結束。 建議您在該日期之前轉換成 Azure Machine Learning

自 2021 年 12 月 1 日起,您將無法建立新的 Machine Learning 工作室 (傳統) 資源。 在 2024 年 8 月 31 日之前,您可以繼續使用現有的 Machine Learning 工作室 (傳統) 資源。

ML 工作室 (傳統) 文件即將淘汰,未來將不再更新。

使用 Azure Resource Manager 部署範本提供了可擴充的方式來部署具有驗證和重試機制的互連元件,為您節省時間。 若要設定 Machine Learning Studio (傳統版) 工作區,例如,您需要先設定 Azure 儲存體帳戶,然後再部署工作區。 假想您要對數百個工作區手動進行此動作。 簡單的替代方法是使用 Azure Resource Manager 範本,來部署 Studio (傳統版) 工作區和所有相依性。 這篇文章會帶領您逐步完成此程序。 如需 Azure Resource Manager 的詳細概觀,請參閱 Azure Resource Manager 概觀

注意

建議您使用 Azure Az PowerShell 模組來與 Azure 互動。 請參閱安裝 Azure PowerShell 以開始使用。 若要瞭解如何遷移至 Az PowerShell 模組,請參閱將 Azure PowerShell 從 AzureRM 遷移至 Az。

逐步說明:建立 Machine Learning 工作區

我們將建立 Azure 資源群組,然後使用 Resource Manager 範本部署新的 Azure 儲存體帳戶和新的 Machine Learning Studio (傳統版) 工作區。 部署完成之後,我們會印出所建立的工作區的重要資訊 (主索引鍵、工作區識別碼和工作區的 URL)。

建立 Azure Resource Manager 範本

Machine Learning 工作區需有 Azure 儲存體帳戶來儲存連結到它的資料集。 以下範本會使用資源群組的名稱來產生儲存體帳戶名稱和工作區名稱。 建立工作區時,它也會使用儲存體帳戶名稱做為屬性。

{
    "contentVersion": "1.0.0.0",
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "variables": {
        "namePrefix": "[resourceGroup().name]",
        "location": "[resourceGroup().location]",
        "mlVersion": "2016-04-01",
        "stgVersion": "2015-06-15",
        "storageAccountName": "[concat(variables('namePrefix'),'stg')]",
        "mlWorkspaceName": "[concat(variables('namePrefix'),'mlwk')]",
        "mlResourceId": "[resourceId('Microsoft.MachineLearning/workspaces', variables('mlWorkspaceName'))]",
        "stgResourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]",
        "storageAccountType": "Standard_LRS"
    },
    "resources": [
        {
            "apiVersion": "[variables('stgVersion')]",
            "name": "[variables('storageAccountName')]",
            "type": "Microsoft.Storage/storageAccounts",
            "location": "[variables('location')]",
            "properties": {
                "accountType": "[variables('storageAccountType')]"
            }
        },
        {
            "apiVersion": "[variables('mlVersion')]",
            "type": "Microsoft.MachineLearning/workspaces",
            "name": "[variables('mlWorkspaceName')]",
            "location": "[variables('location')]",
            "dependsOn": ["[variables('stgResourceId')]"],
            "properties": {
                "UserStorageAccountId": "[variables('stgResourceId')]"
            }
        }
    ],
    "outputs": {
        "mlWorkspaceObject": {"type": "object", "value": "[reference(variables('mlResourceId'), variables('mlVersion'))]"},
        "mlWorkspaceToken": {"type": "string", "value": "[listWorkspaceKeys(variables('mlResourceId'), variables('mlVersion')).primaryToken]"},
        "mlWorkspaceWorkspaceID": {"type": "string", "value": "[reference(variables('mlResourceId'), variables('mlVersion')).WorkspaceId]"},
        "mlWorkspaceWorkspaceLink": {"type": "string", "value": "[concat('https://studio.azureml.net/Home/ViewWorkspace/', reference(variables('mlResourceId'), variables('mlVersion')).WorkspaceId)]"}
    }
}

將此範本在 c:\temp 下儲存為 mlworkspace.json 檔案。

依據範本部署資源群組

  • 開啟 PowerShell
  • 安裝 Azure Resource Manager 和 Azure 服務管理的模組
# Install the Azure Resource Manager modules from the PowerShell Gallery (press "A")
Install-Module Az -Scope CurrentUser

# Install the Azure Service Management modules from the PowerShell Gallery (press "A")
Install-Module Azure -Scope CurrentUser

下列步驟會下載並安裝完成剩餘步驟所需的模組。 這只需要在您執行 PowerShell 命令的環境中執行一次。

  • 向 Azure 驗證
# Authenticate (enter your credentials in the pop-up window)
Connect-AzAccount

需要為每個工作階段重複執行這個步驟。 驗證之後,應該會顯示您的訂用帳戶資訊。

Azure 帳戶

現在,我們已經可以存取 Azure,便可以建立資源群組。

  • 建立資源群組
$rg = New-AzResourceGroup -Name "uniquenamerequired523" -Location "South Central US"
$rg

請確認資源群組已正確佈建。 ProvisioningState 應為「已成功」。範本會使用資源群組名稱來產生儲存體帳戶名稱。 儲存體帳戶名稱必須介於 3 到 24 個字元的長度,而且只能使用數字和小寫字母。

資源群組

  • 使用資源群組部署,部署新的 Machine Learning 工作區。
# Create a Resource Group, TemplateFile is the location of the JSON template.
$rgd = New-AzResourceGroupDeployment -Name "demo" -TemplateFile "C:\temp\mlworkspace.json" -ResourceGroupName $rg.ResourceGroupName

一旦完成部署之後,就可以直接存取您所部署的工作區的屬性。 例如,您可以存取主要金鑰權杖。

# Access Machine Learning Studio (classic) Workspace Token after its deployment.
$rgd.Outputs.mlWorkspaceToken.Value

另一種擷取現有工作區權杖的方式是使用 Invoke-AzResourceAction 命令。 例如,您可以列出所有工作區的主要和次要權杖。

# List the primary and secondary tokens of all workspaces
Get-AzResource |? { $_.ResourceType -Like "*MachineLearning/workspaces*"} |ForEach-Object { Invoke-AzResourceAction -ResourceId $_.ResourceId -Action listworkspacekeys -Force}

佈建工作區之後,您也可以使用適用於 Machine Learning Studio (傳統版) 的 PowerShell 模組,將許多 Machine Learning Studio (傳統版) 工作自動化。

下一步