ML Cloud Deployment
Overview
Use this skill for deploying ML workloads to managed platforms, Kubernetes, serverless systems, GPU/TPU providers, and lakehouse environments. Start from workload requirements: training or inference, batch or online, latency SLO, throughput, model size, data gravity, compliance, region, hardware, team expertise, and budget.
Platform Selection
| Requirement |
Strong choices |
| AWS-native managed lifecycle |
SageMaker Studio, Training, Processing, Pipelines, Model Registry, Endpoints, Feature Store, Clarify, Model Monitor |
| GCP-native managed lifecycle |
Vertex AI Training, Pipelines, Endpoints, Feature Store, Model Monitoring, AutoML, Matching Engine, TPUs |
| Azure-native managed lifecycle |
Azure ML workspaces, compute clusters, pipelines, registries, managed online/batch endpoints, AutoML, Responsible ML |
| Lakehouse/Spark-centric ML |
Databricks on AWS/Azure/GCP with MLflow, Delta, Feature Store, Workflows |
| Kubernetes control |
EKS/GKE/AKS with Kubeflow, KServe, Seldon, Ray, Triton, custom operators |
| Serverless or fast GPU apps |
Modal, Replicate, Cloud Run with GPU where available, Lambda for small CPU inference |
| Flexible GPU rental |
Lambda Labs, RunPod, self-managed cloud GPU VMs |
| Ray-native scale-out |
Anyscale or Ray clusters on Kubernetes/cloud VMs |
Prefer managed services when governance, observability, and team velocity matter more than runtime customization. Prefer Kubernetes or VMs when custom networking, specialized runtimes, or cost/performance tuning dominate.
AWS Patterns
SageMaker handles managed training jobs, feature stores, and real-time or serverless endpoints. The AWS CLI (aws sagemaker and aws sagemaker-runtime) is used to orchestrate these systems programmatically.
AWS SageMaker Endpoint Variant Configuration (endpoint_config.json)
{
"EndpointConfigName": "production-llm-classifier-v1-cfg",
"ProductionVariants": [
{
"VariantName": "AllTraffic",
"ModelName": "llm-classifier-model-v1",
"InitialInstanceCount": 2,
"InstanceType": "ml.g5.2xlarge",
"InitialVariantWeight": 1.0,
"VolumeSizeInGB": 50,
"ManagedInstanceScaling": {
"MinInstanceCount": 2,
"MaxInstanceCount": 10,
"Status": "ENABLED"
},
"RoutingConfig": {
"RoutingStrategy": "LEAST_OUTSTANDING_REQUESTS"
}
}
]
}
AWS CLI SageMaker Lifecycle Management
# 1. Setup Domain and default IAM Role/VPC settings
aws sagemaker create-domain \
--domain-name ProdMLDomain \
--auth-mode IAM \
--default-user-settings ExecutionRole=arn:aws:iam::123456789012:role/SageMakerExecutionRole \
--subnet-ids subnet-1a2b3c,subnet-4d5e6f \
--vpc-id vpc-0abc123 \
--app-network-access-type PublicInternetOnly
# 2. Provision and start/stop an interactive notebook instance
aws sagemaker create-notebook-instance \
--notebook-instance-name dev-notebook-instance \
--instance-type ml.t3.medium \
--role-arn arn:aws:iam::123456789012:role/SageMakerExecutionRole
aws sagemaker start-notebook-instance --notebook-instance-name dev-notebook-instance
aws sagemaker stop-notebook-instance --notebook-instance-name dev-notebook-instance
# 3. Submit a managed GPU training job
aws sagemaker create-training-job \
--training-job-name custom-pytorch-train-job \
--algorithm-specification TrainingImage=763104351884.dkr.ecr.us-east-1.amazonaws.com/pytorch-training:1.12.0-gpu-py38-cu113-ubuntu20.04,TrainingInputMode=File \
--role-arn arn:aws:iam::123456789012:role/SageMakerExecutionRole \
--input-data-config '[{"ChannelName": "training", "DataSource": {"S3DataSource": {"S3DataType": "S3Prefix", "S3Uri": "s3://my-ml-bucket/train-data/", "S3DataDistributionType": "FullyReplicated"}}}]' \
--output-data-config S3OutputPath=s3://my-ml-bucket/checkpoints/ \
--resource-config InstanceType=ml.g5.2xlarge,InstanceCount=1,VolumeSizeInGB=50 \
--stopping-condition MaxRuntimeInSeconds=86400
# 4. Register a model in the SageMaker Model Registry
aws sagemaker create-model-package-group \
--model-package-group-name credit-scoring-group \
--model-package-group-description "Model registry group for credit scoring neural nets"
aws sagemaker create-model \
--model-name credit-scoring-v1 \
--primary-container Image=763104351884.dkr.ecr.us-east-1.amazonaws.com/pytorch-inference:1.12.0-gpu-py38,ModelDataUrl=s3://my-ml-bucket/checkpoints/custom-pytorch-train-job/output/model.tar.gz \
--execution-role-arn arn:aws:iam::123456789012:role/SageMakerExecutionRole
# 5. Create Endpoint Configuration and Deploy Endpoint
aws sagemaker create-endpoint-config \
--endpoint-config-name credit-scoring-v1-cfg \
--production-variants '[{"VariantName": "AllTraffic", "ModelName": "credit-scoring-v1", "InitialInstanceCount": 2, "InstanceType": "ml.m5.xlarge", "InitialVariantWeight": 1.0}]'
aws sagemaker create-endpoint \
--endpoint-name credit-scoring-prod-endpoint \
--endpoint-config-name credit-scoring-v1-cfg
# 6. Invoke/Test Endpoint via CLI
aws sagemaker-runtime invoke-endpoint \
--endpoint-name credit-scoring-prod-endpoint \
--content-type application/json \
--body '{"features": [0.25, 1.4, 0.9]}' \
response_output.json
GCP Patterns
Vertex AI manages training pipelines, hyperparameter tuning sweeps, custom jobs, the model registry, and predictions via gcloud ai.
GCP Vertex AI TPU CustomJob Specification (tpu_job.yaml)
displayName: vertex-ai-tpu-training-job
studySpec:
metrics:
- metricId: val_loss
goal: MINIMIZE
parameters:
- parameterId: learning_rate
doubleValueSpec:
minValue: 1e-5
maxValue: 1e-3
scaleType: UNIT_LOG_SCALE
trialJobSpec:
workerPoolSpecs:
- machineSpec:
machineType: n1-standard-8
replicaCount: 1
containerSpec:
imageUri: gcr.io/my-project/ml-trainer:latest
- machineSpec:
machineType: cloud-tpu-v4-podslice
acceleratorType: TPU_V4
acceleratorCount: 4
replicaCount: 1
containerSpec:
imageUri: gcr.io/my-project/ml-tpu-trainer:latest
args: [
"--data_path", "gs://my-bucket/dataset-v1",
"--epochs", "10"
]
GCP Vertex AI CLI Operations
# 1. Create a user-managed Jupyter Workbench instance
gcloud notebooks instances create dev-workbench-instance \
--location=us-central1-a \
--vm-image-project=deeplearning-platform-release \
--vm-image-family=common-gpu \
--machine-type=n1-standard-4
# 2. Submit containerized custom training job
gcloud ai custom-jobs create \
--region=us-central1 \
--display-name=gpu-pytorch-training-run \
--worker-pool-spec=replica-count=1,machine-type=n1-standard-8,accelerator-type=nvidia-tesla-t4,accelerator-count=1,container-image-uri=gcr.io/my-gcp-project/pytorch-train-custom:v1 \
--args="--epochs=20,--data-path=gs://my-bucket/training-gold"
# 3. Upload model artifact to Model Registry
gcloud ai models upload \
--region=us-central1 \
--display-name=iris-classifier-v1 \
--container-image-uri=us-docker.pkg.dev/vertex-ai/prediction/pytorch-cpu.1-11:latest \
--artifact-uri=gs://my-bucket/models/iris-classifier/
# 4. Provision endpoint and deploy model with 100% traffic allocation
# Note: replace <ENDPOINT-ID> and <MODEL-ID> with their UUIDs
gcloud ai endpoints create \
--region=us-central1 \
--display-name=production-iris-endpoint
gcloud ai endpoints deploy-model <ENDPOINT-ID> \
--region=us-central1 \
--model=<MODEL-ID> \
--display-name=iris-v1-blue-deployment \
--machine-type=n1-standard-4 \
--min-replica-count=2 \
--max-replica-count=10 \
--traffic-split=0=100
# 5. Predict via Vertex AI Endpoint CLI
gcloud ai endpoints predict <ENDPOINT-ID> \
--region=us-central1 \
--json-request=sample_payload.json
Azure Patterns
Azure AI Foundry / Azure Machine Learning Workspace orchestrates the entire ML lifecycle. Workspace, computes, environments, data assets, training jobs, models, and endpoints can be managed natively using the Azure CLI ml extension. For Azure ML code asset registration from CI, ADF orchestration, ADF WebActivity networking, result.version propagation, pointer blobs, or private storage firewall handling, load ml-azureml-adf-automation.
Azure ML v2 CLI Online Endpoint & Deployment YAML (azure_deploy.yaml)
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineEndpoint.schema.json
name: credit-risk-endpoint
auth_mode: key
---
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineDeployment.schema.json
name: credit-risk-blue
endpoint_name: credit-risk-endpoint
model: azureml:credit-risk-model:1
code_configuration:
code: ./src
scoring_script: score.py
environment: azureml:credit-risk-env:1
instance_type: Standard_DS3_v2
instance_count: 2
request_settings:
request_timeout_ms: 3000
max_concurrent_requests_per_instance: 10
scale_settings:
type: default
Azure AI Foundry / Azure ML Workspace CLI Management (az ml)
# Add/update the Machine Learning CLI extension
az extension add -n ml -y
az login
# 1. Create a Resource Group and Azure ML Workspace (Azure AI Foundry Hub)
az group create --name my-ml-rg --location eastus
az ml workspace create --name my-ml-workspace --resource-group my-ml-rg --location eastus
# 2. Provision Computes (Instance, Training Cluster, CPU cluster)
az ml compute create --name dev-compute-ci --type ComputeInstance --size Standard_DS3_v2 -g my-ml-rg -w my-ml-workspace
az ml compute create --name gpu-train-cluster --type AmlCompute --size Standard_NC6s_v3 --min-instances 0 --max-instances 4 -g my-ml-rg -w my-ml-workspace
az ml compute create --name cpu-proc-cluster --type AmlCompute --size Standard_DS12_v2 --min-instances 0 --max-instances 8 -g my-ml-rg -w my-ml-workspace
# 3. Create a URI Data Asset
az ml data create --file data.yaml -g my-ml-rg -w my-ml-workspace
# 4. Create an Environment definition
az ml environment create --file env.yaml -g my-ml-rg -w my-ml-workspace
# 5. Submit, Monitor, and Stream a Command Job
az ml job create --file job.yaml -g my-ml-rg -w my-ml-workspace --web --stream
# View, list and monitor jobs
az ml job list -g my-ml-rg -w my-ml-workspace --output table
az ml job stream --name <job-id> -g my-ml-rg -w my-ml-workspace
az ml job download --name <job-id> --download-path ./outputs -g my-ml-rg -w my-ml-workspace
# 6. Register a Model
az ml model create --file model.yaml -g my-ml-rg -w my-ml-workspace
# 7. Create Endpoint, Deploy, Test, and Cleanup
az ml online-endpoint create --file endpoint.yaml -g my-ml-rg -w my-ml-workspace
az ml online-deployment create --file deployment.yaml --all-traffic -g my-ml-rg -w my-ml-workspace
# List and monitor endpoints:
az ml online-endpoint show --name credit-risk-endpoint -g my-ml-rg -w my-ml-workspace
# Test endpoint with a sample payload file:
az ml online-endpoint invoke --name credit-risk-endpoint --request-file ./sample_request.json -g my-ml-rg -w my-ml-workspace
# Delete endpoint:
az ml online-endpoint delete --name credit-risk-endpoint --yes -g my-ml-rg -w my-ml-workspace
Local & Hybrid Providers (MLflow & Kubernetes/KServe)
For local development or custom multi-cloud Kubernetes clusters, MLflow and KServe provide standardization.
MLflow Local CLI Management
# 1. Start a local tracking and model registry server
mlflow server \
--host 127.0.0.1 \
--port 5000 \
--backend-store-uri sqlite:///mlflow.db \
--default-artifact-root ./mlflow_artifacts_store
# 2. Run a packaged local MLflow Project with runtime parameters
mlflow run . -P alpha=0.1 -P l1_ratio=0.2 --experiment-name iris-training
# 3. Serve a registered model locally
mlflow models serve \
--model-uri models:/iris-classifier/Production \
--port 5001 \
--no-conda
# 4. Invoke the local serving endpoint
curl -X POST -H "Content-Type: application/json" \
-d '{"dataframe_split": {"columns": ["sepal_len", "sepal_wid"], "data": [[5.1, 3.5]]}}' \
http://127.0.0.1:5001/invocations
Kubernetes Native Serving CLI (KServe)
# kserve-inference.yaml
apiVersion: "serving.kserve.io/v1beta1"
kind: "InferenceService"
metadata:
name: "sklearn-iris"
namespace: "ml-serving"
spec:
predictor:
model:
modelFormat:
name: sklearn
storageUri: "gs://kfserving-examples/models/sklearn/1.0/model"
resources:
limits:
cpu: "1"
memory: 2Gi
requests:
cpu: "500m"
memory: 1Gi
# 1. Apply inference manifests via kubectl
kubectl apply -f kserve-inference.yaml -n ml-serving
# 2. Monitor status and readiness of inference service
kubectl get inferenceservice sklearn-iris -n ml-serving
# 3. Port forward or direct payload query through Istio ingress gateway
SERVICE_HOSTNAME=$(kubectl get inferenceservice sklearn-iris -n ml-serving -o jsonpath='{.status.url}' | cut -d/ -f3)
INGRESS_IP=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
curl -v -H "Host: ${SERVICE_HOSTNAME}" \
http://${INGRESS_IP}:${INGRESS_PORT}/v1/models/sklearn-iris:predict \
-d @sample_payload.json
Serverless GPU serving (Modal Pattern)
For serverless deployments on isolated GPUs with zero-cold-start optimization, use Modal.
import modal
app = modal.App("serverless-image-classifier")
# Pre-packaged CUDA image with dependencies
image = (
modal.Image.debian_slim()
.pip_install("torch", "torchvision", "transformers")
)
@app.cls(gpu="A10G", image=image)
class ImageClassifier:
@modal.enter()
def load_model(self):
import torch
from transformers import ViTForImageClassification, ViTImageProcessor
self.device = "cuda" if torch.cuda.is_available() else "cpu"
self.processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
self.model = ViTForImageClassification.from_pretrained("google/vit-base-patch16-224").to(self.device)
@modal.method()
def predict(self, image_bytes: bytes):
from PIL import Image
import io
image = Image.open(io.BytesIO(image_bytes))
inputs = self.processor(images=image, return_tensors="pt").to(self.device)
outputs = self.model(**inputs)
logits = outputs.logits
predicted_class_idx = logits.argmax(-1).item()
return self.model.config.id2label[predicted_class_idx]
Hardware Selection
Match hardware to bottleneck:
- CPU: classical ML, preprocessing, small models, latency-insensitive batch jobs.
- T4/L4/A10-class GPUs: cost-effective inference, fine-tuning smaller models, notebooks.
- A100/H100/H200/B200-class GPUs: large model training, high-throughput inference, memory-heavy workloads.
- TPUs: supported dense tensor workloads at scale, especially JAX/TensorFlow ecosystems.
- Inferentia/Trainium: AWS cost/performance if model operators and framework support are mature.
Estimate memory before launching: model weights, optimizer states, gradients, activations, KV cache, batch size, sequence length, and runtime overhead. For inference, benchmark p50/p95/p99 latency under realistic concurrency and payload sizes.
Endpoint Design
Define request schema, response schema, timeout, max payload, auth, rate limits, autoscaling policy, health checks, logging, and rollback. Use canary or blue/green releases for production. For GPU endpoints, tune dynamic batching and concurrency carefully; too much concurrency can increase tail latency or cause OOM. For multi-region deployments, replicate artifacts, keep model versions consistent, and plan data residency and failover.
Security and Compliance
Use private networking when models access sensitive data. Store secrets in cloud secret managers. Use least-privilege IAM/service accounts/managed identities. Encrypt data and artifacts. Log access and deployment events. Scan containers. Avoid baking credentials into images. For public endpoints, apply auth, input validation, abuse controls, rate limits, and prompt-injection defenses for LLM/RAG systems.
Cost Optimization
Use spot/preemptible instances for checkpointed training and stateless batch jobs. Use autoscaling endpoints with scale-to-zero when acceptable. Prefer batch inference for non-real-time workloads. Quantize or distill models before scaling replicas. Right-size GPU memory, not just GPU count. Use reserved/committed capacity only after workload shape is stable. Track cost per run, per model version, and per 1,000 predictions.
Deployment Readiness Checklist
- Model artifact, preprocessing, tokenizer, and config are versioned together.
- Input schema is validated and compatible with training features.
- Evaluation report includes relevant slices and latency/cost benchmarks.
- Endpoint has health checks, autoscaling, logs, metrics, alerts, and rollback.
- Security controls cover identity, secrets, network, encryption, and audit.
- Monitoring captures drift, data quality, prediction distribution, outcomes, and incidents.
Sources
1---2name: ml-cloud-deployment3description: This skill should be used when the user asks to deploy, scale, or cost-optimize ML workloads on cloud platforms. PROACTIVELY activate for: (1) AWS SageMaker Studio, Training, Processing, Pipelines, Endpoints, Model Monitor, Feature Store, Clarify, Ground Truth, EC2 GPUs, EKS, Lambda, Inferentia, Trainium, (2) GCP Vertex AI Training, Pipelines, Endpoints, Feature Store, Model Monitoring, AutoML, Matching Engine, TPU, GKE, Cloud Run, (3) Azure ML workspaces, pipelines, managed endpoints, AutoML, Responsible ML, AKS/ACI, (4) Databricks, Modal, Replicate, RunPod, Lambda Labs, Anyscale. Provides: cloud ML architecture, autoscaling, hardware, security, and cost guidance.4---5
6# ML Cloud Deployment
7
8## Overview
9
10Use this skill for deploying ML workloads to managed platforms, Kubernetes, serverless systems, GPU/TPU providers, and lakehouse environments. Start from workload requirements: training or inference, batch or online, latency SLO, throughput, model size, data gravity, compliance, region, hardware, team expertise, and budget.
11
12## Platform Selection
13
14| Requirement | Strong choices |
15|---|---|
16| AWS-native managed lifecycle | SageMaker Studio, Training, Processing, Pipelines, Model Registry, Endpoints, Feature Store, Clarify, Model Monitor |
17| GCP-native managed lifecycle | Vertex AI Training, Pipelines, Endpoints, Feature Store, Model Monitoring, AutoML, Matching Engine, TPUs |
18| Azure-native managed lifecycle | Azure ML workspaces, compute clusters, pipelines, registries, managed online/batch endpoints, AutoML, Responsible ML |
19| Lakehouse/Spark-centric ML | Databricks on AWS/Azure/GCP with MLflow, Delta, Feature Store, Workflows |
20| Kubernetes control | EKS/GKE/AKS with Kubeflow, KServe, Seldon, Ray, Triton, custom operators |
21| Serverless or fast GPU apps | Modal, Replicate, Cloud Run with GPU where available, Lambda for small CPU inference |
22| Flexible GPU rental | Lambda Labs, RunPod, self-managed cloud GPU VMs |
23| Ray-native scale-out | Anyscale or Ray clusters on Kubernetes/cloud VMs |
24
25Prefer managed services when governance, observability, and team velocity matter more than runtime customization. Prefer Kubernetes or VMs when custom networking, specialized runtimes, or cost/performance tuning dominate.
26
27## AWS Patterns
28
29SageMaker handles managed training jobs, feature stores, and real-time or serverless endpoints. The AWS CLI (`aws sagemaker` and `aws sagemaker-runtime`) is used to orchestrate these systems programmatically.
30
31### AWS SageMaker Endpoint Variant Configuration (`endpoint_config.json`)
32```json
33{
34 "EndpointConfigName": "production-llm-classifier-v1-cfg",
35 "ProductionVariants": [
36 {
37 "VariantName": "AllTraffic",
38 "ModelName": "llm-classifier-model-v1",
39 "InitialInstanceCount": 2,
40 "InstanceType": "ml.g5.2xlarge",
41 "InitialVariantWeight": 1.0,
42 "VolumeSizeInGB": 50,
43 "ManagedInstanceScaling": {
44 "MinInstanceCount": 2,
45 "MaxInstanceCount": 10,
46 "Status": "ENABLED"
47 },
48 "RoutingConfig": {
49 "RoutingStrategy": "LEAST_OUTSTANDING_REQUESTS"
50 }
51 }
52 ]
53}
54```
55
56### AWS CLI SageMaker Lifecycle Management
57
58```bash
59# 1. Setup Domain and default IAM Role/VPC settings
60aws sagemaker create-domain \
61 --domain-name ProdMLDomain \
62 --auth-mode IAM \
63 --default-user-settings ExecutionRole=arn:aws:iam::123456789012:role/SageMakerExecutionRole \
64 --subnet-ids subnet-1a2b3c,subnet-4d5e6f \
65 --vpc-id vpc-0abc123 \
66 --app-network-access-type PublicInternetOnly
67
68# 2. Provision and start/stop an interactive notebook instance
69aws sagemaker create-notebook-instance \
70 --notebook-instance-name dev-notebook-instance \
71 --instance-type ml.t3.medium \
72 --role-arn arn:aws:iam::123456789012:role/SageMakerExecutionRole
73
74aws sagemaker start-notebook-instance --notebook-instance-name dev-notebook-instance
75aws sagemaker stop-notebook-instance --notebook-instance-name dev-notebook-instance
76
77# 3. Submit a managed GPU training job
78aws sagemaker create-training-job \
79 --training-job-name custom-pytorch-train-job \
80 --algorithm-specification TrainingImage=763104351884.dkr.ecr.us-east-1.amazonaws.com/pytorch-training:1.12.0-gpu-py38-cu113-ubuntu20.04,TrainingInputMode=File \
81 --role-arn arn:aws:iam::123456789012:role/SageMakerExecutionRole \
82 --input-data-config '[{"ChannelName": "training", "DataSource": {"S3DataSource": {"S3DataType": "S3Prefix", "S3Uri": "s3://my-ml-bucket/train-data/", "S3DataDistributionType": "FullyReplicated"}}}]' \
83 --output-data-config S3OutputPath=s3://my-ml-bucket/checkpoints/ \
84 --resource-config InstanceType=ml.g5.2xlarge,InstanceCount=1,VolumeSizeInGB=50 \
85 --stopping-condition MaxRuntimeInSeconds=86400
86
87# 4. Register a model in the SageMaker Model Registry
88aws sagemaker create-model-package-group \
89 --model-package-group-name credit-scoring-group \
90 --model-package-group-description "Model registry group for credit scoring neural nets"
91
92aws sagemaker create-model \
93 --model-name credit-scoring-v1 \
94 --primary-container Image=763104351884.dkr.ecr.us-east-1.amazonaws.com/pytorch-inference:1.12.0-gpu-py38,ModelDataUrl=s3://my-ml-bucket/checkpoints/custom-pytorch-train-job/output/model.tar.gz \
95 --execution-role-arn arn:aws:iam::123456789012:role/SageMakerExecutionRole
96
97# 5. Create Endpoint Configuration and Deploy Endpoint
98aws sagemaker create-endpoint-config \
99 --endpoint-config-name credit-scoring-v1-cfg \
100 --production-variants '[{"VariantName": "AllTraffic", "ModelName": "credit-scoring-v1", "InitialInstanceCount": 2, "InstanceType": "ml.m5.xlarge", "InitialVariantWeight": 1.0}]'
101
102aws sagemaker create-endpoint \
103 --endpoint-name credit-scoring-prod-endpoint \
104 --endpoint-config-name credit-scoring-v1-cfg
105
106# 6. Invoke/Test Endpoint via CLI
107aws sagemaker-runtime invoke-endpoint \
108 --endpoint-name credit-scoring-prod-endpoint \
109 --content-type application/json \
110 --body '{"features": [0.25, 1.4, 0.9]}' \
111 response_output.json
112```
113
114## GCP Patterns
115
116Vertex AI manages training pipelines, hyperparameter tuning sweeps, custom jobs, the model registry, and predictions via `gcloud ai`.
117
118### GCP Vertex AI TPU CustomJob Specification (`tpu_job.yaml`)
119```yaml
120displayName: vertex-ai-tpu-training-job
121studySpec:
122 metrics:
123 - metricId: val_loss
124 goal: MINIMIZE
125 parameters:
126 - parameterId: learning_rate
127 doubleValueSpec:
128 minValue: 1e-5
129 maxValue: 1e-3
130 scaleType: UNIT_LOG_SCALE
131trialJobSpec:
132 workerPoolSpecs:
133 - machineSpec:
134 machineType: n1-standard-8
135 replicaCount: 1
136 containerSpec:
137 imageUri: gcr.io/my-project/ml-trainer:latest
138 - machineSpec:
139 machineType: cloud-tpu-v4-podslice
140 acceleratorType: TPU_V4
141 acceleratorCount: 4
142 replicaCount: 1
143 containerSpec:
144 imageUri: gcr.io/my-project/ml-tpu-trainer:latest
145 args: [
146 "--data_path", "gs://my-bucket/dataset-v1",
147 "--epochs", "10"
148 ]
149```
150
151### GCP Vertex AI CLI Operations
152
153```bash
154# 1. Create a user-managed Jupyter Workbench instance
155gcloud notebooks instances create dev-workbench-instance \
156 --location=us-central1-a \
157 --vm-image-project=deeplearning-platform-release \
158 --vm-image-family=common-gpu \
159 --machine-type=n1-standard-4
160
161# 2. Submit containerized custom training job
162gcloud ai custom-jobs create \
163 --region=us-central1 \
164 --display-name=gpu-pytorch-training-run \
165 --worker-pool-spec=replica-count=1,machine-type=n1-standard-8,accelerator-type=nvidia-tesla-t4,accelerator-count=1,container-image-uri=gcr.io/my-gcp-project/pytorch-train-custom:v1 \
166 --args="--epochs=20,--data-path=gs://my-bucket/training-gold"
167
168# 3. Upload model artifact to Model Registry
169gcloud ai models upload \
170 --region=us-central1 \
171 --display-name=iris-classifier-v1 \
172 --container-image-uri=us-docker.pkg.dev/vertex-ai/prediction/pytorch-cpu.1-11:latest \
173 --artifact-uri=gs://my-bucket/models/iris-classifier/
174
175# 4. Provision endpoint and deploy model with 100% traffic allocation
176# Note: replace <ENDPOINT-ID> and <MODEL-ID> with their UUIDs
177gcloud ai endpoints create \
178 --region=us-central1 \
179 --display-name=production-iris-endpoint
180
181gcloud ai endpoints deploy-model <ENDPOINT-ID> \
182 --region=us-central1 \
183 --model=<MODEL-ID> \
184 --display-name=iris-v1-blue-deployment \
185 --machine-type=n1-standard-4 \
186 --min-replica-count=2 \
187 --max-replica-count=10 \
188 --traffic-split=0=100
189
190# 5. Predict via Vertex AI Endpoint CLI
191gcloud ai endpoints predict <ENDPOINT-ID> \
192 --region=us-central1 \
193 --json-request=sample_payload.json
194```
195
196## Azure Patterns
197
198Azure AI Foundry / Azure Machine Learning Workspace orchestrates the entire ML lifecycle. Workspace, computes, environments, data assets, training jobs, models, and endpoints can be managed natively using the Azure CLI `ml` extension. For Azure ML code asset registration from CI, ADF orchestration, ADF WebActivity networking, `result.version` propagation, pointer blobs, or private storage firewall handling, load `ml-azureml-adf-automation`.
199
200### Azure ML v2 CLI Online Endpoint & Deployment YAML (`azure_deploy.yaml`)
201```yaml
202$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineEndpoint.schema.json
203name: credit-risk-endpoint
204auth_mode: key
205---
206$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineDeployment.schema.json
207name: credit-risk-blue
208endpoint_name: credit-risk-endpoint
209model: azureml:credit-risk-model:1
210code_configuration:
211 code: ./src
212 scoring_script: score.py
213environment: azureml:credit-risk-env:1
214instance_type: Standard_DS3_v2
215instance_count: 2
216request_settings:
217 request_timeout_ms: 3000
218 max_concurrent_requests_per_instance: 10
219scale_settings:
220 type: default
221```
222
223### Azure AI Foundry / Azure ML Workspace CLI Management (`az ml`)
224
225```bash
226# Add/update the Machine Learning CLI extension
227az extension add -n ml -y
228az login
229
230# 1. Create a Resource Group and Azure ML Workspace (Azure AI Foundry Hub)
231az group create --name my-ml-rg --location eastus
232az ml workspace create --name my-ml-workspace --resource-group my-ml-rg --location eastus
233
234# 2. Provision Computes (Instance, Training Cluster, CPU cluster)
235az ml compute create --name dev-compute-ci --type ComputeInstance --size Standard_DS3_v2 -g my-ml-rg -w my-ml-workspace
236az ml compute create --name gpu-train-cluster --type AmlCompute --size Standard_NC6s_v3 --min-instances 0 --max-instances 4 -g my-ml-rg -w my-ml-workspace
237az ml compute create --name cpu-proc-cluster --type AmlCompute --size Standard_DS12_v2 --min-instances 0 --max-instances 8 -g my-ml-rg -w my-ml-workspace
238
239# 3. Create a URI Data Asset
240az ml data create --file data.yaml -g my-ml-rg -w my-ml-workspace
241
242# 4. Create an Environment definition
243az ml environment create --file env.yaml -g my-ml-rg -w my-ml-workspace
244
245# 5. Submit, Monitor, and Stream a Command Job
246az ml job create --file job.yaml -g my-ml-rg -w my-ml-workspace --web --stream
247
248# View, list and monitor jobs
249az ml job list -g my-ml-rg -w my-ml-workspace --output table
250az ml job stream --name <job-id> -g my-ml-rg -w my-ml-workspace
251az ml job download --name <job-id> --download-path ./outputs -g my-ml-rg -w my-ml-workspace
252
253# 6. Register a Model
254az ml model create --file model.yaml -g my-ml-rg -w my-ml-workspace
255
256# 7. Create Endpoint, Deploy, Test, and Cleanup
257az ml online-endpoint create --file endpoint.yaml -g my-ml-rg -w my-ml-workspace
258az ml online-deployment create --file deployment.yaml --all-traffic -g my-ml-rg -w my-ml-workspace
259
260# List and monitor endpoints:
261az ml online-endpoint show --name credit-risk-endpoint -g my-ml-rg -w my-ml-workspace
262
263# Test endpoint with a sample payload file:
264az ml online-endpoint invoke --name credit-risk-endpoint --request-file ./sample_request.json -g my-ml-rg -w my-ml-workspace
265
266# Delete endpoint:
267az ml online-endpoint delete --name credit-risk-endpoint --yes -g my-ml-rg -w my-ml-workspace
268```
269
270## Local & Hybrid Providers (MLflow & Kubernetes/KServe)
271
272For local development or custom multi-cloud Kubernetes clusters, MLflow and KServe provide standardization.
273
274### MLflow Local CLI Management
275
276```bash
277# 1. Start a local tracking and model registry server
278mlflow server \
279 --host 127.0.0.1 \
280 --port 5000 \
281 --backend-store-uri sqlite:///mlflow.db \
282 --default-artifact-root ./mlflow_artifacts_store
283
284# 2. Run a packaged local MLflow Project with runtime parameters
285mlflow run . -P alpha=0.1 -P l1_ratio=0.2 --experiment-name iris-training
286
287# 3. Serve a registered model locally
288mlflow models serve \
289 --model-uri models:/iris-classifier/Production \
290 --port 5001 \
291 --no-conda
292
293# 4. Invoke the local serving endpoint
294curl -X POST -H "Content-Type: application/json" \
295 -d '{"dataframe_split": {"columns": ["sepal_len", "sepal_wid"], "data": [[5.1, 3.5]]}}' \
296 http://127.0.0.1:5001/invocations
297```
298
299### Kubernetes Native Serving CLI (KServe)
300
301```yaml
302# kserve-inference.yaml
303apiVersion: "serving.kserve.io/v1beta1"
304kind: "InferenceService"
305metadata:
306 name: "sklearn-iris"
307 namespace: "ml-serving"
308spec:
309 predictor:
310 model:
311 modelFormat:
312 name: sklearn
313 storageUri: "gs://kfserving-examples/models/sklearn/1.0/model"
314 resources:
315 limits:
316 cpu: "1"
317 memory: 2Gi
318 requests:
319 cpu: "500m"
320 memory: 1Gi
321```
322
323```bash
324# 1. Apply inference manifests via kubectl
325kubectl apply -f kserve-inference.yaml -n ml-serving
326
327# 2. Monitor status and readiness of inference service
328kubectl get inferenceservice sklearn-iris -n ml-serving
329
330# 3. Port forward or direct payload query through Istio ingress gateway
331SERVICE_HOSTNAME=$(kubectl get inferenceservice sklearn-iris -n ml-serving -o jsonpath='{.status.url}' | cut -d/ -f3)
332INGRESS_IP=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
333INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
334
335curl -v -H "Host: ${SERVICE_HOSTNAME}" \
336 http://${INGRESS_IP}:${INGRESS_PORT}/v1/models/sklearn-iris:predict \
337 -d @sample_payload.json
338```
339
340
341## Serverless GPU serving (Modal Pattern)
342
343For serverless deployments on isolated GPUs with zero-cold-start optimization, use Modal.
344
345```python
346import modal
347
348app = modal.App("serverless-image-classifier")
349
350# Pre-packaged CUDA image with dependencies
351image = (
352 modal.Image.debian_slim()
353 .pip_install("torch", "torchvision", "transformers")
354)
355
356@app.cls(gpu="A10G", image=image)
357class ImageClassifier:
358 @modal.enter()
359 def load_model(self):
360 import torch
361 from transformers import ViTForImageClassification, ViTImageProcessor
362 self.device = "cuda" if torch.cuda.is_available() else "cpu"
363 self.processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224")
364 self.model = ViTForImageClassification.from_pretrained("google/vit-base-patch16-224").to(self.device)
365
366 @modal.method()
367 def predict(self, image_bytes: bytes):
368 from PIL import Image
369 import io
370 image = Image.open(io.BytesIO(image_bytes))
371 inputs = self.processor(images=image, return_tensors="pt").to(self.device)
372 outputs = self.model(**inputs)
373 logits = outputs.logits
374 predicted_class_idx = logits.argmax(-1).item()
375 return self.model.config.id2label[predicted_class_idx]
376```
377
378## Hardware Selection
379
380Match hardware to bottleneck:
381- CPU: classical ML, preprocessing, small models, latency-insensitive batch jobs.
382- T4/L4/A10-class GPUs: cost-effective inference, fine-tuning smaller models, notebooks.
383- A100/H100/H200/B200-class GPUs: large model training, high-throughput inference, memory-heavy workloads.
384- TPUs: supported dense tensor workloads at scale, especially JAX/TensorFlow ecosystems.
385- Inferentia/Trainium: AWS cost/performance if model operators and framework support are mature.
386
387Estimate memory before launching: model weights, optimizer states, gradients, activations, KV cache, batch size, sequence length, and runtime overhead. For inference, benchmark p50/p95/p99 latency under realistic concurrency and payload sizes.
388
389## Endpoint Design
390
391Define request schema, response schema, timeout, max payload, auth, rate limits, autoscaling policy, health checks, logging, and rollback. Use canary or blue/green releases for production. For GPU endpoints, tune dynamic batching and concurrency carefully; too much concurrency can increase tail latency or cause OOM. For multi-region deployments, replicate artifacts, keep model versions consistent, and plan data residency and failover.
392
393## Security and Compliance
394
395Use private networking when models access sensitive data. Store secrets in cloud secret managers. Use least-privilege IAM/service accounts/managed identities. Encrypt data and artifacts. Log access and deployment events. Scan containers. Avoid baking credentials into images. For public endpoints, apply auth, input validation, abuse controls, rate limits, and prompt-injection defenses for LLM/RAG systems.
396
397## Cost Optimization
398
399Use spot/preemptible instances for checkpointed training and stateless batch jobs. Use autoscaling endpoints with scale-to-zero when acceptable. Prefer batch inference for non-real-time workloads. Quantize or distill models before scaling replicas. Right-size GPU memory, not just GPU count. Use reserved/committed capacity only after workload shape is stable. Track cost per run, per model version, and per 1,000 predictions.
400
401## Deployment Readiness Checklist
402
403- Model artifact, preprocessing, tokenizer, and config are versioned together.
404- Input schema is validated and compatible with training features.
405- Evaluation report includes relevant slices and latency/cost benchmarks.
406- Endpoint has health checks, autoscaling, logs, metrics, alerts, and rollback.
407- Security controls cover identity, secrets, network, encryption, and audit.
408- Monitoring captures drift, data quality, prediction distribution, outcomes, and incidents.
409
410## Sources
411
412- AWS SageMaker documentation: https://docs.aws.amazon.com/sagemaker/
413- Google Vertex AI documentation: https://cloud.google.com/vertex-ai/docs
414- Azure Machine Learning documentation: https://learn.microsoft.com/azure/machine-learning/
415- Databricks Machine Learning documentation: https://docs.databricks.com/machine-learning/
416- Ray and Anyscale documentation: https://docs.ray.io/ and https://docs.anyscale.com/