如何修复 MLflow UI 中未显示的工件

abd*_*lsn 4 python artifacts mlflow

我使用了 MLflow 并使用下面的函数(来自 pydataberlin)记录了参数。

def train(alpha=0.5, l1_ratio=0.5):
    # train a model with given parameters
    warnings.filterwarnings("ignore")
    np.random.seed(40)

    # Read the wine-quality csv file (make sure you're running this from the root of MLflow!)
    data_path = "data/wine-quality.csv"
    train_x, train_y, test_x, test_y = load_data(data_path)

    # Useful for multiple runs (only doing one run in this sample notebook)    
    with mlflow.start_run():
        # Execute ElasticNet
        lr = ElasticNet(alpha=alpha, l1_ratio=l1_ratio, random_state=42)
        lr.fit(train_x, train_y)

        # Evaluate Metrics
        predicted_qualities = lr.predict(test_x)
        (rmse, mae, r2) = eval_metrics(test_y, predicted_qualities)

        # Print out metrics
        print("Elasticnet model (alpha=%f, l1_ratio=%f):" % (alpha, l1_ratio))
        print("  RMSE: %s" % rmse)
        print("  MAE: %s" % mae)
        print("  R2: %s" % r2)

        # Log parameter, metrics, and model to MLflow
        mlflow.log_param(key="alpha", value=alpha)
        mlflow.log_param(key="l1_ratio", value=l1_ratio)
        mlflow.log_metric(key="rmse", value=rmse)
        mlflow.log_metrics({"mae": mae, "r2": r2})
        mlflow.log_artifact(data_path)
        print("Save to: {}".format(mlflow.get_artifact_uri()))
        
        mlflow.sklearn.log_model(lr, "model")
Run Code Online (Sandbox Code Playgroud)

一旦我train()使用它的参数运行,在 UI 中我看不到工件,但我可以看到模型及其参数和指标。

在工件选项卡中,它被写入No Artifacts Recorded Use the log artifact APIs to store file outputs from MLflow runs.但在模型文件夹的查找器中,所有工件都与模型 Pickle 一起存在。

帮助

aeb*_*ljs 6

这段代码不是在本地运行吗?您是否正在移动 mlruns 文件夹?我建议检查 meta.yaml 文件中存在的工件 URI。如果路径不正确,可能会出现此类问题。

  • @abdoulsn,在您的 mlruns 文件夹中,会有一个用于实验的文件夹。它可以被命名为 0 或 1 等等。假设它是 0。在其中您可以找到一个 meta.yaml 文件。打开它并检查artifact_location 被指定为什么。应该是 mlruns/0。如果不是,就做成这个。同样,此文件夹中的每个运行文件夹都会有一个 meta.yaml 文件。还要检查这些文件中的artifact_uri。它的格式应为 mlruns/0/<run_id>/artifacts。如果需要的话将其更改为此。确保这对我有用。 (3认同)

Cri*_*bal 6

有类似的问题。就我而言,我通过mlflow uimlruns实验目录中运行来解决它。

请在此处查看 Github 上的完整讨论

希望能帮助到你!