You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/06-automate-model-training.md
+14-12Lines changed: 14 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,7 +69,7 @@ To let GitHub Actions authenticate to Azure Machine Learning, you use a service
69
69
1. In the Azure portal, select the **[>_]** (**Cloud Shell**) button at the top of the page to open Cloud Shell.
70
70
1. Select **Bash** if you are prompted to choose a shell type.
71
71
1. Make sure the correct subscription is selected for your Azure Machine Learning workspace.
72
-
1. In Cloud Shell, create a service principal that has **Contributor** access to the resource group that contains your Azure Machine Learning workspace. Replace `<service-principal-name>`, `<subscription-id>`, and `<your-resource-group-name>` with your own values before you run the command:
72
+
1. In Cloud Shell, create a service principal that has **Contributor** access to the resource group that contains your Azure Machine Learning workspace. Replace `<service-principal-name>`, `<subscription-id>`, and `<your-resource-group-name>` with your own values before you run the command. Use a descriptive name such as `sp-mslearn-mlops-github`:
73
73
74
74
```azurecli
75
75
az ad sp create-for-rbac --name "<service-principal-name>" --role contributor \
@@ -82,6 +82,9 @@ To let GitHub Actions authenticate to Azure Machine Learning, you use a service
82
82
1. Select **New repository secret**.
83
83
1. Enter `AZURE_CREDENTIALS` as the **Name** of the secret.
84
84
1. Paste the JSON output from the `az ad sp create-for-rbac` command into the **Value** field and select **Add secret**.
85
+
1. Select the **Variables** tab and then select **New repository variable**.
86
+
1. Enter `AZURE_RESOURCE_GROUP` as the **Name** and your resource group name (for example, `rg-ai300-l<suffix>`) as the **Value**. Select **Add variable**.
87
+
1. Select **New repository variable** again. Enter `AZURE_WORKSPACE_NAME` as the **Name** and your Azure Machine Learning workspace name (for example, `mlw-ai300-l<suffix>`) as the **Value**. Select **Add variable**.
85
88
86
89
Your GitHub repository now has an encrypted secret that GitHub-hosted runners can use to sign in to Azure and submit jobs to your Azure Machine Learning workspace.
87
90
@@ -92,8 +95,8 @@ Your GitHub repository now has an encrypted secret that GitHub-hosted runners ca
92
95
93
96
Before you automate training from GitHub, review how your Azure Machine Learning workspace controls network access.
94
97
95
-
1. In Azure Machine Learning studio, select **Manage** in the left navigation and then select **Networking** under your workspace.
96
-
1. Review the **Public access** and **Private endpoints** settings. Note how you can:
98
+
1. In **Azure Portal** on your Azure Machine Learning workspace, select **Settings** in the left navigation and then select **Networking**.
99
+
1. Review the **Public access** and the **Private endpoints** settings. Note how you can:
97
100
- Allow public network access from all networks.
98
101
- Restrict access to specific IP ranges.
99
102
- Disable public network access and rely on private endpoints.
@@ -109,22 +112,21 @@ Now that you understand the network options, you are ready to automate a trainin
109
112
In this section, you connect your GitHub workflow to Azure Machine Learning and run a command job to train a model. The workflow uses the `AZURE_CREDENTIALS` secret you created earlier.
110
113
111
114
1. Clone your `mslearn-mlops` repository that you created from the template to a development environment where you can edit files and push changes back to GitHub.
112
-
1. In the cloned repository, locate the `.github/workflows/manual-trigger.yml` workflow file.
113
-
1. Open `manual-trigger.yml` and review the existing steps. The workflow should:
115
+
1. In the cloned repository, locate the `.github/workflows/manual-trigger-job.yml` workflow file.
116
+
1. Open `manual-trigger-job.yml` and review the existing steps. The workflow should:
114
117
- Check out the repository code.
115
-
- Use the `AZURE_CREDENTIALS` secret to sign in to Azure.
116
118
- Install the Azure Machine Learning CLI extension.
117
-
1. At the end of the workflow, add a new step that submits the Azure Machine Learning job defined in `src/job.yml`. For example:
119
+
- Use the `AZURE_CREDENTIALS` secret to sign in to Azure via `azure/login@v2`.
120
+
1. At the end of the workflow, add a new step that submits the Azure Machine Learning job defined in `src/job.yml`. The command requires explicit `--resource-group` and `--workspace-name` flags, supplied from the GitHub Actions variables you created:
118
121
119
122
```yml
120
123
- name: Run Azure Machine Learning training job
121
-
run: |
122
-
az ml job create -f src/job.yml --stream
124
+
run: az ml job create -f src/job.yml --stream --resource-group ${{vars.AZURE_RESOURCE_GROUP}} --workspace-name ${{vars.AZURE_WORKSPACE_NAME}}
123
125
```
124
126
125
127
1. Save your changes, commit them to your local repository, and push the changes to the **main** branch of your fork.
126
128
1. In GitHub, go to the **Actions** tab for your repository.
127
-
1. Select the workflow defined in `manual-trigger.yml` and use **Run workflow** to start it manually.
129
+
1. Select the workflow defined in `manual-trigger-job.yml` and use **Run workflow** to start it manually.
128
130
1. Wait for the workflow run to complete. Verify that the **Run Azure Machine Learning training job** step completes successfully.
129
131
1. In Azure Machine Learning studio, select **Jobs** and confirm that a new job based on `src/job.yml` has run successfully. Review the job inputs, metrics, and logs.
130
132
@@ -134,7 +136,7 @@ You have now automated the training job by using a GitHub Actions workflow that
134
136
135
137
Running workflows manually is useful for initial testing, but in a team environment you usually want training workflows to run automatically when someone proposes a change. Next, you update the existing workflow so it runs for pull requests, and then you use feature branches and branch protection rules to control when the workflow runs.
136
138
137
-
1. In your GitHub repository, open the `.github/workflows/manual-trigger.yml` workflow file.
139
+
1. In your GitHub repository, open the `.github/workflows/manual-trigger-job.yml` workflow file.
138
140
1. Update the `on` section so that the workflow can run both manually and when a pull request targets the **main** branch. For example:
139
141
140
142
```yml
@@ -167,7 +169,7 @@ Running workflows manually is useful for initial testing, but in a team environm
167
169
```
168
170
169
171
1. In GitHub, create a pull request from your feature branch into **main**.
170
-
1. On the pull request page, observe that the workflow defined in `manual-trigger.yml` runs automatically because of the `pull_request` trigger you added.
172
+
1. On the pull request page, observe that the workflow defined in `manual-trigger-job.yml` runs automatically because of the `pull_request` trigger you added.
171
173
1. After the workflow completes successfully, review the results and then complete the pull request to merge your changes into **main**.
172
174
173
175
By using feature branches, branch protection rules, and pull request–triggered workflows with the same training workflow definition, you ensure that model training automation is tied to controlled changes in source control.
0 commit comments