8
8
from typing import Dict , List , Optional , Union
9
9
10
10
from cachetools import TTLCache , cached
11
- import concurrent
11
+ from ads .aqua .modeldeployment .constants import DEFAULT_POLL_INTERVAL , DEFAULT_WAIT_TIME
12
+ from ads .common .decorator .threaded import threaded
12
13
from ads .common .work_request import DataScienceWorkRequest
13
14
from oci .data_science .models import ModelDeploymentShapeSummary
14
15
from pydantic import ValidationError
44
45
AQUA_MULTI_MODEL_CONFIG ,
45
46
MODEL_BY_REFERENCE_OSS_PATH_KEY ,
46
47
MODEL_NAME_DELIMITER ,
47
- UNKNOWN_DICT ,
48
- DEFAULT_WAIT_TIME ,
49
- DEFAULT_POLL_INTERVAL
48
+ UNKNOWN_DICT
50
49
)
50
+
51
51
from ads .aqua .data import AquaResourceIdentifier
52
52
from ads .aqua .model import AquaModelApp
53
53
from ads .aqua .model .constants import AquaModelMetadataKeys , ModelCustomMetadataFields
81
81
ModelDeploymentInfrastructure ,
82
82
ModelDeploymentMode ,
83
83
)
84
+
84
85
from ads .model .model_metadata import ModelCustomMetadataItem
85
86
from ads .telemetry import telemetry
86
87
87
- THREAD_POOL_SIZE = 16
88
- thread_pool = concurrent .futures .ThreadPoolExecutor (max_workers = THREAD_POOL_SIZE )
89
-
90
-
91
88
class AquaDeploymentApp (AquaApp ):
92
89
"""Provides a suite of APIs to interact with Aqua model deployments within the Oracle
93
90
Cloud Infrastructure Data Science service, serving as an interface for deploying
@@ -789,15 +786,15 @@ def _create_deployment(
789
786
790
787
791
788
792
- deployment_id = deployment .id ()
789
+ deployment_id = deployment .id
793
790
logger .info (
794
791
f"Aqua model deployment { deployment_id } created for model { aqua_model_id } ."
795
792
)
796
793
797
- thread_pool . submit ( self .get_deployment_status ,
798
- model_deployment_id = deployment_id ,
799
- work_request_id = deployment .dsc_model_deployment .workflow_req_id ,
800
- model_type = model_type )
794
+ self .get_deployment_status (
795
+ model_deployment_id = deployment_id ,
796
+ work_request_id = deployment .dsc_model_deployment .workflow_req_id ,
797
+ model_type = model_type )
801
798
802
799
# we arbitrarily choose last 8 characters of OCID to identify MD in telemetry
803
800
telemetry_kwargs = {"ocid" : get_ocid_substring (deployment_id , key_len = 8 )}
@@ -1325,13 +1322,31 @@ def list_shapes(self, **kwargs) -> List[ComputeShapeSummary]:
1325
1322
for oci_shape in oci_shapes
1326
1323
]
1327
1324
1325
+ @threaded ()
1326
+ def get_deployment_status (self ,model_deployment_id : str , work_request_id : str , model_type : str ) -> None :
1327
+ """Waits for the data science model deployment to be completed and log its status in telemetry.
1328
+
1329
+ Parameters
1330
+ ----------
1328
1331
1329
- def get_deployment_status (self ,model_deployment_id : str , work_request_id : str , model_type : str ) :
1332
+ model_deployment_id: str
1333
+ The id of the deployed aqua model.
1334
+ work_request_id: str
1335
+ The work request Id of the model deployment.
1336
+ model_type: str
1337
+ The type of aqua model to be deployed. Allowed values are: `custom`, `service` and `multi_model`.
1330
1338
1339
+ Returns
1340
+ -------
1341
+ AquaDeployment
1342
+ An Aqua deployment instance.
1343
+ """
1331
1344
telemetry_kwargs = {"ocid" : get_ocid_substring (model_deployment_id , key_len = 8 )}
1345
+
1346
+ data_science_work_request :DataScienceWorkRequest = DataScienceWorkRequest (work_request_id )
1332
1347
1333
1348
try :
1334
- DataScienceWorkRequest ( work_request_id ) .wait_work_request (
1349
+ data_science_work_request .wait_work_request (
1335
1350
progress_bar_description = "Creating model deployment" ,
1336
1351
max_wait_time = DEFAULT_WAIT_TIME ,
1337
1352
poll_interval = DEFAULT_POLL_INTERVAL
@@ -1343,13 +1358,13 @@ def get_deployment_status(self,model_deployment_id: str, work_request_id : str,
1343
1358
self .telemetry .record_event_async (
1344
1359
category = f"aqua/{ model_type } /deployment/status" ,
1345
1360
action = "FAILED" ,
1346
- detail = "Error creating model deployment"
1361
+ detail = data_science_work_request . _error_message
1347
1362
** telemetry_kwargs
1348
1363
)
1364
+ else :
1365
+ self .telemetry .record_event_async (
1366
+ category = f"aqua/{ model_type } /deployment/status" ,
1367
+ action = "SUCCEEDED" ,
1368
+ ** telemetry_kwargs
1369
+ )
1349
1370
1350
- self .telemetry .record_event_async (
1351
- category = f"aqua/{ model_type } /deployment/status" ,
1352
- action = "SUCCEEDED" ,
1353
- detail = " Create model deployment successful" ,
1354
- ** telemetry_kwargs
1355
- )
0 commit comments