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, instance_type='ml.m4.xlarge', instance_count=1, vpc_config=None) Deploy model on SageMaker. Currently active AWS account needs to have correct permissions set up.
Parameters: - app_name – Name of the deployed application.
- path – Path to the model. Either local if no
run_id
or MLflow-relative ifrun_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
- Create an application with the specified name and model. This fails 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) is replaced with the specified model. If no such application exists, it is created with the specified name and model.
mlflow.sagemaker.DEPLOYMENT_MODE_ADD
- Add the specified model to a pre-existing application with the specified name,
if one exists. If the application does not exist, a new application is created
with the specified name and model. NOTE: If the application already exists,
the specified model is 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 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) are preserved. If False, these resources are deleted. - instance_type – The type of SageMaker ML instance on which to deploy the model. For a list of supported instance types, see https://aws.amazon.com/sagemaker/pricing/instance-types/.
- instance_count – The number of SageMaker ML instances on which to deploy the model.
- vpc_config –
A dictionary specifying the VPC configuration to use when creating the new SageMaker model associated with this application. The acceptable values for this parameter are identical to those of the VpcConfig parameter in the SageMaker boto3 client (https://boto3.readthedocs.io/en/latest/reference/ services/sagemaker.html#SageMaker.Client.create_model). For more information, see https://docs.aws.amazon.com/sagemaker/latest/dg/API_VpcConfig.html.
Example:
>>> import mlflow.sagemaker as mfs >>> vpc_config = { ... 'SecurityGroupIds': [ ... 'sg-123456abc', ... ], ... 'Subnets': [ ... 'subnet-123456abc', ... ] ... } >>> mfs.deploy(..., vpc_config=vpc_config)
-
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.
Parameters: - model_path – path to the model. Either local if no
run_id
or MLflow-relative ifrun_id
is specified. - run_id – MLflow run ID.
- port – Local port.
- image – Name of the Docker image to be used.
- model_path – path to the model. Either local if no