【发布时间】: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