Batch endpoints allow you to deploy pipeline components, providing a convenient way to operationalize pipelines in Azure Machine Learning. Batch endpoints accept pipeline components for deployment. However, if you already have a pipeline job that runs successfully, Azure Machine Learning can accept that job as input to your batch endpoint and create the pipeline component automatically for you. In this article, you'll learn how to use your existing pipeline job as input for batch deployment.
You'll learn to:
Run and create the pipeline job that you want to deploy
Create a batch deployment from the existing job
Test the deployment
About this example
In this example, we're going to deploy a pipeline consisting of a simple command job that prints "hello world!". Instead of registering the pipeline component before deployment, we indicate an existing pipeline job to use for deployment. Azure Machine Learning will then create the pipeline component automatically and deploy it as a batch endpoint pipeline component deployment.
The example in this article is based on code samples contained in the azureml-examples repository. To run the commands locally without having to copy or paste YAML and other files, use the following commands to clone the repository and go to the folder for your coding language:
The following permissions in the Azure Machine Learning workspace:
For creating or managing batch endpoints and deployments: Use an Owner, Contributor, or custom role that has been assigned the Microsoft.MachineLearningServices/workspaces/batchEndpoints/* permissions.
For creating Azure Resource Manager deployments in the workspace resource group: Use an Owner, Contributor, or custom role that has been assigned the Microsoft.Resources/deployments/write permission in the resource group where the workspace is deployed.
The Azure Machine Learning CLI or the Azure Machine Learning SDK for Python:
Pipeline component deployments for batch endpoints are introduced in version 2.7 of the ml extension for the Azure CLI. Use the az extension update --name ml command to get the latest version.
The ModelBatchDeployment and PipelineComponentBatchDeployment classes are introduced in version 1.7.0 of the SDK. Use the pip install -U azure-ai-ml command to get the latest version.
Connect to your workspace
The workspace is the top-level resource for Azure Machine Learning. It provides a centralized place to work with all artifacts you create when you use Azure Machine Learning. In this section, you connect to the workspace where you perform your deployment tasks.
Now, configure some run settings to run the test. This article assumes you have a compute cluster named batch-cluster. You can replace the cluster with the name of yours.
Before we deploy the pipeline job, we need to deploy a batch endpoint to host the deployment.
Provide a name for the endpoint. A batch endpoint's name needs to be unique in each region since the name is used to construct the invocation URI. To ensure uniqueness, append any trailing characters to the name specified in the following code.
The deployment-from-job.yml file contains the deployment's configuration. Notice how we use the key job_definition instead of component to indicate that this deployment is created from a pipeline job:
Notice now how we use the property job_definition instead of component:
Python
deployment = PipelineComponentBatchDeployment(
name="hello-batch-from-job",
description="A hello world deployment with a single step. This deployment is created from a pipeline job.",
endpoint_name=endpoint.name,
job_definition=pipeline_job_run,
settings={
"default_compute": "batch-cluster",
"continue_on_step_failure": False
}
)
Tip
This configuration assumes you have a compute cluster named batch-cluster. You can replace this value with the name of your cluster.
Run the following code to create a batch deployment under the batch endpoint and set it as the default deployment.
Azure CLI
az ml batch-deployment create --endpoint$ENDPOINT_NAME--setjob_definition=azureml:$JOB_NAME-f deployment-from-job.yml
Tip
Notice the use of --set job_definition=azureml:$JOB_NAME. Since job names are unique, the command --set is used here to change the name of the job when you run it in your workspace.
This command starts the deployment creation and returns a confirmation response while the deployment creation continues.
Manage data ingestion and preparation, model training and deployment, and machine learning solution monitoring with Python, Azure Machine Learning and MLflow.