Concepts

Azure Machine Learning provides a powerful platform for designing and implementing data science solutions on Azure. One of the key features it offers is the ability to trigger and automate machine learning jobs, allowing you to run experiments, train models, and deploy solutions at scale. In this article, we will explore how to trigger an Azure Machine Learning job, including using Azure DevOps or GitHub.

Triggering with the Azure Machine Learning Python SDK

Triggering an Azure Machine Learning job can be done through the Azure Machine Learning Python SDK. Let’s start by looking at how to trigger a job using the Python SDK:

  1. Connect to your Azure Machine Learning workspace by creating an instance of the Workspace class:
  2. from azureml.core import Workspace

    ws = Workspace.get(
    subscription_id='',
    resource_group='',
    workspace_name=''
    )

  3. Create an experiment within your workspace:
  4. from azureml.core import Experiment

    experiment = Experiment(workspace=ws, name='')

  5. Set up the script run configuration:
  6. from azureml.core import ScriptRunConfig

    script_run_config = ScriptRunConfig(
    source_directory='',
    script='',
    arguments=['', ''],
    environment={'': '', '': ''}
    )

  7. Submit the job using the experiment and script run configuration:
  8. run = experiment.submit(config=script_run_config)

With these steps, you have triggered an Azure Machine Learning job using the Python SDK. The job will be queued for execution and can be monitored using the run object. You can also retrieve its status, logs, and other details as necessary.

Triggering with Azure DevOps or GitHub

Azure Machine Learning integrates seamlessly with Azure DevOps and GitHub, allowing you to trigger and manage machine learning jobs as part of your CI/CD pipelines.

Using Azure DevOps, you can create a pipeline that executes your data science experiments or machine learning models whenever changes are made to your code repository. You can use Azure Machine Learning tasks provided by Azure DevOps to trigger and monitor jobs, upload datasets, and register models. Here’s an example of YAML-based pipeline code that triggers an Azure Machine Learning job:

trigger:
branches:
include:
- main

pool:
vmImage: 'ubuntu-latest'

steps:
- task: AzureMachineLearningRun@v1
inputs:
azureSubscription: ''
mlWorkspaceName: ''
experimentName: ''
script: ''
arguments: '--arg1 --arg2 '
environment: ''

By defining this pipeline and configuring the necessary inputs, you can trigger the Azure Machine Learning job whenever changes are pushed to the main branch of your code repository.

Similarly, when using GitHub, you can create a GitHub Action workflow that integrates with Azure Machine Learning. This workflow automatically triggers a machine learning job whenever code changes are committed to your GitHub repository. Here’s an example of a GitHub Action workflow file that triggers an Azure Machine Learning job:

name: Trigger Azure Machine Learning job
on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Trigger Azure Machine Learning job
uses: azure/actions/ml-remote-run@v1
with:
azure_credentials: ${{ secrets.AZURE_CREDENTIALS }}
workspace: ''
experiment: ''
script: ''
arguments: '--arg1 --arg2 '
environment: ''

In this GitHub Action workflow file, the ml-remote-run action is used to trigger the Azure Machine Learning job. The required inputs such as the workspace, experiment, script, arguments, and environment are provided to the action for job execution.

By leveraging the integration with Azure DevOps or GitHub, you can easily trigger and automate Azure Machine Learning jobs, making it effortless to incorporate data science experiments and machine learning workflows into your CI/CD processes.

With the flexibility and power of Azure Machine Learning, combined with seamless integration with Azure DevOps and GitHub, you can design and implement robust data science solutions on Azure. Triggering and automating machine learning jobs has never been easier, allowing you to scale your data science workflows and accelerate your time to insight.

Start exploring Azure Machine Learning and unleash the potential of your data science projects on Azure!

Answer the Questions in Comment Section

What triggers an Azure Machine Learning job?

– A) A scheduled time

– B) A change in the dataset

– C) A change in the model

– D) All of the above

Answer: D) All of the above

Which service provides built-in integration with Azure DevOps to trigger Azure Machine Learning jobs?

– A) Azure Functions

– B) Azure Logic Apps

– C) Azure Data Factory

– D) Azure Batch AI

Answer: B) Azure Logic Apps

When triggering an Azure Machine Learning job from Azure DevOps, which YAML configuration file is used?

– A) azure-pipelines.yml

– B) machine-learning.yml

– C) deploy.yml

– D) model-training.yml

Answer: A) azure-pipelines.yml

True or False: When triggering an Azure Machine Learning job from GitHub, the repository must be public.

Answer: False

When triggering an Azure Machine Learning job from GitHub, which component is responsible for executing the job?

– A) Azure Pipelines

– B) Azure Machine Learning service

– C) Azure Container Instances

– D) Azure Container Registry

Answer: B) Azure Machine Learning service

Which type of trigger can be used to start a scheduled Azure Machine Learning job?

– A) Time trigger

– B) Webhook trigger

– C) Manual trigger

– D) Batch execution trigger

Answer: A) Time trigger

True or False: Azure Machine Learning pipelines can be triggered by data drift.

Answer: True

When triggering an Azure Machine Learning job, which aspect cannot be changed without creating a new job?

– A) Compute target

– B) Input dataset

– C) Model architecture

– D) Output destination

Answer: C) Model architecture

True or False: Azure Logic Apps provide predefined triggers and actions for integration with Azure Machine Learning service.

Answer: True

When triggering an Azure Machine Learning job, which language(s) can be used for scripting?

– A) Python

– B) R

– C) Java

– D) All of the above

Answer: D) All of the above

0 0 votes
Article Rating
Subscribe
Notify of
guest
21 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Murat Doğan
1 year ago

Great post on triggering Azure ML jobs! I’ve been struggling with this for a while. Thank you!

Svyatopolk Iezerskiy

How do you handle secrets and authentication when triggering from GitHub Actions?

Tim Baker
1 year ago

This is invaluable information for my DP-100 prep. Much appreciated!

Yin Van Doeselaar
8 months ago

Excellent guide on Azure DevOps integration. Quick question: How do you pass parameters to the ML job?

Paulina Saiz
1 year ago

Simple and to the point. Kudos!

Kahaan Rajesh
9 months ago

I’m curious about the cost management aspect when triggering jobs from CI/CD platforms. Anyone has insights?

Teodoro Zamora
1 year ago

This guide helped me troubleshoot my pipeline issue. Thanks a ton!

Alix Durand
11 months ago

How does this integrate with multi-stage YAML pipelines in Azure DevOps?

21
0
Would love your thoughts, please comment.x
()
x