-
Notifications
You must be signed in to change notification settings - Fork 449
feat: Vertex Vizier support in SDK. #1434
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
66 commits
Select commit
Hold shift + click to select a range
1be4dfa
Added the Vizier client in the aiplatform folder.
halio-g 7e9e933
Merge branch 'main' of https://github.com/halio-g/python-aiplatform
halio-g 8a83967
Merge branch 'googleapis:main' into main
halio-g 3efab09
Copied the pyvizier from the open source vizier.
halio-g 2934491
Merge branch 'googleapis:main' into main
halio-g f58f5a2
Added the Trial in the aiplatform folder.
halio-g dfeaa67
Merge remote-tracking branch 'upstream/main'
halio-g 6336040
Merge branch 'main' of https://github.com/halio-g/python-aiplatform
halio-g 9524e9a
Forked the pyvizier from the pyVizier.
halio-g 46cbe4a
imported the objects from the pyvizier.
halio-g 8122807
Added the Vizier client and types in the aiplatform init file.
halio-g bb7c731
Made the pyvizier converters compatible with the Vertex SDK proto.
halio-g 24425ae
Forked the framework for the Vertex Vizier from the Open Source Vizier.
halio-g 6f24f9f
Implemented the interfaces for Study and Trial. Added the unit tests …
halio-g c188ed7
Merge branch 'googleapis:main' into main
halio-g ca96954
Merge remote-tracking branch 'upstream/main'
halio-g 3ac5758
Merge branch 'main' of https://github.com/halio-g/python-aiplatform
halio-g 62ac4d7
Setup the dependencies for the Vizier.
halio-g 101fc60
Fix the lint error by running the nox -s blacken.
halio-g ede8356
Fixed the lint errors for the Vizier.
halio-g f414c0f
Made the unit test import the google credentials.
halio-g eb71423
Merge branch 'googleapis:main' into main
halio-g 1929caf
Merge branch 'googleapis:main' into main
halio-g 6dc42e7
Disable the coverage check for the pyvizier. It will be imported from…
halio-g cf8b213
Remove the converage dependency to avoid the conflicts.
halio-g 73fd1f0
Merge branch 'googleapis:main' into main
halio-g 60a8653
Fixing the py-3.9 issue in the sample/module-builder
halio-g 35e8799
Convert the lambda function to avoid the import numpy be called in th…
halio-g 38b55e0
Revert the requirements file.
halio-g d681cea
Fix the lint error by running the nox -s blacken.
halio-g 603bfa5
Merge branch 'main' into main
halio-g 5644f96
Fixed the syntax issue in the setup.py
halio-g 42fdc02
Merge branch 'main' into main
halio-g e0d82f2
Merge branch 'googleapis:main' into main
halio-g 317a0d6
Setup the local package
halio-g 24098dd
scrube the TODO since it's the documentation ticket.
halio-g 10d3b52
Merge branch 'googleapis:main' into main
halio-g 7c1bd0f
Addresses the comments.
halio-g ddd51eb
Ran blacken on the test_vizier file.
halio-g d01d5ad
Import the OSS in the Vertex SDK.
halio-g 0f31a52
Merge branch 'main' into main
halio-g be868ee
Already imported the package from open source vizier. Removing the co…
halio-g 50aacad
Import the google-vizier and fix the dependencies for Vertex Vizier.
halio-g 5fbc41d
Configured the dependency of the google-vizier.
halio-g 3f09725
Merge branch 'import_pyvizier'
halio-g 6af2782
Merge branch 'main' of https://github.com/halio-g/python-aiplatform
halio-g 842116e
Merge branch 'googleapis:main' into main
halio-g 9be41cc
Ran the nox -s blacken.
halio-g ed0d98d
Fixed the lint issue.
halio-g 6773942
Merge branch 'main' of https://github.com/halio-g/python-aiplatform
halio-g dddaf6a
Merge branch 'googleapis:main' into main
halio-g 4016de2
Clean the debugging logs.
halio-g 04108e9
Decouple the Study, Trial and the aiplatform to make the sample test …
halio-g 49efcd7
Fixed the issue in the system test got an unexpected keyword argument…
halio-g 363a44f
Merge branch 'googleapis:main' into main
halio-g f4d4272
Merge branch 'main' of https://github.com/halio-g/python-aiplatform
halio-g f296d9a
Ran the nox -s blacken to format the python file.
halio-g 116f4de
Fixed the unit test failure.
halio-g b7e7d9b
Merge branch 'main' into main
halio-g 4d9bf75
Merge branch 'main' into main
rosiezou dbae081
Merge branch 'main' into main
halio-g 67e2d78
Merge branch 'main' into main
rosiezou 1add1e8
Merge branch 'main' into main
rosiezou b2b2428
Add the wrapper to give more error information about the vizier impor…
halio-g 0790e23
Merge branch 'main' of https://github.com/halio-g/python-aiplatform
halio-g 04704fd
Merge branch 'main' into main
halio-g 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
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,22 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| # Copyright 2022 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 google.cloud.aiplatform.vizier.study import Study | ||
| from google.cloud.aiplatform.vizier.trial import Trial | ||
|
|
||
| __all__ = ( | ||
| "Study", | ||
| "Trial", | ||
| ) |
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,192 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| # Copyright 2022 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. | ||
| """Cross-platform Vizier client interfaces. | ||
|
halio-g marked this conversation as resolved.
|
||
|
|
||
| Aside from "materialize_" methods, code written using these interfaces are | ||
| compatible with OSS and Cloud Vertex Vizier. Note importantly that subclasses | ||
| may have more methods than what is required by interfaces, and such methods | ||
| are not cross compatible. Our recommendation is to explicitly type your objects | ||
| to be `StudyInterface` or `TrialInterface` when you want to guarantee that | ||
| a code block is cross-platform. | ||
|
|
||
| Keywords: | ||
|
|
||
| #Materialize: The method returns a deep copy of the underlying pyvizier object. | ||
|
halio-g marked this conversation as resolved.
|
||
| Modifying the returned object does not update the Vizier service. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Optional, Collection, Type, TypeVar, Mapping, Any | ||
|
halio-g marked this conversation as resolved.
|
||
| import abc | ||
|
|
||
| from google.cloud.aiplatform.vizier import pyvizier as vz | ||
|
halio-g marked this conversation as resolved.
|
||
|
|
||
| _T = TypeVar("_T") | ||
|
|
||
|
|
||
| class ResourceNotFoundError(LookupError): | ||
| """Error raised by Vizier clients when resource is not found.""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| class TrialInterface(abc.ABC): | ||
| """Responsible for trial-level operations.""" | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def uid(self) -> int: | ||
| """Unique identifier of the trial.""" | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def parameters(self) -> Mapping[str, Any]: | ||
| """Parameters of the trial.""" | ||
|
|
||
| @property | ||
| @abc.abstractmethod | ||
| def status(self) -> vz.TrialStatus: | ||
| """Trial's status.""" | ||
|
|
||
| @abc.abstractmethod | ||
| def delete(self) -> None: | ||
| """Delete the Trial in Vizier service. | ||
|
|
||
| There is currently no promise on how this object behaves after `delete()`. | ||
| If you are sharing a Trial object in parallel processes, proceed with | ||
| caution. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def complete( | ||
| self, | ||
| measurement: Optional[vz.Measurement] = None, | ||
| *, | ||
| infeasible_reason: Optional[str] = None, | ||
| ) -> Optional[vz.Measurement]: | ||
| """Completes the trial and #materializes the measurement. | ||
|
|
||
| * If `measurement` is provided, then Vizier writes it as the trial's final | ||
| measurement and returns it. | ||
| * If `infeasible_reason` is provided, `measurement` is not needed. | ||
| * If neither is provided, then Vizier selects an existing (intermediate) | ||
| measurement to be the final measurement and returns it. | ||
|
|
||
| Args: | ||
| measurement: Final measurement. | ||
| infeasible_reason: Infeasible reason for missing final measurement. | ||
|
|
||
| Returns: | ||
| The final measurement of the trial, or None if the trial is marked | ||
| infeasible. | ||
|
|
||
| Raises: | ||
| ValueError: If neither `measurement` nor `infeasible_reason` is provided | ||
| but the trial does not contain any intermediate measurements. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def should_stop(self) -> bool: | ||
| """Returns true if the trial should stop.""" | ||
|
|
||
| @abc.abstractmethod | ||
| def add_measurement(self, measurement: vz.Measurement) -> None: | ||
| """Adds an intermediate measurement.""" | ||
|
|
||
| @abc.abstractmethod | ||
| def materialize(self, *, include_all_measurements: bool = True) -> vz.Trial: | ||
| """#Materializes the Trial. | ||
|
|
||
| Args: | ||
| include_all_measurements: If True, returned Trial includes all | ||
| intermediate measurements. The final measurement is always provided. | ||
|
|
||
| Returns: | ||
| Trial object. | ||
| """ | ||
|
|
||
|
|
||
| class StudyInterface(abc.ABC): | ||
| """Responsible for study-level operations.""" | ||
|
|
||
| @abc.abstractmethod | ||
| def create_or_load( | ||
| self, display_name: str, problem: vz.ProblemStatement | ||
|
halio-g marked this conversation as resolved.
|
||
| ) -> StudyInterface: | ||
| """ """ | ||
|
|
||
| @abc.abstractmethod | ||
| def suggest( | ||
| self, *, count: Optional[int] = None, worker: str = "" | ||
| ) -> Collection[TrialInterface]: | ||
| """Returns Trials to be evaluated by worker. | ||
|
|
||
| Args: | ||
| count: Number of suggestions. | ||
| worker: When new Trials are generated, their `assigned_worker` field is | ||
| populated with this worker. suggest() first looks for existing Trials | ||
| that are assigned to `worker`, before generating new ones. | ||
|
|
||
| Returns: | ||
| Trials. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def delete(self) -> None: | ||
| """Deletes the study.""" | ||
|
|
||
| @abc.abstractmethod | ||
| def trials( | ||
| self, trial_filter: Optional[vz.TrialFilter] = None | ||
| ) -> Collection[TrialInterface]: | ||
| """Fetches a collection of trials.""" | ||
|
|
||
| @abc.abstractmethod | ||
| def get_trial(self, uid: int) -> TrialInterface: | ||
| """Fetches a single trial. | ||
|
|
||
| Args: | ||
| uid: Unique identifier of the trial within study. | ||
|
|
||
| Returns: | ||
| Trial. | ||
|
|
||
| Raises: | ||
| ResourceNotFoundError: If trial does not exist. | ||
| """ | ||
|
|
||
| @abc.abstractmethod | ||
| def optimal_trials(self) -> Collection[TrialInterface]: | ||
| """Returns optimal trial(s).""" | ||
|
|
||
| @abc.abstractmethod | ||
| def materialize_study_config(self) -> vz.StudyConfig: | ||
| """#Materializes the study config.""" | ||
|
|
||
| @abc.abstractclassmethod | ||
| def from_uid(cls: Type[_T], uid: str) -> _T: | ||
| """Fetches an existing study from the Vizier service. | ||
|
|
||
| Args: | ||
| uid: Unique identifier of the study. | ||
|
|
||
| Returns: | ||
| Study. | ||
|
|
||
| Raises: | ||
| ResourceNotFoundError: If study does not exist. | ||
| """ | ||
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.