Skip to content

Commit f1e82b1

Browse files
authored
Merge pull request #212876 from juliakm/users/jukullam/port-machine-learning-azdevops
Move DevOps ML article and add ref to text repo
2 parents 1e2519a + ae2dffd commit f1e82b1

File tree

7 files changed

+158
-1
lines changed

7 files changed

+158
-1
lines changed

.openpublishing.publish.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,12 @@
955955
"url": "https://github.com/Azure-Samples/cosmos-db-mongodb-api-dotnet-samples",
956956
"branch": "main",
957957
"branch_mapping": {}
958+
},
959+
{
960+
"path_to_root": "reusable-content",
961+
"url": "https://github.com/MicrosoftDocs/reusable-content",
962+
"branch": "main",
963+
"branch_mapping": {}
958964
}
959965
],
960966
"branch_target_mapping": {
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
title: Azure DevOps for CI/CD
3+
titleSuffix: Azure Machine Learning
4+
description: Use Azure Pipelines for flexible MLOps automation
5+
services: machine-learning
6+
ms.service: machine-learning
7+
ms.subservice: mlops
8+
author: juliakm
9+
ms.author: jukullam
10+
ms.date: 09/28/2022
11+
ms.topic: how-to
12+
ms.custom: devops-pipelines-deploy
13+
---
14+
15+
# Use Azure Pipelines with Azure Machine Learning
16+
17+
**Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019**
18+
19+
You can use an [Azure DevOps pipeline](/azure/devops/pipelines/) to automate the machine learning lifecycle. Some of the operations you can automate are:
20+
21+
* Data preparation (extract, transform, load operations)
22+
* Training machine learning models with on-demand scale-out and scale-up
23+
* Deployment of machine learning models as public or private web services
24+
* Monitoring deployed machine learning models (such as for performance or data-drift analysis)
25+
26+
This article will teach you how to create an Azure Pipeline that builds and deploys a machine learning model to [Azure Machine Learning](overview-what-is-azure-machine-learning.md). You'll train a scikit-learn linear regression model on the Diabetes dataset.
27+
28+
This tutorial uses [Azure Machine Learning Python SDK v2](/python/api/overview/azure/ml/installv2) and [Azure CLI ML extension v2](/cli/azure/ml).
29+
30+
## Prerequisites
31+
32+
Complete the [Quickstart: Get started with Azure Machine Learning](quickstart-create-resources.md) to:
33+
* Create a workspace
34+
* Create a cloud-based compute instance to use for your development environment
35+
* Create a cloud-based compute cluster to use for training your model
36+
37+
## Step 1: Get the code
38+
39+
Fork the following repo at GitHub:
40+
41+
```
42+
https://github.com/azure/azureml-examples
43+
```
44+
45+
## Step 2: Sign in to Azure Pipelines
46+
47+
[!INCLUDE [include](~/reusable-content/devops-pipelines/sign-in-azure-pipelines.md)]
48+
49+
[!INCLUDE [include](~/reusable-content/devops-pipelines/create-project.md)]
50+
51+
## Step 3: Create an Azure Resource Manager connection
52+
53+
You'll need an Azure Resource Manager connection to authenticate with Azure portal.
54+
55+
1. In Azure DevOps, open the **Service connections** page.
56+
57+
1. Choose **+ New service connection** and select **Azure Resource Manager**.
58+
59+
1. Select the default authentication method, **Service principal (automatic)**.
60+
61+
1. Create your service connection. Set your subscription, resource group, and connection name.
62+
63+
:::image type="content" source="media/how-to-devops-machine-learning/machine-learning-arm-connection.png" alt-text="Screenshot of ARM service connection.":::
64+
65+
66+
## Step 4: Create a pipeline
67+
68+
1. Go to **Pipelines**, and then select **New pipeline**.
69+
70+
1. Do the steps of the wizard by first selecting **GitHub** as the location of your source code.
71+
72+
1. You might be redirected to GitHub to sign in. If so, enter your GitHub credentials.
73+
74+
1. When you see the list of repositories, select your repository.
75+
76+
1. You might be redirected to GitHub to install the Azure Pipelines app. If so, select **Approve & install**.
77+
78+
1. Select the **Starter pipeline**. You'll update the starter pipeline template.
79+
80+
## Step 5: Create variables
81+
82+
You should already have a resource group in Azure with [Azure Machine Learning](overview-what-is-azure-machine-learning.md). To deploy your DevOps pipeline to AzureML, you'll need to create variables for your subscription ID, resource group, and machine learning workspace.
83+
84+
1. Select the Variables tab on your pipeline edit page.
85+
86+
:::image type="content" source="media/how-to-devops-machine-learning/machine-learning-select-variables.png" alt-text="Screenshot of variables option in pipeline edit. ":::
87+
88+
1. Create a new variable, `Subscription_ID`, and select the checkbox **Keep this value secret**. Set the value to your [Azure portal subscription ID](/azure/azure-portal/get-subscription-tenant-id).
89+
1. Create a new variable for `Resource_Group` with the name of the resource group for Azure Machine Learning (example: `machinelearning`).
90+
1. Create a new variable for `AzureML_Workspace_Name` with the name of your Azure ML workspace (example: `docs-ws`).
91+
1. Select **Save** to save your variables.
92+
93+
## Step 6: Build your YAML pipeline
94+
95+
Delete the starter pipeline and replace it with the following YAML code. In this pipeline, you'll:
96+
97+
* Use the Python version task to set up Python 3.8 and install the SDK requirements.
98+
* Use the Bash task to run bash scripts for the Azure Machine Learning SDK and CLI.
99+
* Use the Azure CLI task to pass the values of your three variables and use papermill to run your Jupyter notebook and push output to AzureML.
100+
101+
```yaml
102+
trigger:
103+
- main
104+
105+
pool:
106+
vmImage: ubuntu-latest
107+
108+
steps:
109+
- task: UsePythonVersion@0
110+
inputs:
111+
versionSpec: '3.8'
112+
- script: pip install -r sdk/dev-requirements.txt
113+
displayName: 'pip install notebook reqs'
114+
- task: Bash@3
115+
inputs:
116+
filePath: 'sdk/setup.sh'
117+
displayName: 'set up sdk'
118+
119+
- task: Bash@3
120+
inputs:
121+
filePath: 'cli/setup.sh'
122+
displayName: 'set up CLI'
123+
124+
- task: AzureCLI@2
125+
inputs:
126+
azureSubscription: 'your-azure-subscription'
127+
scriptType: 'bash'
128+
scriptLocation: 'inlineScript'
129+
inlineScript: |
130+
sed -i -e "s/<SUBSCRIPTION_ID>/$(SUBSCRIPTION_ID)/g" sklearn-diabetes.ipynb
131+
sed -i -e "s/<RESOURCE_GROUP>/$(RESOURCE_GROUP)/g" sklearn-diabetes.ipynb
132+
sed -i -e "s/<AML_WORKSPACE_NAME>/$(AZUREML_WORKSPACE_NAME)/g" sklearn-diabetes.ipynb
133+
sed -i -e "s/DefaultAzureCredential/AzureCliCredential/g" sklearn-diabetes.ipynb
134+
papermill -k python sklearn-diabetes.ipynb sklearn-diabetes.output.ipynb
135+
workingDirectory: 'sdk/jobs/single-step/scikit-learn/diabetes'
136+
```
137+
138+
139+
## Step 7: Verify your pipeline run
140+
141+
1. Open your completed pipeline run and view the AzureCLI task. Check the task view to verify that the output task finished running.
142+
143+
:::image type="content" source="media/how-to-devops-machine-learning/machine-learning-azurecli-output.png" alt-text="Screenshot of machine learning output to AzureML.":::
144+
145+
1. Open Azure Machine Learning studio and navigate to the completed `sklearn-diabetes-example` job. On the **Metrics** tab, you should see the training results.
146+
147+
:::image type="content" source="media/how-to-devops-machine-learning/machine-learning-training-results.png" alt-text="Screenshot of training results.":::
148+
149+
## Clean up resources
150+
151+
If you're not going to continue to use your pipeline, delete your Azure DevOps project. In Azure portal, delete your resource group and Azure Machine Learning instance.
34.2 KB
Loading
37.9 KB
Loading
3.37 KB
Loading
46.2 KB
Loading

articles/machine-learning/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@
607607
items:
608608
- name: Azure Pipelines for CI/CD
609609
displayName: continuous, integration, delivery
610-
href: /azure/devops/pipelines/targets/azure-machine-learning?context=azure/machine-learning/context/ml-context
610+
href: how-to-devops-machine-learning.md
611611
- name: GitHub Actions for CI/CD
612612
href: how-to-github-actions-machine-learning.md
613613
- name: Create event-driven workflows

0 commit comments

Comments
 (0)