-
Notifications
You must be signed in to change notification settings - Fork 448
feat: Add prediction container URI builder method #805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b104d63
Initial container URI builder
vinnysenthil b234f78
Merge branch 'main' into container-uri
vinnysenthil 728208e
Merge branch 'main' into container-uri
vinnysenthil dc5647a
Merge branch 'main' into container-uri
vinnysenthil dde6834
Address minor requested changes
vinnysenthil d34ba3d
Move enhanced_library from helpers to utils
vinnysenthil 9c8742a
Update logic of uri helper to use programmatic map
vinnysenthil 2694705
Split aiplatform.constants into multiple modules
vinnysenthil dc60614
Merge branch 'main' into container-uri
vinnysenthil e0ceb80
Add tests for 1P pred container URI helper, fixes
vinnysenthil 3b2acfc
Merge branch 'main' into container-uri
vinnysenthil 123aa2d
Address final requested changes, update OWNERS
vinnysenthil d3c34a7
Merge branch 'main' into container-uri
vinnysenthil d7a3ae9
Add newest prediction containers
vinnysenthil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from google.cloud.aiplatform.constants import base | ||
| from google.cloud.aiplatform.constants import prediction | ||
|
|
||
| __all__ = ("base", "prediction") |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import re | ||
|
|
||
| from collections import defaultdict | ||
|
|
||
| # [region]-docker.pkg.dev/vertex-ai/prediction/[framework]-[accelerator].[version]:latest | ||
| CONTAINER_URI_PATTERN = re.compile( | ||
| r"(?P<region>[\w]+)\-docker\.pkg\.dev\/vertex\-ai\/prediction\/" | ||
| r"(?P<framework>[\w]+)\-(?P<accelerator>[\w]+)\.(?P<version>[\d-]+):latest" | ||
| ) | ||
|
|
||
| SKLEARN = "sklearn" | ||
| TF = "tf" | ||
| TF2 = "tf2" | ||
| XGBOOST = "xgboost" | ||
|
|
||
| XGBOOST_CONTAINER_URIS = [ | ||
| "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-4:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-4:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-4:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-3:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-3:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-3:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-2:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-2:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-2:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-1:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-1:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-1:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-90:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-90:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-90:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-82:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-82:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-82:latest", | ||
| ] | ||
|
|
||
| SKLEARN_CONTAINER_URIS = [ | ||
| "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.1-0:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.1-0:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.1-0:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-24:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-24:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-24:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-23:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-23:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-23:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-22:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-22:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-22:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-20:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-20:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-20:latest", | ||
| ] | ||
|
|
||
| TF_CONTAINER_URIS = [ | ||
|
abcdefgs0324 marked this conversation as resolved.
|
||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-7:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-7:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-7:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-7:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-7:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-7:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-6:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-6:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-6:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-6:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-6:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-6:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-5:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-5:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-5:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-5:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-5:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-5:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-4:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-4:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-4:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-4:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-4:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-4:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-3:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-3:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-3:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-3:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-3:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-3:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-2:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-2:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-2:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-2:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-2:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-2:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-1:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-1:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-1:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf-cpu.1-15:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf-cpu.1-15:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf-cpu.1-15:latest", | ||
| "us-docker.pkg.dev/vertex-ai/prediction/tf-gpu.1-15:latest", | ||
| "europe-docker.pkg.dev/vertex-ai/prediction/tf-gpu.1-15:latest", | ||
| "asia-docker.pkg.dev/vertex-ai/prediction/tf-gpu.1-15:latest", | ||
| ] | ||
|
|
||
| SERVING_CONTAINER_URIS = ( | ||
| SKLEARN_CONTAINER_URIS + TF_CONTAINER_URIS + XGBOOST_CONTAINER_URIS | ||
| ) | ||
|
|
||
| # Map of all first-party prediction containers | ||
| d = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(str)))) | ||
|
|
||
| for container_uri in SERVING_CONTAINER_URIS: | ||
| m = CONTAINER_URI_PATTERN.match(container_uri) | ||
| region, framework, accelerator, version = m[1], m[2], m[3], m[4] | ||
| version = version.replace("-", ".") | ||
|
|
||
| if framework in (TF2, TF): # Store both `tf`, `tf2` as `tensorflow` | ||
| framework = "tensorflow" | ||
|
|
||
| d[region][framework][accelerator][version] = container_uri | ||
|
|
||
| _SERVING_CONTAINER_URI_MAP = d | ||
|
|
||
| _SERVING_CONTAINER_DOCUMENTATION_URL = ( | ||
| "https://cloud.google.com/vertex-ai/docs/predictions/pre-built-containers" | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,21 @@ | ||
| from google.cloud.aiplatform.helpers import value_converter | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| __all__ = (value_converter,) | ||
| from google.cloud.aiplatform.helpers import container_uri_builders | ||
|
|
||
| get_prebuilt_prediction_container_uri = ( | ||
| container_uri_builders.get_prebuilt_prediction_container_uri | ||
| ) | ||
|
|
||
| __all__ = "get_prebuilt_prediction_container_uri" |
109 changes: 109 additions & 0 deletions
109
google/cloud/aiplatform/helpers/container_uri_builders.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from google.cloud.aiplatform.constants import prediction | ||
| from google.cloud.aiplatform import initializer | ||
|
|
||
|
|
||
| def get_prebuilt_prediction_container_uri( | ||
| framework: str, | ||
| framework_version: str, | ||
| region: Optional[str] = None, | ||
| accelerator: str = "cpu", | ||
| ) -> str: | ||
| """ | ||
| Get a Vertex AI pre-built prediction Docker container URI for | ||
| a given framework, version, region, and accelerator use. | ||
|
|
||
| Example usage: | ||
| ``` | ||
| uri = aiplatform.helpers.get_prebuilt_prediction_container_uri( | ||
| framework="tensorflow", | ||
| framework_version="2.6", | ||
| accelerator="gpu" | ||
| ) | ||
|
|
||
| model = aiplatform.Model.upload( | ||
| display_name="boston_housing_", | ||
| artifact_uri="gs://my-bucket/my-model/", | ||
| serving_container_image_uri=uri | ||
| ) | ||
| ``` | ||
|
|
||
| Args: | ||
| framework (str): | ||
| Required. The ML framework of the pre-built container. For example, | ||
| `"tensorflow"`, `"xgboost"`, or `"sklearn"` | ||
| framework_version (str): | ||
| Required. The version of the specified ML framework as a string. | ||
| region (str): | ||
| Optional. AI region or multi-region. Used to select the correct | ||
| Artifact Registry multi-region repository and reduce latency. | ||
| Must start with `"us"`, `"asia"` or `"europe"`. | ||
| Default is location set by `aiplatform.init()`. | ||
| accelerator (str): | ||
| Optional. The type of accelerator support provided by container. For | ||
| example: `"cpu"` or `"gpu"` | ||
| Default is `"cpu"`. | ||
|
|
||
| Returns: | ||
| uri (str): | ||
| A Vertex AI prediction container URI | ||
|
|
||
| Raises: | ||
| ValueError: If containers for provided framework are unavailable or the | ||
| container does not support the specified version, accelerator, or region. | ||
| """ | ||
| URI_MAP = prediction._SERVING_CONTAINER_URI_MAP | ||
| DOCS_URI_MESSAGE = ( | ||
| f"See {prediction._SERVING_CONTAINER_DOCUMENTATION_URL} " | ||
| "for complete list of supported containers" | ||
| ) | ||
|
|
||
| # If region not provided, use initializer location | ||
| region = region or initializer.global_config.location | ||
| region = region.split("-", 1)[0] | ||
| framework = framework.lower() | ||
|
|
||
| if not URI_MAP.get(region): | ||
| raise ValueError( | ||
| f"Unsupported container region `{region}`, supported regions are " | ||
| f"{', '.join(URI_MAP.keys())}. " | ||
| f"{DOCS_URI_MESSAGE}" | ||
| ) | ||
|
|
||
| if not URI_MAP[region].get(framework): | ||
| raise ValueError( | ||
| f"No containers found for framework `{framework}`. Supported frameworks are " | ||
| f"{', '.join(URI_MAP[region].keys())} {DOCS_URI_MESSAGE}" | ||
| ) | ||
|
|
||
| if not URI_MAP[region][framework].get(accelerator): | ||
| raise ValueError( | ||
| f"{framework} containers do not support `{accelerator}` accelerator. Supported accelerators " | ||
| f"are {', '.join(URI_MAP[region][framework].keys())}. {DOCS_URI_MESSAGE}" | ||
| ) | ||
|
|
||
| final_uri = URI_MAP[region][framework][accelerator].get(framework_version) | ||
|
|
||
| if not final_uri: | ||
| raise ValueError( | ||
| f"No serving container for `{framework}` version `{framework_version}` " | ||
| f"with accelerator `{accelerator}` found. Supported versions " | ||
| f"include {', '.join(URI_MAP[region][framework][accelerator].keys())}. {DOCS_URI_MESSAGE}" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code seems to raise error when the user calls the function with version which is already supported by backend, but not yet supported by the installed SDK. |
||
| ) | ||
|
|
||
| return final_uri | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
google/cloud/aiplatform/utils/enhanced_library/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Copyright 2021 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.