A plugin that integrates TorchServe with MLflow pipeline.
mlflow_torchserve
enables mlflow users to deploy the mlflow pipeline models into TorchServe .
Command line APIs of the plugin (also accessible through mlflow's python package) makes the deployment process seamless.
Following are the list of packages which needs to be installed before running the TorchServe deployment plugin
- torch-model-archiver
- torchserve
- mlflow
Plugin package which is available in pypi and can be installed using
pip install mlflow-torchserve
##Installation from Source
Plugin package could also be installed from source using the following commands
python setup.py build
python setup.py install
Installing this package uses python's 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.
The create
command line argument and create_deployment
python
APIs does the deployment of a model built with MLflow to TorchServe.
mlflow deployments create -t torchserve -m <model uri> --name DEPLOYMENT_NAME -C 'MODEL_FILE=<model file path>' -C 'HANDLER=<handler file path>'
from mlflow.deployments import get_deploy_client
target_uri = 'torchserve'
plugin = get_deploy_client(target_uri)
plugin.create_deployment(name=<deployment name>, model_uri=<model uri>, config={"MODEL_FILE": <model file path>, "HANDLER": <handler file path>})
Update API can used to modify the configuration parameters such as number of workers, version etc., of an already deployed model. TorchServe will make sure the user experience is seamless while changing the model in a live environment.
mlflow deployments update -t torchserve --name <deployment name> -C "min-worker=<number of workers>"
plugin.update_deployment(name=<deployment name>, config={'min-worker': <number of workers>})
Delete an existing deployment. Excepton will be raised if the model is not already deployed.
mlflow deployments delete -t torchserve --name <deployment name / version number>
plugin.delete_deployment(name=<deployment name / version number>)
Lists the names of all the models deployed on the configured TorchServe.
mlflow deployments list -t torchserve
plugin.list_deployments()
Get API fetches the details of the deployed model. By default, Get API fetches all the versions of the deployed model.
mlflow deployments get -t torchserve --name <deployment name>
plugin.get_deployment(name=<deployment name>)
Predict API enables to run prediction on the deployed model.
For the prediction inputs, DataFrame, Tensor and Json formats are supported. The python API supports all of these three formats. When invoked via command line, one needs to pass the json file path that contains the inputs.
mlflow deployments predict -t torchserve --name <deployment name> --input-path <input file path> --output-path <output file path>
output-path is an optional parameter. Without output path parameter result will be printed in console.
plugin.predict(name=<deployment name>, df=<prediction input>)
Run the following command to get the plugin help string.
mlflow deployments help -t torchserve