【问题标题】:How to provide Dockerfile for mlflow models build-docker如何为 mlflow 模型 build-docker 提供 Dockerfile
【发布时间】:2022-12-18 17:51:51
【问题描述】:

我使用带有 mlflow 的 pyfunc 文件创建了一个模型,该模型使用 conda_env 来安装模型所需的包。

pip_env = {
    'pip': [
        'pandas==0.24.1',
        'python-dateutil==2.8.1',
        'fuzzywuzzy==0.7.0'
    ]
}
conda_env = {
    'channels': ['defaults'],
    'dependencies': [
        'python=3.7.0',
        'pip=20.2.3',
        pip_env
    ]
}
mlflow.pyfunc.save_model(path=model_path, python_model=gfeCleanPrediction(), artifacts=artifacts, conda_env=conda_env,code_path=code_path)

我需要使用我自己的 Dockerfile,它将从源代码构建一些包并安装,有没有一种方法可以在运行以下命令时提供它:

mlflow  models build-docker -m MODEL_FOLDER_V-1-0-1 -n my_model --install-mlflow

我可以看到 mlflow 在 /python3.7/site-packages/mlflow/models/docker_utils.py 中提供了一个 custom_setup_steps_hook 参数

def _build_image(image_name, entrypoint, mlflow_home=None, custom_setup_steps_hook=None):
    """
    :param custom_setup_steps_hook: (Optional) Single-argument function that takes the string path
           of a dockerfile context directory and returns a string containing Dockerfile commands to
           run during the image build step.
    """
    mlflow_home = os.path.abspath(mlflow_home) if mlflow_home else None
    with TempDir() as tmp:
        cwd = tmp.path()
        install_mlflow = _get_mlflow_install_step(cwd, mlflow_home)
        custom_setup_steps = custom_setup_steps_hook(cwd) if custom_setup_steps_hook else ""
        with open(os.path.join(cwd, "Dockerfile"), "w") as f:
            f.write(
                _DOCKERFILE_TEMPLATE.format(
                    install_mlflow=install_mlflow,
                    custom_setup_steps=custom_setup_steps,
                    entrypoint=entrypoint,
                )
            )

如何使用 custom_setup_steps_hook 或使用我自己的 Dockerfilemlflow 模型 build-docker??

【问题讨论】:

    标签: docker dockerfile mlflow


    【解决方案1】:

    你可以做的是按照 mlflow 希望你的方式构建一个图像(我们称之为base-mlflow-image),然后将其用作自定义 dockerfile 中的基础图像,因此开始它:

    FROM base-mlflow-image
    
    ... install your custom packages 
    

    然后使用该图像来部署您的模型

    【讨论】:

      猜你喜欢
      • 2021-05-02
      • 2020-11-23
      • 2021-04-29
      • 1970-01-01
      • 2021-12-18
      • 1970-01-01
      • 2015-05-23
      • 1970-01-01
      • 2021-09-11
      相关资源
      最近更新 更多