mlflow.sagemaker

mlflow.sagemaker.build_image(name='mlflow-pyfunc', mlflow_home=None)

This function builds an MLflow Docker image. The image is built locally and it requires Docker to run.

Parameters:name – image name
mlflow.sagemaker.delete(app_name, region_name='us-west-2', archive=False)

Delete the specified application.

Parameters:
  • app_name – Name of the deployed application.
  • region_name – Name of the AWS region in which the application is deployed.
  • archive – If True, resources associated with the specified application, such as its associated models and endpoint configuration, will be preserved. If False, these resources will be deleted.
mlflow.sagemaker.deploy(app_name, model_path, execution_role_arn=None, bucket=None, run_id=None, image_url=None, region_name='us-west-2', mode='create', archive=False)

Deploy model on SageMaker. Current active AWS account needs to have correct permissions setup.

Parameters:
  • app_name – Name of the deployed application.
  • path – Path to the model. Either local if no run_id or MLflow-relative if run_id is specified)
  • execution_role_arn – Amazon execution role with sagemaker rights. defaults to the currently-assumed role.
  • bucket – S3 bucket where model artifacts will be stored. defaults to a SageMaker-compatible bucket name.
  • run_id – MLflow run id.
  • image – name of the Docker image to be used. if not specified, uses a publicly-available pre-built image.
  • region_name – Name of the AWS region to which to deploy the application.
  • mode

    The mode in which to deploy the application. Must be one of the following:

    mlflow.sagemaker.DEPLOYMENT_MODE_CREATE: Creates an application with the specified
    name and model. This will fail if an application of the same name already exists.
    mlflow.sagemaker.DEPLOYMENT_MODE_REPLACE: If an application of the specified name
    exists, its model(s) will be replaced with the specified model. If no such application exists, it will be created with the specified name and model.
    mlflow.sagemaker.DEPLOYMENT_MODE_ADD: Adds the specified model to a pre-existing
    application with the specified name, if one exists. If the application does not exist, a new application will be created with the specified name and model. NOTE: If the application already exists, the specified model will be added to the application’s corresponding SageMaker endpoint with an initial weight of zero (0). To route traffic to the model, update the application’s associated endpoint configuration using either the AWS console or the UpdateEndpointWeightsAndCapacities function defined in the SageMaker API Documentation (https://docs.aws.amazon.com/sagemaker/latest/dg/ API_UpdateEndpointWeightsAndCapacities.html).
  • archive – If True, any pre-existing SageMaker application resources that become inactive (i.e. as a result of deploying in mlflow.sagemaker.DEPLOYMENT_MODE_REPLACE mode) will be preserved. If False, these resources will be deleted.
mlflow.sagemaker.push_image_to_ecr(image='mlflow-pyfunc')

Push local Docker image to ECR.

The image is pushed under current active aws account and to current active AWS region.

Parameters:image – image name
mlflow.sagemaker.run_local(model_path, run_id=None, port=5000, image='mlflow-pyfunc')

Serve model locally in a SageMaker compatible Docker container. :param model_path: Path to the model. Either local if no run_id or MLflow-relative if run_id is specified) :param run_id: MLflow RUN-ID. :param port: local port :param image: name of the Docker image to be used.