Skip to content

Commit 22d2526

Browse files
authored
bootstrap diabetes cleanup (#189)
1 parent 977593a commit 22d2526

File tree

4 files changed

+45
-39
lines changed

4 files changed

+45
-39
lines changed

bootstrap/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
To use this existing project structure and scripts for your new ML project, you can quickly get started from the existing repository, bootstrap and create a template that works for your ML project. Bootstraping will prepare a similar directory structure for your project which includes renaming files and folders, deleting and cleaning up some directories and fixing imports and absolute path based on your project name. This will enable reusing various resources like pre-built pipelines and scripts for your new project.
44

5-
To bootstrap from the existing MLOpsPython repository clone this repository and run bootstrap.py script as below
5+
To bootstrap from the existing MLOpsPython repository clone this repository, ensure Python is installed locally, and run bootstrap.py script as below
66

7-
>python bootstrap.py --d [dirpath] --n [projectname]
7+
`python bootstrap.py --d [dirpath] --n [projectname]`
88

9-
Where [dirpath] is the absolute path to the root of your directory where MLOps repo is cloned and [projectname] is the name of your ML project
9+
Where `[dirpath]` is the absolute path to the root of your directory where MLOps repo is cloned and `[projectname]` is the name of your ML project.
10+
11+
[This article](https://docs.microsoft.com/azure/machine-learning/tutorial-convert-ml-experiment-to-production#use-your-own-model-with-mlopspython-code-template) will also assist to use this code template for your own ML project.

bootstrap/bootstrap.py

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,6 @@ def deletedir(self):
5757
os.system(
5858
'rmdir /S /Q "{}"'.format(os.path.join(self._project_directory, dir))) # NOQA: E501
5959

60-
def replaceprojectname(self):
61-
# Replace instances of diabetes_regression within files
62-
dirs = [r".env.example",
63-
r".pipelines\azdo-base-pipeline.yml",
64-
r".pipelines\azdo-pr-build-train.yml",
65-
r".pipelines\diabetes_regression-ci-build-train.yml",
66-
r".pipelines\diabetes_regression-ci-image.yml",
67-
r".pipelines\diabetes_regression-template-get-model-version.yml", # NOQA: E501
68-
r".pipelines\diabetes_regression-variables.yml",
69-
r"environment_setup\Dockerfile",
70-
r"environment_setup\install_requirements.sh",
71-
r"ml_service\pipelines\diabetes_regression_build_train_pipeline_with_r_on_dbricks.py", # NOQA: E501
72-
r"ml_service\pipelines\diabetes_regression_build_train_pipeline_with_r.py", # NOQA: E501
73-
r"ml_service\pipelines\diabetes_regression_build_train_pipeline.py", # NOQA: E501
74-
r"ml_service\pipelines\diabetes_regression_verify_train_pipeline.py", # NOQA: E501
75-
r"ml_service\util\create_scoring_image.py",
76-
r"diabetes_regression\azureml_environment.json",
77-
r"diabetes_regression\conda_dependencies.yml",
78-
r"diabetes_regression\evaluate\evaluate_model.py",
79-
r"diabetes_regression\training\test_train.py"] # NOQA: E501
80-
81-
for file in dirs:
82-
fin = open(os.path.join(self._project_directory, file),
83-
"rt", encoding="utf8")
84-
data = fin.read()
85-
data = data.replace("diabetes_regression", self.project_name)
86-
fin.close()
87-
fin = open(os.path.join(self._project_directory, file),
88-
"wt", encoding="utf8")
89-
fin.write(data)
90-
fin.close()
91-
9260
def cleandir(self):
9361
# Clean up directories
9462
dirs = ["data", "experimentation"]
@@ -108,6 +76,40 @@ def validateargs(self):
10876
raise Exception("Project name should be 3 to 15 chars long")
10977

11078

79+
def replaceprojectname(project_dir, project_name, rename_name):
80+
# Replace instances of rename_name within files with project_name
81+
dirs = [r".env.example",
82+
r".pipelines\azdo-base-pipeline.yml",
83+
r".pipelines\azdo-pr-build-train.yml",
84+
r".pipelines\diabetes_regression-ci-build-train.yml",
85+
r".pipelines\diabetes_regression-ci-image.yml",
86+
r".pipelines\diabetes_regression-template-get-model-version.yml", # NOQA: E501
87+
r".pipelines\diabetes_regression-variables.yml",
88+
r"environment_setup\Dockerfile",
89+
r"environment_setup\install_requirements.sh",
90+
r"ml_service\pipelines\diabetes_regression_build_train_pipeline_with_r_on_dbricks.py", # NOQA: E501
91+
r"ml_service\pipelines\diabetes_regression_build_train_pipeline_with_r.py", # NOQA: E501
92+
r"ml_service\pipelines\diabetes_regression_build_train_pipeline.py", # NOQA: E501
93+
r"ml_service\pipelines\diabetes_regression_verify_train_pipeline.py", # NOQA: E501
94+
r"ml_service\util\create_scoring_image.py",
95+
r"diabetes_regression\azureml_environment.json",
96+
r"diabetes_regression\conda_dependencies.yml",
97+
r"diabetes_regression\evaluate\evaluate_model.py",
98+
r"diabetes_regression\register\register_model.py",
99+
r"diabetes_regression\training\test_train.py"] # NOQA: E501
100+
101+
for file in dirs:
102+
fin = open(os.path.join(project_dir, file),
103+
"rt", encoding="utf8")
104+
data = fin.read()
105+
data = data.replace(rename_name, project_name)
106+
fin.close()
107+
fin = open(os.path.join(project_dir, file),
108+
"wt", encoding="utf8")
109+
fin.write(data)
110+
fin.close()
111+
112+
111113
def main(args):
112114
parser = argparse.ArgumentParser(description='New Template')
113115
parser.add_argument("--d", type=str,
@@ -122,7 +124,9 @@ def main(args):
122124
helper.validateargs()
123125
# helper.clonerepo()
124126
helper.cleandir()
125-
helper.replaceprojectname()
127+
replaceprojectname(project_directory, project_name,
128+
"diabetes_regression")
129+
replaceprojectname(project_directory, project_name, "diabetes")
126130
helper.deletedir()
127131
helper.renamefiles()
128132
helper.renamedir()

diabetes_regression/register/register_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ def register_aml_model(
119119
if (build_id != 'none'):
120120
model_already_registered(model_name, exp, run_id)
121121
run = Run(experiment=exp, run_id=run_id)
122-
tagsValue = {"area": "diabetes", "type": "regression",
122+
tagsValue = {"area": "diabetes_regression",
123123
"BuildId": build_id, "run_id": run_id,
124124
"experiment_name": exp.name}
125125
if (build_uri is not None):
126126
tagsValue["BuildUri"] = build_uri
127127
else:
128128
run = Run(experiment=exp, run_id=run_id)
129129
if (run is not None):
130-
tagsValue = {"area": "diabetes", "type": "regression",
130+
tagsValue = {"area": "diabetes_regression",
131131
"run_id": run_id, "experiment_name": exp.name}
132132
else:
133133
print("A model run for experiment", exp.name,

ml_service/util/create_scoring_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
runtime="python",
4040
conda_file="conda_dependencies.yml",
4141
description="Image with ridge regression model",
42-
tags={"area": "diabetes", "type": "regression"},
42+
tags={"area": "diabetes_regression"},
4343
)
4444

4545
image = Image.create(

0 commit comments

Comments
 (0)