Vertex AI + MLOps

Machine Learning platforms & pipelines — Azure · AWS · GCP

Concept

Vertex AI is GCP's unified ML platform covering the full MLOps lifecycle. Azure uses Azure Machine Learning, and AWS uses SageMaker.

ML Platform
Azure Machine Learning
Amazon SageMaker
Vertex AI
AutoML
Azure AutoML
SageMaker Autopilot
Vertex AI AutoML
Custom Training
AML Compute Clusters
SageMaker Training Jobs
Vertex AI Custom Training
Pipeline
AML Pipelines (YAML/CLI v2)
SageMaker Pipelines
Vertex AI Pipelines (Kubeflow)
Model Registry
AML Model Registry
SageMaker Model Registry
Vertex AI Model Registry
Online Prediction
AML Managed Online Endpoints
SageMaker Real-Time Inference
Vertex AI Prediction Endpoint
Feature Store
AML Managed Feature Store
SageMaker Feature Store
Vertex AI Feature Store

Vertex AI Pipeline (Kubeflow)

from kfp import dsl
from google.cloud import aiplatform

@dsl.component(base_image="python:3.10")
def preprocess(input_path: str, output_path: str):
    import pandas as pd
    df = pd.read_csv(input_path)
    df = df.dropna()
    df.to_csv(output_path, index=False)

@dsl.component(base_image="python:3.10",
    packages_to_install=["sklearn"])
def train(dataset: str, model_path: str):
    from sklearn.ensemble import RandomForestClassifier
    import joblib, pandas as pd
    df = pd.read_csv(dataset)
    X, y = df.drop("label", axis=1), df["label"]
    model = RandomForestClassifier()
    model.fit(X, y)
    joblib.dump(model, model_path)

@dsl.pipeline(name="fraud-detection-pipeline")
def pipeline(input_csv: str):
    preprocess_task = preprocess(input_path=input_csv,
        output_path="gs://ml-artifacts/processed.csv")
    train_task = train(
        dataset=preprocess_task.outputs["output_path"],
        model_path="gs://ml-artifacts/model.pkl")
    train_task.after(preprocess_task)

Deploy Model to Endpoint

# Create endpoint
gcloud ai endpoints create --region=us-central1 --display-name=fraud-detection

# Deploy model
gcloud ai endpoints deploy-model ENDPOINT_ID --region=us-central1 --model=MODEL_ID --display-name=fraud-detection-v1 --machine-type=n1-standard-4 --min-replica-count=1 --max-replica-count=5