@@ -28,7 +28,13 @@ class ModelManagement(Service):
28
28
# TODO: set ds2MultiType
29
29
@classmethod
30
30
def publish_model (
31
- cls , model , destination , name = None , force = False , reload_model_table = False
31
+ cls ,
32
+ model ,
33
+ destination ,
34
+ model_version = "latest" ,
35
+ name = None ,
36
+ force = False ,
37
+ reload_model_table = False ,
32
38
):
33
39
"""
34
40
@@ -38,6 +44,8 @@ def publish_model(
38
44
The name or id of the model, or a dictionary representation of the model.
39
45
destination : str
40
46
Name of destination to publish the model to.
47
+ model_version_id : str or dict, optional
48
+ Provide the id, name, or dictionary representation of the version to publish. Defaults to 'latest'.
41
49
name : str, optional
42
50
Provide a custom name for the published model. Defaults to None.
43
51
force : bool, optional
@@ -68,6 +76,18 @@ def publish_model(
68
76
69
77
# TODO: Verify allowed formats by destination type.
70
78
# As of 19w04 MAS throws HTTP 500 if name is in invalid format.
79
+ if model_version != "latest" :
80
+ if isinstance (model_version , dict ) and "modelVersionName" in model_version :
81
+ model_version_name = model_version ["modelVersionName" ]
82
+ elif isinstance (model_version , str ) and cls .is_uuid (model_version ):
83
+ model_version_name = mr .get_model_or_version (model , model_version )[
84
+ "modelVersionName"
85
+ ]
86
+ else :
87
+ model_version_name = model_version
88
+ else :
89
+ model_version_name = ""
90
+
71
91
model_name = name or "{}_{}" .format (
72
92
model_obj ["name" ].replace (" " , "" ), model_obj ["id" ]
73
93
).replace ("-" , "" )
@@ -79,6 +99,7 @@ def publish_model(
79
99
{
80
100
"modelName" : mp ._publish_name (model_name ),
81
101
"sourceUri" : model_uri .get ("uri" ),
102
+ "modelVersionID" : model_version_name ,
82
103
"publishLevel" : "model" ,
83
104
}
84
105
],
@@ -104,6 +125,7 @@ def create_performance_definition(
104
125
table_prefix ,
105
126
project = None ,
106
127
models = None ,
128
+ modelVersions = None ,
107
129
library_name = "Public" ,
108
130
name = None ,
109
131
description = None ,
@@ -136,6 +158,9 @@ def create_performance_definition(
136
158
The name or id of the model(s), or a dictionary representation of the model(s). For
137
159
multiple models, input a list of model names, or a list of dictionaries. If no models are specified, all
138
160
models in the project specified will be used. Defaults to None.
161
+ modelVersions: str, list, optional
162
+ The name of the model version(s) for models used in the performance definition. If no model versions
163
+ are specified, all models will use the latest version. Defaults to None.
139
164
library_name : str
140
165
The library containing the input data, default is 'Public'.
141
166
name : str, optional
@@ -239,10 +264,37 @@ def create_performance_definition(
239
264
"property set." % project .name
240
265
)
241
266
267
+ if not modelVersions :
268
+ updated_models = [model .id for model in models ]
269
+ else :
270
+ updated_models = []
271
+ if not isinstance (modelVersions , list ):
272
+ modelVersions = [modelVersions ]
273
+
274
+ if len (models ) < len (modelVersions ):
275
+ raise ValueError (
276
+ "There are too many versions for the amount of models specified."
277
+ )
278
+
279
+ modelVersions = modelVersions + ["" ] * (len (models ) - len (modelVersions ))
280
+ for model , modelVersionName in zip (models , modelVersions ):
281
+ print (model .name )
282
+ if (
283
+ isinstance (modelVersionName , dict )
284
+ and "modelVersionName" in modelVersionName
285
+ ):
286
+ modelVersionName = modelVersionName ["modelVersionName" ]
287
+ elif (
288
+ isinstance (modelVersionName , dict )
289
+ and "modelVersionName" not in modelVersionName
290
+ ):
291
+ raise ValueError ("Model version is not recognized." )
292
+ updated_models .append (model .id + ":" + modelVersionName )
293
+
242
294
request = {
243
295
"projectId" : project .id ,
244
296
"name" : name or project .name + " Performance" ,
245
- "modelIds" : [model . id for model in models ],
297
+ "modelIds" : [model for model in updated_models ],
246
298
"championMonitored" : monitor_champion ,
247
299
"challengerMonitored" : monitor_challenger ,
248
300
"maxBins" : max_bins ,
0 commit comments