Skip to content

Commit 44abcac

Browse files
author
j-so
committed
fix batch scoring
1 parent c9fc6ed commit 44abcac

File tree

4 files changed

+29
-41
lines changed

4 files changed

+29
-41
lines changed

.pipelines/diabetes_regression-batchscoring-ci.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ stages:
4949
timeoutInMinutes: 0
5050
steps:
5151
- template: code-quality-template.yml
52-
- template: diabetes_regression-get-model-id-artifact-template.yml
53-
parameters:
54-
projectId: '$(resources.pipeline.model-train-ci.projectID)'
55-
pipelineId: '$(resources.pipeline.model-train-ci.pipelineID)'
56-
artifactBuildId: ${{ parameters.artifactBuildId }}
5752
- task: AzureCLI@1
5853
name: publish_batchscore
5954
inputs:
@@ -66,19 +61,32 @@ stages:
6661
# Invoke the Python building and publishing a training pipeline
6762
python -m ml_service.pipelines.diabetes_regression_build_parallel_batchscore_pipeline
6863
64+
- job: "Get_Model_Artifact"
65+
displayName: "Get Model Artifact"
66+
container: mlops
67+
timeoutInMinutes: 0
68+
steps:
69+
- template: diabetes_regression-get-model-id-artifact-template.yml
70+
parameters:
71+
projectId: '$(resources.pipeline.model-train-ci.projectID)'
72+
pipelineId: '$(resources.pipeline.model-train-ci.pipelineID)'
73+
artifactBuildId: ${{ parameters.artifactBuildId }}
74+
6975
- job: "Run_Batch_Score_Pipeline"
7076
displayName: "Run Batch Scoring Pipeline"
71-
dependsOn: "Build_Batch_Scoring_Pipeline"
77+
dependsOn: ["Build_Batch_Scoring_Pipeline", "Get_Model_Artifact"]
7278
timeoutInMinutes: 240
7379
pool: server
7480
variables:
7581
pipeline_id: $[ dependencies.Build_Batch_Scoring_Pipeline.outputs['publish_batchscore.pipeline_id']]
82+
model_name: $[ dependencies.Get_Model_Artifact.outputs['MODEL_NAME']]
83+
model_version: $[ dependencies.Get_Model_Artifact.outputs['MODEL_VERSION']]
7684
steps:
7785
- task: ms-air-aiagility.vss-services-azureml.azureml-restApi-task.MLPublishedPipelineRestAPITask@0
7886
displayName: 'Invoke Batch Scoring pipeline'
7987
inputs:
8088
azureSubscription: '$(WORKSPACE_SVC_CONNECTION)'
8189
PipelineId: '$(pipeline_id)'
8290
ExperimentName: '$(EXPERIMENT_NAME)'
83-
PipelineParameters: '"ParameterAssignments": {"model_name": "$(MODEL_NAME)", "model_version": "$(MODEL_VERSION)"}'
91+
PipelineParameters: '"ParameterAssignments": {"model_name": "$(model_name)", "model_version": "$(model_version)"}'
8492

diabetes_regression/scoring/parallel_batchscore.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import sys
3131
from typing import List
3232
from util.model_helper import get_model
33+
from azureml.core import Model
3334

3435
model = None
3536

@@ -64,13 +65,12 @@ def parse_args() -> List[str]:
6465
for idx, itm in enumerate(sys.argv)
6566
if itm == "--model_version"
6667
]
67-
68-
if len(model_version_param) == 0:
69-
raise ValueError(
70-
"Model name is required but no model name parameter was passed to the script" # NOQA: E501
71-
)
72-
73-
model_version = model_version_param[0][1]
68+
model_version = (
69+
None
70+
if len(model_version_param) < 1
71+
or len(model_version_param[0][1].strip()) == 0 # NOQA: E501
72+
else model_version_param[0][1]
73+
)
7474

7575
model_tag_name_param = [
7676
(sys.argv[idx], sys.argv[idx + 1])
@@ -107,15 +107,17 @@ def init():
107107
try:
108108
print("Initializing batch scoring script...")
109109

110+
# Get the model using name/version/tags filter
110111
model_filter = parse_args()
111112
amlmodel = get_model(
112113
model_name=model_filter[0],
113114
model_version=model_filter[1],
114115
tag_name=model_filter[2],
115116
tag_value=model_filter[3])
116117

118+
# Load the model using name/version found
117119
global model
118-
modelpath = Model.get_model_path(model_name=model_filter[0])
120+
modelpath = Model.get_model_path(model_name=amlmodel.name, version=amlmodel.version)
119121
model = joblib.load(modelpath)
120122
print("Loaded model {}".format(model_filter[0]))
121123
except Exception as ex:

diabetes_regression/util/model_helper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ def get_model(
4646
print("No workspace defined - using current experiment workspace.")
4747
aml_workspace = get_current_workspace()
4848

49-
if tagname is not None and tagvalue is not None:
49+
if tag_name is not None and tag_value is not None:
5050
model = AMLModel(
5151
aml_workspace,
5252
name=model_name,
5353
version=model_version,
5454
tags=[[tag_name, tag_value]])
55-
elif (tagname is None and tagvalue is not None) or (
56-
tagvalue is None and tagname is not None
55+
elif (tag_name is None and tag_value is not None) or (
56+
tag_value is None and tag_name is not None
5757
):
5858
raise ValueError(
5959
"model_tag_name and model_tag_value should both be supplied"
6060
+ "or excluded" # NOQA: E501
6161
)
6262
else:
63-
model = AMLModel(aml_workspace, name=env.model_name, version=env.model_version) # NOQA: E501
63+
model = AMLModel(aml_workspace, name=model_name, version=model_version) # NOQA: E501
6464
return model

ml_service/pipelines/diabetes_regression_build_parallel_batchscore_pipeline.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
Workspace,
3434
Dataset,
3535
Datastore,
36-
Model,
3736
RunConfiguration,
3837
)
3938
from azureml.pipeline.core import Pipeline, PipelineData, PipelineParameter
@@ -44,24 +43,6 @@
4443
from typing import Tuple
4544

4645

47-
def parse_args() -> Namespace:
48-
"""
49-
Parse arguments supplied to the pipeline creation script.
50-
The only allowed arguments are model_tag_name and model_tag_value
51-
specifying a custom tag/value pair to help locate a specific model.
52-
53-
54-
:returns: Namespace with two attributes model_tag_name and model_tag_value
55-
and corresponding values
56-
57-
"""
58-
parser = ArgumentParser()
59-
parser.add_argument("--model_tag_name", default=None, type=str)
60-
parser.add_argument("--model_tag_value", default=None, type=str)
61-
args = parser.parse_args()
62-
return args
63-
64-
6546
def get_or_create_datastore(
6647
datastorename: str, ws: Workspace, env: Env, input: bool = True
6748
) -> Datastore:
@@ -312,7 +293,6 @@ def get_scoring_pipeline(
312293
"""
313294
Creates the scoring pipeline.
314295
315-
:param model: The model to use for scoring
316296
:param scoring_dataset: Data to score
317297
:param output_loc: Location to save the scoring results
318298
:param score_run_config: Parallel Run configuration to support
@@ -399,8 +379,6 @@ def build_batchscore_pipeline():
399379
try:
400380
env = Env()
401381

402-
args = parse_args()
403-
404382
# Get Azure machine learning workspace
405383
aml_workspace = Workspace.get(
406384
name=env.workspace_name,

0 commit comments

Comments
 (0)