How to Deploy Scikit-Learn Models on Vertex AI with Minimal Code?
Short answer
B 1. Wrap your model in a custom prediction routine (CPR). and build a container image from the CPR local model.
Question
Key Takeaways
This question tests understanding of Vertex AI serving frameworks, where candidates often mistakenly prioritize prebuilt containers over CPR, overlooking that CPR natively supports custom inference logic with significantly reduced boilerplate.
Deploying machine learning models on Vertex AI requires selecting the right serving abstraction to balance customization and development overhead. Community consensus confirms that Custom Prediction Routines (CPR) provide the most efficient path for handling pre- and post-processing without writing a full HTTP server.
Common mistake: Candidates frequently select Option A, assuming prebuilt containers minimize effort, but they fail to recognize that prebuilt images cannot accommodate the required custom data preprocessing steps.
Expert Analysis
Why the Answer Is Correct
Custom Prediction Routines (CPR) are explicitly designed to simplify model serving by allowing developers to define custom Predictor classes that handle input parsing, preprocessing, model invocation, and output serialization. By leveraging the Vertex AI SDK, you can automatically generate the underlying container image, which eliminates the need to manually write Dockerfiles or configure HTTP servers. This approach directly satisfies the requirement to preprocess data while minimizing additional code.
Why the Other Options Are Wrong
Option A relies on prebuilt containers, which offer zero flexibility for custom preprocessing or postprocessing logic. Options C and D involve building entirely custom containers from scratch, requiring manual setup of web servers, dependency management, and Docker configuration. These methods introduce significant boilerplate and maintenance overhead, contradicting the exam constraint to minimize additional code.
Community Comment Notes
Multiple high-voted comments validate Option B, emphasizing that CPR abstracts away complex serving infrastructure while still supporting custom Python code [1][2]. Users note that while prebuilt containers seem simpler initially, they become impractical when preprocessing is mandatory [3]. The provided documentation links consistently point to Vertex AI official guidance, confirming CPR as the standard for lightweight custom serving [4].
Official Reference
https://cloud.google.com/vertex-ai/docs/predictions/custom-prediction-routines
This link opens the official vendor documentation in a new tab.
Exam Strategy
When Vertex AI questions mention preprocessing, postprocessing, or lightweight custom inference logic, immediately consider Custom Prediction Routines (CPR). Always weigh the minimize code constraint against the flexibility needed; if you do not need a completely new framework, CPR is almost always the exam preferred answer.
Community Votes
100% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 7 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 7
-
shadz10 👍 5 Answered BB - Creating a custom container without CPR adds additional complexity. i.e. write model server write dockerfile and also build and upload image. Where as using a CPR only requires writing a predictor and using vertex SDK to build image. https://cloud.google.com/vertex-ai/docs/predictions/custom-prediction-routines
-
b1a8fae 👍 4 Answered BI go with B: “Custom prediction routines (CPR) lets you build custom containers with pre/post processing code easily, without dealing with the details of setting up an HTTP server or building a container from scratch.” (https://cloud.google.com/vertex-ai/docs/predictions/custom-prediction-routines). This alone makes B preferable to C and D, provided lack of complex model architecture. Regarding A, pre-built containers only allow serving predictions, but not preprocessing of data (https://cloud.google.com/vertex-ai/docs/predictions/pre-built-containers#use_a_prebuilt_container). B thus remains the most likely option.
-
pikachu007 👍 1 Answered DConsidering the goal of minimizing additional code and complexity, option D - "Create a custom container for your scikit-learn model, upload your model and custom container to Vertex AI Model Registry, deploy your model to Vertex AI Endpoints, and create a Vertex AI batch prediction job that uses the instanceConfig.instanceType setting to transform your input data" seems to be a more straightforward and efficient approach. It involves customizing the container for the scikit-learn model, leveraging the Vertex AI Model Registry, and utilizing the specified instance type for batch prediction without introducing unnecessary complexity like custom prediction routines.
-
guilhermebutzke 👍 1 Answered CMy choose: C Option C ensures that the scikit-learn model is properly packaged, deployed, and integrated with Vertex AI services while minimizing the need for additional code beyond what is necessary for customizing the serving function. Option B is not considered correct because it suggests wrapping the scikit-learn model in a custom prediction routine (CPR), which might not be the most suitable approach for deploying scikit-learn models on Vertex AI. Options A and D using InstanceConfig, that is limited for preprocessing. Uploading the container without a serving function won't work.
-
bobjr 👍 1 Answered Bhttps://cloud.google.com/vertex-ai/docs/predictions/custom-prediction-routines
Show 2 more comments
-
desertlotus1211 👍 1 Answered Ayou want to minimize code... all other you need code...
-
gscharly 👍 1 Answered Bagree with shadz10
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All PMLE Questions
Access 65 questions with complete answers and detailed explanations.
View Full PMLE Practice Test →