|
24 | 24 | POSSIBILITY OF SUCH DAMAGE. |
25 | 25 | """ |
26 | 26 | import os |
27 | | -import json |
28 | | -from azureml.core.model import Model |
29 | | -from azureml.core import Run |
| 27 | +from azureml.core import Model, Run |
30 | 28 | import argparse |
31 | 29 |
|
32 | 30 |
|
33 | 31 | # Get workspace |
34 | | -# ws = Workspace.from_config() |
35 | 32 | run = Run.get_context() |
36 | 33 | exp = run.experiment |
37 | 34 | ws = run.experiment.workspace |
38 | 35 |
|
39 | 36 |
|
40 | 37 | parser = argparse.ArgumentParser("evaluate") |
41 | 38 | parser.add_argument( |
42 | | - "--config_suffix", type=str, help="Datetime suffix for json config files" |
| 39 | + "--release_id", |
| 40 | + type=str, |
| 41 | + help="The ID of the release triggering this pipeline run", |
43 | 42 | ) |
44 | 43 | parser.add_argument( |
45 | | - "--json_config", |
| 44 | + "--model_name", |
46 | 45 | type=str, |
47 | | - help="Directory to write all the intermediate json configs", |
| 46 | + help="Name of the Model", |
| 47 | + default="sklearn_regression_model.pkl", |
48 | 48 | ) |
49 | 49 | args = parser.parse_args() |
50 | 50 |
|
51 | | -print("Argument 1: %s" % args.config_suffix) |
52 | | -print("Argument 2: %s" % args.json_config) |
| 51 | +print("Argument 1: %s" % args.release_id) |
| 52 | +print("Argument 2: %s" % args.model_name) |
| 53 | +model_name = args.model_name |
| 54 | +release_id = args.release_id |
53 | 55 |
|
54 | | -if not (args.json_config is None): |
55 | | - os.makedirs(args.json_config, exist_ok=True) |
56 | | - print("%s created" % args.json_config) |
57 | 56 | # Paramaterize the matrics on which the models should be compared |
58 | 57 | # Add golden data set on which all the model performance can be evaluated |
59 | 58 |
|
60 | | -# Get the latest run_id |
61 | | -# with open("aml_config/run_id.json") as f: |
62 | | -# config = json.load(f) |
63 | | - |
64 | | -train_run_id_json = "run_id_{}.json".format(args.config_suffix) |
65 | | -train_output_path = os.path.join(args.json_config, train_run_id_json) |
66 | | -with open(train_output_path) as f: |
67 | | - config = json.load(f) |
68 | | - |
69 | | - |
70 | | -new_model_run_id = config["run_id"] # args.train_run_id |
71 | | -experiment_name = config["experiment_name"] |
72 | | -# exp = Experiment(workspace=ws, name=experiment_name) |
73 | | - |
| 59 | +all_runs = exp.get_runs( |
| 60 | + properties={"release_id": release_id, "run_type": "train"}, |
| 61 | + include_children=True |
| 62 | + ) |
| 63 | +new_model_run = next(all_runs) |
| 64 | +new_model_run_id = new_model_run.id |
| 65 | +print(f'New Run found with Run ID of: {new_model_run_id}') |
74 | 66 |
|
75 | 67 | try: |
76 | 68 | # Get most recently registered model, we assume that |
|
110 | 102 | print("This is the first model to be trained, \ |
111 | 103 | thus nothing to evaluate for now") |
112 | 104 |
|
113 | | -run_id = {} |
114 | | -run_id["run_id"] = "" |
| 105 | + |
115 | 106 | # Writing the run id to /aml_config/run_id.json |
116 | 107 | if promote_new_model: |
117 | | - run_id["run_id"] = new_model_run_id |
118 | | - # register new model |
119 | | - # new_model_run.register_model(model_name='',model_path='outputs/sklearn_regression_model.pkl') |
120 | | - |
121 | | -run_id["experiment_name"] = experiment_name |
122 | | -filename = "run_id_{}.json".format(args.config_suffix) |
123 | | -output_path = os.path.join(args.json_config, filename) |
124 | | -with open(output_path, "w") as outfile: |
125 | | - json.dump(run_id, outfile) |
| 108 | + model_path = os.path.join('outputs', model_name) |
| 109 | + new_model_run.register_model( |
| 110 | + model_name=model_name, |
| 111 | + model_path=model_path, |
| 112 | + properties={"release_id": release_id}) |
| 113 | + print("Registered new model!") |
0 commit comments