Preventing Training-Serving Skew with Vertex AI Custom Handlers

PDE By islever Editorial Last updated

Short answer

A Implement a custom handler within the Vertex AI Endpoint to automatically perform data transformations before the model makes a prediction.

Question

You are preparing data to serve a sales demand prediction model. The training data undergoes several pre-processing steps, including scaling numerical features and one-hot encoding categorical features. The model is deployed on Vertex AI Endpoints. You need to prevent training-serving skew and ensure accurate predictions in production. You want a solution that is easy to implement.
What should you do?
  1. Implement a custom handler within the Vertex AI Endpoint to automatically perform data transformations before the model makes a prediction. Correct Answer
  2. Replicate the exact same pre-processing logic in the inference pipeline that was used during model training.
  3. Store the raw, unprocessed data in a separate Cloud Storage bucket exclusively for serving.
  4. Ensure the serving data is a smaller, random sample of the training data.

Key Takeaways

The main trap is assuming external pipelines are needed; Vertex AI's custom handlers allow inline pre-processing, ensuring identical training and serving transformations.

Learn how to prevent training-serving skew in Vertex AI by using custom prediction handlers to embed pre-processing logic directly in the endpoint.

Common mistake: Many candidates choose B, believing they need a separate inference pipeline. However, Vertex AI's custom handler (Option A) is the specific service feature designed to integrate pre-processing directly with the model, making it the simpler and more correct implementation.

Expert Analysis

Training-Serving Skew Prevention: The core challenge in this scenario is preventing training-serving skew, which occurs when the data distribution or processing logic differs between the model's training phase and its production inference phase. To ensure accurate predictions, the inference pipeline must apply the exact same transformations (scaling, one-hot encoding) as the training pipeline.

Vertex AI Feature Capability: Vertex AI Endpoints support Custom Prediction Routines. This feature allows developers to deploy a Python package that includes both the model artifact and the pre-processing code. When a request arrives at the endpoint, the custom handler executes the pre-processing logic before passing the transformed data to the model for prediction.

Evaluating Options:

  • Option A leverages this native capability. By embedding the transformation logic directly within the Vertex AI Endpoint via a custom handler, you centralize the logic, ensuring that every prediction uses the identical processing steps applied during training. This is the standard, easiest, and most robust way to handle this on Vertex AI without building external orchestration layers.
  • Option B suggests replicating the logic in an "inference pipeline." While conceptually similar, Option A is more precise because it utilizes the specific Vertex AI mechanism (Custom Handlers) designed exactly for this purpose. External pipelines add latency and complexity compared to the integrated handler approach.
  • Option C is incorrect because raw data cannot be fed directly into a model that expects processed features; it would cause errors or meaningless results.
  • Option D is incorrect because sampling data does not address the structural difference in preprocessing required to match the training distribution.

Therefore, implementing a custom handler is the correct architectural choice to embed pre-processing directly with the model serving layer.

Exam Strategy

When a question asks for an 'easy' or 'native' solution to integrate pre-processing with model serving on managed platforms like Vertex AI, look for built-in features like Custom Routines or Handlers. Avoid options suggesting external orchestration if the platform supports inline execution, as this reduces complexity and latency.

Frequently Asked Questions

What is training-serving skew?

It is the discrepancy between the data used to train a model and the data used for inference in production, often caused by differences in pre-processing logic.

Why use a custom handler instead of a separate pipeline?

A custom handler runs pre-processing code directly at the endpoint alongside the model, ensuring consistency and reducing the operational overhead of managing separate data pipelines.

More PDE FAQ →

Community Votes

A
50%
B
50%

50% of anonymous learners picked answer A. Votes are pick records left by other test-takers — they are not the verified answer.

Discussion 2 contributions

Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.

From public community threads 2

  1. jreale64 👍 2 Answered B
    B: Training-serving skew occurs when the data used to train your model differs in its characteristics or processing from the data used for making predictions in production. The problem explicitly mentions preprocessing steps like scaling numerical features and one-hot encoding categorical features. If these transformations are not applied identically during inference as they were during training, the model will receive inconsistent input, leading to inaccurate predictions.
  2. AwesomeGCP 👍 1 Answered A
    The correct answer is A. Implement a custom handler within the Vertex AI Endpoint to automatically perform data transformations before the model makes a prediction. Why the other options are incorrect: B (Replicate preprocessing logic in the inference pipeline): While replicating the logic is a common anti-pattern, maintaining two separate pipelines (one for training and another for inference) is error-prone. Any update, parameter drift, or subtle coding discrepancy between the training pipeline and the serving pipeline introduces training-serving skew. C (Store raw data in a separate GCS bucket for serving): Storing raw data in Cloud Storage does not solve online real-time inference preprocessing for Vertex AI Endpoints; endpoints require processed feature tensors at inference time to generate predictions. D (Ensure serving data is a smaller, random sample): Production inference data depends on live user traffic and customer demand, not a pre-sampled subset of the training set. This does not address feature preprocessing or training-serving skew.

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

← Back to PDE Study Guide