Skip to content

Commit

Permalink
feat: LLM - Added support for the enable_checkpoint_selection tunin…
Browse files Browse the repository at this point in the history
…g 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
  • Loading branch information
Ark-kun authored and copybara-github committed Nov 6, 2023
1 parent 87403a7 commit eaf4420
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/unit/aiplatform/test_language_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ def reverse_string_2(s):""",
"isOptional": True,
"parameterType": "STRING",
},
"enable_checkpoint_selection": {
"defaultValue": "default",
"isOptional": True,
"parameterType": "STRING",
},
"enable_early_stopping": {
"defaultValue": True,
"isOptional": True,
Expand Down Expand Up @@ -1837,6 +1842,7 @@ def test_tune_text_generation_model_ga(
evaluation_data_uri = "gs://bucket/eval.jsonl"
evaluation_interval = 37
enable_early_stopping = True
enable_checkpoint_selection = True
tensorboard_name = f"projects/{_TEST_PROJECT}/locations/{tuning_job_location}/tensorboards/123"

tuning_job = model.tune_model(
Expand All @@ -1849,6 +1855,7 @@ def test_tune_text_generation_model_ga(
evaluation_data=evaluation_data_uri,
evaluation_interval=evaluation_interval,
enable_early_stopping=enable_early_stopping,
enable_checkpoint_selection=enable_checkpoint_selection,
tensorboard=tensorboard_name,
),
accelerator_type="TPU",
Expand All @@ -1862,6 +1869,10 @@ def test_tune_text_generation_model_ga(
assert pipeline_arguments["evaluation_data_uri"] == evaluation_data_uri
assert pipeline_arguments["evaluation_interval"] == evaluation_interval
assert pipeline_arguments["enable_early_stopping"] == enable_early_stopping
assert (
pipeline_arguments["enable_checkpoint_selection"]
== enable_checkpoint_selection
)
assert pipeline_arguments["tensorboard_resource_id"] == tensorboard_name
assert pipeline_arguments["large_model_reference"] == "text-bison@001"
assert pipeline_arguments["accelerator_type"] == "TPU"
Expand Down
9 changes: 9 additions & 0 deletions vertexai/language_models/_language_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ def tune_model(
tuning_parameters[
"enable_early_stopping"
] = eval_spec.enable_early_stopping
if eval_spec.enable_checkpoint_selection is not None:
tuning_parameters[
"enable_checkpoint_selection"
] = eval_spec.enable_checkpoint_selection
if eval_spec.tensorboard is not None:
if isinstance(eval_spec.tensorboard, aiplatform.Tensorboard):
if eval_spec.tensorboard.location != tuning_job_location:
Expand Down Expand Up @@ -677,6 +681,10 @@ class TuningEvaluationSpec:
evaluation_interval tuning steps. Default: 20.
enable_early_stopping: If True, the tuning may stop early before
completing all the tuning steps. Requires evaluation_data.
enable_checkpoint_selection: 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.
If unset, the selection is only enabled for `*-bison@001` models.
tensorboard: Vertex Tensorboard where to write the evaluation metrics.
The Tensorboard must be in the same location as the tuning job.
"""
Expand All @@ -686,6 +694,7 @@ class TuningEvaluationSpec:
evaluation_data: Optional[str] = None
evaluation_interval: Optional[int] = None
enable_early_stopping: Optional[bool] = None
enable_checkpoint_selection: Optional[bool] = None
tensorboard: Optional[Union[aiplatform.Tensorboard, str]] = None


Expand Down

0 comments on commit eaf4420

Please sign in to comment.