Skip to content
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

feat: Add prediction container URI builder method #805

Merged
merged 14 commits into from Nov 24, 2021
Merged

Conversation

vinnysenthil
Copy link
Contributor

Implements a prediction container URI helper as described in this doc and b/197875529

@product-auto-label product-auto-label bot added the api: aiplatform Issues related to the AI Platform API. label Oct 29, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Oct 29, 2021
framework: str,
framework_version: str,
region: str = None,
with_accelerator: bool = False,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure about using a flag here, since with PyTorch containers - there are three flavors xla, cpu, and gpu. But as this seems version dependent, the method could handle searching for the correct URI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should accept cpu, gpu for now to make this more extendable if we support other accelerators in the future.

google/cloud/aiplatform/helpers/container_uri_builders.py Outdated Show resolved Hide resolved
google/cloud/aiplatform/helpers/container_uri_builders.py Outdated Show resolved Hide resolved
)

# All Vertex AI Prediction first-party prediction containers as a string
_SERVING_CONTAINER_URIS_STR = " ".join(SERVING_CONTAINER_URIS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like it may be simpler to build a map based on the match which will avoid having to maintain ACCELERATOR_TO_URI_REF, the framework constants, and this string in favor of the map.

Something like:

container_map = defaultdict(lambda: defaultdict(lambda: defaultdict(dict)))
for container_uri in SERVING_CONTAINER_URIS:
  m =  CONTAINER_URI_PATTERN.match(container_uri)
  container_map[m['region']][d['framework']][d['accelerator']][d['version']] = container_uri

The TF2 bookkeeping can be done here as well.

Updating with a new container uri or framework will only require adding to the list.

google/cloud/aiplatform/constants/prediction.py Outdated Show resolved Hide resolved
framework: str,
framework_version: str,
region: str = None,
with_accelerator: bool = False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should accept cpu, gpu for now to make this more extendable if we support other accelerators in the future.

google/cloud/aiplatform/helpers/container_uri_builders.py Outdated Show resolved Hide resolved
google/cloud/aiplatform/helpers/container_uri_builders.py Outdated Show resolved Hide resolved
google/cloud/aiplatform/helpers/container_uri_builders.py Outdated Show resolved Hide resolved
google/cloud/aiplatform/helpers/container_uri_builders.py Outdated Show resolved Hide resolved

__all__ = (value_converter,)
__all__ = ("get_prediction_container_uri" "value_converter",)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
__all__ = ("get_prediction_container_uri" "value_converter",)
__all__ = ("get_prediction_container_uri", "value_converter",)

I'm uncertain of exposing value_converter as well as it's not a module we currently expose or provide documentation/usage on. It mainly used by the enhanced portions of the library.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we potentially move value_converter into aiplatform.utils so that aiplatform.helpers contains only methods intended for external use?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@nicain nicain added the type: process A process-related concern. May include testing, release, or the like. label Nov 9, 2021
@vinnysenthil vinnysenthil changed the title feat: [Work In Progress] Add container URI builder method feat: Add prediction container URI builder method Nov 18, 2021
@vinnysenthil vinnysenthil marked this pull request as ready for review November 22, 2021 18:48
@vinnysenthil vinnysenthil requested a review from a team as a code owner November 22, 2021 18:48
Copy link
Member

@sasha-gitg sasha-gitg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

google/cloud/aiplatform/helpers/container_uri_builders.py Outdated Show resolved Hide resolved
google/cloud/aiplatform/helpers/container_uri_builders.py Outdated Show resolved Hide resolved
f"{DOCS_URI_MESSAGE}"
)

if not URI_MAP[region][framework]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly can use URI_MAP.get(region, {}).get(framework) and the same pattern below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using URI_MAP[region].get(framework) pattern since region is a key that is known to exist at this line.

google/cloud/aiplatform/utils/enhanced_library/__init__.py Outdated Show resolved Hide resolved
@vinnysenthil vinnysenthil requested a review from a team as a code owner November 23, 2021 22:49
@vinnysenthil vinnysenthil requested review from a team and removed request for a team November 23, 2021 22:49
Copy link
Contributor

@leahecole leahecole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that the rest is approved by team members, i'm approving the codeowners change

@vinnysenthil vinnysenthil merged commit 91dd3c0 into main Nov 24, 2021
@vinnysenthil vinnysenthil deleted the container-uri branch November 24, 2021 20:40
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}"
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
I was asked to mark such case as not an error:
#779 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: aiplatform Issues related to the AI Platform API. cla: yes This human has signed the Contributor License Agreement. type: process A process-related concern. May include testing, release, or the like.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants