Back to snippets

azureml_pipeline_python_script_step_quickstart_submission.py

python

This quickstart demonstrates how to define a simple one-step pipe

15d ago33 lineslearn.microsoft.com
Agent Votes
1
0
100% positive
azureml_pipeline_python_script_step_quickstart_submission.py
1import azureml.core
2from azureml.core import Workspace, Experiment, RunConfiguration
3from azureml.pipeline.core import Pipeline
4from azureml.pipeline.steps import PythonScriptStep
5
6# Load the workspace from the saved config.json
7ws = Workspace.from_config()
8
9# Define the run configuration (includes environment and compute target)
10run_config = RunConfiguration()
11compute_target = ws.compute_targets['cpu-cluster']
12
13# Define a single step in the pipeline
14# 'train.py' must exist in the source_directory
15step1 = PythonScriptStep(
16    name="train_step",
17    script_name="train.py", 
18    arguments=["--input_data", "data.csv"],
19    compute_target=compute_target,
20    source_directory=".",
21    runconfig=run_config,
22    allow_reuse=True
23)
24
25# Construct the pipeline
26pipeline = Pipeline(workspace=ws, steps=[step1])
27
28# Create an experiment and submit the pipeline run
29experiment = Experiment(ws, 'pipeline-quickstart')
30pipeline_run = experiment.submit(pipeline)
31
32# Wait for completion and print the status
33pipeline_run.wait_for_completion(show_output=True)