Azure ML Compute配额无法在门户查看,如何通过SDK/CLI/REST API查询?
Absolutely! Even though Azure Machine Learning Compute quotas aren’t visible in the Azure portal (depending on your subscription type), you can easily retrieve current quota values using the Azure CLI, Python SDK, or REST API. Here’s how to do it with each tool:
Using Azure CLI
First, ensure you have the Azure ML CLI extension installed (run az extension add -n ml if you haven’t already). Then execute this command, replacing the placeholders with your resource group and workspace name:
az ml compute list-usage --resource-group <your-resource-group> --workspace-name <your-workspace-name>
This returns a JSON output with details like quota category, current usage, limit, and unit for each compute type.
Using Python SDK
With the Azure Machine Learning Python SDK v2, use the MLClient to fetch quota information. Here’s a practical example:
from azure.ai.ml import MLClient from azure.identity import DefaultAzureCredential # Initialize MLClient with your workspace details ml_client = MLClient( credential=DefaultAzureCredential(), subscription_id="<your-subscription-id>", resource_group_name="<your-resource-group>", workspace_name="<your-workspace-name>" ) # Fetch and display compute quota data usage_list = ml_client.compute.list_usage() for usage in usage_list: print(f"Compute type: {usage.name.value}") print(f"Current usage: {usage.current_value}") print(f"Quota limit: {usage.limit}") print(f"Unit: {usage.unit}\n")
This loops through each quota category and prints your current usage alongside the assigned limit.
Using REST API
You can also call the Azure ML REST API directly. Send a GET request to the following endpoint, replacing placeholders with your own values:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.MachineLearningServices/workspaces/{workspaceName}/usages?api-version=2024-04-01
Authenticate using an Azure AD access token (you can get one via az account get-access-token). The response will be a JSON object with full quota usage details for your workspace.
内容的提问来源于stack exchange,提问作者Vassily L.

