By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Topic: Vertex AI Endpoints, Batch Predictions, Edge TPU
Deployment strategies determine how your trained ML model serves predictions—whether in real-time (e.g., fraud detection in banking transactions), batch (e.g., nightly credit risk scoring for millions of customers), or on edge devices (e.g., a retail store’s camera detecting shelf stockouts without cloud dependency). Google Cloud’s Vertex AI provides managed endpoints for low-latency inference, batch prediction jobs for offline processing, and Edge TPU for ultra-low-latency, offline inference on IoT devices. Mastering these ensures your model meets business SLAs (e.g., <100ms latency for ad recommendations) while optimizing cost and scalability.
minReplicaCount
maxReplicaCount
minReplicaCount=1
Scenario: Deploy a fraud detection model to serve predictions in <50ms for a banking app.1. Train & Export Model: - Train your model (e.g., XGBoost, TensorFlow) and save it in a supported format (e.g., model.joblib, saved_model.pb). - Upload to Google Cloud Storage (GCS) in a bucket (e.g., gs://my-bucket/models/fraud-detection-v1).2. Create a Model in Vertex AI: - In the GCP Console, navigate to Vertex AI > Models > Create. - Select the model artifact from GCS and specify the framework (e.g., "Scikit-learn" or "TensorFlow"). - Configure explanation settings (optional) for feature attribution (e.g., SHAP values).3. Deploy to an Endpoint: - Create an Endpoint (Vertex AI > Endpoints > Create). - Deploy the model to the endpoint with: - Machine type (e.g., n1-standard-4 for CPU, n1-standard-16 for GPU). - Traffic split (e.g., 100% to v1 initially). - Autoscaling (e.g., minReplicaCount=1, maxReplicaCount=10).4. Test & Monitor: - Send a test request via the REST API or Python SDK: python from google.cloud import aiplatform endpoint = aiplatform.Endpoint("projects/PROJECT_ID/locations/us-central1/endpoints/ENDPOINT_ID") prediction = endpoint.predict(instances=[{"feature1": 0.5, "feature2": 1.2}]) - Monitor latency, errors, and traffic in Cloud Monitoring and Vertex AI Dashboard.
model.joblib
saved_model.pb
gs://my-bucket/models/fraud-detection-v1
n1-standard-4
n1-standard-16
maxReplicaCount=10
python from google.cloud import aiplatform endpoint = aiplatform.Endpoint("projects/PROJECT_ID/locations/us-central1/endpoints/ENDPOINT_ID") prediction = endpoint.predict(instances=[{"feature1": 0.5, "feature2": 1.2}])
Scenario: Score 10M customer records nightly for credit risk.1. Prepare Input Data: - Store input data in GCS (e.g., gs://my-bucket/batch-input/2023-10-01.csv). - Ensure the file format matches the model’s expected schema (e.g., CSV with columns age, income, credit_score).2. Create a Batch Prediction Job: - In Vertex AI, navigate to Batch Predictions > Create. - Select the model and input/output GCS paths. - Configure: - Machine type (e.g., n1-standard-4 for small jobs, n1-highmem-16 for large datasets). - Output format (e.g., JSONL, CSV). - Explanations (optional, for interpretability).3. Run & Monitor: - The job runs asynchronously. Monitor progress in the Vertex AI Jobs tab. - Output is saved to GCS (e.g., gs://my-bucket/batch-output/2023-10-01/).4. Post-Processing: - Load results into BigQuery for analysis or trigger downstream workflows (e.g., email alerts for high-risk customers).
gs://my-bucket/batch-input/2023-10-01.csv
age
income
credit_score
n1-highmem-16
gs://my-bucket/batch-output/2023-10-01/
Scenario: Deploy a retail shelf-monitoring model to a Coral Dev Board for real-time stockout detection.1. Convert Model to TF Lite: - Use TensorFlow’s TFLiteConverter to quantize the model (e.g., float32 → int8): python converter = tf.lite.TFLiteConverter.from_saved_model("saved_model") converter.optimizations = [tf.lite.Optimize.DEFAULT] tflite_model = converter.convert() with open("model_quant.tflite", "wb") as f: f.write(tflite_model) 2. Compile for Edge TPU: - Use the Edge TPU Compiler to optimize the model: bash edgetpu_compiler model_quant.tflite -o output_dir - Output: model_quant_edgetpu.tflite.3. Deploy to Device: - Flash the Coral Dev Board with the latest Mendel OS (Google’s Linux distro for Edge TPU). - Copy the compiled model to the device: bash scp model_quant_edgetpu.tflite mendel@coral-dev:/home/mendel/ 4. Run Inference: - Use the Coral Python API to load and run the model: ```python from pycoral.adapters import common from pycoral.adapters import classify from pycoral.utils.edgetpu import make_interpreter
TFLiteConverter
python converter = tf.lite.TFLiteConverter.from_saved_model("saved_model") converter.optimizations = [tf.lite.Optimize.DEFAULT] tflite_model = converter.convert() with open("model_quant.tflite", "wb") as f: f.write(tflite_model)
bash edgetpu_compiler model_quant.tflite -o output_dir
model_quant_edgetpu.tflite
bash scp model_quant_edgetpu.tflite mendel@coral-dev:/home/mendel/
interpreter = make_interpreter("model_quant_edgetpu.tflite") interpreter.allocate_tensors() common.set_input(interpreter, image) # Preprocessed input interpreter.invoke() classes = classify.get_classes(interpreter, top_k=1) ```
tf.lite.Optimize.DEFAULT
minReplicaCount=0
Edge TPU vs. Vertex AI Endpoints: Edge TPU is for offline/edge (e.g., IoT cameras), while Endpoints are for cloud-based real-time. The exam may ask, "Which for a factory floor quality control camera?" → Edge TPU.
Key Constraints:
Endpoint Autoscaling: Default cooldown period is 5 minutes (adjust for bursty traffic).
Tricky Scenarios:
Cost Optimization: For sporadic traffic, use Vertex AI Endpoints with minReplicaCount=0 (but accept cold starts). For predictable traffic, set minReplicaCount=1.
Security Questions:
Explanation: Endpoints are designed for real-time, low-latency inference with autoscaling.
A retail chain wants to run a one-time batch inference job on 50M customer records stored in BigQuery. What’s the most cost-effective approach?
Explanation: Batch Predictions are serverless and cheaper than running a VM for hours.
An industrial IoT company needs to deploy a TensorFlow model to 10K edge devices with <1ms latency. Which GCP service should they use?
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.