Skip to content

Commit d890685

Browse files
samgoodmanSam Goodmangcf-owl-bot[bot]sasha-gitg
authored
feat: Support for Model Versioning (#1438)
* Initial changes for first ModelRegistry design proposal * More changes for design doc * ModelRegistry class implementation * Added method docs * Changes from book doc * training_jobs versioning changes * More models.py changes for versioning * More version arg plumbing * Tests, implementation changes, and assorted tweaks to make GAPIC stuff work * Batch predict versioning, variable name cleanup * Reset training_jobs changes to limit scope * Prediction test fixes * Blackend and lint changes * Training jobs versioning support * Blackend and lint changes * Added TODO for async support * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Override for _construct_sdk_resource_from_gapic * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Fixed _construct_sdk_resource_from_gapic for Model class and gave documentation * Removed errant futuremanager init * Start of new versioning system test * Pass model version on upload cls init * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Fully-fleshed system test for model versioning * Improvements based on system testing * Nox fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Nox fixes * Initial commit for vertexpreviews, with compat changes * Use compat type for DeploymentResourcesType * PR Feedback * Test compat fixes * More v1->v1beta1 shifts * Plumbing model changes through more tests * chore: release 1.13.1 Release-As: 1.13.1 * Nox run * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Training jobs test fixes * Reverted v1beta1 changes * Blacken and lint changes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * PR feedback changes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Revert "🦉 Updates from OwlBot post-processor" This reverts commit 0bff90b. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Revert "🦉 Updates from OwlBot post-processor" This reverts commit c57f305. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Revert "🦉 Updates from OwlBot post-processor" This reverts commit ee5ff17. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix: Prevent owlbot from re-adding 3.6 dependencies * Test fixes * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * nox blacken * Test fixes for 3.6 compat * Test fix for 3.6 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Quitting the fight against nox * Test fixes for python 3.7 * System test cleanup * retrigger checks * Update google/cloud/aiplatform/models.py Missing '.' Co-authored-by: sasha-gitg <[email protected]> * Update google/cloud/aiplatform/models.py Another missing '.' Co-authored-by: sasha-gitg <[email protected]> * Update google/cloud/aiplatform/models.py Missing return type Co-authored-by: sasha-gitg <[email protected]> * Update google/cloud/aiplatform/models.py Co-authored-by: sasha-gitg <[email protected]> * PR feedback changes * Pass location, project, creds to Model Registry * Credential fix when getting model from registry * Copyright update * Fixed issue with Model update trying to update a version, rather than the base model * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Revert "fix: Prevent owlbot from re-adding 3.6 dependencies" This reverts commit 4322fe2. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * Nox blacken * Revert "🦉 Updates from OwlBot post-processor" This reverts commit fe5a27b. * Fighting with owlbot * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Sam Goodman <[email protected]> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: sasha-gitg <[email protected]>
1 parent 425a32f commit d890685

17 files changed

+2395
-110
lines changed

google/cloud/aiplatform/base.py

+19
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import functools
2222
import inspect
2323
import logging
24+
import re
2425
import sys
2526
import threading
2627
import time
@@ -454,6 +455,24 @@ def _format_resource_name_method(self) -> str:
454455
# to use custom resource id validators per resource
455456
_resource_id_validator: Optional[Callable[[str], None]] = None
456457

458+
@staticmethod
459+
def _revisioned_resource_id_validator(
460+
resource_id: str,
461+
) -> None:
462+
"""Some revisioned resource names can have '@' in them
463+
to separate the resource ID from the revision ID.
464+
Thus, they need their own resource id validator.
465+
See https://google.aip.dev/162
466+
467+
Args:
468+
resource_id(str): A resource ID for a resource type that accepts revision syntax.
469+
See https://google.aip.dev/162.
470+
Raises:
471+
ValueError: If a `resource_id` doesn't conform to appropriate revision syntax.
472+
"""
473+
if not re.compile(r"^[\w-]+@?[\w-]+$").match(resource_id):
474+
raise ValueError(f"Resource {resource_id} is not a valid resource ID.")
475+
457476
def __init__(
458477
self,
459478
project: Optional[str] = None,

google/cloud/aiplatform/jobs.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ def create(
392392
Required. A fully-qualified model resource name or model ID.
393393
Example: "projects/123/locations/us-central1/models/456" or
394394
"456" when project and location are initialized or passed.
395+
May optionally contain a version ID or alias in
396+
{model_name}@{version} form.
395397
396398
Or an instance of aiplatform.Model.
397399
instances_format (str):
@@ -564,6 +566,7 @@ def create(
564566
format_resource_name_method=aiplatform.Model._format_resource_name,
565567
project=project,
566568
location=location,
569+
resource_id_validator=super()._revisioned_resource_id_validator,
567570
)
568571

569572
# Raise error if both or neither source URIs are provided
@@ -713,7 +716,9 @@ def _create(
713716
Required. BatchPredictionJob without _gca_resource populated.
714717
model_or_model_name (Union[str, aiplatform.Model]):
715718
Required. Required. A fully-qualified model resource name or
716-
an instance of aiplatform.Model.
719+
an instance of aiplatform.Model. If a resource name, it may
720+
optionally contain a version ID or alias in
721+
{model_name}@{version} form.
717722
gca_batch_prediction_job (gca_bp_job.BatchPredictionJob):
718723
Required. a batch prediction job proto for creating a batch prediction job on Vertex AI.
719724
generate_explanation (bool):
@@ -731,7 +736,6 @@ def _create(
731736
provided instances_format or predictions_format are not supported
732737
by Vertex AI.
733738
"""
734-
# select v1beta1 if explain else use default v1
735739

736740
parent = initializer.global_config.common_location_path(
737741
project=empty_batch_prediction_job.project,
@@ -741,7 +745,7 @@ def _create(
741745
model_resource_name = (
742746
model_or_model_name
743747
if isinstance(model_or_model_name, str)
744-
else model_or_model_name.resource_name
748+
else model_or_model_name.versioned_resource_name
745749
)
746750

747751
gca_batch_prediction_job.model = model_resource_name

0 commit comments

Comments
 (0)