Azure AI モデル推論のすべてのリソースを作成および構成する
重要
この記事で "(プレビュー)" と付記されている項目は、現在、パブリック プレビュー段階です。 このプレビューはサービス レベル アグリーメントなしで提供されており、運用環境ではお勧めしません。 特定の機能はサポート対象ではなく、機能が制限されることがあります。 詳しくは、Microsoft Azure プレビューの追加使用条件に関するページをご覧ください。
この記事では、Azure AI モデル推論を使用し、Azure AI モデル カタログのフラグシップ モデルを使用するために必要なリソースを作成する方法について説明します。
前提条件
この記事を完了するには、以下が必要です。
- Azure サブスクリプション。 GitHub モデルを使用している場合は、エクスペリエンスをアップグレードし、プロセスで Azure サブスクリプションを作成できます。 このような場合は、「GitHub モデルから Azure AI モデル推論にアップグレードする」をお読みください。
重要
Azure AI Foundry ポータルではプロジェクトとハブを使用して Azure AI サービス アカウントを作成し、Azure AI モデル推論を構成します。 ハブとプロジェクトを使用しない場合は、Azure CLI、Bicep のいずれかを使用してリソースを作成する、または Azure portal を使用して Azure AI サービス リソースを作成することができます。
リソースの作成
Azure AI サービス アカウントを使用してプロジェクトを作成するには、次の手順に従います。
Azure AI Foundry ポータルに移動します。
ランディング ページ上で、[プロジェクトの作成] を選択します。
プロジェクトに名前を付けます (「my-project」など)。
このチュートリアルでは、新しい AI ハブのもとにまったく新しいプロジェクトを作成するため、[新しいハブの作成] を選択します。
ハブに名前を付け (「my-hub」など)、[次へ] を選択します。
ウィザードが更新され、作成されるリソースの詳細が表示されます。 [作成する Azure リソース] を選択して詳細を表示します。
次のリソースが作成されていることがわかります。
プロパティ 説明 リソース グループ Azure 内のすべてのリソースのメイン コンテナー。 これにより、連携して動作するリソースを整理するのに役立ちます。 また、プロジェクト全体に関連付けられているコストのスコープを設定するのにも役立ちます。 Location 作成しているリソースの Azure リージョン。 ハブ Azure AI Foundry 内の AI プロジェクトのメイン コンテナー。 ハブはコラボレーションを促進し、プロジェクトの情報を保存できるようになります。 AI サービス Azure AI モデル カタログ内のフラグシップ モデルへアクセスできるようにするリソース。 このチュートリアルでは新しいアカウントが作成されますが、Azure AI サービス リソースは複数のハブとプロジェクト間で共有できます。 ハブでは、リソースへの接続を使用して、そこで使用可能なモデル デプロイにアクセスできます。 プロジェクトと Azure AI サービス間に接続を作成して Azure AI モデル推論を使用する方法については、AI プロジェクトを接続するをお読みください。 [作成] を選択します リソースの作成プロセスが開始されます。
完了すると、そのプロジェクトを構成する準備が整います。
Azure AI モデル推論は、Azure AI Foundry 内で有効にする必要があるプレビュー機能です。 上部のナビゲーション バーで、右上隅にあるプレビュー機能アイコンを選択します。 画面の右側にコンテキスト ブレードが表示されます。
[Azure AI モデル推論サービスにモデルをデプロイする] の機能をオンにします。
そのパネルを閉じます。
Azure AI モデル推論を使用するには、Azure AI サービス アカウントにモデル デプロイを追加する必要があります。
次のステップ
重要
この記事で "(プレビュー)" と付記されている項目は、現在、パブリック プレビュー段階です。 このプレビューはサービス レベル アグリーメントなしで提供されており、運用環境ではお勧めしません。 特定の機能はサポート対象ではなく、機能が制限されることがあります。 詳しくは、Microsoft Azure プレビューの追加使用条件に関するページをご覧ください。
推論エンドポイントにおいて推論に使用可能なモデルを決定および構成することができます。 特定のモデルが構成されたら、要求でそのモデル名またはデプロイ名を指定することで、そこから予測を生成できます。 これを使用するためにコードをさらに変更する必要はありません。
この記事では、Azure AI Foundry において Azure AI モデル推論に新しいモデルを追加する方法について説明します。
前提条件
この記事を完了するには、以下が必要です。
Azure サブスクリプション。 GitHub モデルを使用している場合は、エクスペリエンスをアップグレードし、プロセスで Azure サブスクリプションを作成できます。 このような場合は、「GitHub モデルから Azure AI モデル推論にアップグレードする」をお読みください。
Azure AI サービス リソース。
Azure AI サービスの Azure CLI と
cognitiveservices
拡張機能をインストールします。az extension add -n cognitiveservices
このチュートリアル内の一部のコマンドでは、ユーザーのシステムにインストールされていない場合がある
jq
ツールを使用します。 インストール手順については、ダウンロードjq
を参照してください。次の情報を特定します。
Azure のサブスクリプション ID。
Azure AI サービス リソース名。
Azure AI サービス リソースがデプロイされているリソース グループ。
モデルの追加
モデルを追加するには、まずデプロイするモデルを特定する必要があります。 使用可能なモデルに対しては、次のようにクエリを実行できます。
Azure サブスクリプションにログインします。
az login
複数のサブスクリプションがある場合は、リソースが配置されているサブスクリプションを選択します。
az account set --subscription $subscriptionId>
使用する予定の Azure AI サービス リソースとリソース グループの名前を使用して、次の環境変数を設定します。
accountName="<ai-services-resource-name>" resourceGroupName="<resource-group>"
Azure AI サービス アカウントをまだ作成していない場合は、次のように作成できます。
az cognitiveservices account create -n $accountName -g $resourceGroupName --custom-domain $accountName
まず、使用可能なモデルと、どの SKU かを見てみましょう。 次のコマンドは、使用可能なすべてのモデル定義を一覧表示します。
az cognitiveservices account list-models \ -n $accountName \ -g $resourceGroupName \ | jq '.[] | { name: .name, format: .format, version: .version, sku: .skus[0].name, capacity: .skus[0].capacity.default }'
出力は次のようになります。
{ "name": "Phi-3.5-vision-instruct", "format": "Microsoft", "version": "2", "sku": "GlobalStandard", "capacity": 1 }
デプロイするモデルを特定します。 必要なプロパティは
name
、format
、version
、sku
です。 デプロイの種類によっては、容量も必要になる場合があります。ヒント
すべての SKU ですべてのモデルを使用可能なわけではないことに注意してください。
モデル デプロイをリソースに追加します。 次の例では、
Phi-3.5-vision-instruct
を追加します。az cognitiveservices account deployment create \ -n $accountName \ -g $resourceGroupName \ --deployment-name Phi-3.5-vision-instruct \ --model-name Phi-3.5-vision-instruct \ --model-version 2 \ --model-format Microsoft \ --sku-capacity 1 \ --sku-name GlobalStandard
モデルを使用する準備ができました。
別のデプロイ名を付ける限り、必要に応じて、同じモデルを複数回デプロイできます。 この機能は、Content Safety など、特定のモデルのさまざまな構成をテストする場合に役立ちます。
展開を管理する
CLI を使用すると、使用可能なすべてのデプロイを表示できます。
次のコマンドを実行して、アクティブなすべてのデプロイを表示します。
az cognitiveservices account deployment list -n $accountName -g $resourceGroupName
特定のデプロイの詳細を表示できます。
az cognitiveservices account deployment show \ --deployment-name "Phi-3.5-vision-instruct" \ -n $accountName \ -g $resourceGroupName
特定のデプロイは次のように削除できます。
az cognitiveservices account deployment delete \ --deployment-name "Phi-3.5-vision-instruct" \ -n $accountName \ -g $resourceGroupName
モデルを使用する
Azure AI モデル推論内にデプロイされたモデルは、リソースの Azure AI モデル推論エンドポイントを使用して利用できます。 要求を作成する際に、パラメーター model
を指定し、作成したモデル デプロイ名を挿入します。 次のコードを使用して、推論エンドポイントの URI をプログラムで取得できます。
推論エンドポイント
az cognitiveservices account show -n $accountName -g $resourceGroupName | jq '.properties.endpoints["Azure AI Model Inference API"]'
Azure AI モデル推論エンドポイントに要求を行うには、ルート models
を追加します (https://<resource>.services.ai.azure.com/models
など)。 エンドポイントの API リファレンスについては、Azure AI モデル推論 API リファレンス ページを参照してください。
推論キー
az cognitiveservices account keys list -n $accountName -g $resourceGroupName
重要
この記事で "(プレビュー)" と付記されている項目は、現在、パブリック プレビュー段階です。 このプレビューはサービス レベル アグリーメントなしで提供されており、運用環境ではお勧めしません。 特定の機能はサポート対象ではなく、機能が制限されることがあります。 詳しくは、Microsoft Azure プレビューの追加使用条件に関するページをご覧ください。
この記事では、Azure AI モデル推論を使用し、Azure AI モデル カタログのフラグシップ モデルを使用するために必要なリソースを作成する方法について説明します。
前提条件
この記事を完了するには、以下が必要です。
- Azure サブスクリプション。 GitHub モデルを使用している場合は、エクスペリエンスをアップグレードし、プロセスで Azure サブスクリプションを作成できます。 このような場合は、「GitHub モデルから Azure AI モデル推論にアップグレードする」をお読みください。
Azure CLI をインストールします。
次の情報を特定します。
- Azure のサブスクリプション ID。
このチュートリアルについて
この記事の中の例は、Azure-Samples/azureai-model-inference-bicep リポジトリに含まれるサンプル コードに基づいています。 ファイル内容のコピーや貼り付けをする必要なく、ローカル環境でコマンドを実行するには、次のコマンドを使用してリポジトリをクローンし、そのコーディング言語のフォルダーに移動します。
git clone https://github.com/Azure-Samples/azureai-model-inference-bicep
この例のファイルは、次の場所にあります。
cd azureai-model-inference-bicep/infra
リソースを理解する
このチュートリアルは、次の作成に役立ちます。
- Azure AI サービス リソース。
- 従量課金制をサポートする各モデルのグローバル標準 SKU でのモデル デプロイ。
- (省略可能) Azure AI プロジェクトとハブ。
- (省略可能) ハブと Azure AI サービス内のモデル間の接続。
リソースの管理、プレイグラウンドの使用、ポータルからのその他の機能に Azure AI Foundry ポータルを使用する予定の場合は、Azure AI プロジェクトとハブをデプロイする必要があることに注目してください。
これらのリソースを作成するには、次の資産を使用します。
テンプレート
modules/ai-services-template.bicep
を使用して、Azure AI サービス リソースについて説明します。modules/ai-services-template.bicep
@description('Location of the resource.') param location string = resourceGroup().location @description('Name of the Azure AI Services account.') param accountName string @description('The resource model definition representing SKU') param sku string = 'S0' @description('Whether or not to allow keys for this account.') param allowKeys bool = true @allowed([ 'Enabled' 'Disabled' ]) @description('Whether or not public endpoint access is allowed for this account.') param publicNetworkAccess string = 'Enabled' @allowed([ 'Allow' 'Deny' ]) @description('The default action for network ACLs.') param networkAclsDefaultAction string = 'Allow' resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = { name: accountName location: location identity: { type: 'SystemAssigned' } sku: { name: sku } kind: 'AIServices' properties: { customSubDomainName: accountName publicNetworkAccess: publicNetworkAccess networkAcls: { defaultAction: networkAclsDefaultAction } disableLocalAuth: allowKeys } } output endpointUri string = 'https://${account.outputs.name}.services.ai.azure.com/models' output id string = account.id
テンプレート
modules/ai-services-deployment-template.bicep
を使用して、モデル デプロイについて説明します。modules/ai-services-deployment-template.bicep
@description('Name of the Azure AI services account') param accountName string @description('Name of the model to deploy') param modelName string @description('Version of the model to deploy') param modelVersion string @allowed([ 'AI21 Labs' 'Cohere' 'Core42' 'DeepSeek' 'Meta' 'Microsoft' 'Mistral AI' 'OpenAI' ]) @description('Model provider') param modelPublisherFormat string @allowed([ 'GlobalStandard' 'Standard' 'GlobalProvisioned' 'Provisioned' ]) @description('Model deployment SKU name') param skuName string = 'GlobalStandard' @description('Content filter policy name') param contentFilterPolicyName string = 'Microsoft.DefaultV2' @description('Model deployment capacity') param capacity int = 1 resource modelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2024-04-01-preview' = { name: '${accountName}/${modelName}' sku: { name: skuName capacity: capacity } properties: { model: { format: modelPublisherFormat name: modelName version: modelVersion } raiPolicyName: contentFilterPolicyName == null ? 'Microsoft.Nill' : contentFilterPolicyName } }
便宜上、JSON ファイルを使用して、サービス内で使用可能にするモデルを定義します。 ファイル infra/models.json には、キー
name
、version
、provider
、sku
を含む JSON オブジェクトの一覧が含まれており、デプロイでプロビジョニングされるモデルが定義されています。 モデルが従量課金制をサポートしているため、モデル デプロイの追加に追加コストは発生しません。 使用可能にするモデル エントリを削除または追加することでファイルを変更します。 次の例は JSON ファイルの最初の 7 行のみを表示します。models.json
[ { "name": "AI21-Jamba-1.5-Large", "version": "1", "provider": "AI21 Labs", "sku": "GlobalStandard" },
プロジェクトを使用する (推奨) 予定の場合、プロジェクト、ハブ、Azure AI サービス リソースへの接続を作成するためのテンプレートが必要です。
modules/project-hub-template.bicep
param location string = resourceGroup().location @description('Name of the Azure AI hub') param hubName string = 'hub-dev' @description('Name of the Azure AI project') param projectName string = 'intelligent-apps' @description('Name of the storage account used for the workspace.') param storageAccountName string = replace(hubName, '-', '') param keyVaultName string = replace(hubName, 'hub', 'kv') param applicationInsightsName string = replace(hubName, 'hub', 'log') @description('The container registry resource id if you want to create a link to the workspace.') param containerRegistryName string = replace(hubName, '-', '') @description('The tags for the resources') param tagValues object = { owner: 'santiagxf' project: 'intelligent-apps' environment: 'dev' } var tenantId = subscription().tenantId var resourceGroupName = resourceGroup().name var storageAccountId = resourceId(resourceGroupName, 'Microsoft.Storage/storageAccounts', storageAccountName) var keyVaultId = resourceId(resourceGroupName, 'Microsoft.KeyVault/vaults', keyVaultName) var applicationInsightsId = resourceId(resourceGroupName, 'Microsoft.Insights/components', applicationInsightsName) var containerRegistryId = resourceId( resourceGroupName, 'Microsoft.ContainerRegistry/registries', containerRegistryName ) resource storageAccount 'Microsoft.Storage/storageAccounts@2019-04-01' = { name: storageAccountName location: location sku: { name: 'Standard_LRS' } kind: 'StorageV2' properties: { encryption: { services: { blob: { enabled: true } file: { enabled: true } } keySource: 'Microsoft.Storage' } supportsHttpsTrafficOnly: true } tags: tagValues } resource keyVault 'Microsoft.KeyVault/vaults@2019-09-01' = { name: keyVaultName location: location properties: { tenantId: tenantId sku: { name: 'standard' family: 'A' } enableRbacAuthorization: true accessPolicies: [] } tags: tagValues } resource applicationInsights 'Microsoft.Insights/components@2018-05-01-preview' = { name: applicationInsightsName location: location kind: 'web' properties: { Application_Type: 'web' } tags: tagValues } resource containerRegistry 'Microsoft.ContainerRegistry/registries@2019-05-01' = { name: containerRegistryName location: location sku: { name: 'Standard' } properties: { adminUserEnabled: true } tags: tagValues } resource hub 'Microsoft.MachineLearningServices/workspaces@2024-07-01-preview' = { name: hubName kind: 'Hub' location: location identity: { type: 'systemAssigned' } sku: { tier: 'Standard' name: 'standard' } properties: { description: 'Azure AI hub' friendlyName: hubName storageAccount: storageAccountId keyVault: keyVaultId applicationInsights: applicationInsightsId containerRegistry: (empty(containerRegistryName) ? null : containerRegistryId) encryption: { status: 'Disabled' keyVaultProperties: { keyVaultArmId: keyVaultId keyIdentifier: '' } } hbiWorkspace: false } tags: tagValues } resource project 'Microsoft.MachineLearningServices/workspaces@2024-07-01-preview' = { name: projectName kind: 'Project' location: location identity: { type: 'systemAssigned' } sku: { tier: 'Standard' name: 'standard' } properties: { description: 'Azure AI project' friendlyName: projectName hbiWorkspace: false hubResourceId: hub.id } tags: tagValues }
modules/ai-services-connection-template.bicep
@description('Name of the hub where the connection will be created') param hubName string @description('Name of the connection') param name string @description('Category of the connection') param category string = 'AIServices' @allowed(['AAD', 'ApiKey', 'ManagedIdentity', 'None']) param authType string = 'AAD' @description('The endpoint URI of the connected service') param endpointUri string @description('The resource ID of the connected service') param resourceId string = '' @secure() param key string = '' resource connection 'Microsoft.MachineLearningServices/workspaces/connections@2024-04-01-preview' = { name: '${hubName}/${name}' properties: { category: category target: endpointUri authType: authType isSharedToAll: true credentials: authType == 'ApiKey' ? { key: key } : null metadata: { ApiType: 'Azure' ResourceId: resourceId } } }
リソースの作成
コンソール内で、次の手順に従います。
主なデプロイを定義します。
deploy-with-project.bicep
@description('Location to create the resources in') param location string = resourceGroup().location @description('Name of the resource group to create the resources in') param resourceGroupName string = resourceGroup().name @description('Name of the AI Services account to create') param accountName string = 'azurei-models-dev' @description('Name of the project hub to create') param hubName string = 'hub-azurei-dev' @description('Name of the project to create in the project hub') param projectName string = 'intelligent-apps' @description('Path to a JSON file with the list of models to deploy. Each model is a JSON object with the following properties: name, version, provider') var models = json(loadTextContent('models.json')) module aiServicesAccount 'modules/ai-services-template.bicep' = { name: 'aiServicesAccount' scope: resourceGroup(resourceGroupName) params: { accountName: accountName location: location } } module projectHub 'modules/project-hub-template.bicep' = { name: 'projectHub' scope: resourceGroup(resourceGroupName) params: { hubName: hubName projectName: projectName } } module aiServicesConnection 'modules/ai-services-connection-template.bicep' = { name: 'aiServicesConnection' scope: resourceGroup(resourceGroupName) params: { name: accountName authType: 'AAD' endpointUri: aiServicesAccount.outputs.endpointUri resourceId: aiServicesAccount.outputs.id hubName: hubName } dependsOn: [ projectHub ] } @batchSize(1) module modelDeployments 'modules/ai-services-deployment-template.bicep' = [ for (item, i) in models: { name: 'deployment-${item.name}' scope: resourceGroup(resourceGroupName) params: { accountName: accountName modelName: item.name modelVersion: item.version modelPublisherFormat: item.provider skuName: item.sku } dependsOn: [ aiServicesAccount ] } ] output endpoint string = aiServicesAccount.outputs.endpointUri
Azure にログインします。
az login
適切なサブスクリプションを使用していることを確認します。
az account set --subscription "<subscription-id>"
デプロイを実行します。
RESOURCE_GROUP="<resource-group-name>" az deployment group create \ --resource-group $RESOURCE_GROUP \ --template-file deploy-with-project.bicep
Azure AI サービス リソースとモデル デプロイのみをデプロイする場合は、次のデプロイ ファイルを使用します。
deploy.bicep
@description('Location to create the resources in') param location string = resourceGroup().location @description('Name of the resource group to create the resources in') param resourceGroupName string = resourceGroup().name @description('Name of the AI Services account to create') param accountName string = 'azurei-models-dev' @description('Path to a JSON file with the list of models to deploy. Each model is a JSON object with the following properties: name, version, provider') var models = json(loadTextContent('models.json')) module aiServicesAccount 'modules/ai-services-template.bicep' = { name: 'aiServicesAccount' scope: resourceGroup(resourceGroupName) params: { accountName: accountName location: location } } @batchSize(1) module modelDeployments 'modules/ai-services-deployment-template.bicep' = [ for (item, i) in models: { name: 'deployment-${item.name}' scope: resourceGroup(resourceGroupName) params: { accountName: accountName modelName: item.name modelVersion: item.version modelPublisherFormat: item.provider skuName: item.sku } dependsOn: [ aiServicesAccount ] } ] output endpoint string = aiServicesAccount.outputs.endpointUri
デプロイを実行します。
RESOURCE_GROUP="<resource-group-name>" az deployment group create \ --resource-group $RESOURCE_GROUP \ --template-file deploy.bicep
このテンプレートは、作成した任意のモデル デプロイを使用するために利用できる Azure AI モデル推論エンドポイントを出力します。