Skip to content

Commit eaf4420

Browse files
Ark-kuncopybara-github
authored andcommitted
feat: LLM - Added support for the enable_checkpoint_selection tuning evaluation parameter
If set to True, the tuning process returns the best model checkpoint (based on model evaluation). If set to False, the latest model checkpoint is returned. By default, the selection is only enabled for `*-bison@001` models. PiperOrigin-RevId: 579980735
1 parent 87403a7 commit eaf4420

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tests/unit/aiplatform/test_language_models.py

+11
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ def reverse_string_2(s):""",
437437
"isOptional": True,
438438
"parameterType": "STRING",
439439
},
440+
"enable_checkpoint_selection": {
441+
"defaultValue": "default",
442+
"isOptional": True,
443+
"parameterType": "STRING",
444+
},
440445
"enable_early_stopping": {
441446
"defaultValue": True,
442447
"isOptional": True,
@@ -1837,6 +1842,7 @@ def test_tune_text_generation_model_ga(
18371842
evaluation_data_uri = "gs://bucket/eval.jsonl"
18381843
evaluation_interval = 37
18391844
enable_early_stopping = True
1845+
enable_checkpoint_selection = True
18401846
tensorboard_name = f"projects/{_TEST_PROJECT}/locations/{tuning_job_location}/tensorboards/123"
18411847

18421848
tuning_job = model.tune_model(
@@ -1849,6 +1855,7 @@ def test_tune_text_generation_model_ga(
18491855
evaluation_data=evaluation_data_uri,
18501856
evaluation_interval=evaluation_interval,
18511857
enable_early_stopping=enable_early_stopping,
1858+
enable_checkpoint_selection=enable_checkpoint_selection,
18521859
tensorboard=tensorboard_name,
18531860
),
18541861
accelerator_type="TPU",
@@ -1862,6 +1869,10 @@ def test_tune_text_generation_model_ga(
18621869
assert pipeline_arguments["evaluation_data_uri"] == evaluation_data_uri
18631870
assert pipeline_arguments["evaluation_interval"] == evaluation_interval
18641871
assert pipeline_arguments["enable_early_stopping"] == enable_early_stopping
1872+
assert (
1873+
pipeline_arguments["enable_checkpoint_selection"]
1874+
== enable_checkpoint_selection
1875+
)
18651876
assert pipeline_arguments["tensorboard_resource_id"] == tensorboard_name
18661877
assert pipeline_arguments["large_model_reference"] == "text-bison@001"
18671878
assert pipeline_arguments["accelerator_type"] == "TPU"

vertexai/language_models/_language_models.py

+9
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ def tune_model(
245245
tuning_parameters[
246246
"enable_early_stopping"
247247
] = eval_spec.enable_early_stopping
248+
if eval_spec.enable_checkpoint_selection is not None:
249+
tuning_parameters[
250+
"enable_checkpoint_selection"
251+
] = eval_spec.enable_checkpoint_selection
248252
if eval_spec.tensorboard is not None:
249253
if isinstance(eval_spec.tensorboard, aiplatform.Tensorboard):
250254
if eval_spec.tensorboard.location != tuning_job_location:
@@ -677,6 +681,10 @@ class TuningEvaluationSpec:
677681
evaluation_interval tuning steps. Default: 20.
678682
enable_early_stopping: If True, the tuning may stop early before
679683
completing all the tuning steps. Requires evaluation_data.
684+
enable_checkpoint_selection: If set to True, the tuning process returns
685+
the best model checkpoint (based on model evaluation).
686+
If set to False, the latest model checkpoint is returned.
687+
If unset, the selection is only enabled for `*-bison@001` models.
680688
tensorboard: Vertex Tensorboard where to write the evaluation metrics.
681689
The Tensorboard must be in the same location as the tuning job.
682690
"""
@@ -686,6 +694,7 @@ class TuningEvaluationSpec:
686694
evaluation_data: Optional[str] = None
687695
evaluation_interval: Optional[int] = None
688696
enable_early_stopping: Optional[bool] = None
697+
enable_checkpoint_selection: Optional[bool] = None
689698
tensorboard: Optional[Union[aiplatform.Tensorboard, str]] = None
690699

691700

0 commit comments

Comments
 (0)