-
Notifications
You must be signed in to change notification settings - Fork 449
feat: Add Vertex Forecasting E2E test. #1248
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
gcf-merge-on-green
merged 8 commits into
googleapis:main
from
TheMichaelHu:mh-e2e-forecast
May 27, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9c1eb6a
feat: Add Vertex Forecasting E2E test.
TheMichaelHu 195f732
update time series dataset test data source
TheMichaelHu e6c28da
fix linting errors
TheMichaelHu e9c5b41
clean up resources
TheMichaelHu e3e69a4
change data source
TheMichaelHu f247c5d
instantiate variables
TheMichaelHu 5caba45
oops
TheMichaelHu 604e85a
update bq uris
TheMichaelHu 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # -*- 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 import aiplatform | ||
| from google.cloud.aiplatform.compat.types import job_state | ||
| from google.cloud.aiplatform.compat.types import pipeline_state | ||
| import pytest | ||
| from tests.system.aiplatform import e2e_base | ||
|
|
||
| _TRAINING_DATASET_BQ_PATH = ( | ||
|
TheMichaelHu marked this conversation as resolved.
|
||
| "bq://ucaip-sample-tests:ucaip_test_us_central1.2020_sales_train" | ||
| ) | ||
| _PREDICTION_DATASET_BQ_PATH = ( | ||
| "bq://ucaip-sample-tests:ucaip_test_us_central1.2021_sales_predict" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("prepare_staging_bucket", "delete_staging_bucket") | ||
| class TestEndToEndForecasting(e2e_base.TestEndToEnd): | ||
| """End to end system test of the Vertex SDK with forecasting data.""" | ||
|
|
||
| _temp_prefix = "temp-vertex-sdk-e2e-forecasting" | ||
|
|
||
| def test_end_to_end_forecasting(self, shared_state): | ||
| """Builds a dataset, trains models, and gets batch predictions.""" | ||
| ds = None | ||
| automl_job = None | ||
| automl_model = None | ||
| automl_batch_prediction_job = None | ||
|
|
||
| aiplatform.init( | ||
| project=e2e_base._PROJECT, | ||
| location=e2e_base._LOCATION, | ||
| staging_bucket=shared_state["staging_bucket_name"], | ||
|
TheMichaelHu marked this conversation as resolved.
|
||
| ) | ||
| try: | ||
| # Create and import to single managed dataset for both training | ||
| # jobs. | ||
| ds = aiplatform.TimeSeriesDataset.create( | ||
| display_name=self._make_display_name("dataset"), | ||
| bq_source=[_TRAINING_DATASET_BQ_PATH], | ||
| sync=False, | ||
| create_request_timeout=180.0, | ||
| ) | ||
|
|
||
| time_column = "date" | ||
| time_series_identifier_column = "store_name" | ||
| target_column = "sale_dollars" | ||
| column_specs = { | ||
| time_column: "timestamp", | ||
| target_column: "numeric", | ||
| "city": "categorical", | ||
| "zip_code": "categorical", | ||
| "county": "categorical", | ||
| } | ||
|
|
||
| # Define both training jobs | ||
| # TODO(humichael): Add seq2seq job. | ||
| automl_job = aiplatform.AutoMLForecastingTrainingJob( | ||
| display_name=self._make_display_name("train-housing-automl"), | ||
| optimization_objective="minimize-rmse", | ||
| column_specs=column_specs, | ||
| ) | ||
|
|
||
| # Kick off both training jobs, AutoML job will take approx one hour | ||
| # to run. | ||
| automl_model = automl_job.run( | ||
| dataset=ds, | ||
| target_column=target_column, | ||
| time_column=time_column, | ||
| time_series_identifier_column=time_series_identifier_column, | ||
| available_at_forecast_columns=[time_column], | ||
| unavailable_at_forecast_columns=[target_column], | ||
| time_series_attribute_columns=["city", "zip_code", "county"], | ||
| forecast_horizon=30, | ||
| context_window=30, | ||
| data_granularity_unit="day", | ||
| data_granularity_count=1, | ||
| budget_milli_node_hours=1000, | ||
| model_display_name=self._make_display_name("automl-liquor-model"), | ||
| sync=False, | ||
| ) | ||
|
|
||
| automl_batch_prediction_job = automl_model.batch_predict( | ||
| job_display_name=self._make_display_name("automl-liquor-model"), | ||
| instances_format="bigquery", | ||
| machine_type="n1-standard-4", | ||
| bigquery_source=_PREDICTION_DATASET_BQ_PATH, | ||
| gcs_destination_prefix=( | ||
| f'gs://{shared_state["staging_bucket_name"]}/bp_results/' | ||
| ), | ||
| sync=False, | ||
| ) | ||
|
|
||
| automl_batch_prediction_job.wait() | ||
|
|
||
| assert ( | ||
| automl_job.state | ||
| == pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED | ||
| ) | ||
| assert ( | ||
| automl_batch_prediction_job.state | ||
| == job_state.JobState.JOB_STATE_SUCCEEDED | ||
| ) | ||
| finally: | ||
| if ds is not None: | ||
| ds.delete() | ||
| if automl_job is not None: | ||
| automl_job.delete() | ||
| if automl_model is not None: | ||
| automl_model.delete() | ||
| if automl_batch_prediction_job is not None: | ||
| automl_batch_prediction_job.delete() | ||
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.