GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: support additional_experiments for AutoML Tables and AutoML For… · googleapis/python-aiplatform@282bb62

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • google/cloud/aiplatform
    • training_jobs.py
  • tests/unit/aiplatform
    • test_automl_forecasting_training_jobs.py
    • test_automl_tabular_training_jobs.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎google/cloud/aiplatform/training_jobs.py‎

Copy file name to clipboardExpand all lines: google/cloud/aiplatform/training_jobs.py
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,6 +2420,8 @@ def __init__(
24202420
optimization_objective_precision_value
24212421
)
24222422

2423+
self._additional_experiments = []
2424+
24232425
def run(
24242426
self,
24252427
dataset: datasets.TabularDataset,
@@ -2664,6 +2666,9 @@ def _run(
26642666
"optimizationObjectivePrecisionValue": self._optimization_objective_precision_value,
26652667
}
26662668

2669+
if self._additional_experiments:
2670+
training_task_inputs_dict["additionalExperiments"] = self._additional_experiments
2671+
26672672
if model_display_name is None:
26682673
model_display_name = self._display_name
26692674

@@ -2691,6 +2696,14 @@ def _model_upload_fail_string(self) -> str:
26912696
"Model."
26922697
)
26932698

2699+
def _add_additional_experiments(self, additional_experiments: List[str]):
2700+
"""Add experiment flag to the training job.
2701+
Args:
2702+
additional_experiments (List[str]):
2703+
Experiment flags that can enable some experimental training features.
2704+
"""
2705+
self._additional_experiments.extend(additional_experiments)
2706+
26942707

26952708
class AutoMLForecastingTrainingJob(_TrainingJob):
26962709
_supported_training_schemas = (schema.training_job.definition.automl_forecasting,)
@@ -2746,6 +2759,7 @@ def __init__(
27462759
)
27472760
self._column_transformations = column_transformations
27482761
self._optimization_objective = optimization_objective
2762+
self._additional_experiments = []
27492763

27502764
def run(
27512765
self,
@@ -3119,6 +3133,9 @@ def _run(
31193133
"overrideExistingTable": export_evaluated_data_items_override_destination,
31203134
}
31213135

3136+
if self._additional_experiments:
3137+
training_task_inputs_dict["additionalExperiments"] = self._additional_experiments
3138+
31223139
if model_display_name is None:
31233140
model_display_name = self._display_name
31243141

@@ -3143,6 +3160,14 @@ def _model_upload_fail_string(self) -> str:
31433160
"Model."
31443161
)
31453162

3163+
def _add_additional_experiments(self, additional_experiments: List[str]):
3164+
"""Add experiment flag to the training job.
3165+
Args:
3166+
additional_experiments (List[str]):
3167+
Experiment flags that can enable some experimental training features.
3168+
"""
3169+
self._additional_experiments.extend(additional_experiments)
3170+
31463171

31473172
class AutoMLImageTrainingJob(_TrainingJob):
31483173
_supported_training_schemas = (
Collapse file

‎tests/unit/aiplatform/test_automl_forecasting_training_jobs.py‎

Copy file name to clipboardExpand all lines: tests/unit/aiplatform/test_automl_forecasting_training_jobs.py
+104-24Lines changed: 104 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,32 +62,41 @@
6262
_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS = 1000
6363
_TEST_TRAINING_WEIGHT_COLUMN = "weight"
6464
_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME = "minimize-rmse"
65+
_TEST_ADDITIONAL_EXPERIMENTS = ["exp1", "exp2"]
66+
_TEST_TRAINING_TASK_INPUTS_DICT = {
67+
# required inputs
68+
"targetColumn": _TEST_TRAINING_TARGET_COLUMN,
69+
"timeColumn": _TEST_TRAINING_TIME_COLUMN,
70+
"timeSeriesIdentifierColumn": _TEST_TRAINING_TIME_SERIES_IDENTIFIER_COLUMN,
71+
"timeSeriesAttributeColumns": _TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS,
72+
"unavailableAtForecastColumns": _TEST_TRAINING_UNAVAILABLE_AT_FORECAST_COLUMNS,
73+
"availableAtForecastColumns": _TEST_TRAINING_AVAILABLE_AT_FORECAST_COLUMNS,
74+
"forecastHorizon": _TEST_TRAINING_FORECAST_HORIZON,
75+
"dataGranularity": {
76+
"unit": _TEST_TRAINING_DATA_GRANULARITY_UNIT,
77+
"quantity": _TEST_TRAINING_DATA_GRANULARITY_COUNT,
78+
},
79+
"transformations": _TEST_TRAINING_COLUMN_TRANSFORMATIONS,
80+
"trainBudgetMilliNodeHours": _TEST_TRAINING_BUDGET_MILLI_NODE_HOURS,
81+
# optional inputs
82+
"weightColumn": _TEST_TRAINING_WEIGHT_COLUMN,
83+
"contextWindow": _TEST_TRAINING_CONTEXT_WINDOW,
84+
"exportEvaluatedDataItemsConfig": {
85+
"destinationBigqueryUri": _TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI,
86+
"overrideExistingTable": _TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION,
87+
},
88+
"quantiles": _TEST_TRAINING_QUANTILES,
89+
"validationOptions": _TEST_TRAINING_VALIDATION_OPTIONS,
90+
"optimizationObjective": _TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME,
91+
}
6592
_TEST_TRAINING_TASK_INPUTS = json_format.ParseDict(
93+
_TEST_TRAINING_TASK_INPUTS_DICT,
94+
struct_pb2.Value(),
95+
)
96+
_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS = json_format.ParseDict(
6697
{
67-
# required inputs
68-
"targetColumn": _TEST_TRAINING_TARGET_COLUMN,
69-
"timeColumn": _TEST_TRAINING_TIME_COLUMN,
70-
"timeSeriesIdentifierColumn": _TEST_TRAINING_TIME_SERIES_IDENTIFIER_COLUMN,
71-
"timeSeriesAttributeColumns": _TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS,
72-
"unavailableAtForecastColumns": _TEST_TRAINING_UNAVAILABLE_AT_FORECAST_COLUMNS,
73-
"availableAtForecastColumns": _TEST_TRAINING_AVAILABLE_AT_FORECAST_COLUMNS,
74-
"forecastHorizon": _TEST_TRAINING_FORECAST_HORIZON,
75-
"dataGranularity": {
76-
"unit": _TEST_TRAINING_DATA_GRANULARITY_UNIT,
77-
"quantity": _TEST_TRAINING_DATA_GRANULARITY_COUNT,
78-
},
79-
"transformations": _TEST_TRAINING_COLUMN_TRANSFORMATIONS,
80-
"trainBudgetMilliNodeHours": _TEST_TRAINING_BUDGET_MILLI_NODE_HOURS,
81-
# optional inputs
82-
"weightColumn": _TEST_TRAINING_WEIGHT_COLUMN,
83-
"contextWindow": _TEST_TRAINING_CONTEXT_WINDOW,
84-
"exportEvaluatedDataItemsConfig": {
85-
"destinationBigqueryUri": _TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI,
86-
"overrideExistingTable": _TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION,
87-
},
88-
"quantiles": _TEST_TRAINING_QUANTILES,
89-
"validationOptions": _TEST_TRAINING_VALIDATION_OPTIONS,
90-
"optimizationObjective": _TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME,
98+
**_TEST_TRAINING_TASK_INPUTS_DICT,
99+
"additionalExperiments": _TEST_ADDITIONAL_EXPERIMENTS,
91100
},
92101
struct_pb2.Value(),
93102
)
@@ -359,6 +368,77 @@ def test_run_call_pipeline_if_no_model_display_name(
359368
training_pipeline=true_training_pipeline,
360369
)
361370

371+
@pytest.mark.usefixtures("mock_pipeline_service_get")
372+
@pytest.mark.parametrize("sync", [True, False])
373+
def test_run_call_pipeline_if_set_additional_experiments(
374+
self,
375+
mock_pipeline_service_create,
376+
mock_dataset_time_series,
377+
mock_model_service_get,
378+
sync,
379+
):
380+
aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME)
381+
382+
job = AutoMLForecastingTrainingJob(
383+
display_name=_TEST_DISPLAY_NAME,
384+
optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME,
385+
column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS,
386+
)
387+
388+
job._add_additional_experiments(_TEST_ADDITIONAL_EXPERIMENTS)
389+
390+
model_from_job = job.run(
391+
dataset=mock_dataset_time_series,
392+
target_column=_TEST_TRAINING_TARGET_COLUMN,
393+
time_column=_TEST_TRAINING_TIME_COLUMN,
394+
time_series_identifier_column=_TEST_TRAINING_TIME_SERIES_IDENTIFIER_COLUMN,
395+
unavailable_at_forecast_columns=_TEST_TRAINING_UNAVAILABLE_AT_FORECAST_COLUMNS,
396+
available_at_forecast_columns=_TEST_TRAINING_AVAILABLE_AT_FORECAST_COLUMNS,
397+
forecast_horizon=_TEST_TRAINING_FORECAST_HORIZON,
398+
data_granularity_unit=_TEST_TRAINING_DATA_GRANULARITY_UNIT,
399+
data_granularity_count=_TEST_TRAINING_DATA_GRANULARITY_COUNT,
400+
weight_column=_TEST_TRAINING_WEIGHT_COLUMN,
401+
time_series_attribute_columns=_TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS,
402+
context_window=_TEST_TRAINING_CONTEXT_WINDOW,
403+
budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS,
404+
export_evaluated_data_items=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS,
405+
export_evaluated_data_items_bigquery_destination_uri=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI,
406+
export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION,
407+
quantiles=_TEST_TRAINING_QUANTILES,
408+
validation_options=_TEST_TRAINING_VALIDATION_OPTIONS,
409+
sync=sync,
410+
)
411+
412+
if not sync:
413+
model_from_job.wait()
414+
415+
true_fraction_split = gca_training_pipeline.FractionSplit(
416+
training_fraction=_TEST_TRAINING_FRACTION_SPLIT,
417+
validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT,
418+
test_fraction=_TEST_TEST_FRACTION_SPLIT,
419+
)
420+
421+
# Test that if defaults to the job display name
422+
true_managed_model = gca_model.Model(display_name=_TEST_DISPLAY_NAME)
423+
424+
true_input_data_config = gca_training_pipeline.InputDataConfig(
425+
fraction_split=true_fraction_split,
426+
dataset_id=mock_dataset_time_series.name,
427+
)
428+
429+
true_training_pipeline = gca_training_pipeline.TrainingPipeline(
430+
display_name=_TEST_DISPLAY_NAME,
431+
training_task_definition=schema.training_job.definition.automl_forecasting,
432+
training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS,
433+
model_to_upload=true_managed_model,
434+
input_data_config=true_input_data_config,
435+
)
436+
437+
mock_pipeline_service_create.assert_called_once_with(
438+
parent=initializer.global_config.common_location_path(),
439+
training_pipeline=true_training_pipeline,
440+
)
441+
362442
@pytest.mark.usefixtures(
363443
"mock_pipeline_service_create",
364444
"mock_pipeline_service_get",
Collapse file

‎tests/unit/aiplatform/test_automl_tabular_training_jobs.py‎

Copy file name to clipboardExpand all lines: tests/unit/aiplatform/test_automl_tabular_training_jobs.py
+97-11Lines changed: 97 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,28 @@
5656
_TEST_TRAINING_DISABLE_EARLY_STOPPING = True
5757
_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME = "minimize-log-loss"
5858
_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE = "classification"
59+
_TEST_ADDITIONAL_EXPERIMENTS = ["exp1", "exp2"]
60+
_TEST_TRAINING_TASK_INPUTS_DICT = {
61+
# required inputs
62+
"targetColumn": _TEST_TRAINING_TARGET_COLUMN,
63+
"transformations": _TEST_TRAINING_COLUMN_TRANSFORMATIONS,
64+
"trainBudgetMilliNodeHours": _TEST_TRAINING_BUDGET_MILLI_NODE_HOURS,
65+
# optional inputs
66+
"weightColumnName": _TEST_TRAINING_WEIGHT_COLUMN,
67+
"disableEarlyStopping": _TEST_TRAINING_DISABLE_EARLY_STOPPING,
68+
"predictionType": _TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE,
69+
"optimizationObjective": _TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME,
70+
"optimizationObjectiveRecallValue": None,
71+
"optimizationObjectivePrecisionValue": None,
72+
}
5973
_TEST_TRAINING_TASK_INPUTS = json_format.ParseDict(
74+
_TEST_TRAINING_TASK_INPUTS_DICT,
75+
struct_pb2.Value(),
76+
)
77+
_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS = json_format.ParseDict(
6078
{
61-
# required inputs
62-
"targetColumn": _TEST_TRAINING_TARGET_COLUMN,
63-
"transformations": _TEST_TRAINING_COLUMN_TRANSFORMATIONS,
64-
"trainBudgetMilliNodeHours": _TEST_TRAINING_BUDGET_MILLI_NODE_HOURS,
65-
# optional inputs
66-
"weightColumnName": _TEST_TRAINING_WEIGHT_COLUMN,
67-
"disableEarlyStopping": _TEST_TRAINING_DISABLE_EARLY_STOPPING,
68-
"predictionType": _TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE,
69-
"optimizationObjective": _TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME,
70-
"optimizationObjectiveRecallValue": None,
71-
"optimizationObjectivePrecisionValue": None,
79+
**_TEST_TRAINING_TASK_INPUTS_DICT,
80+
"additionalExperiments": _TEST_ADDITIONAL_EXPERIMENTS,
7281
},
7382
struct_pb2.Value(),
7483
)
@@ -430,6 +439,83 @@ def test_run_call_pipeline_service_create_if_no_column_transformations(
430439
training_pipeline=true_training_pipeline,
431440
)
432441

442+
@pytest.mark.parametrize("sync", [True, False])
443+
# This test checks that default transformations are used if no columns transformations are provided
444+
def test_run_call_pipeline_service_create_if_set_additional_experiments(
445+
self,
446+
mock_pipeline_service_create,
447+
mock_pipeline_service_get,
448+
mock_dataset_tabular,
449+
mock_model_service_get,
450+
sync,
451+
):
452+
aiplatform.init(
453+
project=_TEST_PROJECT,
454+
staging_bucket=_TEST_BUCKET_NAME,
455+
encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME,
456+
)
457+
458+
job = training_jobs.AutoMLTabularTrainingJob(
459+
display_name=_TEST_DISPLAY_NAME,
460+
optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME,
461+
optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE,
462+
column_transformations=None,
463+
optimization_objective_recall_value=None,
464+
optimization_objective_precision_value=None,
465+
)
466+
467+
job._add_additional_experiments(_TEST_ADDITIONAL_EXPERIMENTS)
468+
469+
model_from_job = job.run(
470+
dataset=mock_dataset_tabular,
471+
target_column=_TEST_TRAINING_TARGET_COLUMN,
472+
model_display_name=_TEST_MODEL_DISPLAY_NAME,
473+
training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT,
474+
validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT,
475+
test_fraction_split=_TEST_TEST_FRACTION_SPLIT,
476+
predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME,
477+
weight_column=_TEST_TRAINING_WEIGHT_COLUMN,
478+
budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS,
479+
disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING,
480+
sync=sync,
481+
)
482+
483+
if not sync:
484+
model_from_job.wait()
485+
486+
true_fraction_split = gca_training_pipeline.FractionSplit(
487+
training_fraction=_TEST_TRAINING_FRACTION_SPLIT,
488+
validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT,
489+
test_fraction=_TEST_TEST_FRACTION_SPLIT,
490+
)
491+
492+
true_managed_model = gca_model.Model(
493+
display_name=_TEST_MODEL_DISPLAY_NAME,
494+
encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC,
495+
)
496+
497+
true_input_data_config = gca_training_pipeline.InputDataConfig(
498+
fraction_split=true_fraction_split,
499+
predefined_split=gca_training_pipeline.PredefinedSplit(
500+
key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME
501+
),
502+
dataset_id=mock_dataset_tabular.name,
503+
)
504+
505+
true_training_pipeline = gca_training_pipeline.TrainingPipeline(
506+
display_name=_TEST_DISPLAY_NAME,
507+
training_task_definition=schema.training_job.definition.automl_tabular,
508+
training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS,
509+
model_to_upload=true_managed_model,
510+
input_data_config=true_input_data_config,
511+
encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC,
512+
)
513+
514+
mock_pipeline_service_create.assert_called_once_with(
515+
parent=initializer.global_config.common_location_path(),
516+
training_pipeline=true_training_pipeline,
517+
)
518+
433519
@pytest.mark.usefixtures(
434520
"mock_pipeline_service_create",
435521
"mock_pipeline_service_get",

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.