Code Monkey home page Code Monkey logo

mlflow-redisai's Introduction

mlflow-redisai

Forum Discord

A plugin that integrates RedisAI with MLflow pipeline. mlflow_redisai enables you to use mlflow to deploy the models built and trained in mlflow pipeline into RedisAI without any extra effort from the user. This plugin provides few command line APIs, which is also accessible through mlflow's python package, to make the deployment process seamless.

Installation

For installing and activating the plugin, you only need to install this package which is available in pypi and can be installed with

pip install mlflow_redisai

What does it do

Installing this package uses python's amazing entrypoint mechanism to register the plugin into MLflow's plugin registry. This registry will be invoked each time you launch MLflow script or command line argument.

Options

This plugin allows you to interact with RedisAI deployment through MLflow using below given options. All of these options are accessible through command line and python API, although the predict command line option is not reliable in the current release. if you are connecting to a non-local RedisAI instance or if your RedisAI instance needs non-default connection parameters such as username or password, take a look at the connection parameters section

Create deployment

Deploy the model to RedisAI. The create command line argument and create_deployment python APIs does the deployment of a model built with MLflow to RedisAI. It fetches the information, such as which framework the model is built on, from the model configuration file implicitly.

CLI
mlflow deployments create -t redisai --name <rediskey> -m <model uri> -C <config option>
Python API
from mlflow.deployments import get_deploy_client
target_uri = 'redisai'  # host = localhost, port = 6379
redisai = get_deploy_client(target_uri)
redisai.create_deployment(rediskey, model_uri, config={'device': 'GPU'})

Update deployment

Update deployment API has a very similar signature to the create API. In face, update deployment does exactly the same operation as create API except that the model should already be deployed. If the model is not present already, it raises an exception. Update API can be used to update a new model after retraining. This type of setup is useful if you want to change the device on which the inference is running or if you want to change the autobatching size, or even if you are doing live training and updating the model on the fly . RedisAI will make sure the user experience is seamless while changing the model in a live environment.

CLI
mlflow deployments update -t redisai --name <rediskey> -m <model uri> -C <config option>
Python API
redisai.update_deployment(rediskey, model_uri, config={'device': 'GPU'})

Delete deployment

Delete an existing deployment. Error will be thrown if the model is not already deployed

CLI
mlflow deployments delete -t redisai --name <rediskey>
Python API
redisai.delete_deployment(rediskey)

List all deployments

List the names of all the deployments. This name can then be used in other APIs or can be used in the get deployment API to get more details about a particular deployment. Currently, it displays every deployment, not just the deployment made through this plugin

CLI
mlflow deployments list -t redisai
Python API
redisai.list_deployments()

Get deployment details

Get API fetches the meta data about a deployment from RedisAI. This metadata includes

  • BACKEND : the backend used by the model as a String
  • DEVICE : the device used to execute the model as a String
  • TAG : the model's tag as a String
  • BATCHSIZE : The maximum size of any batch of incoming requests. If BATCHSIZE is equal to 0 each incoming request is served immediately. When BATCHSIZE is greater than 0, the engine will batch incoming requests from multiple clients that use the model with input tensors of the same shape.
  • MINBATCHSIZE : The minimum size of any batch of incoming requests.
  • INPUTS : array reply with one or more names of the model's input nodes (applicable only for TensorFlow models)
  • OUTPUTS : array reply with one or more names of the model's output nodes (applicable only for TensorFlow models)
CLI
mlflow deployments get -t redisai --name <rediskey>
Python API
redisai.get_deployment(rediskey)

Plugin help

MLflow integration also made a handy help API which is specific to any plugins you install rather than the help string of the mlflow command itself. For quickly checking something out, it'd be easy to use the help API rather than looking out for this document.

PS: Since help is specific to the plugin and not really an attribute of the client object itself, it's not available under client object (redisai variable in the above examples)

CLI
mlflow deployments help -t redisai

Local run

If you are new to RedisAI and trying it out for the first time, you might not know the setup already (although it's quite easy to setup a local RedisAI instance). The local-run API is there to help you, if that's the case. It pulls the latest docker image of RedisAI (yes, you need docker installed in your machine for this to work), run it on the default port, deploy the model you specified.

PS: It's IMPORTANT to note that this API leaves the docker container running. You would need to manually stop the container once you are done with experimentation. Also, remember that if you trying to run this API twice without killing the first container, it throws an error saying the port is already in use.

CLI
mlflow deployments run-local -t redisai --name <rediskey> -m <model uri> -C <config option>

Connection Parameters

For connecting to a RedisAI instance with non-default connection parameters, you'd either need to supply the necessary (and allowed) parameters through environmental variables or modify the target URI that you'd pass through the command line using -t or -target option.

Through environmental variables

Currently this plugin allows five options through environmental variables which are given below (without description because they are self explanatory)

  • REDIS_HOST
  • REDIS_PORT
  • REDIS_DB
  • REDIS_USERNAME
  • REDIS_PASSWORD
Modifying URI

A template for quick verification is given below

redisai:/[[username]:[password]]@[host]:[port]/[db]

where the default value each would be

  • username = None
  • password = None
  • host = localhost
  • port = 6379
  • db = 0

mlflow-redisai's People

Contributors

boat-builder avatar chayim avatar gkorland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mlflow-redisai's Issues

Support PyTorch deployment

MLFlow currently doesn't support saving torchscript model which is required for implementing pytorch deployment on RedisAI through the plugin.
Development of pytorch support in MLFlow core can be tracked here mlflow/mlflow#2263

[FR] Compatibility with MLflow 2.0

Proposal Summary

In MLflow 2.0 (scheduled for release on Nov. 14), we will be making small modifications to the MLflow Model Server's RESTful scoring protocol (documented here: https://output.circle-artifacts.com/output/job/bb07270e-1101-421c-901c-01e72bc7b6df/artifacts/0/docs/build/html/models.html#deploy-mlflow-models) and the MLflow Deployment Client predict() API (documented here: https://output.circle-artifacts.com/output/job/bb07270e-1101-421c-901c-01e72bc7b6df/artifacts/0/docs/build/html/python_api/mlflow.deployments.html#mlflow.deployments.BaseDeploymentClient.predict).

For compatibility with MLflow 2.0, the mlflow-redisai plugin will need to be updated to conform to the new scoring protocol and Deployment Client interface. The MLflow maintainers are happy to assist with this process, and we apologize for the short notice.

Motivation

  • What is the use case for this feature? Provide a richer, more extensible scoring protocol and broaden the deployment client prediction interface beyond dataframe inputs.
  • Why is this use case valuable to support for MLflow RedisAI Deployment plugin users in general? Necessary for compatibility for MLflow 2.0
  • Why is it currently difficult to achieve this use case? Without these changes, the mlflow-redisai plugin will break in MLflow 2.0.

Is this library still working or deprecated?

For me when running - mlflow deployments create -t redisai -m model-uri --name redis-key is giving below error -

Traceback (most recent call last): File "/home/ubuntu/anaconda3/bin/mlflow", line 8, in <module> sys.exit(cli()) File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/click/core.py", line 764, in __call__ return self.main(*args, **kwargs) File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/click/core.py", line 717, in main rv = self.invoke(ctx) File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/click/core.py", line 1137, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/click/core.py", line 1137, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/click/core.py", line 956, in invoke return ctx.invoke(self.callback, **ctx.params) File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/click/core.py", line 555, in invoke return callback(*args, **kwargs) File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/mlflow/deployments/cli.py", line 145, in create_deployment deployment = client.create_deployment(name, model_uri, flavor, config=config_dict) File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/mlflow_redisai/__init__.py", line 122, in create_deployment flavor = get_preferred_deployment_flavor(model_config) File "/home/ubuntu/anaconda3/lib/python3.7/site-packages/mlflow_redisai/utils.py", line 78, in get_preferred_deployment_flavor error_code=RESOURCE_DOES_NOT_EXIST) mlflow.exceptions.MlflowException: The specified model does not contain any of the supported flavors for deployment. The model contains the following flavors: dict_keys(['python_function']). Supported flavors: ['torchscript', 'tensorflow']

Problems connecting redisai container using mlflow-redisai library

Hi,

I want to deploy a model with mlflow and jupyter to redisai. The specifics of my project is that I need mlflow, jupyter notebook, and redis in different docker containers.

This is the docker-compose file

version: '3'
services:
  notebook:
    image: jupyter/base-notebook
    ports:
      - "8888:8888"
    depends_on: 
      - mlflow
      - redisai
    environment: 
      MLFLOW_TRACKING_URI: 'http://mlflow:5000'
      REDISAI_TRACKING_URI: 'https://redisai:6379'
    volumes:
      - /home/jpardo/Documents/MLops/data/mlruns:/home/jovyan/mlruns

  mlflow:
    image: burakince/mlflow
    expose: 
      - "5000"
    ports:
      - "5000:5000"
    volumes:
      - /home/jpardo/Documents/MLops/data/mlruns:/mlflow/mlruns

  redisai:
    image: redislabs/redisai
    expose: 
      - "6379"
    ports:
      - "6379:6379"

I have installed inside de notebook container mlflow_redisai and mlflow libraries.

mlflow==2.10.2
mlflow-redisai==0.1.0

When inside the notebook container I run

from mlflow.deployments import get_deploy_client 
REDISAI_TRACKING_URI = os.getenv("REDISAI_TRACKING_URI")
redisai = get_deploy_client(REDISAI_TRACKING_URI)

the error from the redisai container is

Possible SECURITY ATTACK detected. It looks like somebody is sending POST or Host: commands to Redis. This is likely due to an attacker attempting to use Cross Protocol Scripting to compromise your Redis instance. Connection aborted.

So the problem is, Why I cannot connect to the redisai container with the mlflow-redisai library? On the contrary I have no problems connecting the notebook container with the mlflow container.

Thanks for any help,

Enable Redis connection parameters for mlflow cli deployment

Currently, the plugin supports

  • Hostname
  • Port
  • Username
  • Password
  • DB

through the connection URI or through environmental variables. However, there are more options possible in the base client and we might need to support them for broader use cases

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.