[英]How to get url of mlflow logged artifacts?
我正在运行 ML 管道,最后我使用 mlflow 记录某些信息。 我主要是通过 Databricks 的官方 mlflow 跟踪教程。
import mlflow
import mlflow.sklearn
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error
with mlflow.start_run():
n_estimators = 100
max_depth = 6
max_features = 3
# Create and train model
rf = RandomForestRegressor(n_estimators = n_estimators, max_depth = max_depth, max_features = max_features)
rf.fit(X_train, y_train)
# Make predictions
predictions = rf.predict(X_test)
# Log parameters
mlflow.log_param("num_trees", n_estimators)
mlflow.log_param("maxdepth", max_depth)
mlflow.log_param("max_feat", max_features)
# Log model
mlflow.sklearn.log_model(rf, "random-forest-model")
# Create metrics
mse = mean_squared_error(y_test, predictions)
# Log metrics
mlflow.log_metric("mse", mse)
当我在 Databricks 笔记本中运行上述代码块时,显示以下状态消息:
(1) MLflow run
Logged 1 run to an experiment in MLflow. Learn more
我可以通过点击“1 run”查看记录的信息。
但是,我想自动检索此链接。 特别是,我需要存储工件的 mlflow uri 的链接。 此链接采用以下格式:
https://mycompany-dev.cloud.databricks.com/?o=<ID_1>#mlflow/experiments/<ID_2>/runs/<ID_3>
我尝试调查 url 并通过打印以下信息来查找其中存在的各种 id 代码:
print("Tracking URI: ", mlflow.get_tracking_uri())
print("Run id:", run.info.run_id)
print("Experiment:", run.info.experiment_id)
我发现上面链接中的<ID_2>
是 Experiment_id 而<ID_3>
run_id
experiment_id
。 但我不知道<ID_1>
代表什么。 另外,我相信应该有一个内置的功能来检索保存的工件的链接,而不是手动地从部分建立链接。 但是,到目前为止,我还没有在文档中找到这样的功能。
编辑:现在我发现<ID_1>
是我可以轻松访问的 Databricks 工作场所 ID。
编辑 2:但这仍然是一个问题,我如何以编程方式访问整个 url,而不是通过硬编码代码中 url 的部分来逐个构建它。
这些 id 不依赖于 MLFlow,而是依赖于 Databricks 的配置方式。 此 ID 是指 Databrick 部署环境的唯一标识符(工作场所或实例名称)。
您可以浏览此页面以了解如何获取工作区 ID: https://docs.gcp.databricks.com/workspace/workspace-details.html
我相信这些凭据是 static,因此“以编程方式”访问此信息的最简单方法是将它们写入将在您的代码中解析的(秘密)配置文件(JSON 或 YAML)中。
当您开始探索时,MFlow 允许检索与 MFlow 跟踪服务器和运行实验(ID、URI、时间戳等)相关的多个信息和路径。 例如,要获得:
mlflow.get_tracking_uri()
run.info.artifact_uri
或mlflow.get_artifact_uri()
run.info.run_id
run.info.experiment_id
run.info.user_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.