Skip to content

Commit 966e35c

Browse files
committed
feature: Updated AML Pipeline code and added AML Pipeline trigger step
1 parent 5fa71a9 commit 966e35c

File tree

4 files changed

+75
-26
lines changed

4 files changed

+75
-26
lines changed

aml_service/04-AmlPipelines.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@
4747
parser.add_argument(
4848
"--pipeline_action",
4949
type=str,
50-
choices=["unpublish-test", "publish"],
50+
choices=["pipeline-test", "publish"],
5151
help="Determines if pipeline needs to run on small data set \
5252
or pipeline needs to be republished",
53+
default="pipeline-test",
5354
)
5455

5556
args = parser.parse_args()
@@ -140,9 +141,9 @@
140141
# Create Steps dependency such that they run in sequence
141142
evaluate.run_after(train)
142143
register_model.run_after(evaluate)
143-
create_scoring_image.run_after(register_model)
144+
package_model.run_after(register_model)
144145

145-
steps = [create_scoring_image]
146+
steps = [package_model]
146147

147148

148149
# Build Pipeline
@@ -154,7 +155,7 @@
154155
print("Pipeline validation complete")
155156

156157
# Submit unpublished pipeline with small data set for test
157-
if args.pipeline_action == "unpublish-test":
158+
if args.pipeline_action == "pipeline-test":
158159
pipeline_run1 = Experiment(ws, experiment_name).submit(
159160
pipeline1, regenerate_outputs=True
160161
)
@@ -164,7 +165,6 @@
164165

165166
# RunDetails(pipeline_run1).show()
166167

167-
## Publish Pipeline
168168

169169
# Define pipeline parameters
170170
# run_env = PipelineParameter(
@@ -177,22 +177,19 @@
177177

178178

179179
# Publish Pipeline
180-
181-
published_pipeline1 = pipeline1.publish(
182-
name=aml_pipeline_name, description="Model training/retraining pipeline"
183-
)
184-
185-
186-
# # Run a piblished pipeline
187-
# cli_auth = AzureCliAuthentication()
188-
# aad_token = cli_auth.get_authentication_header()
189-
# rest_endpoint1 = published_pipeline1.endpoint
190-
# print(rest_endpoint1)
191-
192-
# response = requests.post(published_pipeline1.endpoint,
193-
# headers=aad_token,
194-
# json={"ExperimentName": "devops-ai",
195-
# "ParameterAssignments": {"dev_flag": True}})
196-
197-
# run_id = response.json()["Id"]
198-
# print(run_id)
180+
if args.pipeline_action == "publish":
181+
published_pipeline1 = pipeline1.publish(
182+
name=aml_pipeline_name, description="Model training/retraining pipeline"
183+
)
184+
print(
185+
"Pipeline is published as rest_endpoint {} ".format(
186+
published_pipeline1.endpoint
187+
)
188+
)
189+
# write published pipeline details as build artifact
190+
pipeline_config = {}
191+
pipeline_config["pipeline_name"] = published_pipeline1.name
192+
pipeline_config["rest_endpoint"] = published_pipeline1.endpoint
193+
pipeline_config["experiment_name"] = "published-pipeline-exp" # experiment_name
194+
with open("aml_config/pipeline_config.json", "w") as outfile:
195+
json.dump(pipeline_config, outfile)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Copyright (C) Microsoft Corporation. All rights reserved.​
3+
4+
Microsoft Corporation (“Microsoft”) grants you a nonexclusive, perpetual,
5+
royalty-free right to use, copy, and modify the software code provided by us
6+
("Software Code"). You may not sublicense the Software Code or any use of it
7+
(except to your affiliates and to vendors to perform work on your behalf)
8+
through distribution, network access, service agreement, lease, rental, or
9+
otherwise. This license does not purport to express any claim of ownership over
10+
data you may have shared with Microsoft in the creation of the Software Code.
11+
Unless applicable law gives you more rights, Microsoft reserves all other
12+
rights not expressly granted herein, whether by implication, estoppel or
13+
otherwise. ​
14+
15+
THE SOFTWARE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
16+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18+
MICROSOFT OR ITS LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22+
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23+
ARISING IN ANY WAY OUT OF THE USE OF THE SOFTWARE CODE, EVEN IF ADVISED OF THE
24+
POSSIBILITY OF SUCH DAMAGE.
25+
"""
26+
27+
import os, json, requests, datetime
28+
import argparse
29+
from azureml.core.authentication import AzureCliAuthentication
30+
31+
try:
32+
with open("aml_config/pipeline_config.json") as f:
33+
config = json.load(f)
34+
except:
35+
print("No pipeline config found")
36+
sys.exit(0)
37+
38+
# Run a published pipeline
39+
cli_auth = AzureCliAuthentication()
40+
aad_token = cli_auth.get_authentication_header()
41+
rest_endpoint1 = config["rest_endpoint"]
42+
experiment_name = config["experiment_name"]
43+
print(rest_endpoint1)
44+
45+
response = requests.post(
46+
rest_endpoint1, headers=aad_token, json={"ExperimentName": experiment_name}
47+
)
48+
49+
run_id = response.json()["Id"]
50+
print(run_id)
51+
print("Pipeline run initiated")

aml_service/30-CreateScoringImage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from azureml.core.image import ContainerImage, Image
2929
from azureml.core.model import Model
3030
from azureml.core.authentication import AzureCliAuthentication
31+
3132
cli_auth = AzureCliAuthentication()
3233

3334
# Get workspace

code/scoring/create_scoring_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
)
7979
)
8080

81-
os.chdir("./code/scoring")
81+
os.chdir("scoring")
8282
image_name = "diabetes-model-score"
8383

8484
image_config = ContainerImage.image_configuration(
@@ -94,7 +94,7 @@
9494
)
9595

9696
image.wait_for_creation(show_output=True)
97-
os.chdir("../..")
97+
os.chdir("..")
9898

9999
if image.creation_state != "Succeeded":
100100
raise Exception("Image creation status: {image.creation_state}")

0 commit comments

Comments
 (0)