@@ -171,6 +171,78 @@ class TestDataset:
171171 }
172172 ]
173173
174+ model_deployment_object_tei_byoc = [
175+ {
176+ "category_log_details" : oci .data_science .models .CategoryLogDetails (
177+ ** {
178+ "access" : oci .data_science .models .LogDetails (
179+ ** {
180+ "log_group_id" : "ocid1.loggroup.oc1.<region>.<OCID>" ,
181+ "log_id" : "ocid1.log.oc1.<region>.<OCID>" ,
182+ }
183+ ),
184+ "predict" : oci .data_science .models .LogDetails (
185+ ** {
186+ "log_group_id" : "ocid1.loggroup.oc1.<region>.<OCID>" ,
187+ "log_id" : "ocid1.log.oc1.<region>.<OCID>" ,
188+ }
189+ ),
190+ }
191+ ),
192+ "compartment_id" : "ocid1.compartment.oc1..<OCID>" ,
193+ "created_by" : "ocid1.user.oc1..<OCID>" ,
194+ "defined_tags" : {},
195+ "description" : "Mock description" ,
196+ "display_name" : "model-deployment-name" ,
197+ "freeform_tags" : {"OCI_AQUA" : "active" , "aqua_model_name" : "model-name" },
198+ "id" : "ocid1.datasciencemodeldeployment.oc1.<region>.<MD_OCID>" ,
199+ "lifecycle_state" : "ACTIVE" ,
200+ "model_deployment_configuration_details" : oci .data_science .models .SingleModelDeploymentConfigurationDetails (
201+ ** {
202+ "deployment_type" : "SINGLE_MODEL" ,
203+ "environment_configuration_details" : oci .data_science .models .OcirModelDeploymentEnvironmentConfigurationDetails (
204+ ** {
205+ "cmd" : [
206+ "--model-id" ,
207+ "/opt/ds/model/deployed_model/service_models/model-name/artifact/" ,
208+ "--port" ,
209+ "8080" ,
210+ ],
211+ "entrypoint" : [],
212+ "environment_configuration_type" : "OCIR_CONTAINER" ,
213+ "environment_variables" : {
214+ "BASE_MODEL" : "service_models/model-name/artifact" ,
215+ "MODEL_DEPLOY_PREDICT_ENDPOINT" : "/v1/embeddings" ,
216+ },
217+ "health_check_port" : 8080 ,
218+ "image" : "dsmc://image-name:1.0.0.0" ,
219+ "image_digest" : "sha256:mock22373c16f2015f6f33c5c8553923cf8520217da0bd9504471c5e53cbc9d" ,
220+ "server_port" : 8080 ,
221+ }
222+ ),
223+ "model_configuration_details" : oci .data_science .models .ModelConfigurationDetails (
224+ ** {
225+ "bandwidth_mbps" : 10 ,
226+ "instance_configuration" : oci .data_science .models .InstanceConfiguration (
227+ ** {
228+ "instance_shape_name" : DEPLOYMENT_SHAPE_NAME ,
229+ "model_deployment_instance_shape_config_details" : null ,
230+ }
231+ ),
232+ "model_id" : "ocid1.datasciencemodel.oc1.<region>.<OCID>" ,
233+ "scaling_policy" : oci .data_science .models .FixedSizeScalingPolicy (
234+ ** {"instance_count" : 1 , "policy_type" : "FIXED_SIZE" }
235+ ),
236+ }
237+ ),
238+ }
239+ ),
240+ "model_deployment_url" : MODEL_DEPLOYMENT_URL ,
241+ "project_id" : "ocid1.datascienceproject.oc1.<region>.<OCID>" ,
242+ "time_created" : "2024-01-01T00:00:00.000000+00:00" ,
243+ }
244+ ]
245+
174246 aqua_deployment_object = {
175247 "id" : "ocid1.datasciencemodeldeployment.oc1.<region>.<MD_OCID>" ,
176248 "display_name" : "model-deployment-name" ,
@@ -237,6 +309,25 @@ class TestDataset:
237309 "top_k" : 10 ,
238310 }
239311
312+ aqua_deployment_tei_byoc_embeddings_env_vars = {
313+ "BASE_MODEL" : "service_models/model-name/artifact" ,
314+ "MODEL_DEPLOY_PREDICT_ENDPOINT" : "/v1/embeddings" ,
315+ }
316+
317+ aqua_deployment_tei_byoc_embeddings_shape_info = {
318+ "instance_shape" : DEPLOYMENT_SHAPE_NAME ,
319+ "instance_count" : 1 ,
320+ "ocpus" : None ,
321+ "memory_in_gbs" : None ,
322+ }
323+
324+ aqua_deployment_tei_byoc_embeddings_cmd = [
325+ "--model-id" ,
326+ "/opt/ds/model/deployed_model/service_models/model-name/artifact/" ,
327+ "--port" ,
328+ "8080" ,
329+ ]
330+
240331
241332class TestAquaDeployment (unittest .TestCase ):
242333 def setUp (self ):
@@ -489,6 +580,84 @@ def test_create_deployment_for_fine_tuned_model(
489580 expected_result ["state" ] = "CREATING"
490581 assert actual_attributes == expected_result
491582
583+ @patch ("ads.aqua.modeldeployment.deployment.get_container_config" )
584+ @patch ("ads.aqua.model.AquaModelApp.create" )
585+ @patch ("ads.aqua.modeldeployment.deployment.get_container_image" )
586+ @patch ("ads.model.deployment.model_deployment.ModelDeployment.deploy" )
587+ def test_create_deployment_for_tei_byoc_embedding_model (
588+ self ,
589+ mock_deploy ,
590+ mock_get_container_image ,
591+ mock_create ,
592+ mock_get_container_config ,
593+ ):
594+ """Test to create a deployment for fine-tuned model"""
595+ aqua_model = os .path .join (
596+ self .curr_dir , "test_data/deployment/aqua_tei_byoc_embedding_model.yaml"
597+ )
598+ datascience_model = DataScienceModel .from_yaml (uri = aqua_model )
599+ mock_create .return_value = datascience_model
600+
601+ config_json = os .path .join (
602+ self .curr_dir , "test_data/deployment/deployment_config.json"
603+ )
604+ with open (config_json , "r" ) as _file :
605+ config = json .load (_file )
606+
607+ self .app .get_deployment_config = MagicMock (return_value = config )
608+
609+ container_index_json = os .path .join (
610+ self .curr_dir , "test_data/ui/container_index.json"
611+ )
612+ with open (container_index_json , "r" ) as _file :
613+ container_index_config = json .load (_file )
614+ mock_get_container_config .return_value = container_index_config
615+
616+ mock_get_container_image .return_value = TestDataset .DEPLOYMENT_IMAGE_NAME
617+ aqua_deployment = os .path .join (
618+ self .curr_dir , "test_data/deployment/aqua_create_embedding_deployment.yaml"
619+ )
620+ model_deployment_obj = ModelDeployment .from_yaml (uri = aqua_deployment )
621+ model_deployment_dsc_obj = copy .deepcopy (
622+ TestDataset .model_deployment_object_tei_byoc [0 ]
623+ )
624+ model_deployment_dsc_obj ["lifecycle_state" ] = "CREATING"
625+ model_deployment_obj .dsc_model_deployment = (
626+ oci .data_science .models .ModelDeploymentSummary (** model_deployment_dsc_obj )
627+ )
628+ mock_deploy .return_value = model_deployment_obj
629+
630+ result = self .app .create (
631+ model_id = TestDataset .MODEL_ID ,
632+ instance_shape = TestDataset .DEPLOYMENT_SHAPE_NAME ,
633+ display_name = "model-deployment-name" ,
634+ log_group_id = "ocid1.loggroup.oc1.<region>.<OCID>" ,
635+ access_log_id = "ocid1.log.oc1.<region>.<OCID>" ,
636+ predict_log_id = "ocid1.log.oc1.<region>.<OCID>" ,
637+ container_family = "odsc-tei-serving" ,
638+ cmd_var = [],
639+ )
640+
641+ mock_create .assert_called_with (
642+ model_id = TestDataset .MODEL_ID , compartment_id = None , project_id = None
643+ )
644+ mock_get_container_image .assert_called ()
645+ mock_deploy .assert_called ()
646+
647+ expected_attributes = set (AquaDeployment .__annotations__ .keys ())
648+ actual_attributes = asdict (result )
649+ assert set (actual_attributes ) == set (expected_attributes ), "Attributes mismatch"
650+ expected_result = copy .deepcopy (TestDataset .aqua_deployment_object )
651+ expected_result ["state" ] = "CREATING"
652+ expected_result ["shape_info" ] = (
653+ TestDataset .aqua_deployment_tei_byoc_embeddings_shape_info
654+ )
655+ expected_result ["cmd" ] = TestDataset .aqua_deployment_tei_byoc_embeddings_cmd
656+ expected_result ["environment_variables" ] = (
657+ TestDataset .aqua_deployment_tei_byoc_embeddings_env_vars
658+ )
659+ assert actual_attributes == expected_result
660+
492661 @patch ("ads.aqua.modeldeployment.deployment.get_container_config" )
493662 @patch ("ads.aqua.model.AquaModelApp.create" )
494663 @patch ("ads.aqua.modeldeployment.deployment.get_container_image" )
0 commit comments