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/
54
6- import json
75import logging
86from typing import Dict , List , Union
97
10- from oci .data_science .models import ModelDeployment
11-
128from ads .aqua .app import AquaApp , logger
139from ads .aqua .common .enums import (
14- Tags ,
15- InferenceContainerParamType ,
1610 InferenceContainerType ,
1711 InferenceContainerTypeFamily ,
12+ Tags ,
1813)
1914from ads .aqua .common .errors import AquaRuntimeError , AquaValueError
2015from ads .aqua .common .utils import (
16+ get_combined_params ,
2117 get_container_config ,
2218 get_container_image ,
19+ get_container_params_type ,
2320 get_model_by_reference_paths ,
2421 get_ocid_substring ,
25- get_combined_params ,
2622 get_params_dict ,
2723 get_params_list ,
2824 get_resource_name ,
3834from ads .aqua .data import AquaResourceIdentifier
3935from ads .aqua .finetuning .finetuning import FineTuneCustomMetadata
4036from ads .aqua .model import AquaModelApp
37+ from ads .aqua .modeldeployment .constants import (
38+ TGIInferenceRestrictedParams ,
39+ VLLMInferenceRestrictedParams ,
40+ )
4141from ads .aqua .modeldeployment .entities import (
4242 AquaDeployment ,
4343 AquaDeploymentDetail ,
4444 ContainerSpec ,
4545)
46- from ads .aqua .modeldeployment .constants import (
47- VLLMInferenceRestrictedParams ,
48- TGIInferenceRestrictedParams ,
49- )
5046from ads .common .object_storage_details import ObjectStorageDetails
5147from ads .common .utils import get_log_links
5248from ads .config import (
@@ -187,24 +183,24 @@ def create(
187183 model_name = aqua_model .custom_metadata_list .get (
188184 FineTuneCustomMetadata .FINE_TUNE_SOURCE_NAME
189185 ).value
190- except :
186+ except ValueError as err :
191187 raise AquaValueError (
192188 f"Either { FineTuneCustomMetadata .FINE_TUNE_SOURCE } or { FineTuneCustomMetadata .FINE_TUNE_SOURCE_NAME } is missing "
193189 f"from custom metadata for the model { config_source_id } "
194- )
190+ ) from err
195191
196192 # set up env vars
197193 if not env_var :
198- env_var = dict ()
194+ env_var = {}
199195
200196 try :
201197 model_path_prefix = aqua_model .custom_metadata_list .get (
202198 MODEL_BY_REFERENCE_OSS_PATH_KEY
203199 ).value .rstrip ("/" )
204- except ValueError :
200+ except ValueError as err :
205201 raise AquaValueError (
206202 f"{ MODEL_BY_REFERENCE_OSS_PATH_KEY } key is not available in the custom metadata field."
207- )
203+ ) from err
208204
209205 if ObjectStorageDetails .is_oci_path (model_path_prefix ):
210206 os_path = ObjectStorageDetails .from_path (model_path_prefix )
@@ -219,7 +215,7 @@ def create(
219215
220216 if not fine_tune_output_path :
221217 raise AquaValueError (
222- f "Fine tuned output path is not available in the model artifact."
218+ "Fine tuned output path is not available in the model artifact."
223219 )
224220
225221 os_path = ObjectStorageDetails .from_path (fine_tune_output_path )
@@ -232,7 +228,7 @@ def create(
232228 container_type_key = aqua_model .custom_metadata_list .get (
233229 AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME
234230 ).value
235- except ValueError :
231+ except ValueError as err :
236232 message = (
237233 f"{ AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME } key is not available in the custom metadata field "
238234 f"for model { aqua_model .id } ."
@@ -242,7 +238,7 @@ def create(
242238 raise AquaValueError (
243239 f"{ message } . For unverified Aqua models, container_family parameter should be "
244240 f"set and value can be one of { ', ' .join (InferenceContainerTypeFamily .values ())} ."
245- )
241+ ) from err
246242 container_type_key = container_family
247243 try :
248244 # Check if the container override flag is set. If set, then the user has chosen custom image
@@ -282,11 +278,12 @@ def create(
282278 ) # Give precendece to the input parameter
283279
284280 deployment_config = self .get_deployment_config (config_source_id )
285- vllm_params = (
281+
282+ config_params = (
286283 deployment_config .get ("configuration" , UNKNOWN_DICT )
287284 .get (instance_shape , UNKNOWN_DICT )
288285 .get ("parameters" , UNKNOWN_DICT )
289- .get (InferenceContainerParamType . PARAM_TYPE_VLLM , UNKNOWN )
286+ .get (get_container_params_type ( container_type_key ) , UNKNOWN )
290287 )
291288
292289 # validate user provided params
@@ -301,7 +298,7 @@ def create(
301298 f"and cannot be overridden or are invalid."
302299 )
303300
304- deployment_params = get_combined_params (vllm_params , user_params )
301+ deployment_params = get_combined_params (config_params , user_params )
305302
306303 if deployment_params :
307304 params = f"{ params } { deployment_params } "
@@ -429,7 +426,7 @@ def list(self, **kwargs) -> List["AquaDeployment"]:
429426 # tracks unique deployments that were listed in the user compartment
430427 # we arbitrarily choose last 8 characters of OCID to identify MD in telemetry
431428 self .telemetry .record_event_async (
432- category = f "aqua/deployment" ,
429+ category = "aqua/deployment" ,
433430 action = "list" ,
434431 detail = get_ocid_substring (deployment_id , key_len = 8 ),
435432 value = state ,
@@ -574,25 +571,12 @@ def get_deployment_default_params(
574571 container_type_key = container_type_key .lower ()
575572 if container_type_key in InferenceContainerTypeFamily .values ():
576573 deployment_config = self .get_deployment_config (model_id )
577- config_parameters = (
574+ params = (
578575 deployment_config .get ("configuration" , UNKNOWN_DICT )
579576 .get (instance_shape , UNKNOWN_DICT )
580577 .get ("parameters" , UNKNOWN_DICT )
578+ .get (get_container_params_type (container_type_key ))
581579 )
582- if InferenceContainerType .CONTAINER_TYPE_VLLM in container_type_key :
583- params = config_parameters .get (
584- InferenceContainerParamType .PARAM_TYPE_VLLM , UNKNOWN
585- )
586- elif InferenceContainerType .CONTAINER_TYPE_TGI in container_type_key :
587- params = config_parameters .get (
588- InferenceContainerParamType .PARAM_TYPE_TGI , UNKNOWN
589- )
590- else :
591- params = UNKNOWN
592- logger .debug (
593- f"Default inference parameters are not available for the model { model_id } and "
594- f"instance { instance_shape } ."
595- )
596580 if params :
597581 # account for param that can have --arg but no values, e.g. --trust-remote-code
598582 default_params .extend (get_params_list (params ))
@@ -629,7 +613,7 @@ def validate_deployment_params(
629613 container_type_key = model .custom_metadata_list .get (
630614 AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME
631615 ).value
632- except ValueError :
616+ except ValueError as err :
633617 message = (
634618 f"{ AQUA_DEPLOYMENT_CONTAINER_METADATA_NAME } key is not available in the custom metadata field "
635619 f"for model { model_id } ."
@@ -640,7 +624,7 @@ def validate_deployment_params(
640624 raise AquaValueError (
641625 f"{ message } . For unverified Aqua models, container_family parameter should be "
642626 f"set and value can be one of { ', ' .join (InferenceContainerTypeFamily .values ())} ."
643- )
627+ ) from err
644628 container_type_key = container_family
645629
646630 container_config = get_container_config ()
@@ -658,7 +642,7 @@ def validate_deployment_params(
658642 f"Parameters { restricted_params } are set by Aqua "
659643 f"and cannot be overridden or are invalid."
660644 )
661- return dict ( valid = True )
645+ return { " valid" : True }
662646
663647 @staticmethod
664648 def _find_restricted_params (
@@ -689,7 +673,7 @@ def _find_restricted_params(
689673 default_params_dict = get_params_dict (default_params )
690674 user_params_dict = get_params_dict (user_params )
691675
692- for key , items in user_params_dict .items ():
676+ for key , _items in user_params_dict .items ():
693677 if (
694678 key in default_params_dict
695679 or (
@@ -701,6 +685,6 @@ def _find_restricted_params(
701685 and key in TGIInferenceRestrictedParams
702686 )
703687 ):
704- restricted_params .append (key .lstrip ("-- " ))
688+ restricted_params .append (key .lstrip ("-" ))
705689
706690 return restricted_params
0 commit comments