39
39
ModelBackupSetting ,
40
40
ModelRetentionSetting ,
41
41
ModelRetentionOperationDetails ,
42
- ModelBackupOperationDetails
42
+ ModelBackupOperationDetails ,
43
43
)
44
44
from ads .model .service .oci_datascience_model import (
45
45
ModelProvenanceNotFoundError ,
@@ -135,7 +135,7 @@ class DataScienceModel(Builder):
135
135
136
136
137
137
138
-
138
+
139
139
140
140
141
141
Methods
@@ -265,7 +265,7 @@ class DataScienceModel(Builder):
265
265
CONST_BACKUP_SETTING : "backup_setting" ,
266
266
CONST_RETENTION_SETTING : "retention_setting" ,
267
267
CONST_BACKUP_OPERATION_DETAILS : "backup_operation_details" ,
268
- CONST_RETENTION_OPERATION_DETAILS : "retention_operation_details"
268
+ CONST_RETENTION_OPERATION_DETAILS : "retention_operation_details" ,
269
269
}
270
270
271
271
def __init__ (self , spec : Dict = None , ** kwargs ) -> None :
@@ -333,7 +333,7 @@ def lifecycle_state(self) -> Union[str, None]:
333
333
if self .dsc_model :
334
334
return self .dsc_model .status
335
335
return None
336
-
336
+
337
337
@property
338
338
def lifecycle_details (self ) -> str :
339
339
"""
@@ -356,7 +356,6 @@ def lifecycle_details(self, lifecycle_details: str) -> "DataScienceModel":
356
356
"""
357
357
return self .set_spec (self .CONST_LIFECYCLE_DETAILS , lifecycle_details )
358
358
359
-
360
359
@property
361
360
def kind (self ) -> str :
362
361
"""The kind of the object as showing in a YAML."""
@@ -743,30 +742,26 @@ def retention_setting(self) -> ModelRetentionSetting:
743
742
:rtype: RetentionSetting
744
743
"""
745
744
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" :
748
749
"""
749
750
Sets the retention setting details for the model.
750
751
751
752
Parameters
752
753
----------
753
754
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
755
756
an instance of the `RetentionSetting` class.
756
757
757
758
Returns
758
759
-------
759
760
DataScienceModel
760
761
The `DataScienceModel` instance (self) for method chaining.
761
762
"""
762
- if retention_setting and isinstance (retention_setting , dict ):
763
- retention_setting = ModelRetentionSetting .from_dict (retention_setting )
764
-
765
763
return self .set_spec (self .CONST_RETENTION_SETTING , retention_setting )
766
764
767
-
768
-
769
-
770
765
@property
771
766
def backup_setting (self ) -> ModelBackupSetting :
772
767
"""
@@ -776,8 +771,10 @@ def backup_setting(self) -> ModelBackupSetting:
776
771
:rtype: BackupSetting
777
772
"""
778
773
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" :
781
778
"""
782
779
Sets the model's backup setting details.
783
780
@@ -792,12 +789,9 @@ def with_backup_setting(self, backup_setting: Union[Dict, ModelBackupSetting]) -
792
789
DataScienceModel
793
790
The `DataScienceModel` instance (self) for method chaining.
794
791
"""
795
- if backup_setting and isinstance (backup_setting , dict ):
796
- backup_setting = ModelBackupSetting .from_dict (backup_setting )
797
792
798
793
return self .set_spec (self .CONST_BACKUP_SETTING , backup_setting )
799
794
800
-
801
795
@property
802
796
def retention_operation_details (self ) -> ModelRetentionOperationDetails :
803
797
"""
@@ -807,7 +801,7 @@ def retention_operation_details(self) -> ModelRetentionOperationDetails:
807
801
:rtype: ModelRetentionOperationDetails
808
802
"""
809
803
return self .get_spec (self .CONST_RETENTION_OPERATION_DETAILS )
810
-
804
+
811
805
@property
812
806
def backup_operation_details (self ) -> "ModelBackupOperationDetails" :
813
807
"""
@@ -1033,20 +1027,17 @@ def upload_artifact(
1033
1027
artifact_uploader .upload ()
1034
1028
1035
1029
self ._remove_file_description_artifact ()
1036
-
1037
-
1038
1030
1039
1031
def _remove_file_description_artifact (self ):
1040
1032
"""Removes temporary model file description artifact for model by reference."""
1041
1033
# delete if local copy directory was created
1042
1034
if self .local_copy_dir :
1043
1035
shutil .rmtree (self .local_copy_dir , ignore_errors = True )
1044
1036
1045
-
1046
1037
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 ,
1050
1041
):
1051
1042
"""
1052
1043
Restore archived model artifact.
@@ -1073,13 +1064,18 @@ def restore_model(
1073
1064
1074
1065
# Optional: Validate restore_model_for_hours_specified
1075
1066
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
+ )
1078
1074
1079
1075
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
+ )
1083
1079
1084
1080
def download_artifact (
1085
1081
self ,
@@ -1357,8 +1353,6 @@ def _to_oci_dsc_model(self, **kwargs):
1357
1353
self .CONST_CUSTOM_METADATA : "_to_oci_metadata" ,
1358
1354
self .CONST_DEFINED_METADATA : "_to_oci_metadata" ,
1359
1355
self .CONST_PROVENANCE_METADATA : "_to_oci_metadata" ,
1360
- self .CONST_BACKUP_SETTING : "to_json" ,
1361
- self .CONST_RETENTION_SETTING : "to_json"
1362
1356
}
1363
1357
dsc_spec = {}
1364
1358
for infra_attr , dsc_attr in self .attribute_map .items ():
@@ -1375,6 +1369,8 @@ def _to_oci_dsc_model(self, **kwargs):
1375
1369
dsc_spec [dsc_attr ] = value
1376
1370
1377
1371
dsc_spec .update (** kwargs )
1372
+ print ("Model Dsc spec" )
1373
+ print (dsc_spec )
1378
1374
return OCIDataScienceModel (** dsc_spec )
1379
1375
1380
1376
def _update_from_oci_dsc_model (
@@ -1397,12 +1393,15 @@ def _update_from_oci_dsc_model(
1397
1393
self .CONST_OUTPUT_SCHEMA : [Schema .from_json , json .loads ],
1398
1394
self .CONST_CUSTOM_METADATA : ModelCustomMetadata ._from_oci_metadata ,
1399
1395
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 ,
1402
1398
}
1403
1399
1404
1400
# Update the main properties
1401
+
1405
1402
self .dsc_model = dsc_model
1403
+ print ("Model Details from here" )
1404
+ print (dsc_model )
1406
1405
for infra_attr , dsc_attr in self .attribute_map .items ():
1407
1406
value = utils .get_value (dsc_model , dsc_attr )
1408
1407
if value :
0 commit comments