45
45
46
46
_TEST_ENDPOINT_NAME = "projects/test-project/locations/us-central1/endpoints/1234567890"
47
47
_TEST_MODEL_NAME = "projects/test-project/locations/us-central1/models/9876543210"
48
+ _TEST_MODEL_CONTAINER_SPEC = types .ModelContainerSpec (
49
+ image_uri = "us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:20241202_0916_RC00" ,
50
+ command = ["python" , "main.py" ],
51
+ args = ["--model-id=gemma-2b" ],
52
+ env = [types .EnvVar (name = "MODEL_ID" , value = "gemma-2b" )],
53
+ ports = [types .Port (container_port = 7080 )],
54
+ grpc_ports = [types .Port (container_port = 7081 )],
55
+ predict_route = "/predictions/v1/predict" ,
56
+ health_route = "/ping" ,
57
+ deployment_timeout = duration_pb2 .Duration (seconds = 1800 ),
58
+ shared_memory_size_mb = 256 ,
59
+ startup_probe = types .Probe (
60
+ exec_ = types .Probe .ExecAction (command = ["python" , "main.py" ]),
61
+ period_seconds = 10 ,
62
+ timeout_seconds = 10 ,
63
+ ),
64
+ health_probe = types .Probe (
65
+ exec_ = types .Probe .ExecAction (command = ["python" , "health_check.py" ]),
66
+ period_seconds = 10 ,
67
+ timeout_seconds = 10 ,
68
+ ),
69
+ )
48
70
49
71
50
72
@pytest .fixture (scope = "module" )
@@ -65,7 +87,7 @@ def deploy_mock():
65
87
"deploy" ,
66
88
) as deploy :
67
89
mock_lro = mock .Mock (ga_operation .Operation )
68
- mock_lro .result .return_value = types .DeployPublisherModelResponse (
90
+ mock_lro .result .return_value = types .DeployResponse (
69
91
endpoint = _TEST_ENDPOINT_NAME ,
70
92
model = _TEST_MODEL_FULL_RESOURCE_NAME ,
71
93
)
@@ -588,6 +610,71 @@ def test_deploy_with_serving_container_image_success(self, deploy_mock):
588
610
)
589
611
590
612
def test_deploy_with_serving_container_spec_success (self , deploy_mock ):
613
+ """Tests deploying a model with serving container spec."""
614
+ aiplatform .init (
615
+ project = _TEST_PROJECT ,
616
+ location = _TEST_LOCATION ,
617
+ )
618
+ model = model_garden .OpenModel (model_name = _TEST_MODEL_FULL_RESOURCE_NAME )
619
+ model .deploy (serving_container_spec = _TEST_MODEL_CONTAINER_SPEC )
620
+ deploy_mock .assert_called_once_with (
621
+ types .DeployRequest (
622
+ publisher_model_name = _TEST_MODEL_FULL_RESOURCE_NAME ,
623
+ destination = f"projects/{ _TEST_PROJECT } /locations/{ _TEST_LOCATION } " ,
624
+ model_config = types .DeployRequest .ModelConfig (
625
+ container_spec = _TEST_MODEL_CONTAINER_SPEC
626
+ ),
627
+ )
628
+ )
629
+
630
+ def test_deploy_with_serving_container_spec_no_image_uri_raises_error (self ):
631
+ """Tests getting the supported deploy options for a model."""
632
+ aiplatform .init (
633
+ project = _TEST_PROJECT ,
634
+ location = _TEST_LOCATION ,
635
+ )
636
+
637
+ expected_message = (
638
+ "Serving container image uri is required for the serving container" " spec."
639
+ )
640
+ with pytest .raises (ValueError ) as exception :
641
+ model = model_garden .OpenModel (model_name = _TEST_MODEL_FULL_RESOURCE_NAME )
642
+ model .deploy (
643
+ serving_container_spec = types .ModelContainerSpec (
644
+ predict_route = "/predictions/v1/predict" ,
645
+ health_route = "/ping" ,
646
+ )
647
+ )
648
+ assert str (exception .value ) == expected_message
649
+
650
+ def test_deploy_with_serving_container_spec_with_both_image_uri_raises_error (
651
+ self ,
652
+ ):
653
+ """Tests getting the supported deploy options for a model."""
654
+ aiplatform .init (
655
+ project = _TEST_PROJECT ,
656
+ location = _TEST_LOCATION ,
657
+ )
658
+
659
+ expected_message = (
660
+ "Serving container image uri is already set in the serving container"
661
+ " spec."
662
+ )
663
+ with pytest .raises (ValueError ) as exception :
664
+ model = model_garden .OpenModel (model_name = _TEST_MODEL_FULL_RESOURCE_NAME )
665
+ model .deploy (
666
+ serving_container_spec = types .ModelContainerSpec (
667
+ image_uri = "us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:20241202_0916_RC00" ,
668
+ predict_route = "/predictions/v1/predict" ,
669
+ health_route = "/ping" ,
670
+ ),
671
+ serving_container_image_uri = "us-docker.pkg.dev/vertex-ai/vertex-vision-model-garden-dockers/pytorch-vllm-serve:20241202_0916_RC00" ,
672
+ )
673
+ assert str (exception .value ) == expected_message
674
+
675
+ def test_deploy_with_serving_container_spec_individual_fields_success (
676
+ self , deploy_mock
677
+ ):
591
678
"""Tests deploying a model with serving container spec."""
592
679
aiplatform .init (
593
680
project = _TEST_PROJECT ,
@@ -665,7 +752,9 @@ def test_list_deploy_options(self, get_publisher_model_mock):
665
752
model .list_deploy_options ()
666
753
get_publisher_model_mock .assert_called_with (
667
754
types .GetPublisherModelRequest (
668
- name = _TEST_MODEL_FULL_RESOURCE_NAME , is_hugging_face_model = False
755
+ name = _TEST_MODEL_FULL_RESOURCE_NAME ,
756
+ is_hugging_face_model = False ,
757
+ include_equivalent_model_garden_model_deployment_configs = True ,
669
758
)
670
759
)
671
760
@@ -697,8 +786,10 @@ def test_list_deployable_models(self, list_publisher_models_mock):
697
786
types .ListPublisherModelsRequest (
698
787
parent = "publishers/*" ,
699
788
list_all_versions = True ,
700
- filter = "is_hf_wildcard(true) AND "
701
- "labels.VERIFIED_DEPLOYMENT_CONFIG=VERIFIED_DEPLOYMENT_SUCCEED" ,
789
+ filter = (
790
+ "is_hf_wildcard(true) AND "
791
+ "labels.VERIFIED_DEPLOYMENT_CONFIG=VERIFIED_DEPLOYMENT_SUCCEED"
792
+ ),
702
793
)
703
794
)
704
795
assert hf_models == [
0 commit comments