snorkelflow.sdk.MLflowDeployment
- class snorkelflow.sdk.MLflowDeployment(deployment_uid, **kwargs)
Bases:
Deployment
MLflowDeployment class represents a deployment of a Snorkel Flow application as an MLflow model. This class inherits from the Deployment class and provides additional functionality specific to MLflow deployments. Since MLflow is the only supported deployment type at the moment, this class is the only implementation of the Deployment class. This class is intended to be an interface between Snorkel Flow and MLflow.
A typical workflow for deploying an application to production is as follows:
from snorkelflow.sdk import MLflowDeployment
deployment = MLflowDeployment.create("my-application", "my-deployment")
deployment.execute(df)
deployment.download('/path/to/download')Follow with MLflow client calls to deploy your workflow to production.
If you want to get a deployment by its name, you can use the following code:
from snorkelflow.sdk import MLflowDeployment
deployments = MLflowDeployment.list(application="my-application")
matched_deployment = next((deployment for deployment in deployments if deployment.name == "my-deployment"), None)
if matched_deployment is None:
print("Deployment not found")- __init__(deployment_uid, **kwargs)
Initializes a Deployment object. This constructor should not be called directly. Instead, use the Deployment.create method to create a deployment.
Parameters
Parameters
Name Type Default Info deployment_uid int
The unique identifier of the deployment.
\_\_init\_\_
__init__
Methods
__init__
(deployment_uid, **kwargs)Initializes a Deployment object.
create
(application[, name, registry_type, ...])Create a new MLflow deployment from an application.
delete
(deployment_uid)Delete a deployment based on the provided identifier.
download
(local_path[, download_as_zip, ...])Download an MLflow deployment to the specified local path.
execute
(df)Execute a deployment on a pandas DataFrame.
get
(deployment_uid)Fetches a Deployment object based on the provided identifier.
list
([application])List all deployments for an application.
register
(tracking_server_uri, *[, ...])Register an MLflowModel Deployment with an external MLflow model registry.
update
(name)Update the metadata for the deployment.
- classmethod create(application, name=None, registry_type='INTERNAL', model_registry_uid=None, signature=True, experiment_name=None)
Create a new MLflow deployment from an application.
Examples
>>> from snorkelflow.sdk import MLflowDeployment
>>> my_deployment = MLflowDeployment.create(application="my-app", name="my-deployment")
{'deployment_uid': <deployment_uid>}
>>> my_deployment.name
"my-deployment"Parameters
Parameters
Returns
Returns
MLflowDeployment object containing information about the deployed application
Return type
Return type
Name Type Default Info application Union[str, int]
The name or UID of the application to be exported. name Optional[str]
None
The name of the deployment. If this is not provided, deployment name will be created using the application name. Deployment names are not unique and re-running this method with the same name will create a new deployment. To register a model to Databricks Unity Catalog, the name should be in the form of “<catalog>.<schema>.<model>”. registry_type str
'INTERNAL'
The type of the model registry, “INTERNAL” or “EXTERNAL”. model_registry_uid Optional[int]
None
The UID of the external model registry. If registry_type is “INTERNAL”, model_registry_uid is not required. signature bool
True
Whether to add a signature for the input_schema in the MLmodel yaml file. If True, a signature will be added. If False, no signature will be added. experiment_name Optional[str]
None
The name of the experiment to register the model under, used the deployment name if not provided. This is required for certain model registries such as Databricks, where this must an absolute path, e.g. “/Users/<username>/<experiment_name>”.
create
create
- download(local_path, download_as_zip=False, overwrite=False)
Download an MLflow deployment to the specified local path. To see how to use this downloaded package, please go to https://mlflow.org/.
Examples
>>> deployment.download(local_path='./my-folder', download_as_zip=True)
Successfully downloaded deployment to ./my-folder/my-deployment-name.zip
>>> deployment.download(local_path='./my-folder', download_as_zip=False)
Successfully downloaded deployment to ./my-folder/my-deployment-nameParameters
Parameters
Return type
Return type
None
Name Type Default Info local_path str
The local path to download the deployment to. download_as_zip bool
False
Whether to download the deployment as a zip file. If False, the deployment will be downloaded as a directory. overwrite bool
False
Whether to overwrite the local path if it already exists. If False, an error will be thrown if the path already exists.
download
download
- register(tracking_server_uri, *, experiment_name=None, model_name=None, mlflow_s3_endpoint_url=None, aws_access_key_id=None, aws_secret_access_key=None, basic_auth_username=None, basic_auth_password=None, bearer_auth_token=None, timeout_seconds=600)
Register an MLflowModel Deployment with an external MLflow model registry.
Examples
>>> from snorkelflow.sdk import MLflowDeployment
>>> deployment = MLflowDeployment.create(application="my-app")
>>> deployment.register(tracking_server_uri="http://localhost:5000")
<Response [200]>Parameters
Parameters
Returns
Returns
A dictionary describing the model that has been exported to the external service. Resembles a mlflow.model.models.ModelInfo object with extra information on the active Experiment.
Return type
Return type
Dict
Name Type Default Info tracking_server_uri str
URI of the tracking server to export the deployment to. experiment_name Optional[str]
None
The name of the experiment to register the model under, used default if not provided. model_name Optional[str]
None
The name of the model to register the deployment under. Defaults to the parent application name. mlflow_s3_endpoint_url Optional[str]
None
The endpoint of the S3-compatible storage service used by the tracking server. aws_access_key_id Optional[str]
None
The access key for the s3-compatible storage service used by the tracking server. aws_secret_access_key Optional[str]
None
The secret key for the s3-compatible storage service used by the tracking server. basic_auth_username Optional[str]
None
Username needed for access to servers with basic authentication enabled. basic_auth_password Optional[str]
None
Password needed for access to servers with basic authentication enabled. bearer_auth_token Optional[str]
None
Bearer token needed for access to servers with bearer authentication enabled. timeout_seconds int
600
Maximum amount of time to wait for the job to complete before giving up.
register
register