繁体   English   中英

如何在运行 MLflow 的服务器上存储工件

[英]How to store artifacts on a server running MLflow

我定义了以下泊坞窗图像:

FROM python:3.6

RUN pip install --upgrade pip
RUN pip install --upgrade mlflow

ENTRYPOINT mlflow server --host 0.0.0.0 --file-store /mnt/mlruns/

并构建一个名为mlflow-server的映像。 接下来,我从本地机器启动这个服务器:

docker run --rm -it -p 5000:5000 -v ${PWD}/mlruns/:/mnt/mlruns mlflow-server

接下来,我定义了以下函数:

def foo(x, with_af=False):
    mlflow.start_run()
    mlflow.log_param("x", x)
    print(x)
    if with_af:
        with open(str(x), 'wb') as fout:
            fout.write(os.urandom(1024))
        mlflow.log_artifact(str(x))
        mlflow.log_artifact('./foo.data')
    mlflow.end_run()

我从同一个目录运行foo(10)并且参数被正确记录。 但是, foo(10, True)产生以下错误: PermissionError: [Errno 13] Permission denied: '/mnt' 似乎log_artifact试图直接将文件保存在本地文件系统上。

知道我做错了什么吗?

好问题。 只是为了确保,听起来您已经在配置 MLflow 以在运行脚本时与跟踪服务器通信,例如通过MLFLOW_TRACKING_URI=http://localhost:5000 python my-script.py

MLflow 中的工件存储

工件与其他运行数据(指标、参数、标签)的细微差别在于客户端而不是服务器负责持久化它们。 当前流量(从 MLflow 0.6.0 开始)为:

  • 用户代码调用mlflow.start_run
  • MLflow 客户端向跟踪服务器发出 API 请求以创建运行
  • 跟踪服务器为运行确定适当的根工件 URI(当前:运行的工件根是其父实验的工件根目录的子目录)
  • 跟踪服务器保留运行元数据(包括其工件根)并将运行对象返回给客户端
  • 用户代码调用log_artifact
  • 客户端在活动运行的工件根目录下记录工件

问题

当您通过mlflow server --host 0.0.0.0 --file-store /mnt/mlruns/启动 MLflow 服务器时,服务器会在/mnt/mlruns容器中的/mnt/mlruns下记录指标和参数,并在/mnt/mlruns下返回工件路径/mnt/mlruns到客户端。 然后,客户端尝试在本地文件系统/mnt/mlruns下记录工件,这会因您遇到的PermissionError而失败。

修复

使用远程跟踪服务器存储工件的最佳做法是将服务器配置为使用客户端和服务器均可访问的工件根(例如 S3 存储桶或 Azure Blob 存储 URI)。 您可以通过mlflow server --default-artifact-root [artifact-root]

请注意,服务器仅在将工件根分配给新创建的实验时使用此工件根 - 在现有实验下创建的运行将使用现有实验的工件根下的工件根目录。 有关配置跟踪服务器的更多信息,请参阅MLflow 跟踪指南

我遇到了同样的问题,请尝试:

sudo chmod 755 -R /mnt/mlruns
docker run --rm -it -p 5000:5000 -v /mnt/mlruns:/mnt/mlruns mlflow-server

我必须创建一个包含 docker 确切路径的文件夹并更改权限。

我在 docker 内部也做了同样的事情。

FROM python:3.6

RUN pip install --upgrade pip
RUN pip install --upgrade mlflow
RUN mkdir /mnt/mlruns/
RUN chmod 777 -R /mnt/mlruns/

ENTRYPOINT mlflow server --host 0.0.0.0 --file-store /mnt/mlruns/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM