2828from ads .aqua .constants import *
2929from ads .aqua .data import AquaResourceIdentifier
3030from ads .common .auth import default_signer
31+ from ads .common .decorator .threaded import threaded
3132from ads .common .extended_enum import ExtendedEnumMeta
3233from ads .common .object_storage_details import ObjectStorageDetails
3334from ads .common .oci_resource import SEARCH_TYPE , OCIResource
34- from ads .common .utils import get_console_link , upload_to_os , copy_file
35+ from ads .common .utils import copy_file , get_console_link , upload_to_os
3536from ads .config import AQUA_SERVICE_MODELS_BUCKET , CONDA_BUCKET_NS , TENANCY_OCID
3637from ads .model import DataScienceModel , ModelVersionSet
3738
@@ -195,6 +196,7 @@ def read_file(file_path: str, **kwargs) -> str:
195196 return UNKNOWN
196197
197198
199+ @threaded ()
198200def load_config (file_path : str , config_file_name : str , ** kwargs ) -> dict :
199201 artifact_path = f"{ file_path .rstrip ('/' )} /{ config_file_name } "
200202 if artifact_path .startswith ("oci://" ):
@@ -540,8 +542,10 @@ def get_container_image(
540542
541543
542544def fetch_service_compartment () -> Union [str , None ]:
543- """Loads the compartment mapping json from service bucket. This json file has a service-model-compartment key which
544- contains a dictionary of namespaces and the compartment OCID of the service models in that namespace.
545+ """
546+ Loads the compartment mapping json from service bucket.
547+ This json file has a service-model-compartment key which contains a dictionary of namespaces
548+ and the compartment OCID of the service models in that namespace.
545549 """
546550 config_file_name = (
547551 f"oci://{ AQUA_SERVICE_MODELS_BUCKET } @{ CONDA_BUCKET_NS } /service_models/config"
@@ -554,8 +558,8 @@ def fetch_service_compartment() -> Union[str, None]:
554558 )
555559 except Exception as e :
556560 logger .debug (
557- f"Config file { config_file_name } /{ CONTAINER_INDEX } to fetch service compartment OCID could not be found. "
558- f"\n { str (e )} ."
561+ f"Config file { config_file_name } /{ CONTAINER_INDEX } to fetch service compartment OCID "
562+ f"could not be found. \n { str (e )} ."
559563 )
560564 return
561565 compartment_mapping = config .get (COMPARTMENT_MAPPING_KEY )
@@ -664,23 +668,26 @@ def get_model_by_reference_paths(model_file_description: dict):
664668 fine_tune_output_path = UNKNOWN
665669 models = model_file_description ["models" ]
666670
667- for model in models :
668- namespace , bucket_name , prefix = (
669- model ["namespace" ],
670- model ["bucketName" ],
671- model ["prefix" ],
671+ if not models :
672+ raise AquaValueError (
673+ f"Model path is not available in the model json artifact. "
674+ f"Please check if the model created by reference has the correct artifact."
672675 )
673- bucket_uri = f"oci://{ bucket_name } @{ namespace } /{ prefix } " .rstrip ("/" )
674- if bucket_name == AQUA_SERVICE_MODELS_BUCKET :
675- base_model_path = bucket_uri
676- else :
677- fine_tune_output_path = bucket_uri
678676
679- if not base_model_path :
680- raise AquaValueError (
681- f"Base Model should come from the bucket { AQUA_SERVICE_MODELS_BUCKET } . "
682- f"Other paths are not supported by Aqua."
677+ if len (models ) > 0 :
678+ # since the model_file_description json does not have a flag to identify the base model, we consider
679+ # the first instance to be the base model.
680+ base_model_artifact = models [0 ]
681+ base_model_path = f"oci://{ base_model_artifact ['bucketName' ]} @{ base_model_artifact ['namespace' ]} /{ base_model_artifact ['prefix' ]} " .rstrip (
682+ "/"
683+ )
684+ if len (models ) > 1 :
685+ # second model is considered as fine-tuned model
686+ ft_model_artifact = models [1 ]
687+ fine_tune_output_path = f"oci://{ ft_model_artifact ['bucketName' ]} @{ ft_model_artifact ['namespace' ]} /{ ft_model_artifact ['prefix' ]} " .rstrip (
688+ "/"
683689 )
690+
684691 return base_model_path , fine_tune_output_path
685692
686693
0 commit comments