3.7 Training SDKs and Services: Custom Training, Kubeflow on GKE, AutoML and Tabular Workflows

Key Takeaways

  • Vertex AI Custom Training supports three execution modalities: pre-built containers with local scripts, Python source packages staged on Cloud Storage, and custom Docker container images registered in Artifact Registry.
  • The worker_pool_specs configuration divides cluster compute into up to four distinct pools: Pool 0 (master/chief coordinator), Pool 1 (worker replicas), Pool 2 (parameter servers), and Pool 3 (evaluators).
  • Pre-built containers accelerate standard TensorFlow, PyTorch, Scikit-learn, and XGBoost jobs, while custom containers are required when incorporating non-standard C++/CUDA libraries, specific OS dependencies, or proprietary packages.
  • Spot (preemptible) VMs reduce training compute costs by up to 60-91% but require resilient checkpointing to Cloud Storage via AIP_CHECKPOINT_DIR to resume state automatically upon preemption.
  • Custom training jobs should execute under user-managed Service Accounts with least-privilege IAM roles such as roles/storage.objectAdmin and roles/aiplatform.customCodeServiceAgent.
Last updated: September 2026

3.7 Training SDKs and Services: Custom Training, Kubeflow on GKE, AutoML and Tabular Workflows

Transitioning machine learning models from exploratory notebooks into robust, reproducible production training systems requires selecting the right framework, architecting containerized execution environments, and defining scalable compute topologies. Google Cloud's Vertex AI Custom Training service provides a serverless, managed infrastructure layer capable of orchestrating single-node and multi-node distributed training jobs across diverse accelerator hardware.


1. Machine Learning Framework Selection Matrix

Selecting the optimal ML framework depends on the underlying data modality, model architecture complexity, hardware acceleration targets (GPUs vs. TPUs), and serving latency requirements.

FrameworkPrimary Strengths & ArchitecturesHardware AffinityBest GCP Production Use CasesServing & Deployment Ecosystem
TensorFlow 2.x / KerasStatic/dynamic computational graphs, seamless TFX pipeline integration, native SavedModel serialization formatHighly optimized for Google Cloud TPUs and NVIDIA GPUsLarge-scale enterprise recommendation systems, CTR prediction, structured data, end-to-end production pipelinesTF Serving, Vertex AI Prediction, TFLite (edge/mobile), TF.js
PyTorchDynamic eager execution graphs (autograd), intuitive Pythonic debugging, rich open-source transformer ecosystem (Hugging Face)NVIDIA GPUs (CUDA/NCCL), PyTorch/XLA on Cloud TPUsGenerative AI, Large Language Models (LLMs), Computer Vision, academic research translationTorchServe, Triton Inference Server, ONNX Runtime, TensorRT
Scikit-learnHigh-efficiency classical ML algorithms (Linear/Logistic Regression, Random Forests, SVMs, PCA, k-Means)CPU-bound (multi-threaded OpenMP / Joblib)Small-to-medium tabular datasets (< 50 GB), rapid baselines, feature selection, shallow pipelinesVertex AI pre-built Scikit-learn containers, ONNX, joblib/pickle export
XGBoost / LightGBMHighly optimized gradient-boosted decision trees (GBDT), handling sparse tabular data and missing valuesMulti-core CPU and GPU acceleration (tree_method='hist')Tabular classification/regression competitions, credit scoring, fraud scoring, churn predictionVertex AI pre-built XGBoost containers, Treelite compilation for sub-millisecond inference
JAXComposable function transformations (grad, jit, vmap, pmap), pure functional programming, XLA compilationNative first-class optimization on Cloud TPUs and NVIDIA GPUsFrontier LLM pre-training, scientific ML computing, high-performance custom linear algebraT5X, MaxText, Orbax checkpoints, exported via JAX-to-TF / StableHLO

2. Vertex AI Custom Training Packaging Patterns

Vertex AI supports three packaging and execution patterns for running custom training code. Choosing the appropriate pattern depends on environment complexity, dependency governance, and build pipeline automation.

                                VERTEX AI TRAINING EXECUTION PATTERNS
                                                  |
         +----------------------------------------+----------------------------------------+
         |                                        |                                        |
  [ 1. Pre-built + Script ]               [ 2. Python Package Job ]                [ 3. Custom Container ]
         |                                        |                                        |
  - Google-managed image                  - Google-managed base image             - Customer Dockerfile
  - Local Python script injected          - Source distribution (.tar.gz / .whl)  - Complete control of OS, CUDA,
  - Fast iteration, simple deps           - Staged on Cloud Storage bucket          C++ libraries, and binaries
  - Pip installs at runtime               - Dependencies in setup.py              - Stored in Artifact Registry

Pattern 1: Pre-Built Container with Local Script / Python File

  • Mechanism: You supply a standalone Python file (or directory) and specify a Google-managed pre-built training container image URI (e.g., us-docker.pkg.dev/vertex-ai/training/tf-gpu.2-14.py310:latest).
  • Workflow: Vertex AI provisions the compute instance, pulls the Google-managed container, copies your local script into the container at launch, installs any additional requirements passed via requirements.txt, and executes the entrypoint.
  • Trade-offs: Fastest path for rapid experimentation; however, downloading large external pip packages on every job startup increases job initialization latency and exposes training to external network repository outages.

Pattern 2: Python Source Package Staged on Cloud Storage

  • Mechanism: Your training code is structured as a standard Python package containing a setup.py file and packaged into a source distribution (.tar.gz or .whl).
  • Workflow: The archive is uploaded to a Cloud Storage bucket (gs://my-bucket/training_pkg/trainer-0.1.tar.gz). A Vertex AI CustomJob references the python_package_spec, specifying the executor_image_uri, package_uris, and python_module (e.g., trainer.task).
  • Trade-offs: Highly modular and clean for CI/CD pipelines that do not maintain dedicated Docker build agents, but still constrained by the base system libraries present in the Google pre-built image.

Pattern 3: Custom Docker Container (Artifact Registry)

  • Mechanism: You author a custom Dockerfile, compile all system binaries, C++/CUDA drivers, Python wheels, and proprietary code directly into an immutable container image, and push it to Google Cloud Artifact Registry (us-central1-docker.pkg.dev/my-project/my-repo/my-trainer:v1).
  • Workflow: Vertex AI pulls the exact pre-compiled image directly from Artifact Registry and executes the defined ENTRYPOINT or CMD.
  • Trade-offs: Total environment reproducibility, zero startup package installation delay, and full support for custom native C++ accelerators; requires maintaining container build pipelines (e.g., via Cloud Build).
# Example Custom Training Dockerfile for PyTorch with CUDA 12.1
FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04

ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
    python3-pip python3-dev git curl && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /root
COPY requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt

# Copy training application code
COPY trainer/ /root/trainer/

# Set default entrypoint
ENTRYPOINT ["python3", "-m", "trainer.train"]

Container Strategy Comparison

Operational DimensionPre-Built Container + ScriptPython Package on GCSCustom Docker Container
Initialization SpeedSlow (runtime pip installation)Moderate (runtime pip install)Fastest (all dependencies pre-baked)
Custom C++/OS BinariesNot SupportedNot SupportedFully Supported
Air-Gapped / Isolated VPCDifficult (needs external PyPI)Moderate (needs private wheel)Ideal (zero external network calls)
Build Tooling OverheadNoneLow (standard setuptools)High (requires Docker / Cloud Build)
Reproducibility GuaranteeLow (upstream pip drift)ModerateAbsolute (bit-for-bit immutable image)

3. Training Worker Pools & Cluster Specification

When authoring a Vertex AI CustomJob or TrainingPipeline, compute infrastructure is declared via worker_pool_specs. Vertex AI partitions distributed training resources into up to four distinct worker pools:

+-------------------------------------------------------------------------------------------------------+
|                                VERTEX AI WORKER POOL ARCHITECTURE                                    |
+-------------------+--------------------+--------------------+-----------------------------------------+
| Worker Pool Spec  | Role Name          | Replica Count      | Responsibilities & Communication        |
+-------------------+--------------------+--------------------+-----------------------------------------+
| WorkerPoolSpec[0] | Chief / Master     | Strictly 1         | Coordinates cluster synchronization,    |
|                   |                    |                    | orchestrates data shards, logs metrics, |
|                   |                    |                    | checkpoints master model to GCS.        |
+-------------------+--------------------+--------------------+-----------------------------------------+
| WorkerPoolSpec[1] | Workers            | >= 1 (e.g., 7)     | Executes distributed compute tasks;     |
|                   |                    |                    | performs forward/backward passes and    |
|                   |                    |                    | participates in AllReduce gradients.   |
+-------------------+--------------------+--------------------+-----------------------------------------+
| WorkerPoolSpec[2] | Parameter Servers  | >= 1 (e.g., 2)     | Stores and updates global model weights |
|                   |                    |                    | in asynchronous parameter server setups.|
+-------------------+--------------------+--------------------+-----------------------------------------+
| WorkerPoolSpec[3] | Evaluators         | >= 1 (optional)    | Runs independent validation loops on   |
|                   |                    |                    | checkpoints without blocking workers.  |
+-------------------+--------------------+--------------------+-----------------------------------------+

Detailed WorkerPoolSpec Configuration Parameters

Each worker pool definition encapsulates hardware, disk, and container execution specifications:

  • machine_spec: Defines the virtual machine shape (e.g., n1-standard-16, a2-highgpu-1g, g2-standard-96) and accelerator hardware (accelerator_type: NVIDIA_TESLA_A100, accelerator_count: 8).
  • replica_count: Number of identical machine instances provisioned for that specific pool.
  • disk_spec: Boot disk configuration, specifying boot_disk_type (pd-ssd, pd-standard, or hyperdisk-balanced) and boot_disk_size_gb (e.g., 500).
  • container_spec / python_package_spec: Specifies the image URI, command-line entrypoint, container arguments, and environment variables.

Standard Vertex AI Injected Environment Variables

Vertex AI automatically populates environment variables inside running training containers:

  • AIP_MODEL_DIR: The Cloud Storage URI (gs://bucket/model_output) where the primary worker must write final model artifacts. Vertex AI automatically scrapes this URI when registering the model.
  • AIP_CHECKPOINT_DIR: The Cloud Storage URI dedicated to writing intermediate training checkpoints for fault-tolerant recovery.
  • AIP_TENSORBOARD_LOG_DIR: Target GCS directory for streaming TensorBoard event logs to Vertex AI TensorBoard.
  • CLUSTER_SPEC / TF_CONFIG: JSON-formatted cluster configuration string containing hostnames, ports, and worker roles for multi-node TensorFlow synchronization.
  • WORLD_SIZE, RANK, MASTER_ADDR, MASTER_PORT: Injected for PyTorch distributed training (torchrun / DDP).

4. IAM Permissions, Service Accounts & Security Architecture

By default, Vertex AI executes custom training jobs using the Cloud AI Platform Custom Code Service Agent (service-PROJECT_NUMBER@gcp-sa-aiplatform-cc.iam.gserviceaccount.com). However, enterprise production standards dictate running training jobs under dedicated user-managed Service Accounts.

Least-Privilege IAM Roles for Training Service Accounts

  1. Storage Access: roles/storage.objectAdmin or roles/storage.objectViewer scoped strictly to the specific project training data and model artifact Cloud Storage buckets.
  2. Artifact Registry Access: roles/artifactregistry.reader to allow compute workers to pull custom Docker images from Artifact Registry.
  3. Vertex AI Service Agent: roles/aiplatform.customCodeServiceAgent granting internal cluster communication and metrics reporting.
  4. Logging & Monitoring: roles/logging.logWriter and roles/monitoring.metricWriter to emit stdout/stderr logs to Cloud Logging and GPU utilization metrics to Cloud Monitoring.
  5. BigQuery (if using BQ Storage API): roles/bigquery.dataViewer and roles/bigquery.user to stream training batches directly from BigQuery tables.

5. Cost Optimization: Spot VMs & Fault-Tolerant Checkpointing

Spot (Preemptible) VMs for ML Training

Training large deep neural networks across multi-GPU or TPU clusters represents significant infrastructure expenditure. Spot VMs offer 60% to 91% cost discounts compared to on-demand Compute Engine pricing. However, Google Cloud may preempt (reclaim) Spot instances at any time with a 30-second termination notice when compute capacity is needed elsewhere.

                               FAULT-TOLERANT CHECKPOINT LIFECYCLE
                                                |
               +--------------------------------+--------------------------------+
               |                                                                 |
       [ Normal Training Loop ]                                         [ Preemption / Restart ]
               |                                                                 |
       1. Train Epoch K                                                 1. VM Preempted & Terminated
       2. Save Checkpoint to GCS                                        2. Vertex AI auto-provisions replacement VM
          (AIP_CHECKPOINT_DIR/ckpt-K.pt)                                3. Container starts and queries GCS
       3. Emit metrics to TensorBoard                                   4. Load latest checkpoint (ckpt-K.pt)
       4. Proceed to Epoch K+1                                          5. Resume training at Epoch K+1

Resilient Checkpointing Implementation Requirements

To use Spot VMs safely in production without losing training progress:

  1. Atomic Checkpointing to Cloud Storage: Models must persist optimizer states, model weights, and epoch/step counters to AIP_CHECKPOINT_DIR at frequent time or step intervals (e.g., every 30 minutes or every 500 steps).
  2. Automatic Restart on Failure: Configure CustomJob restart policies to automatically retry when workers are preempted.
  3. Initialization State Recovery: At the beginning of the training script, inspect AIP_CHECKPOINT_DIR on GCS. If valid checkpoint files exist, restore the model weights and resume training from the last saved epoch rather than restarting from step 0.
# Example PyTorch Checkpoint Restoration Logic
import os, torch
from google.cloud import storage

checkpoint_dir = os.environ.get('AIP_CHECKPOINT_DIR', '/tmp/checkpoints')
start_epoch = 0

def load_latest_checkpoint(model, optimizer, ckpt_dir):
    # Query GCS or local mount for latest checkpoint file
    latest_ckpt = get_latest_gcs_checkpoint(ckpt_dir)
    if latest_ckpt:
        checkpoint = torch.load(latest_ckpt)
        model.load_state_dict(checkpoint['model_state_dict'])
        optimizer.load_state_dict(checkpoint['optimizer_state_dict'])
        start_epoch = checkpoint['epoch'] + 1
        print(f"Successfully resumed training from epoch {start_epoch}")
    return start_epoch
Loading diagram...
Vertex AI Custom Training Architecture & Multi-Worker Topology
Test Your Knowledge

An enterprise computer vision team is building a deep learning model in PyTorch that relies on a specialized C++ CUDA extension for 3D point cloud convolutions and custom Linux system drivers. The pipeline must run in an isolated VPC Service Controls perimeter without public internet access. Which Vertex AI Custom Training packaging pattern should the team choose?

A
B
C
D
Test Your Knowledge

You are authoring a multi-node distributed TensorFlow training specification on Vertex AI using worker_pool_specs. The cluster requires 1 coordinator node, 7 worker compute nodes, and 2 dedicated parameter servers. How should the worker_pool_specs list be structured?

A
B
C
D
Test Your Knowledge

A machine learning engineering team is training a 500-million parameter vision model on Vertex AI. To minimize compute expenditure, they configure the CustomJob to run on Spot (preemptible) GPU instances. During the 18-hour training run, an instance preemption occurs after 12 hours, and the job restarts from epoch 0, wasting budget. What architectural change is required to make training cost-effective and resilient?

A
B
C
D
Test Your Knowledge

An ML engineer configures a custom training container to train a recommendation model on Vertex AI. The container completes training successfully, but when Vertex AI attempts to register the resulting model, it reports that no model artifacts were found. Where must the training script write its final model artifacts so Vertex AI can locate them automatically?

A
B
C
D