Skip to content

Commit 4547ae3

Browse files
committed
updated test cases
1 parent 754adf8 commit 4547ae3

File tree

5 files changed

+171
-116
lines changed

5 files changed

+171
-116
lines changed

ads/model/datascience_model.py

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
ModelBackupSetting,
4040
ModelRetentionSetting,
4141
ModelRetentionOperationDetails,
42-
ModelBackupOperationDetails
42+
ModelBackupOperationDetails,
4343
)
4444
from ads.model.service.oci_datascience_model import (
4545
ModelProvenanceNotFoundError,
@@ -135,7 +135,7 @@ class DataScienceModel(Builder):
135135
136136
137137
138-
138+
139139
140140
141141
Methods
@@ -265,7 +265,7 @@ class DataScienceModel(Builder):
265265
CONST_BACKUP_SETTING: "backup_setting",
266266
CONST_RETENTION_SETTING: "retention_setting",
267267
CONST_BACKUP_OPERATION_DETAILS: "backup_operation_details",
268-
CONST_RETENTION_OPERATION_DETAILS: "retention_operation_details"
268+
CONST_RETENTION_OPERATION_DETAILS: "retention_operation_details",
269269
}
270270

271271
def __init__(self, spec: Dict = None, **kwargs) -> None:
@@ -333,7 +333,7 @@ def lifecycle_state(self) -> Union[str, None]:
333333
if self.dsc_model:
334334
return self.dsc_model.status
335335
return None
336-
336+
337337
@property
338338
def lifecycle_details(self) -> str:
339339
"""
@@ -356,7 +356,6 @@ def lifecycle_details(self, lifecycle_details: str) -> "DataScienceModel":
356356
"""
357357
return self.set_spec(self.CONST_LIFECYCLE_DETAILS, lifecycle_details)
358358

359-
360359
@property
361360
def kind(self) -> str:
362361
"""The kind of the object as showing in a YAML."""
@@ -743,30 +742,26 @@ def retention_setting(self) -> ModelRetentionSetting:
743742
:rtype: RetentionSetting
744743
"""
745744
return self.get_spec(self.CONST_RETENTION_SETTING)
746-
747-
def with_retention_setting(self, retention_setting: Union[Dict, ModelRetentionSetting]) -> "DataScienceModel":
745+
746+
def with_retention_setting(
747+
self, retention_setting: Union[Dict, ModelRetentionSetting]
748+
) -> "DataScienceModel":
748749
"""
749750
Sets the retention setting details for the model.
750751
751752
Parameters
752753
----------
753754
retention_setting : Union[Dict, RetentionSetting]
754-
The retention setting details for the model. Can be provided as either a dictionary or
755+
The retention setting details for the model. Can be provided as either a dictionary or
755756
an instance of the `RetentionSetting` class.
756757
757758
Returns
758759
-------
759760
DataScienceModel
760761
The `DataScienceModel` instance (self) for method chaining.
761762
"""
762-
if retention_setting and isinstance(retention_setting, dict):
763-
retention_setting = ModelRetentionSetting.from_dict(retention_setting)
764-
765763
return self.set_spec(self.CONST_RETENTION_SETTING, retention_setting)
766764

767-
768-
769-
770765
@property
771766
def backup_setting(self) -> ModelBackupSetting:
772767
"""
@@ -776,8 +771,10 @@ def backup_setting(self) -> ModelBackupSetting:
776771
:rtype: BackupSetting
777772
"""
778773
return self.get_spec(self.CONST_BACKUP_SETTING)
779-
780-
def with_backup_setting(self, backup_setting: Union[Dict, ModelBackupSetting]) -> "DataScienceModel":
774+
775+
def with_backup_setting(
776+
self, backup_setting: Union[Dict, ModelBackupSetting]
777+
) -> "DataScienceModel":
781778
"""
782779
Sets the model's backup setting details.
783780
@@ -792,12 +789,9 @@ def with_backup_setting(self, backup_setting: Union[Dict, ModelBackupSetting]) -
792789
DataScienceModel
793790
The `DataScienceModel` instance (self) for method chaining.
794791
"""
795-
if backup_setting and isinstance(backup_setting, dict):
796-
backup_setting = ModelBackupSetting.from_dict(backup_setting)
797792

798793
return self.set_spec(self.CONST_BACKUP_SETTING, backup_setting)
799794

800-
801795
@property
802796
def retention_operation_details(self) -> ModelRetentionOperationDetails:
803797
"""
@@ -807,7 +801,7 @@ def retention_operation_details(self) -> ModelRetentionOperationDetails:
807801
:rtype: ModelRetentionOperationDetails
808802
"""
809803
return self.get_spec(self.CONST_RETENTION_OPERATION_DETAILS)
810-
804+
811805
@property
812806
def backup_operation_details(self) -> "ModelBackupOperationDetails":
813807
"""
@@ -1033,20 +1027,17 @@ def upload_artifact(
10331027
artifact_uploader.upload()
10341028

10351029
self._remove_file_description_artifact()
1036-
1037-
10381030

10391031
def _remove_file_description_artifact(self):
10401032
"""Removes temporary model file description artifact for model by reference."""
10411033
# delete if local copy directory was created
10421034
if self.local_copy_dir:
10431035
shutil.rmtree(self.local_copy_dir, ignore_errors=True)
10441036

1045-
10461037
def restore_model(
1047-
self,
1048-
model_id: str,
1049-
restore_model_for_hours_specified: Optional[int] = None,
1038+
self,
1039+
model_id: str,
1040+
restore_model_for_hours_specified: Optional[int] = None,
10501041
):
10511042
"""
10521043
Restore archived model artifact.
@@ -1073,13 +1064,18 @@ def restore_model(
10731064

10741065
# Optional: Validate restore_model_for_hours_specified
10751066
if restore_model_for_hours_specified is not None:
1076-
if not isinstance(restore_model_for_hours_specified, int) or restore_model_for_hours_specified <= 0:
1077-
raise ValueError("restore_model_for_hours_specified must be a positive integer.")
1067+
if (
1068+
not isinstance(restore_model_for_hours_specified, int)
1069+
or restore_model_for_hours_specified <= 0
1070+
):
1071+
raise ValueError(
1072+
"restore_model_for_hours_specified must be a positive integer."
1073+
)
10781074

10791075
self.dsc_model.restore_archived_model_artifact(
1080-
model_id=model_id,
1081-
restore_model_for_hours_specified=restore_model_for_hours_specified)
1082-
1076+
model_id=model_id,
1077+
restore_model_for_hours_specified=restore_model_for_hours_specified,
1078+
)
10831079

10841080
def download_artifact(
10851081
self,
@@ -1357,8 +1353,6 @@ def _to_oci_dsc_model(self, **kwargs):
13571353
self.CONST_CUSTOM_METADATA: "_to_oci_metadata",
13581354
self.CONST_DEFINED_METADATA: "_to_oci_metadata",
13591355
self.CONST_PROVENANCE_METADATA: "_to_oci_metadata",
1360-
self.CONST_BACKUP_SETTING: "to_json",
1361-
self.CONST_RETENTION_SETTING: "to_json"
13621356
}
13631357
dsc_spec = {}
13641358
for infra_attr, dsc_attr in self.attribute_map.items():
@@ -1375,6 +1369,8 @@ def _to_oci_dsc_model(self, **kwargs):
13751369
dsc_spec[dsc_attr] = value
13761370

13771371
dsc_spec.update(**kwargs)
1372+
print("Model Dsc spec")
1373+
print(dsc_spec)
13781374
return OCIDataScienceModel(**dsc_spec)
13791375

13801376
def _update_from_oci_dsc_model(
@@ -1397,12 +1393,15 @@ def _update_from_oci_dsc_model(
13971393
self.CONST_OUTPUT_SCHEMA: [Schema.from_json, json.loads],
13981394
self.CONST_CUSTOM_METADATA: ModelCustomMetadata._from_oci_metadata,
13991395
self.CONST_DEFINED_METADATA: ModelTaxonomyMetadata._from_oci_metadata,
1400-
self.CONST_BACKUP_SETTING: ModelBackupSetting.from_json,
1401-
self.CONST_RETENTION_SETTING: ModelRetentionSetting.from_json,
1396+
self.CONST_BACKUP_SETTING: ModelBackupSetting.to_dict,
1397+
self.CONST_RETENTION_SETTING: ModelRetentionSetting.to_dict,
14021398
}
14031399

14041400
# Update the main properties
1401+
14051402
self.dsc_model = dsc_model
1403+
print("Model Details from here")
1404+
print(dsc_model)
14061405
for infra_attr, dsc_attr in self.attribute_map.items():
14071406
value = utils.get_value(dsc_model, dsc_attr)
14081407
if value:

ads/model/generic_model.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,9 +1422,9 @@ def from_model_artifact(
14221422
)
14231423
model.update_summary_status(
14241424
detail=PREPARE_STATUS_POPULATE_METADATA_DETAIL,
1425-
status=ModelState.AVAILABLE.value
1426-
if reload
1427-
else ModelState.NOTAPPLICABLE.value,
1425+
status=(
1426+
ModelState.AVAILABLE.value if reload else ModelState.NOTAPPLICABLE.value
1427+
),
14281428
)
14291429

14301430
return model
@@ -1706,9 +1706,11 @@ def from_model_catalog(
17061706
)
17071707
result_model.update_summary_status(
17081708
detail=SAVE_STATUS_INTROSPECT_TEST_DETAIL,
1709-
status=ModelState.AVAILABLE.value
1710-
if not result_model.ignore_conda_error
1711-
else ModelState.NOTAVAILABLE.value,
1709+
status=(
1710+
ModelState.AVAILABLE.value
1711+
if not result_model.ignore_conda_error
1712+
else ModelState.NOTAVAILABLE.value
1713+
),
17121714
)
17131715
return result_model
17141716

0 commit comments

Comments
 (0)