通过 REST API 列出 AzureML 工作区中正在运行和排队的作业

问题描述 投票:0回答:1

使用 AzureML REST API 列出作业的文档位于:https://learn.microsoft.com/en-us/rest/api/azureml/jobs/list?view=rest-azureml-2024-04-01&tabs =HTTP

但是此查询可以返回数百个已完成的作业。我有兴趣将列表服务器端过滤为仅排队或正在运行的作业。我无法指定正确的属性指令组合来获得这些工作 - 秘诀是什么?

值得注意的是,AzureML Studio 在 https://ml.azure.com/api/.../entities 使用不同的 API 来获取此列表,但 Az REST CLI 不支持此 API。

azure azure-machine-learning-service
1个回答
0
投票

没有选项可以过滤作业服务器端。

因此,唯一可能的方法是获取列表并进行如下过滤。

import requests
from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential

endpoint = "https://management.azure.com/subscriptions/0b36xxxxb0/resourceGroups/<resource_grp>/providers/Microsoft.MachineLearningServices/workspaces/<workspace_name>/jobs?api-version=2024-04-01"

credential = DefaultAzureCredential()
token = credential.get_token("https://management.core.windows.net/.default").token
headers = {
    "Authorization": f"Bearer {token}"
}
response = requests.get(endpoint, headers=headers)

for i in response.json()['value']:
    if i['properties']['status']=="Running" or i['properties']['status']=="Queued":
        print(f"{i['name']}, {i['properties']['displayName']}, {i['properties']['status']}")

输出:

enter image description here

由于您有更多作业,响应包含 nextLink,它是指向 JobBase 对象下一页的链接,您需要在其中再次过滤作业。

如果您想检查单父运行下的作业,可以使用 azure ml python sdk v2,您可以在其中提供父运行名称以列出作业。

client = MLClient.from_config(credential)
client.jobs.list(parent_job_name="")

这仅提供给定父作业下的子作业,从而减少了您列出的作业总数

© www.soinside.com 2019 - 2024. All rights reserved.