我定义了以下docker镜像:
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
试图直接将文件保存在本地文件系统上。
知道我哪里做错了吗
3条答案
按热度按时间q3qa4bjr1#
问得好只是为了确保,听起来你已经配置MLflow在运行脚本时与跟踪服务器对话,例如。通过
MLFLOW_TRACKING_URI=http://localhost:5000 python my-script.py
。MLflow中的Artifact存储
工件与其他运行数据(指标、参数、标记)的细微区别在于,客户端而不是服务器负责持久化它们。当前流量(从MLflow 0.6.0开始)为:
mlflow.start_run
log_artifact
问题
当您通过
mlflow server --host 0.0.0.0 --file-store /mnt/mlruns/
启动MLflow服务器时,服务器会在docker容器中记录/mnt/mlruns
下的指标和参数,并将/mnt/mlruns
下的工件路径返回给客户端。然后,客户端尝试在 * 本地文件系统 * 上的/mnt/mlruns
下记录工件,但遇到的PermissionError
失败了。修复
使用远程跟踪服务器存储工件的最佳实践是将服务器配置为使用客户端和服务器都可以访问的工件根目录(例如S3存储桶或Azure Blob存储URI)。你可以通过
mlflow server --default-artifact-root [artifact-root]
来实现。请注意,服务器仅在将工件根分配给新创建的实验时使用此工件根-在现有实验下创建的运行将使用现有实验的工件根下的工件根目录。有关配置跟踪服务器的详细信息,请参阅MLflow跟踪指南。
uidvcgyl2#
我遇到了同样的问题,试试看:
我不得不创建一个文件夹与docker的确切路径,并更改权限。
我在Docker内部也做了同样的事情。
xam8gpfp3#
当我们将记录MLFlow实体的REST API请求发送到跟踪服务器时,服务器将根据容器中设置的内容使用存储位置进行响应。如果值不同,则客户端将最终假设容器相对路径在主机上可用,这将导致权限错误。
下面是一个docker-compose文件,它将默认存储位置设置为
${HOME}/mnt/mlruns
:./mlflow
的内容:Dockerfile
:requirements.txt
:请确保正确设置${HOME}/mnt/mlruns$的权限,因为客户端将直接访问本地存储。