将模型部署到本地 REST 服务器时出现 MLflow 错误

MLflow Error while deploying the Model to local REST server

System Details:

Operating System: Ubuntu 19.04

Anaconda version: 2019.03

Python version: 3.7.3

mlflow version: 1.0.0

重现步骤: https://mlflow.org/docs/latest/tutorial.html

错误 line/command: mlflow models serve -m [path_to_model] -p 1234

错误: 命令 'source activate mlflow-c4536834c2e6e0e2472b58bfb28dce35b4bd0be6 1>&2 && gunicorn --timeout 60 -b 127.0.0.1:1234 -w 4 mlflow.pyfunc.scoring_server.wsgi:app' returned 非零 return 代码。 Return代码=1

终端日志:

(mlflow) root@user:/home/user/mlflow/mlflow/examples/sklearn_elasticnet_wine/mlruns/0/e3dd02d5d84545ffab858db13ede7366/artifacts/model# mlflow models serve -m $(pwd) -p 1234
2019/06/18 16:15:16 INFO mlflow.models.cli: Selected backend for flavor 'python_function'
2019/06/18 16:15:17 INFO mlflow.pyfunc.backend: === Running command 'source activate mlflow-c4536834c2e6e0e2472b58bfb28dce35b4bd0be6 1>&2 && gunicorn --timeout 60 -b 127.0.0.1:1234 -w 4 mlflow.pyfunc.scoring_server.wsgi:app'
bash: activate: No such file or directory
Traceback (most recent call last):
  File "/root/anaconda3/envs/mlflow/bin/mlflow", line 10, in <module>
    sys.exit(cli())
  File "/root/anaconda3/envs/mlflow/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/root/anaconda3/envs/mlflow/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/root/anaconda3/envs/mlflow/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/root/anaconda3/envs/mlflow/lib/python3.7/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/root/anaconda3/envs/mlflow/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/root/anaconda3/envs/mlflow/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/root/anaconda3/envs/mlflow/lib/python3.7/site-packages/mlflow/models/cli.py", line 43, in serve
    host=host)
  File "/root/anaconda3/envs/mlflow/lib/python3.7/site-packages/mlflow/pyfunc/backend.py", line 76, in serve
    command_env=command_env)
  File "/root/anaconda3/envs/mlflow/lib/python3.7/site-packages/mlflow/pyfunc/backend.py", line 147, in _execute_in_conda_env
    command, rc
Exception: Command 'source activate mlflow-c4536834c2e6e0e2472b58bfb28dce35b4bd0be6 1>&2 && gunicorn --timeout 60 -b 127.0.0.1:1234 -w 4 mlflow.pyfunc.scoring_server.wsgi:app' returned non zero return code. Return code = 1
(mlflow) root@user:/home/user/mlflow/mlflow/examples/sklearn_elasticnet_wine/mlruns/0/e3dd02d5d84545ffab858db13ede7366/artifacts/model# 

按照 GitHub 问题 1507 (https://github.com/mlflow/mlflow/issues/1507 中提到的步骤,我解决了这个问题。

关于此 post,“anaconda/bin/”目录从未添加到环境变量列表,即 PATH 变量。为了解决这个问题,将 conda 初始化代码块的“else”部分从 ~/.bashrc 文件添加到您的 PATH 变量。

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/atulk/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/atulk/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/atulk/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/atulk/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

在这种情况下,我将 export PATH="/home/atulk/anaconda3/bin:$PATH" 添加到 PATH 变量。但是,这只是临时修复,直到问题在项目中得到修复。

导出路径=$路径:/path/to/python/Python/2.7/bin 不使用anaconda时可以使用