1919 get_artifact_path ,
2020 read_file ,
2121 copy_model_config ,
22+ load_config ,
2223)
2324from ads .aqua .constants import (
2425 LICENSE_TXT ,
3233 UNKNOWN ,
3334 VALIDATION_METRICS ,
3435 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 ,
3540)
3641from ads .aqua .model .constants import *
3742from ads .aqua .model .entities import *
3843from ads .common .auth import default_signer
3944from 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
4146from ads .config import (
4247 AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME ,
4348 AQUA_EVALUATION_CONTAINER_METADATA_NAME ,
@@ -688,9 +693,16 @@ def register(
688693 if not import_model_details :
689694 import_model_details = ImportModelDetails (** kwargs )
690695
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+ )
694706 raise AquaRuntimeError (
695707 f"The model path { import_model_details .os_path } does not contain the file config.json. "
696708 f"Please check if the path is correct or the model artifacts are available at this location."
@@ -713,6 +725,30 @@ def register(
713725 )
714726 if model_service_id :
715727 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
716752
717753 # Copy the model name from the service model if `model` is ocid
718754 model_name = (
@@ -734,19 +770,14 @@ def register(
734770 # registered model will always have inference and evaluation container, but
735771 # fine-tuning container may be not set
736772 inference_container = ds_model .custom_metadata_list .get (
737- ModelCustomMetadataFields .DEPLOYMENT_CONTAINER ,
738- ModelCustomMetadataItem (key = ModelCustomMetadataFields .DEPLOYMENT_CONTAINER ),
773+ ModelCustomMetadataFields .DEPLOYMENT_CONTAINER
739774 ).value
740775 evaluation_container = ds_model .custom_metadata_list .get (
741776 ModelCustomMetadataFields .EVALUATION_CONTAINER ,
742- ModelCustomMetadataItem (key = ModelCustomMetadataFields .EVALUATION_CONTAINER ),
743777 ).value
744778 try :
745779 finetuning_container = ds_model .custom_metadata_list .get (
746780 ModelCustomMetadataFields .FINETUNE_CONTAINER ,
747- ModelCustomMetadataItem (
748- key = ModelCustomMetadataFields .FINETUNE_CONTAINER
749- ),
750781 ).value
751782 except :
752783 finetuning_container = None
@@ -756,18 +787,31 @@ def register(
756787 project_id = ds_model .project_id ,
757788 model_card = str (
758789 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 } " ,
764791 auth = default_signer (),
765792 )
766793 ),
767794 inference_container = inference_container ,
768795 finetuning_container = finetuning_container ,
769796 evaluation_container = evaluation_container ,
770797 )
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+
771815 return AquaModel (** aqua_model_attributes )
772816
773817 def _if_show (self , model : DataScienceModel ) -> bool :
0 commit comments