无法在本地提供 mlflow 模型

Unable to serve an mlflow model locally

我已经使用自定义 pyfunc 创建了一个 mlflow 模型。当我将输入发送到 Jupyter Notebook 中的加载模型时,它会显示结果。 但是,如果我试图将它提供给本地端口

!mlflow models serve -m Home/miniconda3/envs/mlruns/0/baa40963927a49258c845421e3175c06/artifacts/model -p 8001

我收到这个错误

 Traceback (most recent call last):
  File "/home/subhojyoti/miniconda3/envs/python3-env/bin/mlflow", line 10, in <module>
    sys.exit(cli())
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/mlflow/models/cli.py", line 56, in serve
    install_mlflow=install_mlflow).serve(model_uri=model_uri, port=port,
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/mlflow/models/cli.py", line 163, in _get_flavor_backend
    append_to_uri_path(underlying_model_uri, "MLmodel"), output_path=tmp.path())
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/mlflow/tracking/artifact_utils.py", line 76, in _download_artifact_from_uri
    artifact_path=artifact_path, dst_path=output_path)
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/mlflow/store/artifact/local_artifact_repo.py", line 67, in download_artifacts
    return super(LocalArtifactRepository, self).download_artifacts(artifact_path, dst_path)
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/mlflow/store/artifact/artifact_repo.py", line 140, in download_artifacts
    return download_file(artifact_path)
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/mlflow/store/artifact/artifact_repo.py", line 105, in download_file
    self._download_file(remote_file_path=fullpath, local_path=local_file_path)
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/site-packages/mlflow/store/artifact/local_artifact_repo.py", line 95, in _download_file
    shutil.copyfile(remote_file_path, local_path)
  File "/home/subhojyoti/miniconda3/envs/python3-env/lib/python3.6/shutil.py", line 120, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: 'Home/miniconda3/envs/mlruns/0/baa40963927a49258c845421e3175c06/artifacts/model/MLmodel'

根据您的错误回溯,无法找到模型工件。在您的代码中,您正在从 Jupyter Notebook 中执行 'mlflow' 命令。我建议尝试以下操作:

  1. 检查您的模型工件是否在您使用的路径上Home/miniconda3/envs/mlruns/0/baa40963927a49258c845421e3175c06/artifacts/model
  2. 尝试打开终端,然后 cd /Home/miniconda3/envs 并执行 mlflow models serve -m ./mlruns/0/baa40963927a49258c845421e3175c06/artifacts/model -p 8001
  3. MLFlow 提供了不同的模型服务解决方案,您可以尝试注册您的模型并将其称为“模型:/{model_name}/{stage}”,如模型注册表中所述docs