Skip to content

Commit 56eb992

Browse files
authored
Pipeline variables comments and clean up (#211)
* adding comments for variables * update default model name
1 parent 73602bd commit 56eb992

File tree

7 files changed

+43
-44
lines changed

7 files changed

+43
-44
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ BUILD_BUILDID = '001'
1313
# Azure ML Workspace Variables
1414
WORKSPACE_NAME = 'aml-workspace'
1515
EXPERIMENT_NAME = ''
16-
SCRIPT_FOLDER = './'
1716

1817
# AML Compute Cluster Config
1918
AML_COMPUTE_CLUSTER_NAME = 'train-cluster'
@@ -32,6 +31,7 @@ EVALUATE_SCRIPT_PATH = 'evaluate/evaluate_model.py'
3231
REGISTER_SCRIPT_PATH = 'register/register_model.py'
3332
SOURCES_DIR_TRAIN = 'diabetes_regression'
3433
DATASET_NAME = 'diabetes_ds'
34+
SCORE_SCRIPT = 'scoring/score.py'
3535

3636
# Optional. Used by a training pipeline with R on Databricks
3737
DB_CLUSTER_ID = ''

.pipelines/azdo-abtest-pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ variables:
2828
- name: 'greenReleaseName'
2929
value: 'model-green'
3030
- name: 'SCORE_SCRIPT'
31-
value: 'scoreA.py'
31+
value: 'scoring/scoreA.py'
3232

3333
stages:
3434
- stage: 'Building'

.pipelines/diabetes_regression-ci-image.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ container: mlops
2727
variables:
2828
- group: devopsforai-aml-vg
2929
- name: 'SCORE_SCRIPT'
30-
value: 'scoreB.py'
30+
value: 'scoring/scoreB.py'
3131

3232
steps:
3333
- task: AzureCLI@1
Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
# Pipeline template that defines common runtime environment variables.
22
variables:
3-
# Azure ML Workspace Variables
3+
4+
# Source Config
5+
# The directory containing the scripts for training, evaluating, and registering the model
6+
- name: SOURCES_DIR_TRAIN
7+
value: diabetes_regression
8+
# The path to the model training script under SOURCES_DIR_TRAIN
9+
- name: TRAIN_SCRIPT_PATH
10+
value: training/train.py
11+
# The path to the model evaluation script under SOURCES_DIR_TRAIN
12+
- name: EVALUATE_SCRIPT_PATH
13+
value: evaluate/evaluate_model.py
14+
# The path to the model registration script under SOURCES_DIR_TRAIN
15+
- name: REGISTER_SCRIPT_PATH
16+
value: register/register_model.py
17+
# The path to the model scoring script relative to SOURCES_DIR_TRAIN
18+
- name: SCORE_SCRIPT
19+
value: scoring/score.py
20+
21+
# Azure ML Variables
422
- name: EXPERIMENT_NAME
523
value: mlopspython
24+
- name: DATASET_NAME
25+
value: diabetes_ds
26+
- name: TRAINING_PIPELINE_NAME
27+
value: "diabetes-Training-Pipeline"
28+
- name: MODEL_NAME
29+
value: diabetes_regression_model.pkl
630

731
# AML Compute Cluster Config
832
- name: AML_COMPUTE_CLUSTER_CPU_SKU
@@ -16,43 +40,23 @@ variables:
1640
- name: AML_CLUSTER_PRIORITY
1741
value: lowpriority
1842

19-
# Training Config
20-
- name: BUILD_TRAIN_SCRIPT
21-
value: diabetes_regression_build_train_pipeline.py
22-
- name: TRAIN_SCRIPT_PATH
23-
value: training/train.py
24-
- name: MODEL_NAME
25-
value: sklearn_regression_model.pkl
26-
- name: MODEL_VERSION
27-
value: "1"
28-
29-
# AML Pipeline Config
30-
- name: TRAINING_PIPELINE_NAME
31-
value: "diabetes-Training-Pipeline"
32-
- name: MODEL_PATH
33-
value: ""
34-
- name: EVALUATE_SCRIPT_PATH
35-
value: evaluate/evaluate_model.py
36-
- name: REGISTER_SCRIPT_PATH
37-
value: register/register_model.py
38-
- name: SOURCES_DIR_TRAIN
39-
value: diabetes_regression
43+
# The name for the (docker/webapp) scoring image
4044
- name: IMAGE_NAME
4145
value: "diabetestrained"
46+
4247
# Optional. Used by a training pipeline with R on Databricks
4348
- name: DB_CLUSTER_ID
4449
value: ""
45-
- name: SCORE_SCRIPT
46-
value: score.py
47-
- name: DATASET_NAME
48-
value: diabetes_ds
50+
4951
# These are the default values set in ml_service\util\env_variables.py. Uncomment and override if desired.
52+
# Set to false to disable the evaluation step in the ML pipeline and register the newly trained model unconditionally.
5053
# - name: RUN_EVALUATION
5154
# value: "true"
55+
# Set to false to register the model regardless of the outcome of the evaluation step in the ML pipeline.
5256
# - name: ALLOW_RUN_CANCEL
5357
# value: "true"
5458

55-
# For debugging deployment issues. Specify a build id with the MODEL_BUILD_ID pipeline variable at queue time
56-
# to skip training and deploy a model registered by a previous build.
59+
# For debugging deployment issues. Specify a build id with the MODEL_BUILD_ID pipeline variable at queue time
60+
# to skip training and deploy a model registered by a previous build.
5761
- name: modelbuildid
5862
value: $[coalesce(variables['MODEL_BUILD_ID'], variables['Build.BuildId'])]

docs/canary_ab_deployment.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ If your target deployment environment is a K8s cluster and you want to implement
66

77
**Note:** It is assumed that you have an AKS instance and configured ***kubectl*** to communicate with the cluster.
88

9-
#### 1. Install Istio on a K8s cluster.
9+
#### 1. Install Istio on a K8s cluster.
1010

1111
This guidance uses [Istio](https://istio.io) service mesh implememtation to control traffic routing between model versions. The instruction on installing Istio is available [here](https://docs.microsoft.com/en-us/azure/aks/servicemesh-istio-install?pivots=client-operating-system-linux).
1212

@@ -28,7 +28,6 @@ There are some extra variables that you need to setup in ***devopsforai-aml-vg**
2828
| K8S_AB_NAMESPACE | Namespace in a K8s cluster to deploy the model |
2929
| IMAGE_REPO_NAME | Image reposiory name (e.g. mlopspyciamlcr.azurecr.io)|
3030

31-
3231
#### 3. Configure a pipeline to build and deploy a scoring Image
3332

3433
Import and run the [azdo-abtest-pipeline.yml](./.pipelines/azdo-abtest-pipeline.yml) multistage deployment pipeline.
@@ -37,17 +36,17 @@ The result of the pipeline will be a registered Docker image in the ACR reposito
3736

3837
![scoring image](./images/scoring_image.png)
3938

40-
The pipeline creates Istio Gateway and VirtualService and deploys the scoring image to the Kubernetes cluster.
39+
The pipeline creates Istio Gateway and VirtualService and deploys the scoring image to the Kubernetes cluster.
4140

4241
```bash
4342
kubectl get deployments --namespace abtesting
4443
NAME READY UP-TO-DATE AVAILABLE AGE
4544
model-green 1/1 1 1 19h
4645
```
4746

48-
#### 4. Build a new Scoring Image.
47+
#### 4. Build a new Scoring Image
4948

50-
Change value of the ***SCORE_SCRIPT*** variable in the [azdo-abtest-pipeline.yml](./.pipelines/azdo-abtest-pipeline.yml) to point to ***scoreA.py*** and merge it to the master branch.
49+
Change value of the ***SCORE_SCRIPT*** variable in the [azdo-abtest-pipeline.yml](./.pipelines/azdo-abtest-pipeline.yml) to point to ***scoring/scoreA.py*** and merge it to the master branch.
5150

5251
**Note:** ***scoreA.py*** and ***scoreB.py*** files used in this tutorial are just mockups returning either "New Model A" or "New Model B" respectively. They are used to demonstrate the concept of testing two scoring images with different models or scoring code. In real life you would implement a scoring file similar to [score.py](./../code/scoring/score.py) (see [getting started](./getting_started.md)).
5352

@@ -61,7 +60,6 @@ It will automatically trigger the pipeline and deploy a new scoring image with t
6160
| Blue_Green |0 |100 |Old green image is removed. The new blue image is copied as green.<br>Blue and Green images are equal.<br>All traffic (100%) is routed to the blue image.|
6261
| Green_100 |100 |0 |All traffic (100%) is routed to the green image.<br>The blue image is removed
6362

64-
6563
**Note:** The pipeline performs the rollout without any pausing. You may want to configure [Approvals and Checks](https://docs.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass) for the stages on your environment for better experience of the model testing. The environment ***abtestenv*** will be added automatically to your AzDo project after the first pipeline run.
6664

6765
At each stage you can verify how the traffic is routed sending requests to $GATEWAY_IP/score with ***Postman*** or with ***curl***:

ml_service/util/create_scoring_image.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828
sources_dir = e.sources_directory_train
2929
if (sources_dir is None):
3030
sources_dir = 'diabetes_regression'
31-
path_to_scoring = os.path.join(".", sources_dir, "scoring")
31+
score_script = os.path.join(".", sources_dir, e.score_script)
32+
score_file = os.path.basename(score_script)
33+
path_to_scoring = os.path.dirname(score_script)
3234
cwd = os.getcwd()
3335
# Copy conda_dependencies.yml into scoring as this method does not accept relative paths. # NOQA: E501
3436
shutil.copy(os.path.join(".", sources_dir,
3537
"conda_dependencies.yml"), path_to_scoring)
3638
os.chdir(path_to_scoring)
3739
image_config = ContainerImage.image_configuration(
38-
execution_script=e.score_script,
40+
execution_script=score_file,
3941
runtime="python",
4042
conda_file="conda_dependencies.yml",
4143
description="Image with ridge regression model",

ml_service/util/env_variables.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def __init__(self):
3636
self._experiment_name = os.environ.get("EXPERIMENT_NAME")
3737
self._model_version = os.environ.get('MODEL_VERSION')
3838
self._image_name = os.environ.get('IMAGE_NAME')
39-
self._model_path = os.environ.get('MODEL_PATH')
4039
self._db_cluster_id = os.environ.get("DB_CLUSTER_ID")
4140
self._score_script = os.environ.get("SCORE_SCRIPT")
4241
self._collection_uri = os.environ.get("SYSTEM_COLLECTIONURI")
@@ -134,10 +133,6 @@ def model_version(self):
134133
def image_name(self):
135134
return self._image_name
136135

137-
@property
138-
def model_path(self):
139-
return self._model_path
140-
141136
@property
142137
def score_script(self):
143138
return self._score_script

0 commit comments

Comments
 (0)