Skip to content

Commit 34bbd0a

Browse files
authored
feature: Vertex AI Prediction Custom Prediction Routine (#1535)
* feature: Vertex AI Prediction Custom Prediction Routine * chore: Changed SDK requirement for CPR to main pypi package
1 parent c0d01f1 commit 34bbd0a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+8522
-32
lines changed

.kokoro/presubmit/system.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ env_vars: {
1111
key: "PYTEST_ADDOPTS"
1212
value: "-n=auto --dist=loadscope"
1313
}
14+
15+
# Kokoro VM timeout of 5 hours for system tests
16+
timeout_mins: 300

google/cloud/aiplatform/base.py

+5
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ def _instantiate_client(
506506
cls,
507507
location: Optional[str] = None,
508508
credentials: Optional[auth_credentials.Credentials] = None,
509+
appended_user_agent: Optional[List[str]] = None,
509510
) -> utils.VertexAiServiceClientWithOverride:
510511
"""Helper method to instantiate service client for resource noun.
511512
@@ -514,6 +515,9 @@ def _instantiate_client(
514515
credentials (google.auth.credentials.Credentials):
515516
Optional custom credentials to use when accessing interacting with
516517
resource noun.
518+
appended_user_agent (List[str]):
519+
Optional. User agent appended in the client info. If more than one,
520+
it will be separated by spaces.
517521
Returns:
518522
client (utils.VertexAiServiceClientWithOverride):
519523
Initialized service client for this service noun with optional overrides.
@@ -522,6 +526,7 @@ def _instantiate_client(
522526
client_class=cls.client_class,
523527
credentials=credentials,
524528
location_override=location,
529+
appended_user_agent=appended_user_agent,
525530
)
526531

527532
@classmethod

google/cloud/aiplatform/constants/prediction.py

+33
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
r"(?P<framework>[\w]+)\-(?P<accelerator>[\w]+)\.(?P<version>[\d-]+):latest"
2323
)
2424

25+
CONTAINER_URI_REGEX = (
26+
r"^(us|europe|asia)-docker.pkg.dev/"
27+
r"vertex-ai/prediction/"
28+
r"(tf|sklearn|xgboost).+$"
29+
)
30+
2531
SKLEARN = "sklearn"
2632
TF = "tf"
2733
TF2 = "tf2"
@@ -145,3 +151,30 @@
145151
_SERVING_CONTAINER_DOCUMENTATION_URL = (
146152
"https://cloud.google.com/vertex-ai/docs/predictions/pre-built-containers"
147153
)
154+
155+
# Variables set by Vertex AI. For more details, please refer to
156+
# https://cloud.google.com/vertex-ai/docs/predictions/custom-container-requirements#aip-variables
157+
DEFAULT_AIP_HTTP_PORT = 8080
158+
AIP_HTTP_PORT = "AIP_HTTP_PORT"
159+
AIP_HEALTH_ROUTE = "AIP_HEALTH_ROUTE"
160+
AIP_PREDICT_ROUTE = "AIP_PREDICT_ROUTE"
161+
AIP_STORAGE_URI = "AIP_STORAGE_URI"
162+
163+
# Default values for Prediction local experience.
164+
DEFAULT_LOCAL_PREDICT_ROUTE = "/predict"
165+
DEFAULT_LOCAL_HEALTH_ROUTE = "/health"
166+
DEFAULT_LOCAL_RUN_GPU_CAPABILITIES = [["utility", "compute"]]
167+
DEFAULT_LOCAL_RUN_GPU_COUNT = -1
168+
169+
CUSTOM_PREDICTION_ROUTINES = "custom-prediction-routines"
170+
171+
# Headers' related constants for the handler usage.
172+
CONTENT_TYPE_HEADER_REGEX = re.compile("^[Cc]ontent-?[Tt]ype$")
173+
ACCEPT_HEADER_REGEX = re.compile("^[Aa]ccept$")
174+
ANY_ACCEPT_TYPE = "*/*"
175+
DEFAULT_ACCEPT_VALUE = "application/json"
176+
177+
# Model filenames.
178+
MODEL_FILENAME_BST = "model.bst"
179+
MODEL_FILENAME_JOBLIB = "model.joblib"
180+
MODEL_FILENAME_PKL = "model.pkl"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2022 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#

0 commit comments

Comments
 (0)