Skip to content

Commit e94c9db

Browse files
authored
feat: AutoML Forecasting, Metadata Experiment Tracking, Tensorboard uploader
2 parents cc1a708 + dcc459d commit e94c9db

35 files changed

+7513
-45
lines changed

google/cloud/aiplatform/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
ImageDataset,
2424
TabularDataset,
2525
TextDataset,
26+
TimeSeriesDataset,
2627
VideoDataset,
2728
)
2829
from google.cloud.aiplatform.models import Endpoint
@@ -33,10 +34,12 @@
3334
CustomContainerTrainingJob,
3435
CustomPythonPackageTrainingJob,
3536
AutoMLTabularTrainingJob,
37+
AutoMLForecastingTrainingJob,
3638
AutoMLImageTrainingJob,
3739
AutoMLTextTrainingJob,
3840
AutoMLVideoTrainingJob,
3941
)
42+
from google.cloud.aiplatform.metadata import metadata
4043

4144
"""
4245
Usage:
@@ -46,12 +49,25 @@
4649
"""
4750
init = initializer.global_config.init
4851

52+
log_params = metadata.metadata_service.log_params
53+
log_metrics = metadata.metadata_service.log_metrics
54+
get_experiment_df = metadata.metadata_service.get_experiment_df
55+
get_pipeline_df = metadata.metadata_service.get_pipeline_df
56+
start_run = metadata.metadata_service.start_run
57+
58+
4959
__all__ = (
5060
"explain",
5161
"gapic",
5262
"init",
63+
"log_params",
64+
"log_metrics",
65+
"get_experiment_df",
66+
"get_pipeline_df",
67+
"start_run",
5368
"AutoMLImageTrainingJob",
5469
"AutoMLTabularTrainingJob",
70+
"AutoMLForecastingTrainingJob",
5571
"AutoMLTextTrainingJob",
5672
"AutoMLVideoTrainingJob",
5773
"BatchPredictionJob",
@@ -63,5 +79,6 @@
6379
"Model",
6480
"TabularDataset",
6581
"TextDataset",
82+
"TimeSeriesDataset",
6683
"VideoDataset",
6784
)

google/cloud/aiplatform/compat/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
services.specialist_pool_service_client = (
3535
services.specialist_pool_service_client_v1beta1
3636
)
37+
services.metadata_service_client = services.metadata_service_client_v1beta1
38+
services.tensorboard_service_client = services.tensorboard_service_client_v1beta1
3739

3840
types.accelerator_type = types.accelerator_type_v1beta1
3941
types.annotation = types.annotation_v1beta1
@@ -69,6 +71,13 @@
6971
types.specialist_pool = types.specialist_pool_v1beta1
7072
types.specialist_pool_service = types.specialist_pool_service_v1beta1
7173
types.training_pipeline = types.training_pipeline_v1beta1
74+
types.metadata_service = types.metadata_service_v1beta1
75+
types.tensorboard_service = types.tensorboard_service_v1beta1
76+
types.tensorboard_data = types.tensorboard_data_v1beta1
77+
types.tensorboard_experiment = types.tensorboard_experiment_v1beta1
78+
types.tensorboard_run = types.tensorboard_run_v1beta1
79+
types.tensorboard_service = types.tensorboard_service_v1beta1
80+
types.tensorboard_time_series = types.tensorboard_time_series_v1beta1
7281

7382
if DEFAULT_VERSION == V1:
7483

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636
from google.cloud.aiplatform_v1beta1.services.specialist_pool_service import (
3737
client as specialist_pool_service_client_v1beta1,
3838
)
39+
from google.cloud.aiplatform_v1beta1.services.metadata_service import (
40+
client as metadata_service_client_v1beta1,
41+
)
42+
from google.cloud.aiplatform_v1beta1.services.tensorboard_service import (
43+
client as tensorboard_service_client_v1beta1,
44+
)
3945

4046
from google.cloud.aiplatform_v1.services.dataset_service import (
4147
client as dataset_service_client_v1,
@@ -76,4 +82,6 @@
7682
pipeline_service_client_v1beta1,
7783
prediction_service_client_v1beta1,
7884
specialist_pool_service_client_v1beta1,
85+
metadata_service_client_v1beta1,
86+
tensorboard_service_client_v1beta1,
7987
)

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
specialist_pool as specialist_pool_v1beta1,
5151
specialist_pool_service as specialist_pool_service_v1beta1,
5252
training_pipeline as training_pipeline_v1beta1,
53+
metadata_service as metadata_service_v1beta1,
54+
tensorboard_service as tensorboard_service_v1beta1,
55+
tensorboard_data as tensorboard_data_v1beta1,
56+
tensorboard_experiment as tensorboard_experiment_v1beta1,
57+
tensorboard_run as tensorboard_run_v1beta1,
58+
tensorboard_service as tensorboard_service_v1beta1,
59+
tensorboard_time_series as tensorboard_time_series_v1beta1,
5360
)
5461
from google.cloud.aiplatform_v1.types import (
5562
accelerator_type as accelerator_type_v1,
@@ -155,4 +162,11 @@
155162
specialist_pool_v1beta1,
156163
specialist_pool_service_v1beta1,
157164
training_pipeline_v1beta1,
165+
metadata_service_v1beta1,
166+
tensorboard_service_v1beta1,
167+
tensorboard_data_v1beta1,
168+
tensorboard_experiment_v1beta1,
169+
tensorboard_run_v1beta1,
170+
tensorboard_service_v1beta1,
171+
tensorboard_time_series_v1beta1,
158172
)

google/cloud/aiplatform/datasets/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from google.cloud.aiplatform.datasets.dataset import _Dataset
1919
from google.cloud.aiplatform.datasets.tabular_dataset import TabularDataset
20+
from google.cloud.aiplatform.datasets.time_series_dataset import TimeSeriesDataset
2021
from google.cloud.aiplatform.datasets.image_dataset import ImageDataset
2122
from google.cloud.aiplatform.datasets.text_dataset import TextDataset
2223
from google.cloud.aiplatform.datasets.video_dataset import VideoDataset
@@ -25,6 +26,7 @@
2526
__all__ = (
2627
"_Dataset",
2728
"TabularDataset",
29+
"TimeSeriesDataset",
2830
"ImageDataset",
2931
"TextDataset",
3032
"VideoDataset",

google/cloud/aiplatform/datasets/_datasources.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ def create_datasource(
225225
raise ValueError("tabular dataset does not support data import.")
226226
return TabularDatasource(gcs_source, bq_source)
227227

228+
if metadata_schema_uri == schema.dataset.metadata.time_series:
229+
if import_schema_uri:
230+
raise ValueError("time series dataset does not support data import.")
231+
return TabularDatasource(gcs_source, bq_source)
232+
228233
if not import_schema_uri and not gcs_source:
229234
return NonTabularDatasource()
230235
elif import_schema_uri and gcs_source:

google/cloud/aiplatform/datasets/dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def create(
162162
if their content bytes are identical (e.g. image bytes or
163163
pdf bytes). These labels will be overridden by Annotation
164164
labels specified inside index file refenced by
165-
[import_schema_uri][google.cloud.aiplatform.v1beta1.ImportDataConfig.import_schema_uri],
165+
``import_schema_uri``,
166166
e.g. jsonl file.
167167
project (str):
168168
Project to upload this model to. Overrides project set in
@@ -449,7 +449,7 @@ def import_data(
449449
if their content bytes are identical (e.g. image bytes or
450450
pdf bytes). These labels will be overridden by Annotation
451451
labels specified inside index file refenced by
452-
[import_schema_uri][google.cloud.aiplatform.v1beta1.ImportDataConfig.import_schema_uri],
452+
``import_schema_uri``,
453453
e.g. jsonl file.
454454
sync (bool):
455455
Whether to execute this method synchronously. If False, this method

google/cloud/aiplatform/datasets/image_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def create(
8282
if their content bytes are identical (e.g. image bytes or
8383
pdf bytes). These labels will be overridden by Annotation
8484
labels specified inside index file refenced by
85-
[import_schema_uri][google.cloud.aiplatform.v1beta1.ImportDataConfig.import_schema_uri],
85+
``import_schema_uri``,
8686
e.g. jsonl file.
8787
project (str):
8888
Project to upload this model to. Overrides project set in

google/cloud/aiplatform/datasets/text_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def create(
8989
if their content bytes are identical (e.g. image bytes or
9090
pdf bytes). These labels will be overridden by Annotation
9191
labels specified inside index file refenced by
92-
[import_schema_uri][google.cloud.aiplatform.v1beta1.ImportDataConfig.import_schema_uri],
92+
``import_schema_uri``,
9393
e.g. jsonl file.
9494
project (str):
9595
Project to upload this model to. Overrides project set in
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2020 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
from typing import Optional, Sequence, Tuple, Union
19+
20+
from google.auth import credentials as auth_credentials
21+
22+
from google.cloud.aiplatform import datasets
23+
from google.cloud.aiplatform.datasets import _datasources
24+
from google.cloud.aiplatform import initializer
25+
from google.cloud.aiplatform import schema
26+
from google.cloud.aiplatform import utils
27+
28+
29+
class TimeSeriesDataset(datasets._Dataset):
30+
"""Managed time series dataset resource for AI Platform"""
31+
32+
_supported_metadata_schema_uris: Optional[Tuple[str]] = (
33+
schema.dataset.metadata.time_series,
34+
)
35+
36+
@classmethod
37+
def create(
38+
cls,
39+
display_name: str,
40+
gcs_source: Optional[Union[str, Sequence[str]]] = None,
41+
bq_source: Optional[str] = None,
42+
project: Optional[str] = None,
43+
location: Optional[str] = None,
44+
credentials: Optional[auth_credentials.Credentials] = None,
45+
request_metadata: Optional[Sequence[Tuple[str, str]]] = (),
46+
encryption_spec_key_name: Optional[str] = None,
47+
sync: bool = True,
48+
) -> "TimeSeriesDataset":
49+
"""Creates a new tabular dataset.
50+
51+
Args:
52+
display_name (str):
53+
Required. The user-defined name of the Dataset.
54+
The name can be up to 128 characters long and can be consist
55+
of any UTF-8 characters.
56+
gcs_source (Union[str, Sequence[str]]):
57+
Google Cloud Storage URI(-s) to the
58+
input file(s). May contain wildcards. For more
59+
information on wildcards, see
60+
https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames.
61+
examples:
62+
str: "gs://bucket/file.csv"
63+
Sequence[str]: ["gs://bucket/file1.csv", "gs://bucket/file2.csv"]
64+
bq_source (str):
65+
BigQuery URI to the input table.
66+
example:
67+
"bq://project.dataset.table_name"
68+
project (str):
69+
Project to upload this model to. Overrides project set in
70+
aiplatform.init.
71+
location (str):
72+
Location to upload this model to. Overrides location set in
73+
aiplatform.init.
74+
credentials (auth_credentials.Credentials):
75+
Custom credentials to use to upload this model. Overrides
76+
credentials set in aiplatform.init.
77+
request_metadata (Sequence[Tuple[str, str]]):
78+
Strings which should be sent along with the request as metadata.
79+
encryption_spec_key_name (Optional[str]):
80+
Optional. The Cloud KMS resource identifier of the customer
81+
managed encryption key used to protect the dataset. Has the
82+
form:
83+
``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``.
84+
The key needs to be in the same region as where the compute
85+
resource is created.
86+
87+
If set, this Dataset and all sub-resources of this Dataset will be secured by this key.
88+
89+
Overrides encryption_spec_key_name set in aiplatform.init.
90+
sync (bool):
91+
Whether to execute this method synchronously. If False, this method
92+
will be executed in concurrent Future and any downstream object will
93+
be immediately returned and synced when the Future has completed.
94+
95+
Returns:
96+
time_series_dataset (TimeSeriesDataset):
97+
Instantiated representation of the managed time series dataset resource.
98+
99+
"""
100+
101+
utils.validate_display_name(display_name)
102+
103+
api_client = cls._instantiate_client(location=location, credentials=credentials)
104+
105+
metadata_schema_uri = schema.dataset.metadata.time_series
106+
107+
datasource = _datasources.create_datasource(
108+
metadata_schema_uri=metadata_schema_uri,
109+
gcs_source=gcs_source,
110+
bq_source=bq_source,
111+
)
112+
113+
return cls._create_and_import(
114+
api_client=api_client,
115+
parent=initializer.global_config.common_location_path(
116+
project=project, location=location
117+
),
118+
display_name=display_name,
119+
metadata_schema_uri=metadata_schema_uri,
120+
datasource=datasource,
121+
project=project or initializer.global_config.project,
122+
location=location or initializer.global_config.location,
123+
credentials=credentials or initializer.global_config.credentials,
124+
request_metadata=request_metadata,
125+
encryption_spec=initializer.global_config.get_encryption_spec(
126+
encryption_spec_key_name=encryption_spec_key_name
127+
),
128+
sync=sync,
129+
)
130+
131+
def import_data(self):
132+
raise NotImplementedError(
133+
f"{self.__class__.__name__} class does not support 'import_data'"
134+
)

0 commit comments

Comments
 (0)