Azure Resource Manager を使用して Machine Learning Studio (クラシック) ワークスペースをデプロイする

適用対象:適用対象。Machine Learning Studio (classic) 適用対象外。Azure Machine Learning

重要

Machine Learning Studio (クラシック) のサポートは、2024 年 8 月 31 日に終了します。 その日までに、Azure Machine Learning に切り替えすることをお勧めします。

2021 年 12 月 1 日以降、新しい Machine Learning Studio (クラシック) リソースは作成できません。 2024 年 8 月 31 日まで、既存の Machine Learning Studio (クラシック) リソースを引き続き使用できます。

ML Studio (クラシック) のドキュメントは廃止予定であり、今後更新されない可能性があります。

Azure Resource Manager デプロイ テンプレートは、検証および再試行メカニズムで相互接続されたコンポーネントをデプロイできるように、スケーラブルな方法を提供し、時間を節約します。 Machine Learning Studio (クラシック) ワークスペースを設定するには、たとえば、Azure ストレージ アカウントを構成してから、ワークスペースをデプロイする必要があります。 この作業を何百ものワークスペースに対して手動で行うことを想像してください。 代わりに Azure Resource Manager テンプレートを使用すれば、もっと簡単に Studio (クラシック) ワークスペースとそのすべての依存関係をデプロイできます。 この記事では、このプロセスを順を追って説明します。 Azure Resource Manager の概要については、「Azure Resource Manager の概要」を参照してください。

注意

Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を開始するには、Azure PowerShell のインストールに関する記事を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。

詳細な手順: Machine Learning ワークスペースの作成

Azure リソース グループを作成し、Resource Manager テンプレートを使用して、新しい Azure ストレージ アカウントと新しい Machine Learning Studio (クラシック) ワークスペースをデプロイします。 デプロイが完了したら、作成されたワークスペースに関する重要な情報 (プライマリ キー、workspaceID、およびワークスペースへの 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)]"}
    }
}

このテンプレートを mlworkspace.json ファイルとして c:\temp に保存します。

テンプレートに基づいてリソース グループをデプロイ

  • 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 が "Succeeded" になっているはずです。リソース グループ名は、ストレージ アカウント名を生成するときにテンプレートによって使用されます。 ストレージ アカウント名の長さは 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

既存のワークスペースのトークンを取得するもう 1 つの方法として、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 (クラシック) タスクを自動化することもできます。

次のステップ