Skip to content

Commit 6a00ed7

Browse files
vertex-sdk-botcopybara-github
authored andcommitted
feat: adding serving_container_grpc_ports parameter to Model.upload() method
PiperOrigin-RevId: 590350209
1 parent 4347c9c commit 6a00ed7

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

google/cloud/aiplatform/models.py

+16
Original file line numberDiff line numberDiff line change
@@ -2977,6 +2977,7 @@ def upload(
29772977
serving_container_args: Optional[Sequence[str]] = None,
29782978
serving_container_environment_variables: Optional[Dict[str, str]] = None,
29792979
serving_container_ports: Optional[Sequence[int]] = None,
2980+
serving_container_grpc_ports: Optional[Sequence[int]] = None,
29802981
local_model: Optional["LocalModel"] = None,
29812982
instance_schema_uri: Optional[str] = None,
29822983
parameters_schema_uri: Optional[str] = None,
@@ -3083,6 +3084,14 @@ def upload(
30833084
no impact on whether the port is actually exposed, any port listening on
30843085
the default "0.0.0.0" address inside a container will be accessible from
30853086
the network.
3087+
serving_container_grpc_ports: Optional[Sequence[int]]=None,
3088+
Declaration of ports that are exposed by the container. Vertex AI sends gRPC
3089+
prediction requests that it receives to the first port on this list. Vertex
3090+
AI also sends liveness and health checks to this port.
3091+
If you do not specify this field, gRPC requests to the container will be
3092+
disabled.
3093+
Vertex AI does not use ports other than the first one listed. This field
3094+
corresponds to the `ports` field of the Kubernetes Containers v1 core API.
30863095
local_model (Optional[LocalModel]):
30873096
Optional. A LocalModel instance that includes a `serving_container_spec`.
30883097
If provided, the `serving_container_spec` of the LocalModel instance
@@ -3238,6 +3247,7 @@ def upload(
32383247

32393248
env = None
32403249
ports = None
3250+
grpc_ports = None
32413251
deployment_timeout = (
32423252
duration_pb2.Duration(seconds=serving_container_deployment_timeout)
32433253
if serving_container_deployment_timeout
@@ -3256,6 +3266,11 @@ def upload(
32563266
gca_model_compat.Port(container_port=port)
32573267
for port in serving_container_ports
32583268
]
3269+
if serving_container_grpc_ports:
3270+
grpc_ports = [
3271+
gca_model_compat.Port(container_port=port)
3272+
for port in serving_container_grpc_ports
3273+
]
32593274
if (
32603275
serving_container_startup_probe_exec
32613276
or serving_container_startup_probe_period_seconds
@@ -3293,6 +3308,7 @@ def upload(
32933308
args=serving_container_args,
32943309
env=env,
32953310
ports=ports,
3311+
grpc_ports=grpc_ports,
32963312
predict_route=serving_container_predict_route,
32973313
health_route=serving_container_health_route,
32983314
deployment_timeout=deployment_timeout,

google/cloud/aiplatform/prediction/local_model.py

+16
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def __init__(
6060
serving_container_args: Optional[Sequence[str]] = None,
6161
serving_container_environment_variables: Optional[Dict[str, str]] = None,
6262
serving_container_ports: Optional[Sequence[int]] = None,
63+
serving_container_grpc_ports: Optional[Sequence[int]] = None,
6364
serving_container_deployment_timeout: Optional[int] = None,
6465
serving_container_shared_memory_size_mb: Optional[int] = None,
6566
serving_container_startup_probe_exec: Optional[Sequence[str]] = None,
@@ -110,6 +111,14 @@ def __init__(
110111
no impact on whether the port is actually exposed, any port listening on
111112
the default "0.0.0.0" address inside a container will be accessible from
112113
the network.
114+
serving_container_grpc_ports: Optional[Sequence[int]]=None,
115+
Declaration of ports that are exposed by the container. Vertex AI sends gRPC
116+
prediction requests that it receives to the first port on this list. Vertex
117+
AI also sends liveness and health checks to this port.
118+
If you do not specify this field, gRPC requests to the container will be
119+
disabled.
120+
Vertex AI does not use ports other than the first one listed. This field
121+
corresponds to the `ports` field of the Kubernetes Containers v1 core API.
113122
serving_container_deployment_timeout (int):
114123
Optional. Deployment timeout in seconds.
115124
serving_container_shared_memory_size_mb (int):
@@ -156,6 +165,7 @@ def __init__(
156165

157166
env = None
158167
ports = None
168+
grpc_ports = None
159169
deployment_timeout = (
160170
duration_pb2.Duration(seconds=serving_container_deployment_timeout)
161171
if serving_container_deployment_timeout
@@ -174,6 +184,11 @@ def __init__(
174184
gca_model_compat.Port(container_port=port)
175185
for port in serving_container_ports
176186
]
187+
if serving_container_grpc_ports:
188+
grpc_ports = [
189+
gca_model_compat.Port(container_port=port)
190+
for port in serving_container_grpc_ports
191+
]
177192
if (
178193
serving_container_startup_probe_exec
179194
or serving_container_startup_probe_period_seconds
@@ -211,6 +226,7 @@ def __init__(
211226
args=serving_container_args,
212227
env=env,
213228
ports=ports,
229+
grpc_ports=grpc_ports,
214230
predict_route=serving_container_predict_route,
215231
health_route=serving_container_health_route,
216232
deployment_timeout=deployment_timeout,

tests/unit/aiplatform/test_models.py

+8
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
"loss_fn": "mse",
114114
}
115115
_TEST_SERVING_CONTAINER_PORTS = [8888, 10000]
116+
_TEST_SERVING_CONTAINER_GRPC_PORTS = [7777, 7000]
116117
_TEST_SERVING_CONTAINER_DEPLOYMENT_TIMEOUT = 100
117118
_TEST_SERVING_CONTAINER_SHARED_MEMORY_SIZE_MB = 1000
118119
_TEST_SERVING_CONTAINER_STARTUP_PROBE_EXEC = ["a", "b"]
@@ -1606,6 +1607,7 @@ def test_upload_uploads_and_gets_model_with_all_args(
16061607
serving_container_args=_TEST_SERVING_CONTAINER_ARGS,
16071608
serving_container_environment_variables=_TEST_SERVING_CONTAINER_ENVIRONMENT_VARIABLES,
16081609
serving_container_ports=_TEST_SERVING_CONTAINER_PORTS,
1610+
serving_container_grpc_ports=_TEST_SERVING_CONTAINER_GRPC_PORTS,
16091611
explanation_metadata=_TEST_EXPLANATION_METADATA,
16101612
explanation_parameters=_TEST_EXPLANATION_PARAMETERS,
16111613
labels=_TEST_LABEL,
@@ -1634,6 +1636,11 @@ def test_upload_uploads_and_gets_model_with_all_args(
16341636
for port in _TEST_SERVING_CONTAINER_PORTS
16351637
]
16361638

1639+
grpc_ports = [
1640+
gca_model.Port(container_port=port)
1641+
for port in _TEST_SERVING_CONTAINER_GRPC_PORTS
1642+
]
1643+
16371644
deployment_timeout = duration_pb2.Duration(
16381645
seconds=_TEST_SERVING_CONTAINER_DEPLOYMENT_TIMEOUT
16391646
)
@@ -1662,6 +1669,7 @@ def test_upload_uploads_and_gets_model_with_all_args(
16621669
args=_TEST_SERVING_CONTAINER_ARGS,
16631670
env=env,
16641671
ports=ports,
1672+
grpc_ports=grpc_ports,
16651673
deployment_timeout=deployment_timeout,
16661674
shared_memory_size_mb=_TEST_SERVING_CONTAINER_SHARED_MEMORY_SIZE_MB,
16671675
startup_probe=startup_probe,

tests/unit/aiplatform/test_prediction.py

+25
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
"loss_fn": "mse",
112112
}
113113
_TEST_SERVING_CONTAINER_PORTS = [8888, 10000]
114+
_TEST_SERVING_CONTAINER_GRPC_PORTS = [7777, 7000]
114115
_TEST_ID = "1028944691210842416"
115116
_TEST_LABEL = {"team": "experimentation", "trial_id": "x435"}
116117
_TEST_APPENDED_USER_AGENT = ["fake_user_agent"]
@@ -1112,6 +1113,10 @@ def test_init_with_serving_container_spec(self):
11121113
gca_model_compat.Port(container_port=port)
11131114
for port in _TEST_SERVING_CONTAINER_PORTS
11141115
]
1116+
grpc_ports = [
1117+
gca_model_compat.Port(container_port=port)
1118+
for port in _TEST_SERVING_CONTAINER_GRPC_PORTS
1119+
]
11151120
container_spec = gca_model_compat.ModelContainerSpec(
11161121
image_uri=_TEST_SERVING_CONTAINER_IMAGE,
11171122
predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE,
@@ -1120,6 +1125,7 @@ def test_init_with_serving_container_spec(self):
11201125
args=_TEST_SERVING_CONTAINER_ARGS,
11211126
env=env,
11221127
ports=ports,
1128+
grpc_ports=grpc_ports,
11231129
)
11241130

11251131
local_model = LocalModel(
@@ -1139,6 +1145,9 @@ def test_init_with_serving_container_spec(self):
11391145
assert local_model.serving_container_spec.args == container_spec.args
11401146
assert local_model.serving_container_spec.env == container_spec.env
11411147
assert local_model.serving_container_spec.ports == container_spec.ports
1148+
assert (
1149+
local_model.serving_container_spec.grpc_ports == container_spec.grpc_ports
1150+
)
11421151

11431152
def test_init_with_serving_container_spec_but_not_image_uri_throws_exception(self):
11441153
env = [
@@ -1149,13 +1158,18 @@ def test_init_with_serving_container_spec_but_not_image_uri_throws_exception(sel
11491158
gca_model_compat.Port(container_port=port)
11501159
for port in _TEST_SERVING_CONTAINER_PORTS
11511160
]
1161+
grpc_ports = [
1162+
gca_model_compat.Port(container_port=port)
1163+
for port in _TEST_SERVING_CONTAINER_GRPC_PORTS
1164+
]
11521165
container_spec = gca_model_compat.ModelContainerSpec(
11531166
predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE,
11541167
health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE,
11551168
command=_TEST_SERVING_CONTAINER_COMMAND,
11561169
args=_TEST_SERVING_CONTAINER_ARGS,
11571170
env=env,
11581171
ports=ports,
1172+
grpc_ports=grpc_ports,
11591173
)
11601174
expected_message = "Image uri is required for the serving container spec to initialize a LocalModel instance."
11611175

@@ -1175,6 +1189,7 @@ def test_init_with_separate_args(self):
11751189
serving_container_args=_TEST_SERVING_CONTAINER_ARGS,
11761190
serving_container_environment_variables=_TEST_SERVING_CONTAINER_ENVIRONMENT_VARIABLES,
11771191
serving_container_ports=_TEST_SERVING_CONTAINER_PORTS,
1192+
serving_container_grpc_ports=_TEST_SERVING_CONTAINER_GRPC_PORTS,
11781193
)
11791194

11801195
env = [
@@ -1187,6 +1202,11 @@ def test_init_with_separate_args(self):
11871202
for port in _TEST_SERVING_CONTAINER_PORTS
11881203
]
11891204

1205+
grpc_ports = [
1206+
gca_model_compat.Port(container_port=port)
1207+
for port in _TEST_SERVING_CONTAINER_GRPC_PORTS
1208+
]
1209+
11901210
container_spec = gca_model_compat.ModelContainerSpec(
11911211
image_uri=_TEST_SERVING_CONTAINER_IMAGE,
11921212
predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE,
@@ -1195,6 +1215,7 @@ def test_init_with_separate_args(self):
11951215
args=_TEST_SERVING_CONTAINER_ARGS,
11961216
env=env,
11971217
ports=ports,
1218+
grpc_ports=grpc_ports,
11981219
)
11991220

12001221
assert local_model.serving_container_spec.image_uri == container_spec.image_uri
@@ -1210,6 +1231,9 @@ def test_init_with_separate_args(self):
12101231
assert local_model.serving_container_spec.args == container_spec.args
12111232
assert local_model.serving_container_spec.env == container_spec.env
12121233
assert local_model.serving_container_spec.ports == container_spec.ports
1234+
assert (
1235+
local_model.serving_container_spec.grpc_ports == container_spec.grpc_ports
1236+
)
12131237

12141238
def test_init_with_separate_args_but_not_image_uri_throws_exception(self):
12151239
expected_message = "Serving container image uri is required to initialize a LocalModel instance."
@@ -1222,6 +1246,7 @@ def test_init_with_separate_args_but_not_image_uri_throws_exception(self):
12221246
serving_container_args=_TEST_SERVING_CONTAINER_ARGS,
12231247
serving_container_environment_variables=_TEST_SERVING_CONTAINER_ENVIRONMENT_VARIABLES,
12241248
serving_container_ports=_TEST_SERVING_CONTAINER_PORTS,
1249+
serving_container_grpc_ports=_TEST_SERVING_CONTAINER_GRPC_PORTS,
12251250
)
12261251

12271252
assert str(exception.value) == expected_message

0 commit comments

Comments
 (0)