8
8
from typing import Dict , List , Optional , Union
9
9
10
10
from cachetools import TTLCache , cached
11
+ import concurrent
12
+ from ads .common .work_request import DataScienceWorkRequest
11
13
from oci .data_science .models import ModelDeploymentShapeSummary
12
14
from pydantic import ValidationError
13
15
43
45
MODEL_BY_REFERENCE_OSS_PATH_KEY ,
44
46
MODEL_NAME_DELIMITER ,
45
47
UNKNOWN_DICT ,
48
+ DEFAULT_WAIT_TIME ,
49
+ DEFAULT_POLL_INTERVAL
46
50
)
47
51
from ads .aqua .data import AquaResourceIdentifier
48
52
from ads .aqua .model import AquaModelApp
80
84
from ads .model .model_metadata import ModelCustomMetadataItem
81
85
from ads .telemetry import telemetry
82
86
87
+ THREAD_POOL_SIZE = 16
88
+ thread_pool = concurrent .futures .ThreadPoolExecutor (max_workers = THREAD_POOL_SIZE )
89
+
83
90
84
91
class AquaDeploymentApp (AquaApp ):
85
92
"""Provides a suite of APIs to interact with Aqua model deployments within the Oracle
@@ -780,11 +787,18 @@ def _create_deployment(
780
787
.with_runtime (container_runtime )
781
788
).deploy (wait_for_completion = False )
782
789
783
- deployment_id = deployment .id
790
+
791
+
792
+ deployment_id = deployment .id ()
784
793
logger .info (
785
794
f"Aqua model deployment { deployment_id } created for model { aqua_model_id } ."
786
795
)
787
796
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 )
801
+
788
802
# we arbitrarily choose last 8 characters of OCID to identify MD in telemetry
789
803
telemetry_kwargs = {"ocid" : get_ocid_substring (deployment_id , key_len = 8 )}
790
804
@@ -1312,22 +1326,30 @@ def list_shapes(self, **kwargs) -> List[ComputeShapeSummary]:
1312
1326
]
1313
1327
1314
1328
1315
- def get_deployment_status (self ,model_deployment_id : str , work_request_id : str ) :
1316
- # category= "aqua/{model_type}/deployment/status", action= "FAILED/SUCCEEDED", detail="Error message from Work request", value= {"ocid": md_ocid[:8]}
1317
- # # tracks unique evaluation that were created for the given evaluation source
1318
- # self.telemetry.record_event_async(
1319
- # category="aqua/evaluation",
1320
- # action="create",
1321
- # detail=self._get_service_model_name(evaluation_source),
1322
- # )
1323
-
1324
-
1325
- return
1329
+ def get_deployment_status (self ,model_deployment_id : str , work_request_id : str , model_type : str ) :
1330
+
1331
+ telemetry_kwargs = {"ocid" : get_ocid_substring (model_deployment_id , key_len = 8 )}
1326
1332
1327
- def get_deployment_status_async (self ,model_deployment_id : str , work_request_id : str ) :
1328
- # tracks unique evaluation that were created for the given evaluation source
1333
+ try :
1334
+ DataScienceWorkRequest (work_request_id ).wait_work_request (
1335
+ progress_bar_description = "Creating model deployment" ,
1336
+ max_wait_time = DEFAULT_WAIT_TIME ,
1337
+ poll_interval = DEFAULT_POLL_INTERVAL
1338
+ )
1339
+ except Exception as e :
1340
+ logger .error (
1341
+ "Error while trying to create model deployment: " + str (e )
1342
+ )
1343
+ self .telemetry .record_event_async (
1344
+ category = f"aqua/{ model_type } /deployment/status" ,
1345
+ action = "FAILED" ,
1346
+ detail = "Error creating model deployment"
1347
+ ** telemetry_kwargs
1348
+ )
1349
+
1329
1350
self .telemetry .record_event_async (
1330
- category = "aqua/evaluation" ,
1331
- action = "create" ,
1332
- detail = self ._get_service_model_name (evaluation_source ),
1333
- )
1351
+ category = f"aqua/{ model_type } /deployment/status" ,
1352
+ action = "SUCCEEDED" ,
1353
+ detail = " Create model deployment successful" ,
1354
+ ** telemetry_kwargs
1355
+ )
0 commit comments