Containerized preprocessing for serving is the practice of embedding all data transformation logic and software dependencies directly inside the model serving container image. This ensures that raw input data is processed in exactly the same way during training and online inference. In Google Cloud, Vertex AI hosts the containerized models to serve real-time predictions, while machine learning pipelines orchestrate training data transformations. Packaging the feature transformation code within the prediction environment prevents discrepancies between how features are calculated during model training and how they are handled during live prediction requests.
A custom container is a user-built Docker image that packages the custom preprocessing code, inference serving framework, and all required library dependencies into a single deployable unit. When standard prebuilt containers for frameworks like TensorFlow, PyTorch, or scikit-learn cannot support specific feature transformation logic or private libraries, engineers build a custom container image and publish it to Artifact Registry. Cloud Build can automate the compilation and testing of these container images, ensuring the environment is validated before registration. Choosing a custom container provides full control over the runtime environment, allowing the container to apply complex preprocessing functions directly to raw JSON or payload inputs before passing tensors to the trained model.
Training-serving skew is a mismatch between the performance or data distributions of a machine learning model in production and its performance during development, often caused by inconsistent data transformation logic. When data transformations like text tokenization, missing value imputation, or categorical factorizations are maintained in separate codebases for training pipelines and production servers, subtle calculation differences lead to invalid predictions. Embedding the identical preprocessing functions utilized in Vertex AI Pipelines into the serving container guarantees deterministic input preparation across both environments. Furthermore, Vertex AI Model Monitoring pairs with Vertex Explainable AI to monitor deployed endpoints, alerting teams if feature attributions drift or if production distributions diverge from saved training baselines.
A Vertex AI Endpoint is a managed compute resource that hosts models imported from Vertex AI Model Registry to serve low-latency online predictions. When deploying a containerized preprocessing solution, the workflow follows a precise sequence: first, the model artifacts stored in Cloud Storage are registered with the custom container image URI from Artifact Registry in the Vertex AI Model Registry. Second, the registered model is deployed to a Vertex AI Endpoint configured with specific machine types and optional machine accelerators like GPUs. Third, the client application sends an inference request containing raw feature values across the network to the Vertex AI Endpoint. Fourth, inside the container instance, the self-contained preprocessing routine intercepts the payload, executes necessary validations and mathematical transformations, and feeds the processed inputs into the model weights. Finally, the model computes the inference, and the container formats and returns the prediction result back to the requesting client.
Implementing transformation artifacts and versioning is the practice of packaging data preprocessing logic into reusable, versioned components that are stored and deployed alongside the trained model. This ensures the exact same transformations are applied to data during model training and production inference, preventing data skew and maintaining model reliability.
A reusable transformation artifact is a serialized representation of data preprocessing logic, such as a TensorFlow Transform (TFT) graph or a scikit-learn preprocessing pipeline. This artifact is generated during the training pipeline run. The pipeline first applies the defined transformations to the training data, fitting the preprocessing steps (like calculating normalization statistics or encoding vocabulary) to that data. It then exports the fitted transformation logic as a graph or pipeline object. This exported artifact must be stored in a central repository like Artifact Registry or Cloud Storage, making it accessible for later use.
Versioning is the process of assigning unique identifiers to transformation artifacts and linking them to specific model versions. When a model is trained and registered in the Vertex AI Model Registry, the training pipeline must also upload and register the corresponding transformation artifact. The model's metadata in the registry should include a pointer to the exact version of the transformation artifact used. This creates an immutable link, guaranteeing that any deployment of that model version will use the identical preprocessing logic. Artifacts are versioned using the same systems that manage model binaries, such as Artifact Registry for container images or Cloud Storage for serialized files.
During the training phase, the transformation artifact is applied within the orchestrated pipeline. The pipeline loads raw data, executes the transformations using the artifact, and outputs the transformed features used for model training. For online serving with Vertex AI Endpoints or batch prediction with Vertex AI Prediction, the serving system must load both the model binary and the linked transformation artifact. The prediction service first applies the stored transformation logic to the incoming raw request data, then passes the transformed features to the model for inference. This sequence ensures the model receives data in the same format it saw during training.
This process is integrated into an automated end-to-end ML pipeline orchestrated by Vertex AI Pipelines. A typical pipeline component first validates incoming data, then generates and fits the transformation logic, exporting the artifact. A subsequent component uses this artifact to transform the training dataset before model training. Finally, the pipeline registers the trained model and uploads the transformation artifact, recording their relationship in Vertex ML Metadata. This automated, versioned workflow is the key mechanism for ensuring consistent data preprocessing between training and serving environments.
Consistent feature engineering between training and serving is critical for model reliability. When the data transformations applied during training differ from those applied during inference, the resulting training-serving skew causes model performance degradation in production. Vertex AI Pipelines and Kubeflow Pipelines provide the orchestration layer that embeds preprocessing components directly into the ML workflow, ensuring that the same transformations execute at every stage of the pipeline lifecycle.
Vertex AI Pipelines is a Google Cloud managed service that orchestrates and automates ML pipelines where each pipeline component runs as a containerized task. The service provides a Python SDK for defining pipelines, a UI for tracking experiments and runs, and integration with Vertex ML Metadata for lineage and execution tracking. Pipeline components are self-contained code packaged as Docker images that perform individual stepsâsuch as data validation, transformation, or model trainingâand produce artifacts that flow to downstream components. The topology of the workflow is defined by connecting outputs from upstream steps to inputs of downstream steps through a Python domain-specific language, creating a directed acyclic graph that executes in sequence or parallel as dependencies require.
The Kubeflow Pipelines SDK lets you create components, define their orchestration, and run them as a pipeline. You can also use the TensorFlow Extended (TFX) Pipeline DSL and TFX components, where each component encapsulates metadata capabilitiesâthe driver supplies metadata to the executor by querying the metadata store, and the publisher accepts the results and stores them in metadata. Custom components integrate with the same metadata system, enabling full traceability of pipeline executions and artifacts. TFX components available include TensorFlow Data Validation (TFDV) for anomaly detection, TensorFlow Transform (TFT) for preprocessing and feature engineering, and TensorFlow Model Analysis (TFMA) for evaluation.
TensorFlow Data Validation (TFDV) detects anomalies in data by validating datasets against an expected schema. During pipeline execution, TFDV validates training data against the schema created during development and detects anomalies related to both data distribution and schema skews. The outputs include detected anomalies and a decision on whether to proceed with downstream pipeline steps. For production serving, TFDV can validate incoming request data against the same schema to ensure that inference requests conform to expected formats, preventing errors from malformed inputs. The schema itself is fixed during the development phase before deployment, establishing a contract that both training and serving data must satisfy.
TensorFlow Transform (TFT) performs data preprocessing and feature engineering within the pipeline, producing transformation artifacts that embed the transformation process into the exported saved model. When you use TFT during training, the same transformation logic is serialized into the model itself, so serving applies identical preprocessing without requiring separate transformation code. This tight coupling ensures that feature engineering remains consistent between training and inference. TFT outputs transformed data filesâtypically in TFRecord formatâalong with transformation artifacts that define how to construct model inputs, making the preprocessing step inherently portable across environments.
Vertex AI Feature Store provides a central location to create, maintain, share, and serve ML features. The feature store is optimized for low-latency serving workloads and lets you store feature data in a BigQuery table or view. You create an online store instance and define feature views, where BigQuery stores all feature data including historical data for offline training. Feature serving comes in two forms: online serving retrieves the latest feature values for real-time inference, while offline or batch serving exports high volumes of feature dataâincluding historical dataâfor training. By centralizing feature definitions in the feature store, both training pipelines and serving infrastructure reference the same feature computations, eliminating divergence between how features are computed in each context.
Once deployed to production, ML pipelines need automated execution based on triggering conditions. Pipeline automation can be triggered on demand, on a schedule, on the availability of new data, on model performance degradation, on significant changes in statistical properties of the data, or based on other conditions. The Vertex AI SDK lets you operate pipelines programmatically through the PipelineJob class, which includes APIs to create experiments, deploy pipelines, and submit pipeline runs. Triggers can originate from Cloud Scheduler for scheduled executions, Cloud Composer as part of larger workflows, Cloud Logging based on log filters, or Pub/Sub messages when new data arrives. This automation ensures that models retrain with fresh data without manual intervention, maintaining alignment between training data patterns and serving data patterns over time.
Embedding preprocessing in a custom container means you write and package the transformation code yourself inside a Docker image, giving full control over the runtime environment. TensorFlow Transform (TFT) artifacts, on the other hand, are generated during training and serialized into the saved model itself, so serving automatically applies the same logic without separate code. Choose a custom container when you need complex or proprietary transformations that TFT cannot express; choose TFT when you want a tightly coupled, automatically consistent pipeline.
Use TensorFlow Data Validation (TFDV) during pipeline development to generate a schema from the training data. Then, in the serving environment, validate incoming inference requests against that same schema before passing them to the model. TFDV can be embedded in a custom prediction container or run as a separate pipeline component, and the schema is stored as an artifact in Artifact Registry or Cloud Storage, linked to the model version.
Use Vertex AI Feature Store when features are shared across multiple models or need to be updated frequently without retraining the model. The feature store provides low-latency online serving for real-time inference and offline batch exports for training, ensuring all models use the same feature definitions. Embedding features in the container is simpler for single-model deployments where features are static and derived directly from raw inputs.
Professional Machine Learning Engineer
Prepare and test your skills
Prepare and test your skills