Preventing Training-Serving Skew with Vertex AI Custom Handlers
Short answer
A Implement a custom handler within the Vertex AI Endpoint to automatically perform data transformations before the model makes a prediction.
Question
What should you do?
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?
Why use a custom handler instead of a separate pipeline?
Community Votes
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
-
jreale64 👍 2 Answered BB: 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.
-
AwesomeGCP 👍 1 Answered AThe 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.