Skip to content

Commit 24d1bb6

Browse files
authored
feat: Vertex AI Experiments GA (#1410)
1 parent e3eb82f commit 24d1bb6

File tree

92 files changed

+7502
-720
lines changed

Some content is hidden

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

92 files changed

+7502
-720
lines changed

google/cloud/aiplatform/__init__.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
MatchingEngineIndex,
4343
MatchingEngineIndexEndpoint,
4444
)
45-
from google.cloud.aiplatform.metadata import metadata
45+
from google.cloud.aiplatform import metadata
4646
from google.cloud.aiplatform.models import Endpoint
4747
from google.cloud.aiplatform.models import Model
4848
from google.cloud.aiplatform.model_evaluation import ModelEvaluation
@@ -56,6 +56,7 @@
5656
Tensorboard,
5757
TensorboardExperiment,
5858
TensorboardRun,
59+
TensorboardTimeSeries,
5960
)
6061
from google.cloud.aiplatform.training_jobs import (
6162
CustomTrainingJob,
@@ -78,24 +79,39 @@
7879
"""
7980
init = initializer.global_config.init
8081

81-
log_params = metadata.metadata_service.log_params
82-
log_metrics = metadata.metadata_service.log_metrics
83-
get_experiment_df = metadata.metadata_service.get_experiment_df
84-
get_pipeline_df = metadata.metadata_service.get_pipeline_df
85-
start_run = metadata.metadata_service.start_run
82+
get_pipeline_df = metadata.metadata._LegacyExperimentService.get_pipeline_df
83+
84+
log_params = metadata.metadata._experiment_tracker.log_params
85+
log_metrics = metadata.metadata._experiment_tracker.log_metrics
86+
get_experiment_df = metadata.metadata._experiment_tracker.get_experiment_df
87+
start_run = metadata.metadata._experiment_tracker.start_run
88+
start_execution = metadata.metadata._experiment_tracker.start_execution
89+
log = metadata.metadata._experiment_tracker.log
90+
log_time_series_metrics = metadata.metadata._experiment_tracker.log_time_series_metrics
91+
end_run = metadata.metadata._experiment_tracker.end_run
92+
93+
Experiment = metadata.experiment_resources.Experiment
94+
ExperimentRun = metadata.experiment_run_resource.ExperimentRun
95+
Artifact = metadata.artifact.Artifact
96+
Execution = metadata.execution.Execution
8697

8798

8899
__all__ = (
100+
"end_run",
89101
"explain",
90102
"gapic",
91103
"init",
92104
"helpers",
93105
"hyperparameter_tuning",
106+
"log",
94107
"log_params",
95108
"log_metrics",
109+
"log_time_series_metrics",
96110
"get_experiment_df",
97111
"get_pipeline_df",
98112
"start_run",
113+
"start_execution",
114+
"Artifact",
99115
"AutoMLImageTrainingJob",
100116
"AutoMLTabularTrainingJob",
101117
"AutoMLForecastingTrainingJob",
@@ -108,6 +124,9 @@
108124
"CustomPythonPackageTrainingJob",
109125
"Endpoint",
110126
"EntityType",
127+
"Execution",
128+
"Experiment",
129+
"ExperimentRun",
111130
"Feature",
112131
"Featurestore",
113132
"MatchingEngineIndex",
@@ -122,6 +141,7 @@
122141
"Tensorboard",
123142
"TensorboardExperiment",
124143
"TensorboardRun",
144+
"TensorboardTimeSeries",
125145
"TextDataset",
126146
"TimeSeriesDataset",
127147
"VideoDataset",

google/cloud/aiplatform/base.py

+19
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,25 @@ def name(self) -> str:
610610
self._assert_gca_resource_is_available()
611611
return self._gca_resource.name.split("/")[-1]
612612

613+
@property
614+
def _project_tuple(self) -> Tuple[Optional[str], Optional[str]]:
615+
"""Returns the tuple of project id and project inferred from the local instance.
616+
617+
Another option is to use resource_manager_utils but requires the caller have resource manager
618+
get role.
619+
"""
620+
# we may not have the project if project inferred from the resource name
621+
maybe_project_id = self.project
622+
if self._gca_resource is not None and self._gca_resource.name:
623+
project_no = self._parse_resource_name(self._gca_resource.name)["project"]
624+
else:
625+
project_no = None
626+
627+
if maybe_project_id == project_no:
628+
return (None, project_no)
629+
else:
630+
return (maybe_project_id, project_no)
631+
613632
@property
614633
def resource_name(self) -> str:
615634
"""Full qualified resource name."""

google/cloud/aiplatform/compat/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
types.io = types.io_v1beta1
8181
types.job_service = types.job_service_v1beta1
8282
types.job_state = types.job_state_v1beta1
83+
types.lineage_subgraph = types.lineage_subgraph_v1beta1
8384
types.machine_resources = types.machine_resources_v1beta1
8485
types.manual_batch_tuning_parameters = types.manual_batch_tuning_parameters_v1beta1
8586
types.matching_engine_deployed_index_ref = (
@@ -88,6 +89,7 @@
8889
types.matching_engine_index = types.index_v1beta1
8990
types.matching_engine_index_endpoint = types.index_endpoint_v1beta1
9091
types.metadata_service = types.metadata_service_v1beta1
92+
types.metadata_schema = types.metadata_schema_v1beta1
9193
types.metadata_store = types.metadata_store_v1beta1
9294
types.model = types.model_v1beta1
9395
types.model_evaluation = types.model_evaluation_v1beta1
@@ -162,6 +164,7 @@
162164
types.io = types.io_v1
163165
types.job_service = types.job_service_v1
164166
types.job_state = types.job_state_v1
167+
types.lineage_subgraph = types.lineage_subgraph_v1
165168
types.machine_resources = types.machine_resources_v1
166169
types.manual_batch_tuning_parameters = types.manual_batch_tuning_parameters_v1
167170
types.matching_engine_deployed_index_ref = (
@@ -170,6 +173,7 @@
170173
types.matching_engine_index = types.index_v1
171174
types.matching_engine_index_endpoint = types.index_endpoint_v1
172175
types.metadata_service = types.metadata_service_v1
176+
types.metadata_schema = types.metadata_schema_v1
173177
types.metadata_store = types.metadata_store_v1
174178
types.model = types.model_v1
175179
types.model_evaluation = types.model_evaluation_v1

google/cloud/aiplatform/compat/types/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@
5252
io as io_v1beta1,
5353
job_service as job_service_v1beta1,
5454
job_state as job_state_v1beta1,
55+
lineage_subgraph as lineage_subgraph_v1beta1,
5556
machine_resources as machine_resources_v1beta1,
5657
manual_batch_tuning_parameters as manual_batch_tuning_parameters_v1beta1,
58+
metadata_schema as metadata_schema_v1beta1,
5759
metadata_service as metadata_service_v1beta1,
5860
metadata_store as metadata_store_v1beta1,
5961
model as model_v1beta1,
@@ -113,9 +115,11 @@
113115
io as io_v1,
114116
job_service as job_service_v1,
115117
job_state as job_state_v1,
118+
lineage_subgraph as lineage_subgraph_v1,
116119
machine_resources as machine_resources_v1,
117120
manual_batch_tuning_parameters as manual_batch_tuning_parameters_v1,
118121
metadata_service as metadata_service_v1,
122+
metadata_schema as metadata_schema_v1,
119123
metadata_store as metadata_store_v1,
120124
model as model_v1,
121125
model_evaluation as model_evaluation_v1,
@@ -173,12 +177,14 @@
173177
io_v1,
174178
job_service_v1,
175179
job_state_v1,
180+
lineage_subgraph_v1,
176181
machine_resources_v1,
177182
manual_batch_tuning_parameters_v1,
178183
matching_engine_deployed_index_ref_v1,
179184
index_v1,
180185
index_endpoint_v1,
181186
metadata_service_v1,
187+
metadata_schema_v1,
182188
metadata_store_v1,
183189
model_v1,
184190
model_evaluation_v1,
@@ -233,12 +239,14 @@
233239
io_v1beta1,
234240
job_service_v1beta1,
235241
job_state_v1beta1,
242+
lineage_subgraph_v1beta1,
236243
machine_resources_v1beta1,
237244
manual_batch_tuning_parameters_v1beta1,
238245
matching_engine_deployed_index_ref_v1beta1,
239246
index_v1beta1,
240247
index_endpoint_v1beta1,
241248
metadata_service_v1beta1,
249+
metadata_schema_v1beta1,
242250
metadata_store_v1beta1,
243251
model_v1beta1,
244252
model_evaluation_v1beta1,

google/cloud/aiplatform/initializer.py

+39-11
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from google.cloud.aiplatform import utils
3434
from google.cloud.aiplatform.metadata import metadata
3535
from google.cloud.aiplatform.utils import resource_manager_utils
36+
from google.cloud.aiplatform.tensorboard import tensorboard_resource
3637

3738
from google.cloud.aiplatform.compat.types import (
3839
encryption_spec as gca_encryption_spec_compat,
@@ -58,6 +59,9 @@ def init(
5859
location: Optional[str] = None,
5960
experiment: Optional[str] = None,
6061
experiment_description: Optional[str] = None,
62+
experiment_tensorboard: Optional[
63+
Union[str, tensorboard_resource.Tensorboard]
64+
] = None,
6165
staging_bucket: Optional[str] = None,
6266
credentials: Optional[auth_credentials.Credentials] = None,
6367
encryption_spec_key_name: Optional[str] = None,
@@ -68,8 +72,15 @@ def init(
6872
project (str): The default project to use when making API calls.
6973
location (str): The default location to use when making API calls. If not
7074
set defaults to us-central-1.
71-
experiment (str): The experiment name.
72-
experiment_description (str): The description of the experiment.
75+
experiment (str): Optional. The experiment name.
76+
experiment_description (str): Optional. The description of the experiment.
77+
experiment_tensorboard (Union[str, tensorboard_resource.Tensorboard]):
78+
Optional. The Vertex AI TensorBoard instance, Tensorboard resource name,
79+
or Tensorboard resource ID to use as a backing Tensorboard for the provided
80+
experiment.
81+
82+
Example tensorboard resource name format:
83+
"projects/123/locations/us-central1/tensorboards/456"
7384
staging_bucket (str): The default staging bucket to use to stage artifacts
7485
when making API calls. In the form gs://...
7586
credentials (google.auth.credentials.Credentials): The default custom
@@ -84,15 +95,29 @@ def init(
8495
resource is created.
8596
8697
If set, this resource and all sub-resources will be secured by this key.
98+
Raises:
99+
ValueError:
100+
If experiment_description is provided but experiment is not.
101+
If experiment_tensorboard is provided but expeirment is not.
87102
"""
88103

104+
if experiment_description and experiment is None:
105+
raise ValueError(
106+
"Experiment needs to be set in `init` in order to add experiment descriptions."
107+
)
108+
109+
if experiment_tensorboard and experiment is None:
110+
raise ValueError(
111+
"Experiment needs to be set in `init` in order to add experiment_tensorboard."
112+
)
113+
89114
# reset metadata_service config if project or location is updated.
90115
if (project and project != self._project) or (
91116
location and location != self._location
92117
):
93-
if metadata.metadata_service.experiment_name:
94-
logging.info("project/location updated, reset Metadata config.")
95-
metadata.metadata_service.reset()
118+
if metadata._experiment_tracker.experiment_name:
119+
logging.info("project/location updated, reset Experiment config.")
120+
metadata._experiment_tracker.reset()
96121

97122
if project:
98123
self._project = project
@@ -107,12 +132,10 @@ def init(
107132
self._encryption_spec_key_name = encryption_spec_key_name
108133

109134
if experiment:
110-
metadata.metadata_service.set_experiment(
111-
experiment=experiment, description=experiment_description
112-
)
113-
if experiment_description and experiment is None:
114-
raise ValueError(
115-
"Experiment name needs to be set in `init` in order to add experiment descriptions."
135+
metadata._experiment_tracker.set_experiment(
136+
experiment=experiment,
137+
description=experiment_description,
138+
backing_tensorboard=experiment_tensorboard,
116139
)
117140

118141
def get_encryption_spec(
@@ -214,6 +237,11 @@ def encryption_spec_key_name(self) -> Optional[str]:
214237
"""Default encryption spec key name, if provided."""
215238
return self._encryption_spec_key_name
216239

240+
@property
241+
def experiment_name(self) -> Optional[str]:
242+
"""Default experiment name, if provided."""
243+
return metadata._experiment_tracker.experiment_name
244+
217245
def get_client_options(
218246
self,
219247
location_override: Optional[str] = None,

0 commit comments

Comments
 (0)