Serving and scaling models

PMLE notes, 20% of the exam, updated November 2026

This domain is about 20% of the exam. Questions give a latency, throughput, cost or governance requirement and ask which serving pattern, endpoint type, hardware or optimisation fits. The first decision is always batch or online.

Batch and online inference

Property Batch prediction Online prediction
Latency need Minutes to hours acceptable Milliseconds to seconds
Trigger Schedule or pipeline step over a whole dataset Request from an app
Infrastructure Job spins up and tears down. No always-on endpoint A deployed endpoint with at least one running replica
Cost shape Pay for the job duration Pay for replica-hours, even when idle
Examples Nightly churn scores, weekly recommendations, scoring a data lake Fraud check at checkout, search ranking, chat

Always ask: does the prediction need to be fresh at request time? If predictions can be precomputed (for example daily recommendations per user) then batch plus a lookup store (BigQuery, Bigtable, Firestore) is far cheaper and simpler than an online endpoint.

Where batch inference can run

Service Use
Vertex AI batch prediction Registered models. Input from Cloud Storage (JSONL, CSV, TFRecord) or BigQuery. Output to Cloud Storage or BigQuery. Scales workers automatically. Also supports Gemini batch for LLM volume at lower price
BigQuery ML ML.PREDICT Data already in BigQuery. Just SQL. Remote models can call Vertex endpoints
Dataflow Streaming or batch inference inside a pipeline, using the RunInference Beam transform with a model (TensorFlow, PyTorch, scikit-learn, XGBoost, Vertex endpoint). Good when inference is one step among transformations, or for near-real-time streaming scoring from Pub/Sub
Dataproc / Spark Existing Spark ML models or Spark-scale scoring

Batch-prediction options to know: machine type and accelerator for the job, number of replicas (starting and max), explanations can be included, and model monitoring for batch jobs is supported. Large batch jobs split inputs, so ordering of output isn’t guaranteed. Include an ID column to join back.

Online prediction

  • Deploy a model to a Vertex AI endpoint, then call predict (REST, gRPC, SDK). Use rawPredict for custom request formats and streaming methods for token streaming from generative models.
  • Request size limits apply (roughly 1.5 MB per request for online prediction). Send large payloads as batch or Cloud Storage references.
  • A deployed model is a model version on a machine type with min and max replicas. An endpoint can hold several deployed models.

Serving frameworks and containers

Option Detail
Prebuilt prediction containers TensorFlow, PyTorch (TorchServe-based), scikit-learn, XGBoost, plus optimised TensorFlow runtimes. Give a SavedModel/artifacts directory and you’re done
Custom container Any HTTP server that exposes the health and predict routes on the port you declare. Use when you need a custom framework (ONNX Runtime, Triton, vLLM, Hugging Face TGI), custom pre/post-processing, or a non-Python stack. Vertex injects environment variables such as AIP_HTTP_PORT, AIP_HEALTH_ROUTE and AIP_PREDICT_ROUTE
Custom prediction routines (CPR) Python classes (Predictor) that wrap a model with pre/post-processing and build the container for you. Less Docker work
NVIDIA Triton / optimised TensorFlow runtime Multi-framework, dynamic batching, concurrent model execution. High-throughput GPU serving
Model Garden deployments One-click deployment of open models using optimised serving stacks (vLLM and similar)
Cloud Run / GKE Containerised serving outside Vertex AI. Pick when you need full infrastructure control, scale-to-zero (Cloud Run), existing Kubernetes platform, or one serving stack across clouds. You carry more operational burden

Pre- and post-processing belongs in the serving path consistent with training: bake it into the model graph (TFT), the custom container, CPR, or a serving pipeline (inference pipelines chain containers, for example preprocessor then model). Avoid reimplementing it in the client.

Framework tips: PyTorch models are packaged as a .mar archive for TorchServe or served from a custom handler. XGBoost and scikit-learn use their native saved formats (model.bst, model.joblib/pickle). TensorFlow uses SavedModel. Vertex expects specific file names for prebuilt containers, so a “model not found” error often means the artifact has the wrong name or is in the wrong path.

Model registry

Vertex AI Model Registry is the central catalogue of models and versions.

  • Register trained models from training jobs, BigQuery ML (model_registry), AutoML, or by importing artifacts and a serving container.
  • Each model has versions with aliases (for example default, champion, staging). Deploy by alias so promoting a version is an alias change instead of a redeploy of consumers.
  • Attach evaluation metrics, labels, lineage back to training pipeline and dataset, and the container image and explanation settings.
  • Governance patterns: models trained in a dev project, promoted to a registry in a prod project after tests and approvals. Use IAM for who can register, deploy and read.
  • From the registry you can deploy to an endpoint, run batch prediction, or start evaluation.

Organise by one model per business problem, versions per retrain, and keep the production alias explicit. Use model labels and descriptions for ownership and risk class. Include a model card and fairness notes with high-impact models.

A/B testing and rollout of model versions

An endpoint can hold multiple deployed models and a traffic split that sums to 100%.

  • Canary / gradual rollout: deploy v2 with 5-10% of traffic, compare metrics, then ramp up. Roll back by moving traffic to v1, with no redeploy.
  • A/B test: split between two versions, then compare business metrics (conversion, revenue), not just model metrics, over enough traffic for statistical significance. Keep users sticky to a variant if the experience needs it (the endpoint splits per request, so do sticky assignment in the application).
  • Shadow (mirror) testing: send a copy of live traffic to a new model, log its predictions without returning them, and compare offline. Safest, with no user impact. Implement with request logging or a mirror in your service layer.
  • Blue/green: deploy a second endpoint, switch the client or load balancer.
  • Champion/challenger with a rolling evaluation using ground truth that arrives later.
  • Every deployed model on an endpoint must serve the same input and output schema for a split to work. Each consumes its own replicas, so you pay for both.
  • Request-response logging to BigQuery supports comparison.

Scaling online serving

Endpoints: public and private

Endpoint Behaviour Choose when
Public endpoint (shared) Reachable over the internet via Google front end, IAM-authenticated Default. Simple apps with internet clients
Dedicated public endpoint Dedicated networking for better performance and isolation, larger payloads, and streaming High-throughput or latency-sensitive public use
Private endpoint via VPC Network Peering Reachable only from your VPC (private services access) Lower latency, traffic never over the public internet. Older approach
Private Service Connect (PSC) endpoint Reaches the endpoint through a private IP in your VPC, with no peering required, and works across projects Current recommended private option, including with VPC-SC for data exfiltration control

IAM: callers need aiplatform.endpoints.predict (role Vertex AI User). Use service accounts, not user credentials, in production. Combine with VPC Service Controls and CMEK on regulated workloads.

Autoscaling

  • You set min replica count and max replica count. Autoscaling adds replicas when utilisation passes a target (default CPU utilisation 60% for CPU machines, GPU duty cycle for GPU models, or a custom metric such as requests per second or queue depth).
  • Min replicas of at least 1 keeps a warm instance for latency. Setting min to 0 isn’t available on classic endpoints (Cloud Run does scale to zero), but newer features support scale-to-zero for some deployments. Cold starts with large models are slow, so prefer a warm minimum when latency matters.
  • Min of 2 or more across zones gives availability. A single replica is a single point of failure.
  • Scaling lags behind spikes, so keep headroom (lower target utilisation) for bursts.
  • Throughput planning: measure requests per second one replica handles at target latency (load test), then size max replicas to peak divided by that. Use larger batches or dynamic batching to raise accelerator utilisation, at some cost to latency.
  • Multi-model hosting: co-hosting several models on one VM/replica set cuts cost for many small models. Deployment resource pools share replicas across models.
  • Use Cloud Monitoring metrics (prediction/online/prediction_latencies, replicas, cpu/utilization, accelerator/duty_cycle) and alerts. Check error rates (429 = throttled/overloaded, 5xx = model or container faults).

Feature Store at serving time

For models with many features computed from history (user purchases in the last 30 days), look the features up at request time:

  1. Compute features offline in BigQuery and keep them in a feature group.
  2. Sync a feature view to the online store on a schedule.
  3. At prediction, the serving code (or the custom container) calls the online store by entity ID (low-latency read), merges with request features, and calls the model.

Use Bigtable-backed online serving for large scale and optimized online serving for the lowest latency (with some constraints). Using the same feature definitions in training and serving avoids skew. Alternatives: Memorystore (Redis), Bigtable, or Firestore directly when you don’t need the feature store’s governance.

Hardware for serving

Model Hardware
scikit-learn, XGBoost, small trees CPU machines (n1/n2/e2), often enough
Small or moderate neural networks, low QPS CPU with optimised runtime, or a single T4/L4
Image, speech, vision-transformer models at higher QPS GPU (L4, T4, A100) with batching
LLMs and large generative models A100/H100/H200 GPUs or TPUs (v5e/v6e), often multi-accelerator with tensor parallelism, plus an optimised server (vLLM, Triton, TGI)
Mobile, offline, IoT Edge (TF Lite, Edge TPU, on-device Gemini Nano)
  • Right-size: GPUs are wasted on small models at low QPS, and CPUs can’t meet latency for big networks.
  • Pre-warm and keep a warm minimum for large models, since loading weights takes minutes.
  • GPU batching raises throughput, and multi-instance GPU/time sharing can host several small models.
  • Provisioned Throughput (reserved capacity) gives predictable performance for Gemini on production workloads. Pay-as-you-go quotas can throttle (429s) during spikes.

Optimising models for production

Goals: lower latency, memory and cost, and higher throughput, with minimal accuracy loss.

Technique What it does Notes
Quantisation Use lower precision (float32 to float16/bfloat16 or int8 or int4) 2 to 4 times smaller and faster. Post-training quantisation is easiest, quantisation-aware training keeps accuracy better
Pruning Remove low-importance weights or neurons Sparse models, combine with fine-tuning
Knowledge distillation Train a small student to imitate a large teacher Great latency reduction and the basis for smaller LLMs
Architecture choice Use efficient designs (MobileNet, EfficientNet, DistilBERT) Choose early
Graph compilation XLA, TensorRT, ONNX Runtime, TF-TRT, optimised TensorFlow runtime Fuses ops, speeds inference on GPU/CPU
Batching Dynamic/server-side batching of requests Raises accelerator utilisation, adds a bit of waiting latency
Caching Cache frequent predictions or embeddings. Context caching for LLM prompts Big wins for repeated input
Feature reduction Drop low-value features Lowers feature lookup and compute cost
LLM-specific KV-cache, speculative decoding, continuous batching, shorter prompts, smaller models, streaming Cut cost per token and time to first token
Training-side: mixed precision, gradient checkpointing, efficient input pipelines Faster, cheaper training Same ideas as the previous domain

Match the technique to the constraint: latency-bound means smaller or faster model, compiled graph, better hardware, caching. Memory-bound means quantisation, pruning, sharding. Throughput-bound means batching, more replicas, better utilisation. Cost-bound means right-size, distil, batch instead of online, Spot for batch jobs.

Exam checklist

  • Batch if predictions can be precomputed. Online only when freshness at request time is required.
  • BigQuery ML for in-warehouse scoring, Dataflow RunInference for streaming scoring, Vertex batch prediction for registered models.
  • Prebuilt containers for standard frameworks, custom containers or CPR for custom logic, Triton/vLLM for high-throughput GPU and LLM serving.
  • Model Registry with versions and aliases governs promotion. Deploy by alias.
  • Traffic split gives canary and A/B. Shadow tests risk-free. Compare business metrics. Same schema required.
  • PSC endpoints for private access. Dedicated public endpoints for performance. IAM aiplatform.endpoints.predict.
  • Autoscale on utilisation with min replicas of 2 or more for availability and warm starts for large models.
  • Feature Store online serving looks up precomputed features by entity ID and shares definitions with training.
  • Optimise with quantisation, distillation, compilation, batching and caching, picking the one that matches the bottleneck.

Test what you just read. 66 practice questions on serving and scaling models.

Practise this domain

All PMLE notes