[Python] MLFlow doesnt copy properly my artifacts to the mlruns folder when used in a container

Discussão em 'Python' iniciado por Stack, Junho 1, 2025.

  1. Stack

    Stack Membro Participativo

    I am logging a few models using MLflow. The corresponding scripts are executed in a docker container.

    The command mlflow.log_artifacts doesn't seem to work properly since I can t see the corresponding files under the mlruns folder. The command doesn't return any error though.

    EDIT1: after some further investigations, it seems that the problem arises whenever I mount the folder containing mlruns/ as a docker volume. I did some tests with the example provided by the docstring of log_artifacts

    import os
    import json
    import mlflow
    # Create some files to preserve as artifacts
    features = "rooms, zipcode, median_price, school_rating, transport"
    data = {"state": "TX", "Available": 25, "Type": "Detached"}
    # Create couple of artifact files under the directory "data"
    os.makedirs("data", exist_ok=True)
    with open("data/data.json", 'w', encoding='utf-8') as f:
    json.dump(data, f, indent=2)
    with open("data/features.txt", 'w') as f:
    f.write(features)
    # Write all files in "data" to root artifact_uri/states
    with mlflow.start_run():
    mlflow.log_artifacts("data", artifact_path="states")


    If I run this in a container without volume mounting, it runs just fine, ie the artifacts appear under mlruns/<exp-id>/<run-id>/artifacts/state

    However If I run this in a container with the folder containing mlruns/ mounted, it doesn't work, ie the folder mlruns/<exp-id>/<run-id>/artifacts/ is empty.

    Continue reading...

Compartilhe esta Página