Skip to content

Commit 3d43497

Browse files
Ark-kuncopybara-github
authored andcommitted
feat: LLM - Added new regions for tuning and tuned model inference
PiperOrigin-RevId: 576294181
1 parent ffbd872 commit 3d43497

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

vertexai/language_models/_language_models.py

+37-20
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ def tune_model(
190190
Learning rate to use in tuning.
191191
learning_rate_multiplier: Learning rate multiplier to use in tuning.
192192
tuning_job_location: GCP location where the tuning job should be run.
193-
Only "europe-west4" and "us-central1" locations are supported for now.
194-
tuned_model_location: GCP location where the tuned model should be deployed. Only "us-central1" is supported for now.
193+
tuned_model_location: GCP location where the tuned model should be deployed.
195194
model_display_name: Custom display name for the tuned model.
196195
tuning_evaluation_spec: Specification for the model evaluation during tuning.
197196
default_context: The context to use for all training samples by default.
@@ -294,8 +293,7 @@ def _tune_model(
294293
See https://cloud.google.com/vertex-ai/docs/generative-ai/models/tune-models#dataset_format
295294
tuning_parameters: Tuning pipeline parameter values.
296295
tuning_job_location: GCP location where the tuning job should be run.
297-
Only "europe-west4" and "us-central1" locations are supported for now.
298-
tuned_model_location: GCP location where the tuned model should be deployed. Only "us-central1" is supported for now.
296+
tuned_model_location: GCP location where the tuned model should be deployed.
299297
model_display_name: Custom display name for the tuned model.
300298
301299
Returns:
@@ -312,9 +310,10 @@ def _tune_model(
312310
"Please specify the tuning job location (`tuning_job_location`)."
313311
f"Tuning is supported in the following locations: {_TUNING_LOCATIONS}"
314312
)
315-
if tuned_model_location != _TUNED_MODEL_LOCATION:
313+
if tuned_model_location not in _TUNED_MODEL_LOCATIONS:
316314
raise ValueError(
317-
f'Model deployment is only supported in the following locations: tuned_model_location="{_TUNED_MODEL_LOCATION}"'
315+
"Tuned model deployment is only supported in the following locations: "
316+
f"{_TUNED_MODEL_LOCATIONS}"
318317
)
319318
model_info = _model_garden_models._get_model_info(
320319
model_id=self._model_id,
@@ -329,6 +328,7 @@ def _tune_model(
329328
tuning_parameters=tuning_parameters,
330329
model_display_name=model_display_name,
331330
tuning_job_location=tuning_job_location,
331+
tuned_model_location=tuned_model_location,
332332
)
333333

334334
job = _LanguageModelTuningJob(
@@ -369,8 +369,7 @@ def tune_model(
369369
train_steps: Number of training batches to tune on (batch size is 8 samples).
370370
learning_rate_multiplier: Learning rate multiplier to use in tuning.
371371
tuning_job_location: GCP location where the tuning job should be run.
372-
Only "europe-west4" and "us-central1" locations are supported for now.
373-
tuned_model_location: GCP location where the tuned model should be deployed. Only "us-central1" is supported for now.
372+
tuned_model_location: GCP location where the tuned model should be deployed.
374373
model_display_name: Custom display name for the tuned model.
375374
tuning_evaluation_spec: Specification for the model evaluation during tuning.
376375
accelerator_type: Type of accelerator to use. Can be "TPU" or "GPU".
@@ -436,8 +435,7 @@ def tune_model(
436435
Learning rate to use in tuning.
437436
learning_rate_multiplier: Learning rate multiplier to use in tuning.
438437
tuning_job_location: GCP location where the tuning job should be run.
439-
Only "europe-west4" and "us-central1" locations are supported for now.
440-
tuned_model_location: GCP location where the tuned model should be deployed. Only "us-central1" is supported for now.
438+
tuned_model_location: GCP location where the tuned model should be deployed.
441439
model_display_name: Custom display name for the tuned model.
442440
tuning_evaluation_spec: Specification for the model evaluation during tuning.
443441
accelerator_type: Type of accelerator to use. Can be "TPU" or "GPU".
@@ -503,8 +501,7 @@ def tune_model(
503501
Learning rate to use in tuning.
504502
learning_rate_multiplier: Learning rate multiplier to use in tuning.
505503
tuning_job_location: GCP location where the tuning job should be run.
506-
Only "europe-west4" and "us-central1" locations are supported for now.
507-
tuned_model_location: GCP location where the tuned model should be deployed. Only "us-central1" is supported for now.
504+
tuned_model_location: GCP location where the tuned model should be deployed.
508505
model_display_name: Custom display name for the tuned model.
509506
default_context: The context to use for all training samples by default.
510507
accelerator_type: Type of accelerator to use. Can be "TPU" or "GPU".
@@ -570,8 +567,7 @@ def tune_model(
570567
Learning rate to use in tuning.
571568
learning_rate_multiplier: Learning rate multiplier to use in tuning.
572569
tuning_job_location: GCP location where the tuning job should be run.
573-
Only "europe-west4" and "us-central1" locations are supported for now.
574-
tuned_model_location: GCP location where the tuned model should be deployed. Only "us-central1" is supported for now.
570+
tuned_model_location: GCP location where the tuned model should be deployed.
575571
model_display_name: Custom display name for the tuned model.
576572
default_context: The context to use for all training samples by default.
577573
accelerator_type: Type of accelerator to use. Can be "TPU" or "GPU".
@@ -2697,9 +2693,29 @@ class _PreviewCodeGenerationModel(
26972693

26982694
###### Model tuning
26992695
# Currently, tuning can only work in this location
2700-
_TUNING_LOCATIONS = ("europe-west4", "us-central1")
2701-
# Currently, deployment can only work in this location
2702-
_TUNED_MODEL_LOCATION = "us-central1"
2696+
2697+
_SUPPORTED_LOCATIONS = [
2698+
# 1
2699+
"us-central1",
2700+
"europe-west4",
2701+
"asia-southeast1",
2702+
# 2
2703+
"us-west1",
2704+
"europe-west3",
2705+
"europe-west2",
2706+
"asia-northeast1",
2707+
# 3
2708+
"us-east4",
2709+
"us-west4",
2710+
"northamerica-northeast1",
2711+
"europe-west9",
2712+
"europe-west1",
2713+
"asia-northeast3",
2714+
]
2715+
2716+
_TUNING_LOCATIONS = _SUPPORTED_LOCATIONS
2717+
# Currently, deployment can only work in these locations
2718+
_TUNED_MODEL_LOCATIONS = _SUPPORTED_LOCATIONS
27032719

27042720

27052721
class _LanguageModelTuningJob:
@@ -2771,7 +2787,7 @@ def _list_tuned_model_names(model_id: str) -> List[str]:
27712787
tuned_models = aiplatform.Model.list(
27722788
filter=f'labels.{_TUNING_BASE_MODEL_ID_LABEL_KEY}="{model_id.replace("@", "-")}"',
27732789
# TODO(b/275444096): Remove the explicit location once models are deployed to the user's selected location
2774-
location=_TUNED_MODEL_LOCATION,
2790+
location=aiplatform_initializer.global_config.location,
27752791
)
27762792
model_names = [model.resource_name for model in tuned_models]
27772793
return model_names
@@ -2789,8 +2805,9 @@ def _launch_tuning_job(
27892805
model_id: str,
27902806
tuning_pipeline_uri: str,
27912807
tuning_parameters: Dict[str, Any],
2808+
tuning_job_location: str,
2809+
tuned_model_location: str,
27922810
model_display_name: Optional[str] = None,
2793-
tuning_job_location: str = _TUNING_LOCATIONS[0],
27942811
) -> aiplatform.PipelineJob:
27952812
output_dir_uri = _generate_tuned_model_dir_uri(model_id=model_id)
27962813
if isinstance(training_data, str):
@@ -2836,7 +2853,7 @@ def _launch_tuning_job(
28362853
"project": aiplatform_initializer.global_config.project,
28372854
# TODO(b/275444096): Remove the explicit location once tuning can happen in all regions
28382855
# "location": aiplatform_initializer.global_config.location,
2839-
"location": _TUNED_MODEL_LOCATION,
2856+
"location": tuned_model_location,
28402857
"large_model_reference": model_id,
28412858
"model_display_name": model_display_name,
28422859
}

0 commit comments

Comments
 (0)