【问题标题】:How to get run id from run name in MLflow如何从 MLflow 中的运行名称获取运行 ID
【发布时间】:2021-06-24 23:38:40
【问题描述】:

要从运行中下载工件,您需要运行 ID。我从 UI 中获取运行 ID,如下所示。

Run id from the UI

但是当我设置运行名称参数时,运行 ID 在 UI 中不可见。如何在 MLflow 中找到特定运行的运行 ID?

【问题讨论】:

  • 请告诉我这是否能解决您的问题。

标签: mlflow


【解决方案1】:

mlflow 中的 run id 是随机生成的 stamp id。我有同样的问题,因为我写了一个 mlflow 装饰器,它需要在运行完成后访问运行 id 以设置标签。

问题是,在获得运行 ID 后,您想做什么?那么该方法将需要额外的信息。

如果您只想访问最新的运行:

使用mlflow.list_run_infos()函数并插入experiment_id,可以通过mlflow的mlflow.get_experiment_by_name函数得到。我猜你知道你的实验ID。这是list_run_infos函数

def list_run_infos(
        self,
        experiment_id: str,
        run_view_type: int = ViewType.ACTIVE_ONLY,
        max_results: int = SEARCH_MAX_RESULTS_DEFAULT,
        order_by: Optional[List[str]] = None,
        page_token: Optional[str] = None,
    )

然后你应该得到一个运行对象的列表。但是,请进一步阅读:

如果您的实验中有多个运行对象(这种情况发生在多次运行,甚至是来自使用 Gridsearch 和 sklearn 的父运行的子运行)。

循环遍历每个!来自list__run_infos() 输出的Runobject 并查看Runobject 的end_time 属性。 endtime 属性是一个UNIX 时间戳。因此,即使您有父运行或单次运行,end_time 属性中的最高 UNIX 时间戳也将始终是您的最后一次运行(如果您在实验中没有在循环中使用多个估计器,则需要进行一些重构)。并由此确定合适的 RunObject。

只有这样!您才能访问运行时对象的属性:run_id:

这里你可以看到来自mlflow的run对象的类,记住你还需要exp_id。

classmlflow.entities.RunInfo
(
    run_uuid, 
    experiment_id, 
    user_id, 
    status, 
    start_time, 
    end_time, 
    lifecycle_stage, 
    artifact_uri=None, 
    run_id=None
)

如果您需要具体代码:

last_parent_run = set()
exp_id = mlflow.get_experiment_by_name("your_exp_name"].experiment_id

for item in mlflow.list_run_infos(exp_id):
    last_parent_run.add((item.__getattribute__("end_time"), item.__getattribute__("run_id")))

然后当然是在你的集合中寻找最大的条目

如果您有任何其他问题,请提出;我已经用这个测试了我的装饰器,它工作正常并且保持 mlflow 语句的主要代码干净。虽然有点 hacky,但要在运行后访问 run_id。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-03-19
    • 2019-11-24
    • 2023-01-17
    • 2021-05-15
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 2010-11-17
    相关资源
    最近更新 更多