Content-Length: 464546 | pFad | https://github.com/googleapis/python-aiplatform/commit/62ff30daa718ac7869714c68e55d6955d6355945

52 feat: LLM - Released `TextGenerationModel` tuning to GA · googleapis/python-aiplatform@62ff30d · GitHub
Skip to content

Commit 62ff30d

Browse files
Ark-kuncopybara-github
authored andcommitted
feat: LLM - Released TextGenerationModel tuning to GA
Changes from Preview: * `tune_model()` no longer blocks while the model is being tuned. * `tune_model()` no longer updates the model in-place once tuning has fnished. Instead, it returns a job that can be used to get the newly tuned model. * `tune_model()` now returns a tuning job object. The `tuning_job.tuned_model` property can be used to get the tuned model, waiting for the tuning to finish if needed. (This is also working in Preview) * The `learning_rate` parameter has been removed. Use `learning_rate_multiplier` instead. * The default value for `train_steps` has changed from 1000 to the tuning pipeline default value (usually 300). PiperOrigin-RevId: 558650122
1 parent 6f7ea84 commit 62ff30d

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

tests/system/aiplatform/test_language_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_tuning(self, shared_state):
165165
"""Test tuning, listing and loading models."""
166166
aiplatform.init(project=e2e_base._PROJECT, location=e2e_base._LOCATION)
167167

168-
model = TextGenerationModel.from_pretrained("google/text-bison@001")
168+
model = language_models.TextGenerationModel.from_pretrained("text-bison@001")
169169

170170
import pandas
171171

tests/unit/aiplatform/test_language_models.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,86 @@ def test_tune_text_generation_model(
13841384
== test_constants.EndpointConstants._TEST_ENDPOINT_NAME
13851385
)
13861386

1387+
@pytest.mark.parametrize(
1388+
"job_spec",
1389+
[_TEST_PIPELINE_SPEC_JSON, _TEST_PIPELINE_JOB],
1390+
)
1391+
@pytest.mark.parametrize(
1392+
"mock_request_urlopen",
1393+
["https://us-central1-kfp.pkg.dev/proj/repo/pack/latest"],
1394+
indirect=True,
1395+
)
1396+
def test_tune_text_generation_model_ga(
1397+
self,
1398+
mock_pipeline_service_create,
1399+
mock_pipeline_job_get,
1400+
mock_pipeline_bucket_exists,
1401+
job_spec,
1402+
mock_load_yaml_and_json,
1403+
mock_gcs_from_string,
1404+
mock_gcs_upload,
1405+
mock_request_urlopen,
1406+
mock_get_tuned_model,
1407+
):
1408+
"""Tests tuning the text generation model."""
1409+
aiplatform.init(
1410+
project=_TEST_PROJECT,
1411+
location=_TEST_LOCATION,
1412+
encryption_spec_key_name=_TEST_ENCRYPTION_KEY_NAME,
1413+
)
1414+
with mock.patch.object(
1415+
target=model_garden_service_client.ModelGardenServiceClient,
1416+
attribute="get_publisher_model",
1417+
return_value=gca_publisher_model.PublisherModel(
1418+
_TEXT_BISON_PUBLISHER_MODEL_DICT
1419+
),
1420+
):
1421+
model = language_models.TextGenerationModel.from_pretrained(
1422+
"text-bison@001"
1423+
)
1424+
1425+
tuning_job_location = "europe-west4"
1426+
evaluation_data_uri = "gs://bucket/eval.jsonl"
1427+
evaluation_interval = 37
1428+
enable_early_stopping = True
1429+
tensorboard_name = f"projects/{_TEST_PROJECT}/locations/{tuning_job_location}/tensorboards/123"
1430+
1431+
tuning_job = model.tune_model(
1432+
training_data=_TEST_TEXT_BISON_TRAINING_DF,
1433+
tuning_job_location=tuning_job_location,
1434+
tuned_model_location="us-central1",
1435+
learning_rate_multiplier=2.0,
1436+
train_steps=10,
1437+
tuning_evaluation_spec=preview_language_models.TuningEvaluationSpec(
1438+
evaluation_data=evaluation_data_uri,
1439+
evaluation_interval=evaluation_interval,
1440+
enable_early_stopping=enable_early_stopping,
1441+
tensorboard=tensorboard_name,
1442+
),
1443+
)
1444+
call_kwargs = mock_pipeline_service_create.call_args[1]
1445+
pipeline_arguments = call_kwargs[
1446+
"pipeline_job"
1447+
].runtime_config.parameter_values
1448+
assert pipeline_arguments["learning_rate_multiplier"] == 2.0
1449+
assert pipeline_arguments["train_steps"] == 10
1450+
assert pipeline_arguments["evaluation_data_uri"] == evaluation_data_uri
1451+
assert pipeline_arguments["evaluation_interval"] == evaluation_interval
1452+
assert pipeline_arguments["enable_early_stopping"] == enable_early_stopping
1453+
assert pipeline_arguments["tensorboard_resource_id"] == tensorboard_name
1454+
assert pipeline_arguments["large_model_reference"] == "text-bison@001"
1455+
assert (
1456+
call_kwargs["pipeline_job"].encryption_spec.kms_key_name
1457+
== _TEST_ENCRYPTION_KEY_NAME
1458+
)
1459+
1460+
# Testing the tuned model
1461+
tuned_model = tuning_job.get_tuned_model()
1462+
assert (
1463+
tuned_model._endpoint_name
1464+
== test_constants.EndpointConstants._TEST_ENDPOINT_NAME
1465+
)
1466+
13871467
@pytest.mark.parametrize(
13881468
"job_spec",
13891469
[_TEST_PIPELINE_SPEC_JSON],

vertexai/language_models/_language_models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,9 @@ def batch_predict(
894894
)
895895

896896

897-
class TextGenerationModel(_TextGenerationModel, _ModelWithBatchPredict):
897+
class TextGenerationModel(
898+
_TextGenerationModel, _TunableTextModelMixin, _ModelWithBatchPredict
899+
):
898900
pass
899901

900902

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/googleapis/python-aiplatform/commit/62ff30daa718ac7869714c68e55d6955d6355945

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy