跳转到主要内容

未提供项目描述

项目描述

mlflow-algorithmia

PyPI License

将MLflow模型部署到Algorithmia

安装

pip install mlflow-algorithmia

用法

这是基于mlflow教程,我们在此重现了一些步骤,但更详细的信息请参阅官方的mlflow文档

通过运行此脚本创建一个模型

mlflow run examples/sklearn_elasticnet_wine/

这将创建一个包含训练模型的mlruns目录,您可以运行mlflow ui以运行mlflow UI或使用运行mlflow服务器的mlflow server在本地提供服务

mlflow models serve -m mlruns/0/<run-id>/artifacts/model -p 1234

并进行测试查询

curl -X POST -H "Content-Type:application/json; format=pandas-split" --data '{"columns":["alcohol", "chlorides", "citric acid", "density", "fixed acidity", "free sulfur dioxide", "pH", "residual sugar", "sulphates", "total sulfur dioxide", "volatile acidity"],"data":[[12.8, 0.029, 0.48, 0.98, 6.2, 29, 3.33, 1.2, 0.39, 75, 0.66]]}' http://127.0.0.1:1234/invocations

[5.120775719594933]

现在让我们在Algorithmia中部署相同的模型,您需要

  1. 具有读+写数据访问权限的Algorithmia API密钥
  2. 您想部署的模型路径(在mlruns下),例如:mlruns/0/<run-id>/artifacts/model

将您的Algorithmia API密钥和用户名设置为环境变量

export ALGORITHMIA_USERNAME=<username>
export ALGORITHMIA_API_KEY=<api-key>

创建部署

mlflow deployments create -t algorithmia --name mlflow_sklearn_demo -m mlruns/0/<run-id>/artifacts/model
INFO: Creating Mlflow bundle
INFO: Uploading Mlflow bundle
INFO: MLflow bundle uploaded to: ...
INFO: Cloning algorithm source to: ./algorithmia_tmp/
INFO: Updating algorithm source and building model
INFO: Algorithm repo updated: Update - MLflow run_id: 6df340cd6d294fe59d1b4652fb25969a
INFO: New model version ready: c6b883b325ee0bb63d91dd0cadfe0baf6bd84fb3

从输出保存新模型版本以查询模型。

在Algorithmia中查询模型

您需要上述新模型版本以及之前使用的ALGORITHMIA_USERNAMEALGORITHMIA_API_KEY变量。

<version>替换为上一条命令输出的模型版本。

curl -X POST -d '{"columns":["alcohol", "chlorides", "citric acid", "density", "fixed acidity", "free sulfur dioxide", "pH", "residual sugar", "sulphates", "total sulfur dioxide", "volatile acidity"],"data":[[12.8, 0.029, 0.48, 0.98, 6.2, 29, 3.33, 1.2, 0.39, 75, 0.66]]}' -H 'Content-Type: application/json' -H 'Authorization: Simple '${ALGORITHMIA_API_KEY} https://api.algorithmia.com/v1/algo/$ALGORITHMIA_USERNAME/mlflow_sklearn_demo/<version>

您还可以使用mlflow deployments predict命令查询模型,在这种情况下,它将始终查询模型的最新公开发布版本,要查询特定版本,请使用上述方法。

首先创建一个predict_input.json文件

echo '{"alcohol":{"0":12.8},"chlorides":{"0":0.029},"citric acid":{"0":0.48},"density":{"0":0.98},"fixed acidity":{"0":6.2},"free sulfur dioxide":{"0":29},"pH":{"0":3.33},"residual sugar":{"0":1.2},"sulphates":{"0":0.39},"total sulfur dioxide":{"0":75},"volatile acidity":{"0":0.66}}' > predict_input.json

现在查询模型的最新公开发布版本

mlflow deployments predict -t algorithmia --name mlflow_sklearn_demo -I predict_input.json

更新部署,例如在训练新模型之后

mlflow deployments update -t algorithmia --name mlflow_sklearn_demo -m <path-to-new-model-dir>

删除部署

mlflow deployments delete -t algorithmia --name mlflow_sklearn_demo

算法设置

通过环境变量控制特定算法的部署选项,例如使用algorithmia环境。例如

export ALGO_PACKAGE_SET=python38
mlflow deployments create -t algorithmia --name mlflow_sklearn_demo -m mlruns/0/<run-id>/artifacts/model

将使用Python 3.8的包集创建一个算法,而不是默认的3.7。

变量及其默认值的完整列表

变量 默认值 描述
ALGO_LANGUAGE python3 包集
ALGO_ENV_ID `` 默认为在集群上找到的Python 3.8环境ID
ALGO_SRC_VISIBILITY closed 算法源可见性 closedopen
ALGO_LICENSE apl 算法许可证
ALGO_NETWORK_ACCESS full 网络访问
ALGO_PIPELINE True 算法管道启用或未启用
ALGO_PACKAGE_SET 可选的遗留环境包集名称

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

mlflow-algorithmia-0.1.6.tar.gz (21.4 kB 查看哈希值)

上传时间

支持