Prepare and test your skills
Prepare and test your skills
Automated optimization pipelines turn one-off hyperparameter searches into repeatable production workflows. A HyperparameterTuningJob (opens in a new tab) runs many trials of the same training application with different hyperparameter values, reports a numeric metric from each trial, and returns the most effective configuration plus a per-trial summary for analysis and retraining.
Trial results are the record of how each hyperparameter configuration performed against the study objective. A studySpec defines one or more metrics by metricId and goal, where the goal is either MAXIMIZE such as accuracy or MINIMIZE such as loss, and defines each tuned hyperparameter by parameterId, data type, and allowed range. The training application must parse a command-line flag with the same name as each parameterId and must report the metric back to the tuning service, so the service can link the values it sent to the outcome it received.
For custom training on Gemini Enterprise Agent Platform, the reporting path flows from training code to the tuning service through the cloudml-hypertune Python package. The training process calls report_hyperparameter_tuning_metric with the metric value, the service stores the value against that trial, and Bayesian optimization uses completed trial results to choose values for subsequent trials. The service also improves across related tuning jobs when models are similar and only the objective function or an input column changes, which makes repeated tuning more efficient over time.
Job configuration controls the cost and quality tradeoff of the search. Billing is based on the duration of the trials initiated by the tuning job, and every additional tuned hyperparameter can increase the number of trials needed for a successful result. Three controls bound the search:
maxTrialCount sets the maximum number of trials the service may run, where more trials generally improve results but increase time and cost.parallelTrialCount sets how many trials can run at the same time, which shortens wall-clock time but can reduce the benefit of sequential Bayesian updates.Exam tip: Hyperparameters stay constant during a single trial while model parameters such as neural network weights change during training; tune hyperparameters by comparing aggregate trial metrics, not by inspecting in-trial weight updates.
Performance analysis compares trial metrics, hyperparameter values, and resource cost to select a configuration that generalizes and fits budget. When the tuning job finishes, the platform reports the best configuration according to the specified goal and a summary for each trial, including the hyperparameter values tried and the metric values observed. That summary is the basis for judging whether gains came from a meaningful region of the search space or from noise, overfitting, or an overly narrow range.
Vertex AI Experiments (opens in a new tab) and Vertex AI TensorBoard provide experiment tracking and visualization for that comparison. Experiments automatically logs parameters, code versions, dataset versions, and results for each training and evaluation run, which creates a versioned history for comparison, debugging, and reproducibility. TensorBoard visualizes metric curves and hyperparameter relationships, while pipeline logging and tracing plus Cloud Monitoring alerts expose resource usage such as GPU utilization, throughput, latency, and errors during tuning trials.
Continuous validation extends visualization into a deployment decision. An automated evaluation step checks each candidate against thresholds such as minimum accuracy, maximum error rate, and minimum F1 score, and only a model that meets all thresholds is considered for deployment. Evaluation includes task-specific quality measures for generated output, factual accuracy, safety attributes, and style or format adherence, and successful artifacts are versioned in Cloud Storage or registered in Model Registry with their tuning lineage intact.
Vertex AI Pipelines is the serverless orchestrator for embedding hyperparameter tuning into a continuous training workflow. A pipeline defines the end-to-end lifecycle as modular components that pass artifacts and metadata in order:
The tuning step depends on upstream data components for its dataset and downstream evaluation components depend on the tuning step for its best model and trial summary.
The pipeline component for tuning is HyperparameterTuningJobRunOp from the Google Cloud Pipeline Components SDK. The component creates a HyperparameterTuningJob resource with a studySpec for metrics and parameters and a trialJobSpec for the per-trial serverless training job, including machine type, accelerator choice, replica count, and either a custom container image or Python package. A custom container (opens in a new tab) used for tuning must install cloudml-hypertune, define and parse each hyperparameter as a command-line argument with argparse, assign those argument values to hyperparameters in code, and for GPU training pre-install CUDA and cuDNN, typically by building from an nvidia/cuda base image.
Pipeline execution is automated through schedules or event triggers such as new data arrival, code changes, or monitoring signals like data drift. Each run uses automated parameterization and versioning, monitors progress with built-in logging and tracing, and stores intermediate files such as materialized datasets and models in a root output directory in Cloud Storage. The console path creates this automation as a TrainingPipeline that launches a HyperparameterTuningJob, while programmatic paths use the Kubeflow Pipelines (KFP) SDK or TensorFlow Extended SDK, the gcloud ai hp-tuning-jobs create command with --max-trial-count and --parallel-trial-count, or the Vertex AI SDK for Python with DoubleParameterSpec, IntegerParameterSpec, CategoricalParameterSpec, and DiscreteParameterSpec.
Continuous retraining connects tuning pipelines to production data, infrastructure, and governance so optimization repeats without manual toil. Cloud Composer, the managed Airflow service, orchestrates end-to-end enterprise MLOps workflows that span Google Cloud services, while Vertex AI Pipelines orchestrates serverless ML workflows natively inside the platform. Both approaches coordinate the same supporting services: Dataflow for data processing, custom training for tuning trials and distributed training, Model Registry for versioned artifacts, and platform endpoints for serving.
The two orchestrators differ in scope and operational model:
| Orchestrator | Execution model | Choose when |
|---|---|---|
| Vertex AI Pipelines | Serverless workflow built into the platform, defined with KFP SDK components | The workflow is ML-centric and benefits from native tuning, evaluation, registry, and endpoint components |
| Cloud Composer | Managed Airflow for cross-service DAGs across the enterprise | The workflow must coordinate many Google Cloud and external systems beyond training, such as ingestion, warehouse, and IT operations |
Reliability controls (opens in a new tab) surround the automated loop. Infrastructure is managed as code with Terraform, Cluster Toolkit blueprints, and Config Connector manifests, with separate dev, staging, and prod configurations promoted through Cloud Build and Infrastructure Manager CI/CD pipelines. Data and checkpoint redundancy uses multi-regional or dual-region Cloud Storage buckets, metadata uses globally consistent storage, and serving uses multi-region endpoints with global load balancing. Hyperparameter tuning jobs in this loop do not support TPUs, so accelerator planning must select CPU or GPU machine types available in the training region.
GCP hyperparameter tuning services in this scope are the Vertex AI and GKE mechanisms that run optimization trials and serve the resulting models under explicit resource and metric constraints. Selection depends on model type, scale, and constraints: Vertex AI Training (opens in a new tab) with custom jobs provides managed compute for large-model preparation, GKE Inference Gateway provides AI-aware routing and autoscaling for generative AI and large language model (LLM) serving, and GKE Gateway with Custom Metrics provides general-purpose Application Load Balancer control driven by application-reported signals.
Vertex AI Training with CustomJob runs preparation work on a managed virtual machine when a model is too large to fit into local memory or disk. The job is defined by aiplatform.CustomJob.from_local_script() with a container image such as us-docker.pkg.dev/vertex-ai/training/pytorch-gpu.1-13:latest, a machine_type such as e2-highmem-2, a boot_disk_size_gb such as 100, and Python requirements such as transformers. The model must fit into the virtual machine memory, and the disk must have enough space to stage the entire model while it is copied to Cloud Storage. A typical pattern mounts Cloud Storage with Cloud Storage FUSE at /gcs, replaces a gs:// path with /gcs/, creates the destination directory, and calls torch.save(model.state_dict(), state_dict_path) so training and tuning artifacts flow from the training virtual machine to the Cloud Storage bucket.
Vertex AI prediction autoscaling (opens in a new tab) allocates replicas between MIN_REPLICA_COUNT and MAX_REPLICA_COUNT based on a named metric and a TARGET_THRESHOLD. Traffic flows from the endpoint to deployed model replicas, and the autoscaler adds or removes replicas to hold the per-replica metric near its target. If deployment is configured to scale only on CPU usage, the deployment will not scale up even when GPU usage is high, so the metric must match the bottleneck resource.
The supported autoscaling metrics are:
aiplatform.googleapis.com/prediction/online/cpu/utilization): CPU utilization per replica, target 0-100 percent, default 60 percent.aiplatform.googleapis.com/prediction/online/accelerator/duty_cycle): GPU utilization per replica, target 0-100 percent, default 60 percent.prometheus.googleapis.com/vertex_dcgm_fi_dev_gpu_util): DCGM-based GPU utilization per replica, target 0-100 percent, disabled by default.prometheus.googleapis.com/vertex_vllm_gpu_cache_usage_perc): KV cache usage per replica, target 0-100 percent, disabled by default.prometheus.googleapis.com/vertex_vllm_num_requests_waiting): waiting requests per replica, target as integer, disabled by default.aiplatform.googleapis.com/prediction/online/request_count): requests per minute per replica, target as integer, disabled by default.pubsub.googleapis.com/subscription/num_undelivered_messages): undelivered messages per replica, target as integer, disabled by default.Deployment uses gcloud ai endpoints deploy-model with ENDPOINT_ID, PROJECT_ID, LOCATION, MODEL_ID, MACHINE_TYPE such as n1-standard-4, optional ACCELERATOR_TYPE such as NVIDIA_L4 and ACCELERATOR_COUNT, plus the replica bounds and metric target. The gCloud metric keywords are cpu-usage, gpu-duty-cycle, dcgm-fi-dev-gpu-util, vllm-gpu-cache-usage-perc, vllm-num-requests-waiting, and request-counts-per-minute.
GKE Inference Gateway (opens in a new tab) is the GKE Gateway API extension for demanding generative AI and LLM inference workloads with non-uniform request costs. The gateway monitors KV cache utilization, pending request queue length, GPU/TPU utilization, LoRA adapter availability, and per-request computational cost, then distributes traffic from the gateway to the most suitable and least loaded model server replica such as vLLM. The gateway also applies request criticality levels for prioritization, drives autoscaling from AI-specific signals such as KV cache utilization, and exposes built-in observability for GPU/TPU utilization, KV cache hits, queue length, and model latency. Configuration extends the standard Gateway API with InferencePool and InferenceModel Custom Resource Definitions (CRDs) and supports a user-managed Endpoint Picker, with gateway-level AI-content filtering through Model Armor plus TLS, Identity and Access Management (IAM), role-based access control (RBAC), and namespaces.
GKE Gateway with Custom Metrics is the general-purpose alternative that distributes HTTP(S) traffic through Application Load Balancers using application-reported load signals. The application reports metrics through the Open Request Cost Aggregation (ORCA) standard in HTTP headers, including standard CPU and memory signals and custom-named signals for constrained resources, and the load balancer applies policies such as WEIGHTED_ROUND_ROBIN for endpoint weighting within a locality. The solution integrates with the Horizontal Pod Autoscaler (HPA) on custom metrics, uses the standard Application Load Balancer security stack of Google Cloud Armor, TLS termination, and IAM, and surfaces reported metrics in Cloud Monitoring. Choose this option when requests have relatively uniform cost, one or two custom metrics describe load, and no LLM-specific routing, LoRA affinity, or request prioritization is required.
| Feature | GKE Inference Gateway | GKE Gateway with Custom Metrics |
|---|---|---|
| Primary use case | Latency-sensitive GPU/TPU LLM serving with fair access to model resources | General-purpose HTTP(S) balancing on application-reported utilization |
| Supported metrics | Native AI metrics plus optional application-reported headers | ORCA-reported standard and custom-named metrics only |
| Request handling | Non-uniform LLM costs with criticality levels and prioritization | Uniform-cost traffic with no native prioritization |
| LoRA support | Native affinity-based routing to backends with specific adapters | No native LoRA affinity routing |
| Autoscaling input | AI-specific signals such as KV cache utilization | Generic HPA signals reported to the load balancer |
Exam tip: Choose GKE Inference Gateway when routing must use KV cache utilization, queue length, or LoRA adapter availability; choose GKE Gateway with Custom Metrics when one or two ORCA-reported metrics are sufficient and LLM-specific features are not needed.
TPU7x (Ironwood) (opens in a new tab) performance options control how tuning trials consume high-bandwidth memory (HBM), memory bandwidth, and matrix-multiply throughput. Each chip provides 192 GB of HBM and hardware acceleration for FP8 with 4614 TFLOPS peak, yielding about 1.3x improvement over BF16 training on dense matrix multiplications common in AI workloads. Compared to BF16, FP8 doubles peak FLOPs and halves the footprint for weights and activations, so FP8 is the primary lever for compute-bound trials and for trials constrained by capacity or bandwidth.
FP8 reduces optimization cost in three related ways:
FP8 quality depends on scaling granularity, scaling mode, and format choice. Start with per-tensor scaling and move to per-axis scaling only if quality or performance issues appear, since subchannel scaling may be unnecessary. Use dynamic scaling that computes factors at runtime as the default for quality, use static scaling only after profiling determines correct factors, and consider fixing the scale to the FP8 limit for robust models to reduce quantization overhead. Use a mixed format of E4M3 for weights and activations in the forward pass for higher precision and E5M2 for gradients in the backward pass for wider dynamic range.
Designing efficient search spaces and optimization strategies means defining exactly which hyperparameters Agent Platform may vary, what values each may take, and which search algorithm chooses the next trial under a fixed trial budget. Agent Platform hyperparameter tuning (opens in a new tab) runs multiple trials of the same training application with different configurations, tracks the reported metric from each trial, and uses those results to suggest better configurations for later trials. When the job finishes, the service returns the most effective configuration plus a summary of all trials.
Hyperparameters are the configuration variables that govern the training process itself, such as number of hidden layers, nodes per layer, batch size, or learning rate. Hyperparameters differ from the other two data categories handled during training: input data are the training instances with features, and parameters are the learned variables such as deep neural network (DNN) neuron weights that change during a single training job, while hyperparameters are usually constant during that job. Parameters are optimized inside one training run by comparing inferences to true values, while hyperparameters are optimized across whole training runs by comparing aggregate accuracy.
A tuning job formalizes that outer loop as a study. The developer defines a StudySpec with goal metrics to maximize or minimize, such as accuracy or loss, and a set of ParameterSpec objects that bound each hyperparameter. Trial values flow from the StudySpec to the training application as command-line arguments, so the training module must define a matching argument for each tuned hyperparameter and use that argument value in code. Metric values flow back from the training application to Agent Platform through the cloudml-hypertune Python package, which reports each trial's numeric result for the named metric.
The search space in a ParameterSpec is parameterized by choosing one value specification that controls the data type, allowed range, and sampling behavior. Each additional hyperparameter expands the volume of the space and can increase the number of trials needed for a successful job, and because charges are based on the duration of initiated trials, a tight, well-chosen space directly controls time and cost. Agent Platform also improves efficiency across related tuning jobs, reusing what it learned when only the objective function changes or a new input column is added.
| Value specification | Data type | Range definition | Holds |
|---|---|---|---|
| DoubleValueSpec | DOUBLE | minValue and maxValue | Floating-point continuous values, for example learning rate bounds |
| IntegerValueSpec | INTEGER | minValue and maxValue | Integer continuous values, for example layer size bounds |
| CategoricalValueSpec | CATEGORICAL | categoricalValues | List of category strings, for example optimizer names |
| DiscreteValueSpec | DISCRETE | discreteValues | List of values in ascending order, for example a fixed set of batch sizes |
In BigQuery ML (opens in a new tab), the same distinction is expressed in the CREATE MODEL statement. Tuning is enabled by setting the NUM_TRIALS option, and each hyperparameter uses HPARAM_RANGE, a two-element ARRAY(FLOAT64) with minimum and maximum bounds for continuous search, or HPARAM_CANDIDATES, an array of structs that lists the discrete values to try. AutoML Tables models embed automatic tuning by default, while ARIMA_PLUS models tune only the trend module through AUTO_ARIMA and do not support tuning the full modeling pipeline.
Scaling in a ParameterSpec reshapes how Agent Platform samples from the feasible space for DOUBLE and INTEGER types, and scaling is recommended for those types. Scaling maps the feasible interval to 0 through 1 so the optimizer explores evenly in the transformed space rather than bunching samples in one region. The choice matters most when a hyperparameter spans orders of magnitude, such as a learning rate from 0.0001 to 1.0.
SCALE_TYPE_UNSPECIFIED: No scaling is applied to the hyperparameter, so sampling follows the raw numeric interval.UNIT_LINEAR_SCALE: Scales the feasible space linearly from 0 through 1, preserving equal numeric distances.UNIT_LOG_SCALE: Scales the feasible space logarithmically from 0 through 1, spreading out small values; the entire feasible space must be strictly positive.UNIT_REVERSE_LOG_SCALE: Scales the feasible space reverse-logarithmically from 0 through 1, spreading out values close to the top of the space more than points near the bottom; the entire feasible space must be strictly positive.A ConditionalParameterSpec adds hyperparameters to a trial only when a parent hyperparameter value matches a specified condition, which defines the search space as a graph rather than a flat list. The parent is typically categorical, such as a training_method hyperparameter with LINEAR_REGRESSION and DNN options, while the child is added only for matching trials, such as adding num_hidden_layers only when training_method is DNN. The match rule depends on the parent type: a categorical parent matches listed strings, while a discrete parent matches listed integers.
Conditional hyperparameters also control whether learning transfers across branches. A shared child, such as one learning_rate used by both LINEAR_REGRESSION and DNN trials, lets the optimizer apply lessons from one branch to the other. Separate children with the same name, such as one learning_rate added under LINEAR_REGRESSION and a different learning_rate added under DNN, keep tuning independent when the optimal values should not influence each other. Choose separate conditionals when techniques have different dynamics, and choose shared conditionals only when knowledge should carry over.
The search algorithm in the StudySpec controls how Agent Platform selects the next hyperparameter configuration from prior trial results. If no algorithm is specified, the job uses the default Agent Platform algorithm, which applies Bayesian optimization to reach an optimal solution with a more effective search over the parameter space. Bayesian optimization models the relationship between hyperparameters and the goal metric and then balances exploration of uncertain regions against exploitation of known good regions.
| Algorithm | How values are chosen | Choose when |
|---|---|---|
Default Bayesian optimization (ALGORITHM_UNSPECIFIED) | Agent Platform chooses among Gaussian process bandits, linear combination search, or their variants | Maximum performance per trial is needed and the space includes continuous DOUBLE ranges |
| GRID_SEARCH | Exhaustive grid search within the feasible space | Trial count will exceed the number of distinct points, where the default algorithm could generate duplicate suggestions |
| RANDOM_SEARCH | Random sampling within the feasible space | A simple baseline or broad coverage is needed without model-guided suggestions |
Exam tip: GRID_SEARCH requires all parameters to be INTEGER, CATEGORICAL, or DISCRETE; a space containing a DOUBLE range cannot use grid search.
Trial budget settings translate the algorithm choice into cost control. maxTrialCount caps the total trials, parallelTrialCount caps how many trials run at the same time, and maxFailedTrialCount stops the study early after too many trial failures. In BigQuery ML, NUM_TRIALS plays the same budgeting role by fixing how many configurations are evaluated. Set a larger budget when the space is high-dimensional, conditional, or log-scaled, and narrow ranges, remove weak hyperparameters, or use parallel trials when faster wall-clock time is worth higher concurrent spend.
cloudml-hypertune, and Bayesian optimization uses completed trials to choose later configurations.maxTrialCount caps total trials, parallelTrialCount caps concurrent trials, and maximum failed trial count stops the job early to control time and cost.Hyperparameters stay constant during a single trial while model parameters such as neural network weights change during training. Hyperparameters are optimized across whole training runs by comparing aggregate trial metrics, not by inspecting in-trial weight updates.
Choose GKE Inference Gateway when routing must use KV cache utilization, queue length, or LoRA adapter availability for demanding generative AI and large language model inference. Choose GKE Gateway with Custom Metrics when requests have relatively uniform cost, one or two ORCA-reported metrics describe load, and LLM-specific routing, LoRA affinity, or request prioritization is not needed.
maxTrialCount sets the maximum number of trials the service may run, where more trials generally improve results but increase time and cost because billing is based on the duration of initiated trials. parallelTrialCount sets how many trials can run at the same time, which shortens wall-clock time but can reduce the benefit of sequential Bayesian updates. Maximum failed trial count stops the job early if too many trials fail, which prevents spending budget on a broken configuration.
Last updated