Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 39 additions & 18 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Please make note of the following values after creating a service principal, we

### 4. Create a Variable Group

We make use of variable group inside Azure DevOps to store variables and their values that we want to make available across multiple pipelines. You can either store the values directly in [Azure DevOps](https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=designer#create-a-variable-group) or connect to an Azure Key Vault in your subscription. Please refer to the documentation [here](https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=designer#create-a-variable-group) to learn more about how to create a variable group and [link](https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=designer#use-a-variable-group) it to your pipeline.
We make use of variable group inside Azure DevOps to store variables and their values that we want to make available across multiple pipelines. You can either store the values directly in [Azure DevOps](https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=designer#create-a-variable-group) or connect to an Azure Key Vault in your subscription. Please refer to the documentation [here](https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=designer#create-a-variable-group) to learn more about how to create a variable group and [link](https://docs.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=designer#use-a-variable-group) it to your pipeline. Click on **Library** in the **Pipelines** section as indicated below:

![library_variable groups](./images/library_variable_groups.png)

Please name your variable group **``devopsforai-aml-vg``** as we are using this name within our build yaml file.

Expand Down Expand Up @@ -66,7 +68,7 @@ The easiest way to create all required resources (Resource Group, ML Workspace,

![create service connection](./images/create-rm-service-connection.png)

Give the connection name **``AzureResourceConnection``** as it is referred by the pipeline definition.
Give the connection name **``AzureResourceConnection``** as it is referred by the pipeline definition. Leave the **``Resource Group``** field empty.

In your DevOps project create a build pipeline from your forked **GitHub** repository:

Expand Down Expand Up @@ -106,23 +108,23 @@ Great, you now have the build pipeline setup, you can either manually trigger it

### 7. Train the Model

The next step is to invoke the training pipeline created in the previous step. It can be done with a **Release Pipeline**:
The next step is to invoke the training pipeline created in the previous step. It can be done with a **Release Pipeline**. Click on the Pipelines/Releases menu, and then **New pipeline**, and then click on "Empty Job" on the "Select a template" window that pops to the right:

![invoke training pipeline](./images/invoke-training-pipeline.png)

An artifact of this pipeline will be the result of the build pipeline **ci-buid**:

![artifact invoke pipeline](./images/artifact-invoke-pipeline.png)

Configure a pipeline to see values from the previously defined variable group **devopsforai-aml-vg**:
Configure a pipeline to see values from the previously defined variable group **devopsforai-aml-vg**. Click on the "Variable groups", and to the right, click on "Link variable group". From there, pick the **devopsforai-aml-vg** variable group we created in an earlier step, choose "Release" as a variable group scope, and click on "Link":

![retrain pipeline vg](./images/retrain-pipeline-vg.png)

Add an empty stage with name **Invoke Training Pipeline** and make sure that the **Agent Specification** is **ubuntu-16.04**:
Rename the default "Stage 1" to **Invoke Training Pipeline** and make sure that the **Agent Specification** is **ubuntu-16.04** under the Agent Job:

![agent specification](./images/agent-specification.png)

Add a command line step **Run Training Pipeline** with the following script:
Add a **Command Line Script** step, rename it to **Run Training Pipeline** with the following script:

```bash
docker run -v $(System.DefaultWorkingDirectory)/_ci-build/mlops-pipelines/ml_service/pipelines:/pipelines \
Expand All @@ -131,11 +133,19 @@ docker run -v $(System.DefaultWorkingDirectory)/_ci-build/mlops-pipelines/ml_se
mcr.microsoft.com/mlops/python:latest python run_train_pipeline.py
```

This release pipeline should be automatically triggered (continuous deployment) whenever a new **ML training pipeline** is published by the **AzDo builder pipeline**. It can also be triggered manually or configured to run on a scheduled basis. Create a new release to trigger the pipeline manually:
as in the screen shot below, leaving all other fields to their default value:

![Run Training Pipeline Task](./images/run_training_pipeline_task.png)

Now, add the automation to trigger a run of this pipeline whenever the **ci_build** build is completed, click on the lightning bolt icon on the top right of the **\_ci-build** artifact is selected, and enable the automatic release :

![automate_infoke_training_pipeline](./images/automate_infoke_training_pipeline.png)

This release pipeline should now be automatically triggered (continuous deployment) whenever a new **ML training pipeline** is published by the **ci-build builder pipeline**. It can also be triggered manually or configured to run on a scheduled basis. Create a new release to trigger the pipeline manually by clicking on the "Create release" button on the top right of your screen, when selecting this new build pipeline:

![create release](./images/create-release.png)

Once the release pipeline is completed, check out in the **ML Workspace** that the training pipeline is running:
Leave the fields empty and click on "create". Once the release pipeline is completed, check out in the **ML Workspace** that the training pipeline is running:

![running training pipeline](./images/running-training-pipeline.png)

Expand All @@ -147,7 +157,7 @@ Good! Now we have a trained model.

### 8. Deploy the Model

The final step is to deploy the model across environments with a release pipeline. There will be a **``QA``** environment running on [Azure Container Instances](https://azure.microsoft.com/en-us/services/container-instances/) and a **``Prod``** environment running on [Azure Kubernetes Service](https://azure.microsoft.com/en-us/services/kubernetes-service).
The final step is to deploy the model across environments with a release pipeline. There will be a **``QA``** environment running on [Azure Container Instances](https://azure.microsoft.com/en-us/services/container-instances/) and a **``Prod``** environment running on [Azure Kubernetes Service](https://azure.microsoft.com/en-us/services/kubernetes-service). This is the final picture of what your release pipeline should look like:

![deploy model](./images/deploy-model.png)

Expand All @@ -156,19 +166,19 @@ This pipeline leverages the **Azure Machine Learning** extension that should be

The pipeline consumes two artifacts: the result of the **Build Pipeline** as it contains configuration files and the **model** trained and registered by the ML training pipeline.

Configuration of a code **_ci-build** artifact is similar to what we did in the previous chapter.
Add the **\_ci-build** artifact using the same process as what we did in the previous step.

In order to configure a model artifact there should be a service connection to **mlops-AML-WS** workspace:
In order to configure a model artifact there should be a service connection to **mlops-AML-WS** workspace. To get there, go to the project settings (by clicking on the cog wheel to the bottom left of the screen), and then click on **Service connections** under the **Pipelines** section:

**Note:** Creating service connection using Azure Machine Learning extension requires 'Owner' or 'User Access Administrator' permissions on the Workspace.

![workspace connection](./images/workspace-connection.png)

Add an artifact to the pipeline and select **AzureML Model Artifact** source type. Select the **Service Endpoint** and **Model Names** from the drop down lists:
Add an artifact to the pipeline and select **AzureML Model Artifact** source type. Select the **Service Endpoint** and **Model Names** from the drop down lists. **Service Endpoint** refers to the **Service connection** created in the previous step:

![model artifact](./images/model-artifact.png)

Create a stage **QA (ACI)** and add a single task to the job **Azure ML Model Deploy**:
Go to the new **Releases Pipelines** section, and click new to create a new release pipeline. A first stage is automatically created and choose **start with an Empty job**. Name the stage **QA (ACI)** and add a single task to the job **Azure ML Model Deploy**. Make sure that the Agent Specification is ubuntu-16.04 under the Agent Job:

![deploy aci](./images/deploy-aci.png)

Expand All @@ -186,7 +196,7 @@ Specify task parameters as it is shown in the table below:
| Overwrite existing deployment | X |


In a similar way create a stage **Prod (AKS** and add a single task to the job **Azure ML Model Deploy**:
In a similar way create a stage **Prod (AKS)** and add a single task to the job **Azure ML Model Deploy**. Make sure that the Agent Specification is ubuntu-16.04 under the Agent Job:

![deploy aks](./images/deploy-aks.png)

Expand All @@ -203,22 +213,33 @@ Specify task parameters as it is shown in the table below:
| Deployment Configuration file | `$(System.DefaultWorkingDirectory)/_ci-build/mlops-pipelines/code/scoring/deployment_config_aks.yml` |
| Overwrite existing deployment | X |

Similarly to the **Invoke Training Pipeline** release pipeline, previously created, in order to trigger a coutinuous integration, click on the lightning bolt icon, make sure the **Continuous deployment trigger** is checked and save the trigger:

![Automate Deploy Model Pipeline](./images/automate_deploy_model_pipeline.png)

**Note:** Creating of a Kubernetes cluster on AKS is out of scope of this tutorial, so you should take care of it on your own.

**Deploy trained model to Azure Web App for containers**

Note: This is an optional step and can be used only if you are deploying your scoring service on Azure Web Apps.

[Create Image Script](../ml_service/util/create_scoring_image.py)
can be used to create a scoring image from the release pipeline. Image created by this script will be registered under Azure Container Registry(ACR) instance that belongs to Azure Machine Learning Service. Any dependencies that scoring file depends on can also be packaged with the container with Image config. To learn more on how to create a container with AML SDK click [here](https://docs.microsoft.com/en-us/python/api/azureml-core/azureml.core.image.image.image?view=azure-ml-py#create-workspace--name--models--image-config-).
can be used to create a scoring image from the release pipeline. Image created by this script will be registered under Azure Container Registry (ACR) instance that belongs to Azure Machine Learning Service. Any dependencies that scoring file depends on can also be packaged with the container with Image config. To learn more on how to create a container with AML SDK click [here](https://docs.microsoft.com/en-us/python/api/azureml-core/azureml.core.image.image.image?view=azure-ml-py#create-workspace--name--models--image-config-).

Below is release pipeline with two tasks one to create an image using the above script and second is the deploy the image to Web App for containers
![release_webapp](./images/release-webapp-pipeline.PNG)

Using bash script task to invoke [Create Image Script](../ml_service/util/create_scoring_image.py)
For the bash script task to invoke the [Create Image Script](../ml_service/util/create_scoring_image.py), specify the following task parameters:

| Parameter | Value |
| ------------------ | --------------------------------------------------------------------------------------------------- |
| Display Name | Create Scoring Image |
| Script | python3 $(System.DefaultWorkingDirectory)/\_MLOpsPythonRepo/mlservice/util/create_scoring_image.py |

Finally
![release_createimage](./images/release-task-createimage.PNG)

Specify task parameters as it is shown in the table below:
Finally for the Azure WebApp on Container Task, specify the following task parameters as it is shown in the table below:


| Parameter | Value |
Expand All @@ -230,7 +251,7 @@ Specify task parameters as it is shown in the table below:
![release_webapp](./images/release-task-webappdeploy.PNG)


Save the pipeline and create a release to trigger it manually. Once the pipeline execution is finished, check out deployments in the **mlops-AML-WS** workspace.
Save the pipeline and create a release to trigger it manually. To create the trigger, click on the "Create release" button on the top right of your screen, leave the fields blank and click on **Create** at the bottom of the screen. Once the pipeline execution is finished, check out deployments in the **mlops-AML-WS** workspace.



Expand Down
Binary file added docs/images/automate_deploy_model_pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/library_variable_groups.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/run_training_pipeline_task.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.