I have to specify Hyperparameters Tuning Variables in Python, for a custom Job in Vertex AI in google Cloud.
https://cloud.google.com/vertex-ai/docs/training/using-hyperparameter-tuning?hl=en
from google.cloud import aiplatform
from google.cloud.aiplatform import hyperparameter_tuning as hpt
def create_hyperparameter_tuning_job_sample(
project: str,
location: str,
staging_bucket: str,
display_name: str,
container_uri: str, ):
aiplatform.init(project=project, location=location, staging_bucket=staging_bucket)
worker_pool_specs = [
{
"machine_spec": {
"machine_type": "n1-standard-4",
"accelerator_type": "NVIDIA_TESLA_K80",
"accelerator_count": 1,
},
"replica_count": 1,
"container_spec": {
"image_uri": container_uri,
"command": [],
"args": [],
},
}
]
custom_job = aiplatform.CustomJob(
display_name='custom_job',
worker_pool_specs=worker_pool_specs,
)
hpt_job = aiplatform.HyperparameterTuningJob(
display_name=display_name,
custom_job=custom_job,
metric_spec={
'loss': 'minimize',
},
parameter_spec={
'lr': hpt.DoubleParameterSpec(min=0.001, max=0.1, scale='log'),
'units': hpt.IntegerParameterSpec(min=4, max=128, scale='linear'),
'activation': hpt.CategoricalParameterSpec(values=['relu', 'selu']),
'batch_size': hpt.DiscreteParameterSpec(values=[128, 256], scale='linear')
},
max_trial_count=128,
parallel_trial_count=8,
labels={'my_key': 'my_value'},
)
hpt_job.run()
print(hpt_job.resource_name)
return hpt_job
This job in the example is creating an hyperparameter tuning job.
How to specify the StudySpec ?
StudySpec contains the specification of the algorythm that you want to use. See this page: https://cloud.google.com/vertex-ai/docs/reference/rest/v1/StudySpec?hl=en
Just see this screenshot to better understand, this is when you create the hyper parameters in Google Cloud.
Also see the dropdown menu option: