mlflow 异常:使用 UUID 运行已处于活动状态

new*_*eaf 3 mlflow

使用mlflow.set_tracking_uri设置tracking_uri和set_experiment,出现错误并再次检查以运行以下代码。收到错误“异常:使用 UUID 运行已处于活动状态。” 尝试使用mlflow.end_run结束当前运行,但得到 RestException:RESOURCE_DOES_NOT_EXIST:未找到运行 UUID。目前陷入了这个无限循环。有什么建议吗?

    mlflow.set_experiment("my_experiment")
    mlflow.start_run(run_name='my_project')
    mlflow.set_tag('input_len',len(input))
    mlflow.log_param('metrics', r2)
Run Code Online (Sandbox Code Playgroud)

小智 7

就我而言,我在 set_tracking_uri() 之后使用 mlflow.get_artifact_uri() 。

Mlflow 为 get_artifact_uri() 函数创建一个运行,当我们再次尝试启动运行时,它会抛出上述异常。

有缺陷的代码

mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment('Exp1')
print('artifact uri:', mlflow.get_artifact_uri())

with mlflow.start_run():
    mlflow.log_param('SIZE',100)        
Run Code Online (Sandbox Code Playgroud)
Exception: Run with UUID f7d3c1318eeb403cbcf6545b061654e1 is already active. To start a new run, first end the current run with mlflow.end_run(). To start a nested run, call start_run with nested=True
Run Code Online (Sandbox Code Playgroud)

因此 get_artifact_uri() 必须在 start_run 内容中使用。它起作用了。

工作代码

mlflow.set_tracking_uri("http://localhost:5000")
mlflow.set_experiment('Exp1')

with mlflow.start_run():
    print('artifact uri:', mlflow.get_artifact_uri())
    mlflow.log_param('SIZE',100)    
Run Code Online (Sandbox Code Playgroud)


Add*_*nke 6

我的情况略有不同,但我在这里发布解决方案,以防它对这个线程的新手有所帮助。我在开始运行之前不小心设置了运行标签

mlflow.set_experiment('my_experiment')
mlflow.set_tag('input_len', len(input))  # Auto-creates a run ID
mlflow.start_run(run_name='my_project')  # Tries to name the same run, throwing error
Run Code Online (Sandbox Code Playgroud)

确保start_run在所有其他日志记录/标签解决问题之前出现