Building Training Pipelines
This lesson shows how training pipelines are defined in YAML and Python, explains how step outputs connect steps and how reuse works, and describes how pipelines are scheduled and triggered.
Learning outcomes
After completing this lesson, you will be able to:
- Connect pipeline steps with output bindings.
- Define a pipeline with the @pipeline decorator.
- Explain step reuse and the settings that prevent it.
- Describe schedules and other pipeline triggers.
Why pipelines
A training process has several stages: validate and prepare data, engineer features, train, evaluate, and register. Run by hand, the stages are easy to forget or run out of order, and nothing records how they connected. A pipeline job defines the stages as steps in a graph, passes each step's outputs to the next step's inputs, runs independent steps in parallel, and records the whole run as one job with child jobs for each step.
- Repeatability: the same graph runs the same way every time.
- Modularity: each step is a component that can be developed and versioned on its own.
- Efficiency: unchanged steps are reused, and each step can use the compute that suits it.
- Automation: pipelines run on schedules, from workflows, or in response to events.
Defining a pipeline in YAML
A pipeline YAML file declares pipeline-level inputs and outputs, settings, and a jobs section with one entry per step. Bindings connect them: ${{parent.inputs.name}} refers to a pipeline input, and ${{parent.jobs.step.outputs.name}} refers to an earlier step's output, which also defines the order of execution.
$schema: https://azuremlschemas.azureedge.net/latest/pipelineJob.schema.json
type: pipeline
experiment_name: churn-training
settings:
default_compute: azureml:cpu-cluster
continue_on_step_failure: false
inputs:
raw_data:
type: uri_folder
path: azureml:churn-raw@latest
jobs:
prep:
type: command
component: azureml:prep_churn_data:2
inputs:
raw: ${{parent.inputs.raw_data}}
train:
type: command
component: azureml://registries/contoso-ml/components/train_churn_model/versions/3
inputs:
training_data: ${{parent.jobs.prep.outputs.clean}}
learning_rate: 0.05
evaluate:
type: command
component: azureml:evaluate_model:1
inputs:
model: ${{parent.jobs.train.outputs.model}}
test_data: ${{parent.jobs.prep.outputs.test}}az ml job create --file pipelines/train.yml --resource-group rg-ml-dev --workspace-name mlw-churn-devDefining a pipeline in Python
The Python SDK builds the same graph with the @pipeline decorator. Loaded components are called like functions, and their outputs are passed as arguments to later components.
from azure.ai.ml import load_component, Input
from azure.ai.ml.dsl import pipeline
prep = load_component(source="components/prep.yml")
train = load_component(source="components/train.yml")
@pipeline(default_compute="cpu-cluster")
def churn_training(raw_data):
prep_step = prep(raw=raw_data)
train_step = train(training_data=prep_step.outputs.clean, learning_rate=0.05)
train_step.compute = "gpu-cluster" # override compute for one step
return {"model": train_step.outputs.model}
pipeline_job = churn_training(raw_data=Input(type="uri_folder", path="azureml:churn-raw@latest"))
ml_client.jobs.create_or_update(pipeline_job, experiment_name="churn-training")Setting default_compute to serverless runs every step on serverless compute, and individual steps can still request specific sizes.
Reuse and step settings
When a step's component, code, environment and inputs are unchanged from an earlier run, Azure Machine Learning can reuse that step's outputs instead of running it again. This makes iterating on a later step, such as evaluation, fast and cheap. Components that are not deterministic, such as a step that reads live data from an external API, should set is_deterministic: false so they always run, and a whole pipeline can force every step to run with settings.force_rerun: true.
Other settings control behaviour across steps: continue_on_step_failure lets independent branches finish when one step fails, default_datastore sets where outputs are written, and outputs can be given explicit paths and modes. A pipeline can also be registered as a pipeline component and nested in larger pipelines or deployed to a batch endpoint.
Scheduling and triggering
A schedule runs a pipeline job automatically. It has a trigger, either a cron expression or a recurrence such as every week on Monday at 02:00, a time zone, and the job to create.
$schema: https://azuremlschemas.azureedge.net/latest/schedule.schema.json
name: weekly-churn-retraining
trigger:
type: cron
expression: "0 2 * * 1"
time_zone: "W. Europe Standard Time"
create_job: ./train.ymlaz ml schedule create --file schedules/weekly.yml -g rg-ml-dev -w mlw-churn-devPipelines can also be started by a GitHub Actions workflow, for example after a merge, or by an event such as a monitoring alert or new data, through Azure Event Grid and a function or logic app that submits the job. Schedules can be disabled and enabled without being deleted, which is useful during maintenance.
Faster iteration on a long pipeline
A pipeline has three steps: a two-hour feature engineering step, a 30-minute training step and a five-minute evaluation step. A data scientist is changing only the evaluation code and reruns the pipeline many times a day, and every run takes almost three hours. The feature step reads a pinned data asset version.
Step reuse should skip the unchanged feature engineering and training steps, so the reruns should take minutes. If every step reruns, check whether reuse is being prevented: force_rerun set in the pipeline settings, components marked is_deterministic: false, or inputs that change each run, such as @latest data or a timestamp parameter. Removing the cause lets only the changed evaluation step run.
A larger cluster would shorten each run but still repeat unneeded work. Moving the evaluation into a notebook loses the pipeline's tracking and repeatability. Splitting the pipeline into separate jobs would work but loses the connected lineage that reuse provides automatically.
A team reruns a pipeline after changing only the training step. Why do the data preparation steps finish instantly?
Show answer
Steps whose component, inputs and settings are unchanged are reused from earlier runs. Setting force_rerun on the pipeline or is_deterministic: false on a component prevents reuse.
Exam Tips
Remember for the exam
- Bindings such as ${{parent.jobs.prep.outputs.clean}} connect steps and set their order.
- Define pipelines in YAML or with the @pipeline decorator; default_compute applies to all steps.
- Unchanged steps are reused unless force_rerun or is_deterministic: false prevents it.
- Schedules use cron or recurrence triggers; workflows and events can also start pipelines.