gpt4 book ai didi

python - 如何向完成的 MLflow 运行添加更多指标?

转载 作者:行者123 更新时间:2023-12-05 03:43:24 25 4
gpt4 key购买 nike

MLflow 运行完成后,外部脚本可以使用 python mlflow 客户端和 mlflow.get_run(run_id) 方法访问其参数和指标,但是 get_run 返回的 Run 对象似乎是只读的。

具体来说,.log_param .log_metric,或者.log_artifact不能用在get_run返回的对象上,引发如下错误:

AttributeError: 'Run' object has no attribute 'log_param'

如果我们尝试在 mlflow 上运行任何 .log_* 方法,它会将它们记录到一个新的运行中,并在 Default 实验。

例子:

final_model_mlflow_run = mlflow.get_run(final_model_mlflow_run_id)

with mlflow.ActiveRun(run=final_model_mlflow_run) as myrun:

# this read operation uses correct run
run_id = myrun.info.run_id
print(run_id)

# this write operation writes to a new run
# (with auto-generated random run ID)
# in the "Default" experiment (with exp. ID of 0)
mlflow.log_param("test3", "This is a test")

请注意,无论Run 状态如何(.info.status 可以是“FINISHED”或“RUNNING”,没有任何区别),上述问题都存在。

我想知道这种只读行为是否是设计使然(假设不可变建模运行提高了实验的可重复性)?我能理解这一点,但如果所有事情都必须在单个整体中完成,比如 with mlflow.start_run() context...

最佳答案

正如 Hans Bambel 向我指出的那样正如所记录的那样here mlflow.start_run(与 mlflow.ActiveRun 对比)接受现有运行的 run_id 参数。

这是一个经过测试可在 v1.13 到 v1.19 中运行的示例 - 如您所见,甚至可以覆盖现有指标以纠正错误:

with mlflow.start_run(run_id=final_model_mlflow_run_id):

# print(mlflow.active_run().info)

mlflow.log_param("start_run_test", "This is a test")
mlflow.log_metric("start_run_test", 1.23)
mlflow.log_metric("start_run_test", 1.33)
mlflow.log_artifact("/home/jovyan/_tmp/formula-features-20201103.json", "start_run_test")

关于python - 如何向完成的 MLflow 运行添加更多指标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66855807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com