11#!/usr/bin/env python
2- # -*- coding: utf-8 -*-
32# Copyright (c) 2024 Oracle and/or its affiliates.
43# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
54import os
1211
1312from ads .aqua import ODSC_MODEL_COMPARTMENT_OCID
1413from ads .aqua .app import AquaApp
15- from ads .aqua .common .enums import Tags
14+ from ads .aqua .common .enums import Tags , InferenceContainerTypeFamily
1615from ads .aqua .common .errors import AquaRuntimeError
1716from ads .aqua .common .utils import (
1817 create_word_icon ,
3635 AQUA_MODEL_ARTIFACT_CONFIG ,
3736 AQUA_MODEL_ARTIFACT_CONFIG_MODEL_NAME ,
3837 AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE ,
39- AQUA_MODEL_TYPE_CUSTOM ,
38+ AQUA_MODEL_TYPE_CUSTOM , ARM_CPU , NVIDIA_GPU ,
4039)
4140from ads .aqua .model .constants import *
4241from ads .aqua .model .entities import *
@@ -268,8 +267,7 @@ def get(self, model_id: str, load_model_card: Optional[bool] = True) -> "AquaMod
268267
269268 job_run_status = (
270269 jobrun .lifecycle_state
271- if jobrun
272- and not jobrun .lifecycle_state == JobRun .LIFECYCLE_STATE_DELETED
270+ if jobrun and jobrun .lifecycle_state != JobRun .LIFECYCLE_STATE_DELETED
273271 else (
274272 JobRun .LIFECYCLE_STATE_SUCCEEDED
275273 if self .if_artifact_exist (ds_model .id )
@@ -540,7 +538,7 @@ def clear_model_list_cache(
540538 dict with the key used, and True if cache has the key that needs to be deleted.
541539 """
542540 res = {}
543- logger .info (f "Clearing _service_models_cache" )
541+ logger .info ("Clearing _service_models_cache" )
544542 with self ._cache_lock :
545543 if ODSC_MODEL_COMPARTMENT_OCID in self ._service_models_cache .keys ():
546544 self ._service_models_cache .pop (key = ODSC_MODEL_COMPARTMENT_OCID )
@@ -561,6 +559,7 @@ def _create_model_catalog_entry(
561559 verified_model : DataScienceModel ,
562560 compartment_id : Optional [str ],
563561 project_id : Optional [str ],
562+ is_gguf_model : bool ,
564563 ) -> DataScienceModel :
565564 """Create model by reference from the object storage path
566565
@@ -583,9 +582,13 @@ def _create_model_catalog_entry(
583582 Tags .AQUA_SERVICE_MODEL_TAG : verified_model .id ,
584583 }
585584 if verified_model
586- else {Tags .AQUA_TAG : "active" , Tags .BASE_MODEL_CUSTOM : "true" }
585+ else {
586+ Tags .AQUA_TAG : "active" ,
587+ Tags .BASE_MODEL_CUSTOM : "true" ,
588+ }
587589 )
588590 tags .update ({Tags .BASE_MODEL_CUSTOM : "true" })
591+ tags .update ({Tags .PLATFORM : ARM_CPU if is_gguf_model else NVIDIA_GPU })
589592
590593 # Remove `ready_to_import` tag that might get copied from service model.
591594 tags .pop (Tags .READY_TO_IMPORT , None )
@@ -615,8 +618,8 @@ def _create_model_catalog_entry(
615618 )
616619 else :
617620 logger .warn (
618- f "Proceeding with model registration without the fine-tuning container information. "
619- f "This model will not be available for fine tuning."
621+ "Proceeding with model registration without the fine-tuning container information. "
622+ "This model will not be available for fine tuning."
620623 )
621624
622625 metadata .add (
@@ -693,24 +696,26 @@ def register(
693696 The registered model as a AquaModel object.
694697 """
695698 verified_model_details : DataScienceModel = None
696-
699+ model_config = None
697700 if not import_model_details :
698701 import_model_details = ImportModelDetails (** kwargs )
699-
700- try :
701- model_config = load_config (
702- file_path = import_model_details .os_path ,
703- config_file_name = AQUA_MODEL_ARTIFACT_CONFIG ,
704- )
705- except Exception as ex :
706- logger .error (
707- f"Exception occurred while loading config file from { import_model_details .os_path } "
708- f"Exception message: { ex } "
709- )
710- raise AquaRuntimeError (
711- f"The model path { import_model_details .os_path } does not contain the file config.json. "
712- f"Please check if the path is correct or the model artifacts are available at this location."
713- )
702+ is_gguf_model = import_model_details .inference_container == InferenceContainerTypeFamily .AQUA_LLAMA_CPP_CONTAINER_FAMILY
703+ platform = ARM_CPU if is_gguf_model else NVIDIA_GPU
704+ if not is_gguf_model :
705+ try :
706+ model_config = load_config (
707+ file_path = import_model_details .os_path ,
708+ config_file_name = AQUA_MODEL_ARTIFACT_CONFIG ,
709+ )
710+ except Exception as ex :
711+ logger .error (
712+ f"Exception occurred while loading config file from { import_model_details .os_path } "
713+ f"Exception message: { ex } "
714+ )
715+ raise AquaRuntimeError (
716+ f"The model path { import_model_details .os_path } does not contain the file config.json. "
717+ f"Please check if the path is correct or the model artifacts are available at this location."
718+ )
714719
715720 model_service_id = None
716721 # If OCID of a model is passed, we need to copy the defaults for Tags and metadata from the service model.
@@ -770,6 +775,7 @@ def register(
770775 verified_model = verified_model_details ,
771776 compartment_id = import_model_details .compartment_id ,
772777 project_id = import_model_details .project_id ,
778+ is_gguf_model = is_gguf_model ,
773779 )
774780 # registered model will always have inference and evaluation container, but
775781 # fine-tuning container may be not set
@@ -798,17 +804,23 @@ def register(
798804 inference_container = inference_container ,
799805 finetuning_container = finetuning_container ,
800806 evaluation_container = evaluation_container ,
807+ platform = platform ,
801808 )
802809
803810 if verified_model_details :
804811 telemetry_model_name = model_name
812+ elif (
813+ model_config is not None
814+ and AQUA_MODEL_ARTIFACT_CONFIG_MODEL_NAME in model_config
815+ ):
816+ telemetry_model_name = f"{ AQUA_MODEL_TYPE_CUSTOM } _{ model_config [AQUA_MODEL_ARTIFACT_CONFIG_MODEL_NAME ]} "
817+ elif (
818+ model_config is not None
819+ and AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE in model_config
820+ ):
821+ telemetry_model_name = f"{ AQUA_MODEL_TYPE_CUSTOM } _{ model_config [AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE ]} "
805822 else :
806- if AQUA_MODEL_ARTIFACT_CONFIG_MODEL_NAME in model_config :
807- telemetry_model_name = f"{ AQUA_MODEL_TYPE_CUSTOM } _{ model_config [AQUA_MODEL_ARTIFACT_CONFIG_MODEL_NAME ]} "
808- elif AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE in model_config :
809- telemetry_model_name = f"{ AQUA_MODEL_TYPE_CUSTOM } _{ model_config [AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE ]} "
810- else :
811- telemetry_model_name = AQUA_MODEL_TYPE_CUSTOM
823+ telemetry_model_name = AQUA_MODEL_TYPE_CUSTOM
812824
813825 self .telemetry .record_event_async (
814826 category = "aqua/model" ,
0 commit comments