19
19
get_artifact_path ,
20
20
read_file ,
21
21
copy_model_config ,
22
+ load_config ,
22
23
)
23
24
from ads .aqua .constants import (
24
25
LICENSE_TXT ,
32
33
UNKNOWN ,
33
34
VALIDATION_METRICS ,
34
35
VALIDATION_METRICS_FINAL ,
36
+ AQUA_MODEL_ARTIFACT_CONFIG ,
37
+ AQUA_MODEL_ARTIFACT_CONFIG_MODEL_NAME ,
38
+ AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE ,
39
+ AQUA_MODEL_TYPE_CUSTOM ,
35
40
)
36
41
from ads .aqua .model .constants import *
37
42
from ads .aqua .model .entities import *
38
43
from ads .common .auth import default_signer
39
44
from ads .common .oci_resource import SEARCH_TYPE , OCIResource
40
- from ads .common .utils import get_console_link , is_path_exists
45
+ from ads .common .utils import get_console_link
41
46
from ads .config import (
42
47
AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME ,
43
48
AQUA_EVALUATION_CONTAINER_METADATA_NAME ,
@@ -688,9 +693,16 @@ def register(
688
693
if not import_model_details :
689
694
import_model_details = ImportModelDetails (** kwargs )
690
695
691
- if not is_path_exists (
692
- f"{ import_model_details .os_path .rstrip ('/' )} /config.json"
693
- ):
696
+ try :
697
+ model_config = load_config (
698
+ file_path = import_model_details .os_path ,
699
+ config_file_name = AQUA_MODEL_ARTIFACT_CONFIG ,
700
+ )
701
+ except Exception as ex :
702
+ logger .error (
703
+ f"Exception occurred while loading config file from { import_model_details .os_path } "
704
+ f"Exception message: { ex } "
705
+ )
694
706
raise AquaRuntimeError (
695
707
f"The model path { import_model_details .os_path } does not contain the file config.json. "
696
708
f"Please check if the path is correct or the model artifacts are available at this location."
@@ -713,6 +725,30 @@ def register(
713
725
)
714
726
if model_service_id :
715
727
verified_model_details = DataScienceModel .from_id (model_service_id )
728
+ try :
729
+ metadata_model_type = verified_model_details .custom_metadata_list .get (
730
+ AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE
731
+ ).value
732
+ if metadata_model_type :
733
+ if AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE in model_config :
734
+ if (
735
+ model_config [AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE ]
736
+ != metadata_model_type
737
+ ):
738
+ raise AquaRuntimeError (
739
+ f"The { AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE } attribute in { AQUA_MODEL_ARTIFACT_CONFIG } "
740
+ f" at { import_model_details .os_path } is invalid, expected { metadata_model_type } for "
741
+ f"the model { import_model_details .model } . Please check if the path is correct or "
742
+ f"the correct model artifacts are available at this location."
743
+ f""
744
+ )
745
+ else :
746
+ logger .debug (
747
+ f"Could not find { AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE } attribute in "
748
+ f"{ AQUA_MODEL_ARTIFACT_CONFIG } . Proceeding with model registration."
749
+ )
750
+ except :
751
+ pass
716
752
717
753
# Copy the model name from the service model if `model` is ocid
718
754
model_name = (
@@ -734,19 +770,14 @@ def register(
734
770
# registered model will always have inference and evaluation container, but
735
771
# fine-tuning container may be not set
736
772
inference_container = ds_model .custom_metadata_list .get (
737
- ModelCustomMetadataFields .DEPLOYMENT_CONTAINER ,
738
- ModelCustomMetadataItem (key = ModelCustomMetadataFields .DEPLOYMENT_CONTAINER ),
773
+ ModelCustomMetadataFields .DEPLOYMENT_CONTAINER
739
774
).value
740
775
evaluation_container = ds_model .custom_metadata_list .get (
741
776
ModelCustomMetadataFields .EVALUATION_CONTAINER ,
742
- ModelCustomMetadataItem (key = ModelCustomMetadataFields .EVALUATION_CONTAINER ),
743
777
).value
744
778
try :
745
779
finetuning_container = ds_model .custom_metadata_list .get (
746
780
ModelCustomMetadataFields .FINETUNE_CONTAINER ,
747
- ModelCustomMetadataItem (
748
- key = ModelCustomMetadataFields .FINETUNE_CONTAINER
749
- ),
750
781
).value
751
782
except :
752
783
finetuning_container = None
@@ -756,18 +787,31 @@ def register(
756
787
project_id = ds_model .project_id ,
757
788
model_card = str (
758
789
read_file (
759
- file_path = (
760
- f"{ import_model_details .os_path .rstrip ('/' )} /config/{ README } "
761
- if verified_model_details
762
- else f"{ import_model_details .os_path .rstrip ('/' )} /{ README } "
763
- ),
790
+ file_path = f"{ import_model_details .os_path .rstrip ('/' )} /{ README } " ,
764
791
auth = default_signer (),
765
792
)
766
793
),
767
794
inference_container = inference_container ,
768
795
finetuning_container = finetuning_container ,
769
796
evaluation_container = evaluation_container ,
770
797
)
798
+
799
+ if verified_model_details :
800
+ telemetry_model_name = model_name
801
+ else :
802
+ if AQUA_MODEL_ARTIFACT_CONFIG_MODEL_NAME in model_config :
803
+ telemetry_model_name = f"{ AQUA_MODEL_TYPE_CUSTOM } _{ model_config [AQUA_MODEL_ARTIFACT_CONFIG_MODEL_NAME ]} "
804
+ elif AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE in model_config :
805
+ telemetry_model_name = f"{ AQUA_MODEL_TYPE_CUSTOM } _{ model_config [AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE ]} "
806
+ else :
807
+ telemetry_model_name = AQUA_MODEL_TYPE_CUSTOM
808
+
809
+ self .telemetry .record_event_async (
810
+ category = "aqua/model" ,
811
+ action = "register" ,
812
+ detail = telemetry_model_name ,
813
+ )
814
+
771
815
return AquaModel (** aqua_model_attributes )
772
816
773
817
def _if_show (self , model : DataScienceModel ) -> bool :
0 commit comments