Skip to content

Commit 3ca41c6

Browse files
authored
Enhancing Model-Defined Metadata Handling (#1069)
2 parents 14b4b6c + 25a55dc commit 3ca41c6

File tree

4 files changed

+239
-134
lines changed

4 files changed

+239
-134
lines changed

ads/model/model_metadata.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,10 @@ def _from_oci_metadata(cls, metadata_list):
15091509
metadata = cls()
15101510
for oci_item in metadata_list:
15111511
item = ModelTaxonomyMetadataItem._from_oci_metadata(oci_item)
1512-
metadata[item.key].update(value=item.value)
1512+
if item.key in metadata.keys:
1513+
metadata[item.key].update(value=item.value)
1514+
else:
1515+
metadata._items.add(item)
15131516
return metadata
15141517

15151518
def to_dataframe(self) -> pd.DataFrame:
@@ -1562,7 +1565,10 @@ def from_dict(cls, data: Dict) -> "ModelTaxonomyMetadata":
15621565
metadata = cls()
15631566
for item in data["data"]:
15641567
item = ModelTaxonomyMetadataItem.from_dict(item)
1565-
metadata[item.key].update(value=item.value)
1568+
if item.key in metadata.keys:
1569+
metadata[item.key].update(value=item.value)
1570+
else:
1571+
metadata._items.add(item)
15661572
return metadata
15671573

15681574

tests/unitary/default_setup/model/test_datascience_model.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
ModelArtifactSizeError,
2727
BucketNotVersionedError,
2828
ModelFileDescriptionError,
29-
InvalidArtifactType, ModelRetentionSetting, ModelBackupSetting,
29+
InvalidArtifactType,
30+
ModelRetentionSetting,
31+
ModelBackupSetting,
3032
)
3133
from ads.model.model_metadata import (
3234
ModelCustomMetadata,
@@ -44,7 +46,7 @@
4446
from ads.config import AQUA_SERVICE_MODELS_BUCKET as SERVICE_MODELS_BUCKET
4547

4648
MODEL_OCID = "ocid1.datasciencemodel.oc1.iad.<unique_ocid>"
47-
49+
4850
OCI_MODEL_PAYLOAD = {
4951
"id": MODEL_OCID,
5052
"compartment_id": "ocid1.compartment.oc1..<unique_ocid>",
@@ -71,16 +73,17 @@
7173
{"key": "UseCaseType", "value": "multinomial_classification"},
7274
{"key": "Hyperparameters"},
7375
{"key": "ArtifactTestResults"},
76+
{"key": "UnexpectedKey", "value": "unexpected_value"},
7477
],
7578
"backup_setting": {
7679
"is_backup_enabled": True,
7780
"backup_region": "us-phoenix-1",
78-
"customer_notification_type": "ALL"
81+
"customer_notification_type": "ALL",
7982
},
8083
"retention_setting": {
8184
"archive_after_days": 30,
8285
"delete_after_days": 90,
83-
"customer_notification_type": "ALL"
86+
"customer_notification_type": "ALL",
8487
},
8588
"input_schema": '{"schema": [{"dtype": "int64", "feature_type": "Integer", "name": 0, "domain": {"values": "", "stats": {}, "constraints": []}, "required": true, "description": "0", "order": 0}], "version": "1.1"}',
8689
"output_schema": '{"schema": [{"dtype": "int64", "feature_type": "Integer", "name": 0, "domain": {"values": "", "stats": {}, "constraints": []}, "required": true, "description": "0", "order": 0}], "version": "1.1"}',
@@ -148,6 +151,7 @@
148151
{"key": "UseCaseType", "value": "multinomial_classification"},
149152
{"key": "Hyperparameters", "value": None},
150153
{"key": "ArtifactTestResults", "value": None},
154+
{"key": "UnexpectedKey", "value": "unexpected_value"},
151155
]
152156
},
153157
"provenanceMetadata": {
@@ -161,12 +165,12 @@
161165
"backupSetting": {
162166
"is_backup_enabled": True,
163167
"backup_region": "us-phoenix-1",
164-
"customer_notification_type": "ALL"
168+
"customer_notification_type": "ALL",
165169
},
166170
"retentionSetting": {
167171
"archive_after_days": 30,
168172
"delete_after_days": 90,
169-
"customer_notification_type": "ALL"
173+
"customer_notification_type": "ALL",
170174
},
171175
"artifact": "ocid1.datasciencemodel.oc1.iad.<unique_ocid>.zip",
172176
}
@@ -327,8 +331,8 @@ def test_with_methods_1(self, mock_load_default_properties):
327331
.with_defined_metadata_list(self.payload["definedMetadataList"])
328332
.with_provenance_metadata(self.payload["provenanceMetadata"])
329333
.with_artifact(self.payload["artifact"])
330-
.with_backup_setting(self.payload['backupSetting'])
331-
.with_retention_setting(self.payload['retentionSetting'])
334+
.with_backup_setting(self.payload["backupSetting"])
335+
.with_retention_setting(self.payload["retentionSetting"])
332336
)
333337
assert self.prepare_dict(dsc_model.to_dict()["spec"]) == self.prepare_dict(
334338
self.payload
@@ -356,8 +360,12 @@ def test_with_methods_2(self):
356360
ModelProvenanceMetadata.from_dict(self.payload["provenanceMetadata"])
357361
)
358362
.with_artifact(self.payload["artifact"])
359-
.with_backup_setting(ModelBackupSetting.from_dict(self.payload['backupSetting']))
360-
.with_retention_setting(ModelRetentionSetting.from_dict(self.payload['retentionSetting']))
363+
.with_backup_setting(
364+
ModelBackupSetting.from_dict(self.payload["backupSetting"])
365+
)
366+
.with_retention_setting(
367+
ModelRetentionSetting.from_dict(self.payload["retentionSetting"])
368+
)
361369
)
362370
assert self.prepare_dict(dsc_model.to_dict()["spec"]) == self.prepare_dict(
363371
self.payload

tests/unitary/default_setup/model/test_model_artifact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pickle
88
import sys
99

10-
import mock
10+
from unittest import mock
1111
import pytest
1212
import yaml
1313
from ads.common.model import ADSModel

0 commit comments

Comments
 (0)