Launch price: every exam for $29.99 a year, for the first 300 buyers. See the price

CertStreak
Menu

A worked example

Put in order

You work in a notebook that uses the Azure Machine Learning Python SDK v2. An authenticated ml_client is connected to your workspace. Two components are already loaded as loaded_component_prep and loaded_component_train. Neither component definition specifies a compute target.

You must run one training pipeline now. It must meet these requirements:

  • The data preparation step reads the registered data asset azureml:data:1 (type uri_file) as the pipeline input.
  • The training step uses the output of the data preparation step as its training data.
  • Both steps run on the existing compute cluster aml-cluster.
  • The run is submitted under the experiment pipeline_job.
  • No recurring runs are created.

Which actions should you perform, in order?

Your order

You didn't answer this one.

Correct order
1Define a function decorated with @pipeline() that calls loaded_component_prep(input_data=pipeline_job_input), passes prep_data.outputs.output_data to loaded_component_train(training_data=...), and returns the pipeline outputs.
2Call the pipeline function with Input(type=AssetTypes.URI_FILE, path="azureml:data:1") and assign the result to pipeline_job.
3Set pipeline_job.settings.default_compute = "aml-cluster".
4Submit the job by running pipeline_job = ml_client.jobs.create_or_update(pipeline_job, experiment_name="pipeline_job").
Why

The @pipeline() function only defines the workflow. Calling it with the registered data asset as input produces the pipeline_job object. Pipeline-level settings such as default_compute are edited on that object after the call, and a component without its own compute target uses that default. The configured object is then submitted with ml_client.jobs.create_or_update under the required experiment name.

  • Step 1: Define a function decorated with @pipeline() that calls loaded_component_prep(input_data=pipeline_job_input), passes prep_data.outputs.output_data to loaded_component_train(training_data=...), and returns the pipeline outputs. Nothing can come first: the pipeline_job object that all later steps configure and submit is produced by calling this decorated function, so the function must exist before anything else.
  • Step 2: Call the pipeline function with Input(type=AssetTypes.URI_FILE, path="azureml:data:1") and assign the result to pipeline_job. Calling the function defined in step 1 with the registered data asset builds the pipeline_job object and supplies the required pipeline input.
  • Step 3: Set pipeline_job.settings.default_compute = "aml-cluster". The settings are edited on the pipeline_job object that step 2 creates. Because neither component specifies a compute target, both steps use this pipeline-level default.
  • Step 4: Submit the job by running pipeline_job = ml_client.jobs.create_or_update(pipeline_job, experiment_name="pipeline_job"). Submission sends the configured object to the workspace. If you submit before step 3, the job runs without the aml-cluster default, which breaks the compute requirement.
  • Not needed: Create a JobSchedule with a RecurrenceTrigger for pipeline_job and call ml_client.schedules.begin_create_or_update. A schedule makes the pipeline run repeatedly. The scenario requires a single run now and forbids recurring runs.
  • Not needed: Set pipeline_job.settings.default_datastore = "aml-cluster". default_datastore sets the datastore where outputs are stored, not the compute. aml-cluster is a compute cluster, so this does not make the steps run on it.

Practise this topic until it's automatic.

Ten questions a day, every answer explained, and misses that come back until you beat them.

Start free