Skip to content

Commit 15c294c

Browse files
committed
model name as aml pipeline parameter
1 parent f56ae22 commit 15c294c

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

aml_config/security_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"remote_vm_ip" : "<>",
99
"experiment_name" : "devops-ai-demo",
1010
"aml_cluster_name" : "aml-compute",
11+
"model_name" : "sklearn_regression_model2.pkl",
1112
"vnet_resourcegroup_name" : "<>",
1213
"vnet_name" : "<>",
1314
"subnet_name" : "<>"

aml_service/04-AmlPipelines.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
experiment_name = config["experiment_name"]
6868
aml_cluster_name = config["aml_cluster_name"]
6969
aml_pipeline_name = "training-pipeline"
70+
#model_name = config["model_name"]
71+
model_name = PipelineParameter(name="model_name", default_value="sklearn_regression_model.pkl")
7072

7173
source_directory = "code"
7274

@@ -76,8 +78,9 @@
7678
cd = CondaDependencies("aml_config/conda_dependencies.yml")
7779

7880
run_config = RunConfiguration(conda_dependencies=cd)
79-
8081
aml_compute = ws.compute_targets[aml_cluster_name]
82+
run_config.environment.docker.enabled = True
83+
run_config.environment.spark.precache_packages = False
8184

8285
jsonconfigs = PipelineData("jsonconfigs", datastore=def_blob_store)
8386

@@ -91,7 +94,11 @@
9194
script_name="training/train.py",
9295
compute_target=aml_compute,
9396
source_directory=source_directory,
94-
arguments=["--config_suffix", config_suffix, "--json_config", jsonconfigs],
97+
arguments=[
98+
"--config_suffix", config_suffix,
99+
"--json_config", jsonconfigs,
100+
"--model_name", model_name,
101+
],
95102
runconfig=run_config,
96103
# inputs=[jsonconfigs],
97104
outputs=[jsonconfigs],
@@ -104,7 +111,10 @@
104111
script_name="evaluate/evaluate_model.py",
105112
compute_target=aml_compute,
106113
source_directory=source_directory,
107-
arguments=["--config_suffix", config_suffix, "--json_config", jsonconfigs],
114+
arguments=[
115+
"--config_suffix", config_suffix,
116+
"--json_config", jsonconfigs,
117+
],
108118
runconfig=run_config,
109119
inputs=[jsonconfigs],
110120
# outputs=[jsonconfigs],
@@ -117,7 +127,11 @@
117127
script_name="register/register_model.py",
118128
compute_target=aml_compute,
119129
source_directory=source_directory,
120-
arguments=["--config_suffix", config_suffix, "--json_config", jsonconfigs],
130+
arguments=[
131+
"--config_suffix", config_suffix,
132+
"--json_config", jsonconfigs,
133+
"--model_name", model_name,
134+
],
121135
runconfig=run_config,
122136
inputs=[jsonconfigs],
123137
# outputs=[jsonconfigs],

aml_service/05-TriggerAmlPipeline.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
try:
3232
with open("aml_config/pipeline_config.json") as f:
3333
config = json.load(f)
34+
with open("aml_config/security_config.json") as f:
35+
security_config = json.load(f)
3436
except:
3537
print("No pipeline config found")
3638
sys.exit(0)
@@ -40,10 +42,14 @@
4042
aad_token = cli_auth.get_authentication_header()
4143
rest_endpoint1 = config["rest_endpoint"]
4244
experiment_name = config["experiment_name"]
45+
model_name = security_config["experiment_name"]
46+
4347
print(rest_endpoint1)
4448

4549
response = requests.post(
46-
rest_endpoint1, headers=aad_token, json={"ExperimentName": experiment_name}
50+
rest_endpoint1, headers=aad_token,
51+
json={"ExperimentName": experiment_name,
52+
"ParameterAssignments": {"model_name":model_name}}
4753
)
4854

4955
run_id = response.json()["Id"]

code/register/register_model.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
type=str,
5151
help="Directory to write all the intermediate json configs",
5252
)
53+
parser.add_argument(
54+
"--model_name",
55+
type=str,
56+
help="Name of the Model",
57+
default="sklearn_regression_model.pkl",
58+
)
59+
5360
args = parser.parse_args()
5461

5562
print("Argument 1: %s" % args.config_suffix)
@@ -61,6 +68,7 @@
6168

6269
evaluate_run_id_json = "run_id_{}.json".format(args.config_suffix)
6370
evaluate_output_path = os.path.join(args.json_config, evaluate_run_id_json)
71+
model_name = args.model_name
6472

6573
# Get the latest evaluation result
6674
try:
@@ -85,7 +93,7 @@
8593
os.makedirs(model_local_dir, exist_ok=True)
8694

8795
# Download Model to Project root directory
88-
model_name = "sklearn_regression_model.pkl"
96+
# model_name = "sklearn_regression_model.pkl"
8997
run.download_file(
9098
name="./outputs/" + model_name, output_file_path="./model/" + model_name
9199
)

code/training/train.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,20 @@
4848
type=str,
4949
help="Directory to write all the intermediate json configs",
5050
)
51+
parser.add_argument(
52+
"--model_name",
53+
type=str,
54+
help="Name of the Model",
55+
default="sklearn_regression_model.pkl",
56+
)
57+
5158
args = parser.parse_args()
5259

5360
print("Argument 1: %s" % args.config_suffix)
5461
print("Argument 2: %s" % args.json_config)
5562

63+
model_name = args.model_name
64+
5665
if not (args.json_config is None):
5766
os.makedirs(args.json_config, exist_ok=True)
5867
print("%s created" % args.json_config)
@@ -80,7 +89,7 @@
8089

8190

8291
# Save model as part of the run history
83-
model_name = "sklearn_regression_model.pkl"
92+
8493
# model_name = "."
8594

8695
with open(model_name, "wb") as file:

0 commit comments

Comments
 (0)