如何使用工作區診斷

適用於:Python SDK azureml v1

Azure Machine Learning 提供診斷 API,可用來識別工作區的問題。 診斷報表中傳回的錯誤包含關於如何解決問題的資訊。

您可以使用 Azure Machine Learning 工作室或 Python SDK 中的工作區診斷。

必要條件

遵循本文中的步驟之前,請確定您已滿足下列必要條件:

來自工作室的診斷

Azure Machine Learning 工作室中,您可以執行工作區診斷以檢查設定。 若要執行診斷,請選取頁面右上角的 『』 圖示。 然後選取 [執行工作區診斷]。

工作區診斷按鈕的螢幕快照。

診斷執行完成後,會傳回所有偵測到的問題清單。 這份清單包含可能的解決方案連結。

來自 Python 的診斷

下列代碼段示範如何使用來自 Python 的工作區診斷。

適用於Python SDK azure-ai-ml v2 (目前)

from azure.ai.ml import MLClient
from azure.ai.ml.entities import Workspace
from azure.identity import DefaultAzureCredential

subscription_id = '<your-subscription-id>'
resource_group = '<your-resource-group-name>'
workspace = '<your-workspace-name>'

ml_client = MLClient(DefaultAzureCredential(), subscription_id, resource_group)
resp = ml_client.workspaces.begin_diagnose(workspace).result()
# Inspect the attributes of the response you are interested in
for result in resp.application_insights_results:
    print(f"Diagnostic result: {result.code}, {result.level}, {result.message}")

回應是 DiagnoseResponseResultValue 物件,其中包含工作區所偵測到任何問題的相關信息。

適用於:Python SDK azureml 第 1 版

from azureml.core import Workspace

ws = Workspace.from_config()

diag_param = {
      "value": {
      }
    }

resp = ws.diagnose_workspace(diag_param)
print(resp)

回應是 JSON 文件,其包含工作區所偵測到之任何問題的相關資訊。 下列 JSON 是回應範例:

{
    "value": {
        "user_defined_route_results": [],
        "network_security_rule_results": [],
        "resource_lock_results": [],
        "dns_resolution_results": [{
            "code": "CustomDnsInUse",
            "level": "Warning",
            "message": "It is detected VNet '/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Network/virtualNetworks/<virtual-network-name>' of private endpoint '/subscriptions/<subscription-id>/resourceGroups/<myresourcegroup>/providers/Microsoft.Network/privateEndpoints/<workspace-private-endpoint>' is not using Azure default DNS. You need to configure your DNS server and check https://learn.microsoft.com/azure/machine-learning/how-to-custom-dns to make sure the custom DNS is set up correctly."
        }],
        "storage_account_results": [],
        "key_vault_results": [],
        "container_registry_results": [],
        "application_insights_results": [],
        "other_results": []
    }
}

如果未偵測到任何問題,則會傳回空的 JSON 文件。

如需詳細資訊,請參閱工作區參考。

如需詳細資訊,請參閱 Workspace.diagnose_workspace() 參考。

後續步驟