1
1
#!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
2
# Copyright (c) 2024 Oracle and/or its affiliates.
4
3
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
5
4
import os
12
11
13
12
from ads .aqua import ODSC_MODEL_COMPARTMENT_OCID
14
13
from ads .aqua .app import AquaApp
15
- from ads .aqua .common .enums import Tags
14
+ from ads .aqua .common .enums import Tags , InferenceContainerTypeFamily
16
15
from ads .aqua .common .errors import AquaRuntimeError
17
16
from ads .aqua .common .utils import (
18
17
create_word_icon ,
36
35
AQUA_MODEL_ARTIFACT_CONFIG ,
37
36
AQUA_MODEL_ARTIFACT_CONFIG_MODEL_NAME ,
38
37
AQUA_MODEL_ARTIFACT_CONFIG_MODEL_TYPE ,
39
- AQUA_MODEL_TYPE_CUSTOM ,
38
+ AQUA_MODEL_TYPE_CUSTOM , ARM_CPU , NVIDIA_GPU ,
40
39
)
41
40
from ads .aqua .model .constants import *
42
41
from ads .aqua .model .entities import *
@@ -268,8 +267,7 @@ def get(self, model_id: str, load_model_card: Optional[bool] = True) -> "AquaMod
268
267
269
268
job_run_status = (
270
269
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
273
271
else (
274
272
JobRun .LIFECYCLE_STATE_SUCCEEDED
275
273
if self .if_artifact_exist (ds_model .id )
@@ -540,7 +538,7 @@ def clear_model_list_cache(
540
538
dict with the key used, and True if cache has the key that needs to be deleted.
541
539
"""
542
540
res = {}
543
- logger .info (f "Clearing _service_models_cache" )
541
+ logger .info ("Clearing _service_models_cache" )
544
542
with self ._cache_lock :
545
543
if ODSC_MODEL_COMPARTMENT_OCID in self ._service_models_cache .keys ():
546
544
self ._service_models_cache .pop (key = ODSC_MODEL_COMPARTMENT_OCID )
@@ -561,6 +559,7 @@ def _create_model_catalog_entry(
561
559
verified_model : DataScienceModel ,
562
560
compartment_id : Optional [str ],
563
561
project_id : Optional [str ],
562
+ is_gguf_model : bool ,
564
563
) -> DataScienceModel :
565
564
"""Create model by reference from the object storage path
566
565
@@ -583,9 +582,13 @@ def _create_model_catalog_entry(
583
582
Tags .AQUA_SERVICE_MODEL_TAG : verified_model .id ,
584
583
}
585
584
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
+ }
587
589
)
588
590
tags .update ({Tags .BASE_MODEL_CUSTOM : "true" })
591
+ tags .update ({Tags .PLATFORM : ARM_CPU if is_gguf_model else NVIDIA_GPU })
589
592
590
593
# Remove `ready_to_import` tag that might get copied from service model.
591
594
tags .pop (Tags .READY_TO_IMPORT , None )
@@ -615,8 +618,8 @@ def _create_model_catalog_entry(
615
618
)
616
619
else :
617
620
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."
620
623
)
621
624
622
625
metadata .add (
@@ -693,24 +696,26 @@ def register(
693
696
The registered model as a AquaModel object.
694
697
"""
695
698
verified_model_details : DataScienceModel = None
696
-
699
+ model_config = None
697
700
if not import_model_details :
698
701
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
+ )
714
719
715
720
model_service_id = None
716
721
# 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(
770
775
verified_model = verified_model_details ,
771
776
compartment_id = import_model_details .compartment_id ,
772
777
project_id = import_model_details .project_id ,
778
+ is_gguf_model = is_gguf_model ,
773
779
)
774
780
# registered model will always have inference and evaluation container, but
775
781
# fine-tuning container may be not set
@@ -798,17 +804,23 @@ def register(
798
804
inference_container = inference_container ,
799
805
finetuning_container = finetuning_container ,
800
806
evaluation_container = evaluation_container ,
807
+ platform = platform ,
801
808
)
802
809
803
810
if verified_model_details :
804
811
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 ]} "
805
822
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
812
824
813
825
self .telemetry .record_event_async (
814
826
category = "aqua/model" ,
0 commit comments